1 # graph-comm.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1998-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #import SRMv2_Source
32 #import SRMv2_Session
33 import Source/SRMv2
34 import Session/SRMv2
35
36 Class GraphComm;
37
38 GraphComm instproc destroy {} {
39 $self instvar sess_list_
40
41 if {[info exists sess_list_]} {
42 foreach s $sess_list_ {
43 $s callback_object ""
44 }
45 }
46 $self next
47 }
48
49 GraphComm instproc init {src_id addr port {ttl 16}} {
50 $self next;
51 fxcontrol::debug_message "GraphComm::init-1 {$src_id, $addr, $port, $ttl}"
52
53 $self instvar primary_sess_ sess_list_ local_source_
54 $self instvar sess_map_;
55
56 #set primary_sess_ [new SRMv2_Session $addr $port $port $ttl];
57 set primary_sess_ [new Session/SRMv2 $addr $port $port $ttl];
58 fxcontrol::debug_message "GraphComm::init-2 got Session/SRMv2"
59 lappend sess_list_ $primary_sess_;
60
61 #set local_source_ [new SRMv2_Source $primary_sess_ $src_id];
62 set local_source_ [new Source/SRMv2 $primary_sess_ $src_id];
63 fxcontrol::debug_message "GraphComm::init-3 got Source/SRMv2"
64
65 $primary_sess_ callback_object $self;
66
67 $self instvar local_src_cids_;
68
69 set local_src_cids_(inputs) [$local_source_ calloc 0 inputs];
70 set local_src_cids_(outputs) [$local_source_ calloc 0 outputs];
71 set local_src_cids_(parameters) [$local_source_ calloc 0 parameters];
72 set local_src_cids_(misc) [$local_source_ calloc 0 misc];
73 set local_src_cids_(trigger_cmds) [$local_source_ calloc 0 trigger_cmds];
74 set local_src_cids_(map_cmds) [$local_source_ calloc 0 map_cmds];
75 set local_src_cids_(debug) [$local_source_ calloc 0 debug];
76
77 $self instvar input_names_ output_names_ parameter_names_;
78
79 set input_names_ "";
80 set output_names_ "";
81 set parameter_names_ "";
82
83 set sess_map_($primary_sess_,inputs) 1;
84 set sess_map_($primary_sess_,outputs) 1;
85 set sess_map_($primary_sess_,parameters) 1;
86 set sess_map_($primary_sess_,misc) 1;
87 set sess_map_($primary_sess_,trigger_cmds) 1;
88 set sess_map_($primary_sess_,map_cmds) 1;
89 set sess_map_($primary_sess_,debug) 1;
90
91 $self instvar read_adu_callback_map_;
92
93 set read_adu_callback_map_($local_source_,$local_src_cids_(map_cmds)) "$self handle_map_cmd_read_adu ";
94 set read_adu_callback_map_($local_source_,$local_src_cids_(misc)) "$self handle_misc_read_adu ";
95 set read_adu_callback_map_($local_source_,$local_src_cids_(debug)) "$self handle_debug_read_adu ";
96 <<<<<<< graph-comm.tcl
97
98 fxcontrol::debug_message "GraphComm::init-END"
99 =======
100
101 >>>>>>> 1.7
102 }
103
104 GraphComm instproc search_for_session {addr port} {
105 $self instvar sess_list_;
106
107 foreach s $sess_list_ {
108 if {[$s set addr_] == $addr} {
109 if {[$s set rport_] == $port} {
110 return $s;
111 }
112 }
113 }
114 return "";
115 }
116
117 GraphComm instproc add_session {addr port ttl} {
118 $self instvar sess_list_ sess_map_;
119
120 #set s [new SRMv2_Session $addr $port $port $ttl];
121 set s [new Session/SRMv2 $addr $port $port $ttl];
122 lappend sess_list_ $s;
123
124 set sess_map_($s,inputs) 1;
125 set sess_map_($s,outputs) 1;
126 set sess_map_($s,parameters) 1;
127 set sess_map_($s,misc) 1;
128 set sess_map_($s,trigger_cmds) 1;
129 set sess_map_($s,map_cmds) 1;
130 set sess_map_($s,debug) 1;
131
132 $s callback_object $self;
133
134 return $s;
135 }
136
137 GraphComm instproc srm_source_update {src info} {
138 # puts "SourceUpdate: $src $info";
139
140 $self instvar recv_cid_callback_map_;
141 $self instvar should_recover_callback_map_;
142
143 set recv_cid_callback_map_($src,0) "$self handle_root_recv_cid";
144 set should_recover_callback_map_($src,0) "$self always_recover";
145 }
146
147 GraphComm instproc srm_recv_cid {src cid pcid name} {
148 # puts "RecvCID: $src $cid $pcid $name";
149
150 $self instvar recv_cid_callback_map_;
151
152 if [info exists recv_cid_callback_map_($src,$pcid)] {
153 eval $recv_cid_callback_map_($src,$pcid) [list $src $cid $pcid $name];
154 }
155 }
156
157 GraphComm instproc srm_recv {src cid seqno data} {
158 # puts "Recv: $src $cid $seqno $data";
159
160 $self instvar recv_callback_map_;
161
162 if [info exists recv_callback_map_($src,$cid)] {
163 eval $recv_callback_map_($src,$cid) [list $src $cid $seqno $data];
164 }
165 }
166
167 GraphComm instproc srm_should_recover {src cid sseq eseq} {
168 # puts "ShouldRecover: $src $cid $sseq $eseq";
169
170 $self instvar should_recover_callback_map_;
171
172 if [info exists should_recover_callback_map_($src,$cid)] {
173 set ret_val [eval $should_recover_callback_map_($src,$cid) [list $src $cid $sseq $eseq]]
174 } else {
175 set ret_val 0;
176 }
177 # puts "ShouldRecover: returning $ret_val";
178
179 return $ret_val;
180 }
181
182 GraphComm instproc srm_read_adu {src cid seqno} {
183 # puts "ReadAdu: $src $cid $seqno";
184
185 $self instvar read_adu_callback_map_
186
187 if [info exists read_adu_callback_map_($src,$cid)] {
188 set ret_val [eval $read_adu_callback_map_($src,$cid) [list $src $cid $seqno]];
189 } else {
190 set ret_val "";
191 }
192 # puts "ReadAdu: returning $ret_val";
193 return $ret_val;
194 }
195
196 GraphComm instproc handle_root_recv_cid {src cid pcid name} {
197 $self instvar recv_cid_callback_map_;
198 $self instvar recv_callback_map_;
199 $self instvar should_recover_callback_map_;
200 $self instvar sess_map_;
201
202 set sess [$src session];
203
204 switch -exact -- $name {
205 "inputs" {
206 if {$sess_map_($sess,inputs) == 1} {
207 set recv_cid_callback_map_($src,$cid) "$self handle_input_recv_cid"
208 set should_recover_callback_map_($src,$cid) "$self always_recover";
209 } elseif {$sess_map_($sess,inputs) == "conditional"} {
210 set recv_cid_callback_map_($src,$cid) "$self handle_conditioned_input_recv_cid"
211 set should_recover_callback_map_($src,$cid) "$self always_recover";
212 }
213 }
214 "outputs" {
215 if {$sess_map_($sess,outputs) == 1} {
216 set recv_cid_callback_map_($src,$cid) "$self handle_output_recv_cid"
217 set should_recover_callback_map_($src,$cid) "$self always_recover";
218 } elseif {$sess_map_($sess,outputs) == "conditional"} {
219 set recv_cid_callback_map_($src,$cid) "$self handle_conditioned_output_recv_cid"
220 set should_recover_callback_map_($src,$cid) "$self always_recover";
221 }
222 }
223 "parameters" {
224 if {$sess_map_($sess,parameters) == 1} {
225 set recv_cid_callback_map_($src,$cid) "$self handle_parameter_recv_cid"
226 set should_recover_callback_map_($src,$cid) "$self always_recover";
227 } elseif {$sess_map_($sess,parameters) == "conditional"} {
228 set recv_cid_callback_map_($src,$cid) "$self handle_conditioned_parameter_recv_cid"
229 set should_recover_callback_map_($src,$cid) "$self always_recover";
230 }
231 }
232 "trigger_cmds" {
233 if {$sess_map_($sess,trigger_cmds) == 1} {
234 set recv_callback_map_($src,$cid) "$self handle_trigger_recv"
235 set should_recover_callback_map_($src,$cid) "$self never_recover";
236 }
237 }
238 "map_cmds" {
239 if {$sess_map_($sess,map_cmds) == 1} {
240 set recv_callback_map_($src,$cid) "$self handle_map_recv"
241 set should_recover_callback_map_($src,$cid) "$self always_recover";
242 }
243 }
244 "misc" {
245 if {$sess_map_($sess,misc) == 1} {
246 set recv_callback_map_($src,$cid) "$self handle_misc_recv"
247 set should_recover_callback_map_($src,$cid) "$self always_recover";
248 }
249 }
250 "debug" {
251 if {$sess_map_($sess,debug) == 1} {
252 set recv_callback_map_($src,$cid) "$self handle_debug_recv"
253 set should_recover_callback_map_($src,$cid) "$self never_recover";
254 }
255 }
256 }
257 }
258
259 GraphComm instproc handle_input_recv_cid {src cid pcid name} {
260 $self instvar input_names_;
261 $self instvar recv_cid_callback_map_;
262
263 if {[lsearch $input_names_ $name] == -1} {
264 # New input !!!!
265 $self new_input $name;
266 }
267 set recv_cid_callback_map_($src,$cid) "$self handle_input_attr_recv_cid $name"
268
269 $self instvar should_recover_callback_map_;
270 set should_recover_callback_map_($src,$cid) "$self always_recover";
271 }
272
273 GraphComm instproc handle_conditioned_input_recv_cid {src cid pcid name} {
274 $self instvar input_names;
275 $self instvar recv_cid_callback_map_;
276
277 $self instvar sess_map_;
278
279 set sess [$src session];
280
281 if {![info exists sess_map_($sess,inputs,mappings,$name)]} {
282 # This input not mapped. Return doing nothing.
283 return;
284 }
285
286 set mapped_name $sess_map_($sess,inputs,mappings,$name);
287
288 $self handle_input_recv_cid $src $cid $pcid $mapped_name;
289 }
290
291 GraphComm instproc handle_input_attr_recv_cid {input_name src cid pcid name} {
292 $self instvar input_names_;
293 $self instvar input_info_;
294
295 if {[lsearch $input_info_($input_name,attr_list) $name] == -1} {
296 # New attribute for an input!!!!
297 $self new_input_attribute $input_name $name;
298 }
299
300 $self instvar recv_callback_map_;
301 set recv_callback_map_($src,$cid) "$self handle_input_attr_value_recv $input_name $name ";
302
303 $self instvar should_recover_callback_map_;
304 set should_recover_callback_map_($src,$cid) "$self handle_input_attr_should_recover $input_name $name "
305
306 $self instvar read_adu_callback_map_;
307 set read_adu_callback_map_($src,$cid) "$self handle_input_attr_read_adu $input_name $name "
308 }
309
310 GraphComm instproc handle_output_recv_cid {src cid pcid name} {
311 $self instvar output_names_;
312 $self instvar recv_cid_callback_map_;
313
314 if {[lsearch $output_names_ $name] == -1} {
315 # New output !!!!
316 $self new_output $name;
317 }
318 set recv_cid_callback_map_($src,$cid) "$self handle_output_attr_recv_cid $name"
319
320 $self instvar should_recover_callback_map_;
321 set should_recover_callback_map_($src,$cid) "$self always_recover";
322 }
323
324 GraphComm instproc handle_conditioned_output_recv_cid {src cid pcid name} {
325 $self instvar output_names;
326 $self instvar recv_cid_callback_map_;
327
328 $self instvar sess_map_;
329
330 set sess [$src session];
331
332 if {![info exists sess_map_($sess,outputs,mappings,$name)]} {
333 # This output not mapped. Return doing nothing.
334 return;
335 }
336
337 set mapped_name $sess_map_($sess,outputs,mappings,$name);
338
339 $self handle_output_recv_cid $src $cid $pcid $mapped_name;
340 }
341
342 GraphComm instproc handle_output_attr_recv_cid {output_name src cid pcid name} {
343 $self instvar output_names_;
344 $self instvar output_info_;
345
346 if {[lsearch $output_info_($output_name,attr_list) $name] == -1} {
347 # New attribute for an output!!!!
348 $self new_output_attribute $output_name $name;
349 }
350 $self instvar recv_callback_map_;
351 set recv_callback_map_($src,$cid) "$self handle_output_attr_value_recv $output_name $name ";
352
353 $self instvar should_recover_callback_map_;
354 set should_recover_callback_map_($src,$cid) "$self handle_output_attr_should_recover $output_name $name "
355
356 $self instvar read_adu_callback_map_;
357 set read_adu_callback_map_($src,$cid) "$self handle_output_attr_read_adu $output_name $name "
358
359 }
360
361 GraphComm instproc handle_parameter_recv_cid {src cid pcid name} {
362 $self instvar parameter_names_;
363 $self instvar recv_cid_callback_map_;
364
365 if {[lsearch $parameter_names_ $name] == -1} {
366 # New parameter !!!!
367 $self new_parameter $name;
368 }
369 set recv_cid_callback_map_($src,$cid) "$self handle_parameter_attr_recv_cid $name"
370
371 $self instvar should_recover_callback_map_;
372 set should_recover_callback_map_($src,$cid) "$self always_recover";
373 }
374
375 GraphComm instproc handle_conditioned_parameter_recv_cid {src cid pcid name} {
376 $self instvar parameter_names;
377 $self instvar recv_cid_callback_map_;
378
379 $self instvar sess_map_;
380
381 set sess [$src session];
382
383 if {![info exists sess_map_($sess,parameters,mappings,$name)]} {
384 # This parameter not mapped. Return doing nothing.
385 return;
386 }
387
388 set mapped_name $sess_map_($sess,parameters,mappings,$name);
389
390 $self handle_parameter_recv_cid $src $cid $pcid $mapped_name;
391 }
392
393 GraphComm instproc handle_parameter_attr_recv_cid {parameter_name src cid pcid name} {
394 $self instvar parameter_names_;
395 $self instvar parameter_info_;
396
397 if {[lsearch $parameter_info_($parameter_name,attr_list) $name] == -1} {
398 # New attribute for an parameter!!!!
399 $self new_parameter_attribute $parameter_name $name;
400 }
401 $self instvar recv_callback_map_;
402 set recv_callback_map_($src,$cid) "$self handle_parameter_attr_value_recv $parameter_name $name ";
403
404 $self instvar should_recover_callback_map_;
405 set should_recover_callback_map_($src,$cid) "$self handle_parameter_attr_should_recover $parameter_name $name "
406
407 $self instvar read_adu_callback_map_;
408 set read_adu_callback_map_($src,$cid) "$self handle_parameter_attr_read_adu $parameter_name $name "
409
410 }
411
412 GraphComm instproc handle_input_attr_value_recv {input_name attr_name src cid seqno data} {
413 $self instvar input_info_;
414
415 # Check to see whether this message is later than previous message
416 # from same source. If not, throw away.
417
418 if [info exists input_info_($input_name,$attr_name,last_seqno,$src)] {
419 set last_seqno $input_info_($input_name,$attr_name,last_seqno,$src);
420 if {$last_seqno > $seqno} {
421 return;
422 }
423 }
424
425 # Message is good. Record that this as most recent seqno from this source
426 set input_info_($input_name,$attr_name,last_seqno,$src) $seqno;
427
428 # Deliver data
429
430 $self update_input_attr_value $input_name $attr_name $data
431 }
432
433 GraphComm instproc handle_input_attr_read_adu {input_name attr_name src cid seqno} {
434 $self instvar input_info_;
435
436 if {[info exists input_info_($input_name,$attr_name,cur_value)]} {
437 return $input_info_($input_name,$attr_name,cur_value);
438 }
439 }
440
441 GraphComm instproc handle_output_attr_read_adu {output_name attr_name
442 src cid seqno} {
443 $self instvar output_info_;
444
445 if {[info exists output_info_($output_name,$attr_name,cur_value)]} {
446 return $output_info_($output_name,$attr_name,cur_value);
447 }
448 }
449
450 GraphComm instproc handle_parameter_attr_read_adu {parameter_name attr_name src cid seqno} {
451 $self instvar parameter_info_;
452
453 if {[info exists parameter_info_($parameter_name,$attr_name,cur_value)]} {
454 return $parameter_info_($parameter_name,$attr_name,cur_value);
455 }
456 }
457
458 GraphComm instproc handle_map_cmd_read_adu {src cid seqno} {
459 $self instvar map_command_datastore_;
460
461 if {[info exists map_command_datastore_($seqno)]} {
462 return $map_command_datastore_($seqno);
463 }
464 return "";
465 }
466
467 GraphComm instproc handle_misc_read_adu {src cid seqno} {
468 $self instvar misc_datastore_;
469
470 if {[info exists misc_datastore_($seqno)]} {
471 return $misc_datastore_($seqno);
472 }
473 return "";
474 }
475
476 GraphComm instproc handle_debug_read_adu {src cid seqno} {
477 $self instvar debug_datastore_;
478
479 if {[info exists debug_datastore_($seqno)]} {
480 return $debug_datastore_($seqno);
481 }
482 return "";
483 }
484
485 GraphComm instproc handle_input_attr_should_recover {input_name attr_name src cid sseq eseq} {
486 $self instvar input_info_;
487
488 if [info exists input_info_($input_name,$attr_name,last_seqno,$src)] {
489 set last_seqno $input_info_($input_name,$attr_name,last_seqno,$src);
490 if {$last_seqno > $eseq} {
491 return 0;
492 } else {
493 if {[info exists input_info_($input_name,$attr_name,cur_value)]} {
494 unset input_info_($input_name,$attr_name,cur_value);
495 }
496 $src recover $cid $eseq $eseq;
497 return 0;
498 }
499 } else {
500 if {[info exists input_info_($input_name,$attr_name,cur_value)]} {
501 unset input_info_($input_name,$attr_name,cur_value);
502 }
503 $src recover $cid $eseq $eseq;
504 return 0;
505 }
506 }
507
508 GraphComm instproc handle_output_attr_should_recover {output_name attr_name src cid sseq eseq} {
509 $self instvar output_info_;
510
511 if [info exists output_info_($output_name,$attr_name,last_seqno,$src)] {
512 set last_seqno $output_info_($output_name,$attr_name,last_seqno,$src);
513 if {$last_seqno > $eseq} {
514 return 0;
515 } else {
516 if {[info exists output_info_($output_name,$attr_name,cur_value)]} {
517 unset output_info_($output_name,$attr_name,cur_value);
518 }
519 $src recover $cid $eseq $eseq;
520 return 0;
521 }
522 } else {
523 if {[info exists output_info_($output_name,$attr_name,cur_value)]} {
524 unset output_info_($output_name,$attr_name,cur_value);
525 }
526 $src recover $cid $eseq $eseq;
527 return 0;
528 }
529 }
530
531 GraphComm instproc handle_parameter_attr_should_recover {parameter_name attr_name src cid sseq eseq} {
532 $self instvar parameter_info_;
533
534 if [info exists parameter_info_($parameter_name,$attr_name,last_seqno,$src)] {
535 set last_seqno $parameter_info_($parameter_name,$attr_name,last_seqno,$src);
536 if {$last_seqno > $eseq} {
537 return 0;
538 } else {
539 if {[info exists parameter_info_($parameter_name,$attr_name,cur_value)]} {
540 unset parameter_info_($parameter_name,$attr_name,cur_value);
541 }
542 $src recover $cid $eseq $eseq;
543 return 0;
544 }
545 } else {
546 if {[info exists parameter_info_($parameter_name,$attr_name,cur_value)]} {
547 unset parameter_info_($parameter_name,$attr_name,cur_value);
548 }
549 $src recover $cid $eseq $eseq;
550 return 0;
551 }
552 }
553
554 GraphComm instproc handle_output_attr_value_recv {output_name attr_name src cid seqno data} {
555 $self instvar output_info_;
556
557 # Check to see whether this message is later than previous message
558 # from same source. If not, throw away.
559
560 if [info exists output_info_($output_name,$attr_name,last_seqno,$src)] {
561 set last_seqno $output_info_($output_name,$attr_name,last_seqno,$src);
562 if {$last_seqno > $seqno} {
563 return;
564 }
565 }
566
567 # Message is good. Record that this as most recent seqno from this source
568 set output_info_($output_name,$attr_name,last_seqno,$src) $seqno;
569
570 # Deliver data
571
572 $self update_output_attr_value $output_name $attr_name $data
573 }
574
575
576 GraphComm instproc handle_parameter_attr_value_recv {parameter_name attr_name src cid seqno data} {
577 $self instvar parameter_info_;
578
579 # Check to see whether this message is later than previous message
580 # from same source. If not, throw away.
581
582 if [info exists parameter_info_($parameter_name,$attr_name,last_seqno,$src)] {
583 set last_seqno $parameter_info_($parameter_name,$attr_name,last_seqno,$src);
584 if {$last_seqno > $seqno} {
585 return;
586 }
587 }
588
589 # Message is good. Record that this as most recent seqno from this source
590 set parameter_info_($parameter_name,$attr_name,last_seqno,$src) $seqno;
591
592 # Deliver data
593
594 $self update_parameter_attr_value $parameter_name $attr_name $data
595 }
596
597 GraphComm instproc handle_trigger_recv {src cid seqno data} {
598 $self recv_trigger_command $data;
599 }
600
601 GraphComm instproc handle_map_recv {src cid seqno data} {
602 $self recv_map_command $data;
603 }
604
605 GraphComm instproc handle_misc_recv {src cid seqno data} {
606 $self recv_misc $data
607 }
608
609 GraphComm instproc handle_debug_recv {src cid seqno data} {
610 $self recv_debug $data
611 }
612
613 GraphComm instproc parameter_values_are_uptodate {} {
614 $self instvar parameter_names_ parameter_info_;
615
616 foreach p $parameter_names_ {
617 if {![info exists parameter_info_($p,value,cur_value)]} {
618 return 0;
619 }
620 }
621 return 1;
622 }
623
624 GraphComm instproc parameter_attr_has_value {parameter_name attr_name} {
625 $self instvar parameter_info_;
626
627 if {[info exists parameter_info_($parameter_name,$attr_name,cur_value)]} {
628 return 1;
629 } else {
630 return 0;
631 }
632 }
633
634 GraphComm instproc get_parameter_attr_value {parameter_name attr_name} {
635 $self instvar parameter_info_;
636
637 return $parameter_info_($parameter_name,$attr_name,cur_value);
638 }
639
640 GraphComm instproc primary_addr {} {
641 $self instvar primary_sess_;
642
643 return [$primary_sess_ set addr_];
644 }
645
646 GraphComm instproc primary_port {} {
647 $self instvar primary_sess_;
648
649 return [$primary_sess_ set rport_];
650 }
651
652 GraphComm instproc primary_ttl {} {
653 $self instvar primary_sess_;
654
655 return [$primary_sess_ set ttl_];
656 }
657
658 GraphComm instproc always_recover {args} {
659 return 1;
660 }
661
662 GraphComm instproc never_recover {args} {
663 return 0;
664 }
665
666 #####################################################
667 # Below here is the general interface that gets used (and for
668 # many things overridden) by the specific entity in charge
669 # If overriding a function that is not empty, be sure
670 # to do an "$self next" call.
671 #####################################################
672
673
674 GraphComm instproc recv_trigger_command {cmd} {
675 }
676
677 GraphComm instproc recv_map_command {cmd} {
678 $self instvar sess_map_;
679
680 set type [lindex $cmd 0];
681 set addr [lindex $cmd 1];
682 set port [lindex $cmd 2];
683 set ttl [lindex $cmd 3];
684
685 set sess [$self search_for_session $addr $port];
686
687 switch -exact -- $type {
688 map_sess {
689 if {$sess == ""} {
690 set sess [$self add_session $addr $port $ttl];
691 }
692 set sess_map_($sess,inputs) 1;
693 set sess_map_($sess,outputs) 1;
694 set sess_map_($sess,parameters) 1;
695 set sess_map_($sess,misc) 1;
696 set sess_map_($sess,trigger_cmds) 1;
697 set sess_map_($sess,map_cmds) 1;
698 set sess_map_($sess,debug) 1;
699 }
700 map_inputs {
701 if {$sess == ""} {
702 set sess [$self add_session $addr $port $ttl];
703 set sess_map_($sess,outputs) 0;
704 set sess_map_($sess,parameters) 0;
705 set sess_map_($sess,misc) 0;
706 set sess_map_($sess,debug) 0;
707 set sess_map_($sess,trigger_cmds) 0;
708 set sess_map_($sess,map_cmds) 0;
709 }
710 set sess_map_($sess,inputs) 1;
711 }
712 map_outputs {
713 if {$sess == ""} {
714 set sess [$self add_session $addr $port $ttl];
715 set sess_map_($sess,inputs) 0;
716 set sess_map_($sess,parameters) 0;
717 set sess_map_($sess,misc) 0;
718 set sess_map_($sess,debug) 0;
719 set sess_map_($sess,trigger_cmds) 0;
720 set sess_map_($sess,map_cmds) 0;
721 }
722 set sess_map_($sess,outputs) 1;
723 }
724 map_parameters {
725 if {$sess == ""} {
726 set sess [$self add_session $addr $port $ttl];
727 set sess_map_($sess,outputs) 0;
728 set sess_map_($sess,inputs) 0;
729 set sess_map_($sess,misc) 0;
730 set sess_map_($sess,debug) 0;
731 set sess_map_($sess,trigger_cmds) 0;
732 set sess_map_($sess,map_cmds) 0;
733 }
734 set sess_map_($sess,parameters) 1;
735 }
736 map_misc {
737 if {$sess == ""} {
738 set sess [$self add_session $addr $port $ttl];
739 set sess_map_($sess,outputs) 0;
740 set sess_map_($sess,parameters) 0;
741 set sess_map_($sess,inputs) 0;
742 set sess_map_($sess,trigger_cmds) 0;
743 set sess_map_($sess,map_cmds) 0;
744 set sess_map_($sess,debug) 0;
745 }
746 set sess_map_($sess,misc) 1;
747 }
748 map_trigger_cmds {
749 if {$sess == ""} {
750 set sess [$self add_session $addr $port $ttl];
751 set sess_map_($sess,outputs) 0;
752 set sess_map_($sess,parameters) 0;
753 set sess_map_($sess,misc) 0;
754 set sess_map_($sess,debug) 0;
755 set sess_map_($sess,inputs) 0;
756 set sess_map_($sess,map_cmds) 0;
757 }
758 set sess_map_($sess,trigger_cmds) 1;
759 }
760 map_map_cmds {
761 if {$sess == ""} {
762 set sess [$self add_session $addr $port $ttl];
763 set sess_map_($sess,outputs) 0;
764 set sess_map_($sess,parameters) 0;
765 set sess_map_($sess,misc) 0;
766 set sess_map_($sess,debug) 0;
767 set sess_map_($sess,trigger_cmds) 0;
768 set sess_map_($sess,inputs) 0;
769 }
770 set sess_map_($sess,map_cmds) 1;
771 }
772 map_input {
773 set in_name [lindex $cmd 4];
774 set in_mapped_name [lindex $cmd 5];
775
776 if {$sess == ""} {
777 set sess [$self add_session $addr $port $ttl];
778 set sess_map_($sess,inputs) "conditional"
779 set sess_map_($sess,outputs) 0;
780 set sess_map_($sess,parameters) 0;
781 set sess_map_($sess,misc) 0;
782 set sess_map_($sess,debug) 0;
783 set sess_map_($sess,trigger_cmds) 0;
784 set sess_map_($sess,map_cmds) 0;
785 set sess_map_($sess,inputs,mappings,$in_name) $in_mapped_name;
786 } else {
787 if {$sess_map_($sess,inputs) == "conditional"} {
788 set sess_map_($sess,inputs,mappings,$in_name) $in_mapped_name;
789 } elseif {$sess_map_($sess,inputs) == 0} {
790 set sess_map_($sess,inputs) "conditional";
791 set sess_map_($sess,inputs,mappings,$in_name) $in_mapped_name;
792 }
793 }
794 }
795 map_output {
796 set out_name [lindex $cmd 4];
797 set out_mapped_name [lindex $cmd 5];
798
799 if {$sess == ""} {
800 set sess [$self add_session $addr $port $ttl];
801 set sess_map_($sess,outputs) "conditional"
802 set sess_map_($sess,inputs) 0;
803 set sess_map_($sess,parameters) 0;
804 set sess_map_($sess,misc) 0;
805 set sess_map_($sess,debug) 0;
806 set sess_map_($sess,trigger_cmds) 0;
807 set sess_map_($sess,map_cmds) 0;
808 set sess_map_($sess,outputs,mappings,$out_name) $out_mapped_name;
809 } else {
810 if {$sess_map_($sess,outputs) == "conditional"} {
811 set sess_map_($sess,outputs,mappings,$out_name) $out_mapped_name;
812 } elseif {$sess_map_($sess,outputs) == 0} {
813 set sess_map_($sess,outputs) "conditional";
814 set sess_map_($sess,outputs,mappings,$out_name) $out_mapped_name;
815 }
816 }
817 }
818 map_parameter {
819 set p_name [lindex $cmd 4];
820 set p_mapped_name [lindex $cmd 5];
821
822 if {$sess == ""} {
823 set sess [$self add_session $addr $port $ttl];
824 set sess_map_($sess,parameters) "conditional"
825 set sess_map_($sess,outputs) 0;
826 set sess_map_($sess,inputs) 0;
827 set sess_map_($sess,misc) 0;
828 set sess_map_($sess,debug) 0;
829 set sess_map_($sess,trigger_cmds) 0;
830 set sess_map_($sess,map_cmds) 0;
831 set sess_map_($sess,parameters,mappings,$p_name) $p_mapped_name;
832 } else {
833 if {$sess_map_($sess,parameters) == "conditional"} {
834 set sess_map_($sess,parameters,mappings,$p_name) $p_mapped_name;
835 } elseif {$sess_map_($sess,parameters) == 0} {
836 set sess_map_($sess,parameters) "conditional";
837 set sess_map_($sess,parameters,mappings,$p_name) $p_mapped_name;
838 }
839 }
840 }
841 }
842 }
843
844 GraphComm instproc recv_misc {cmd} {
845 # puts "Received misc: $cmd";
846 }
847
848 GraphComm instproc new_input {new_name} {
849 $self instvar input_names_ input_info_;
850
851 lappend input_names_ $new_name;
852 set input_info_($new_name,attr_list) "";
853 }
854
855 GraphComm instproc new_output {new_name} {
856 $self instvar output_names_ output_info_;
857
858 lappend output_names_ $new_name;
859 set output_info_($new_name,attr_list) "";
860 }
861
862 GraphComm instproc new_parameter {new_name} {
863 $self instvar parameter_names_ parameter_info_;
864
865 lappend parameter_names_ $new_name;
866 set parameter_info_($new_name,attr_list) "";
867 }
868
869 GraphComm instproc new_parameter_attribute {parameter_name attr_name} {
870 $self instvar parameter_info_;
871
872 lappend parameter_info_($parameter_name,attr_list) $attr_name;
873 }
874
875 GraphComm instproc new_output_attribute {output_name attr_name} {
876 $self instvar output_info_;
877
878 lappend output_info_($output_name,attr_list) $attr_name;
879 }
880
881 GraphComm instproc new_input_attribute {input_name attr_name} {
882 $self instvar input_info_;
883
884 lappend input_info_($input_name,attr_list) $attr_name;
885 }
886
887 GraphComm instproc update_parameter_attr_value {parameter_name attr_name value} {
888 $self instvar parameter_info_;
889
890 set parameter_info_($parameter_name,$attr_name,cur_value) $value;
891 }
892
893 GraphComm instproc update_output_attr_value {output_name attr_name value} {
894 $self instvar output_info_;
895
896 set output_info_($output_name,$attr_name,cur_value) $value;
897 }
898
899 GraphComm instproc update_input_attr_value {input_name attr_name value} {
900 $self instvar input_info_;
901
902 set input_info_($input_name,$attr_name,cur_value) $value;
903 }
904
905 GraphComm instproc create_input {input_name} {
906 $self instvar input_names_;
907 $self instvar input_info_;
908
909 if {[lsearch $input_names_ $input_name] == -1} {
910 lappend input_names_ $input_name;
911 set input_info_($input_name,attr_list) "";
912 }
913
914 if {![info exists input_info_($input_name,local_cid)]} {
915 $self instvar local_source_;
916 $self instvar local_src_cids_;
917
918 set input_info_($input_name,local_cid) [$local_source_ calloc $local_src_cids_(inputs) $input_name];
919 }
920 }
921
922 GraphComm instproc create_output {output_name} {
923 $self instvar output_names_;
924 $self instvar output_info_;
925
926 if {[lsearch $output_names_ $output_name] == -1} {
927 lappend output_names_ $output_name;
928 set output_info_($output_name,attr_list) "";
929 }
930
931 if {![info exists output_info_($output_name,local_cid)]} {
932 $self instvar local_source_;
933 $self instvar local_src_cids_;
934
935 set output_info_($output_name,local_cid) [$local_source_ calloc $local_src_cids_(outputs) $output_name];
936 }
937 }
938
939 GraphComm instproc create_parameter {parameter_name} {
940 $self instvar parameter_names_;
941 $self instvar parameter_info_;
942
943 if {[lsearch $parameter_names_ $parameter_name] == -1} {
944 lappend parameter_names_ $parameter_name;
945 set parameter_info_($parameter_name,attr_list) "";
946 }
947
948 if {![info exists parameter_info_($parameter_name,local_cid)]} {
949 $self instvar local_source_;
950 $self instvar local_src_cids_;
951
952 set parameter_info_($parameter_name,local_cid) [$local_source_ calloc $local_src_cids_(parameters) $parameter_name];
953 }
954 }
955
956 GraphComm instproc create_input_attr {input_name attr_name} {
957 $self instvar input_names_;
958 $self instvar input_info_;
959
960 if {[lsearch $input_names_ $input_name] == -1} {
961 return;
962 }
963
964 if {![info exists input_info_($input_name,local_cid)]} {
965 return;
966 }
967
968 if [info exists input_info_($input_name,attr_list)] {
969 if {[lsearch $input_info_($input_name,attr_list) $attr_name] == -1} {
970 lappend input_info_($input_name,attr_list) $attr_name;
971 }
972 } else {
973 lappend input_info_($input_name,attr_list) $attr_name;
974 }
975
976 if {![info exists input_info_($input_name,$attr_name,local_cid)]} {
977 $self instvar local_source_;
978
979 set input_info_($input_name,$attr_name,local_cid) [$local_source_ calloc $input_info_($input_name,local_cid) $attr_name];
980
981 $self instvar read_adu_callback_map_;
982 set read_adu_callback_map_($local_source_,$input_info_($input_name,$attr_name,local_cid)) "$self handle_input_attr_read_adu $input_name $attr_name ";
983
984 }
985 }
986
987 GraphComm instproc create_output_attr {output_name attr_name} {
988 $self instvar output_names_;
989 $self instvar output_info_;
990
991 if {[lsearch $output_names_ $output_name] == -1} {
992 return;
993 }
994
995 if {![info exists output_info_($output_name,local_cid)]} {
996 return;
997 }
998
999 if [info exists output_info_($output_name,attr_list)] {
1000 if {[lsearch $output_info_($output_name,attr_list) $attr_name] == -1} {
1001 lappend output_info_($output_name,attr_list) $attr_name;
1002 }
1003 } else {
1004 lappend output_info_($output_name,attr_list) $attr_name;
1005 }
1006
1007 if {![info exists output_info_($output_name,$attr_name,local_cid)]} {
1008 $self instvar local_source_;
1009
1010 set output_info_($output_name,$attr_name,local_cid) [$local_source_ calloc $output_info_($output_name,local_cid) $attr_name];
1011
1012 $self instvar read_adu_callback_map_;
1013 set read_adu_callback_map_($local_source_,$output_info_($output_name,$attr_name,local_cid)) "$self handle_output_attr_read_adu $output_name $attr_name ";
1014 }
1015 }
1016
1017 GraphComm instproc create_parameter_attr {parameter_name attr_name} {
1018 $self instvar parameter_names_;
1019 $self instvar parameter_info_;
1020
1021 if {[lsearch $parameter_names_ $parameter_name] == -1} {
1022 return;
1023 }
1024
1025 if {![info exists parameter_info_($parameter_name,local_cid)]} {
1026 return;
1027 }
1028
1029 if [info exists parameter_info_($parameter_name,attr_list)] {
1030 if {[lsearch $parameter_info_($parameter_name,attr_list) $attr_name] == -1} {
1031 lappend parameter_info_($parameter_name,attr_list) $attr_name;
1032 }
1033 } else {
1034 lappend parameter_info_($parameter_name,attr_list) $attr_name;
1035 }
1036
1037 if {![info exists parameter_info_($parameter_name,$attr_name,local_cid)]} {
1038 $self instvar local_source_;
1039
1040 set parameter_info_($parameter_name,$attr_name,local_cid) [$local_source_ calloc $parameter_info_($parameter_name,local_cid) $attr_name];
1041
1042 $self instvar read_adu_callback_map_;
1043 set read_adu_callback_map_($local_source_,$parameter_info_($parameter_name,$attr_name,local_cid)) "$self handle_parameter_attr_read_adu $parameter_name $attr_name ";
1044 }
1045 }
1046
1047 GraphComm instproc set_input_attr {input_name attr_name value} {
1048 $self instvar input_info_;
1049
1050 if {[info exists input_info_($input_name,$attr_name,local_cid)]} {
1051
1052 $self instvar local_source_;
1053
1054 $local_source_ send $input_info_($input_name,$attr_name,local_cid) $value
1055 set input_info_($input_name,$attr_name,cur_value) $value;
1056 }
1057 }
1058
1059 GraphComm instproc set_output_attr {output_name attr_name value} {
1060 $self instvar output_info_;
1061
1062 if {[info exists output_info_($output_name,$attr_name,local_cid)]} {
1063
1064 $self instvar local_source_;
1065
1066 $local_source_ send $output_info_($output_name,$attr_name,local_cid) $value
1067 set output_info_($output_name,$attr_name,cur_value) $value;
1068 }
1069 }
1070
1071 GraphComm instproc set_parameter_attr {parameter_name attr_name value} {
1072 $self instvar parameter_info_
1073
1074 if {[info exists parameter_info_($parameter_name,$attr_name,local_cid)]} {
1075
1076 $self instvar local_source_;
1077
1078 $local_source_ send $parameter_info_($parameter_name,$attr_name,local_cid) $value
1079 set parameter_info_($parameter_name,$attr_name,cur_value) $value;
1080 }
1081 }
1082
1083 GraphComm instproc send_trigger_command {cmd} {
1084 $self instvar local_source_ local_src_cids_;
1085
1086 $local_source_ send $local_src_cids_(trigger_cmds) $cmd;
1087 }
1088
1089 GraphComm instproc send_map_command {cmd {store_data_flag 1}} {
1090 $self instvar local_source_ local_src_cids_;
1091
1092 set seqno [$local_source_ send $local_src_cids_(map_cmds) $cmd];
1093
1094 if {$store_data_flag} {
1095 $self instvar map_command_datastore_;
1096 set map_command_datastore_($seqno) $cmd;
1097 }
1098 }
1099
1100 GraphComm instproc send_misc {misc_data {store_data_flag 1}} {
1101 $self instvar local_source_ local_src_cids_;
1102
1103 set seqno [$local_source_ send $local_src_cids_(misc) $misc_data];
1104
1105 if {$store_data_flag} {
1106 $self instvar misc_datastore_;
1107 set misc_datastore_($seqno) $misc_data;
1108 }
1109 }
1110
1111
1112 GraphComm instproc send_debug {data {store_data_flag 1}} {
1113 $self instvar local_source_ local_src_cids_;
1114
1115 set seqno [$local_source_ send $local_src_cids_(debug) $data];
1116
1117 if {$store_data_flag} {
1118 $self instvar debug_datastore_;
1119 set debug_datastore_($seqno) $data;
1120 }
1121 }