~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/psvp/fx_forward/front.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # front.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1999-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 #!/bin/sh
 32 # the next line restarts using mash \
 33 exec mash "$0" "$@"
 34 
 35 
 36 import RTPApplication
 37 import GraphComm
 38 import FAgent
 39 
 40 Class FX_Forward_Front -superclass RTPApplication
 41 
 42 FX_Forward_Front instproc init args {
 43     $self next fx_forw_front
 44 
 45     $self init_resources
 46 
 47     [$self options] register_option -from_cntrl from_cntrl
 48     [$self options] register_option -to_cntrl to_cntrl
 49 
 50     eval [$self options] parse_args $args;
 51 
 52     $self instvar from_cntrl_obj_
 53     $self instvar to_cntrl_obj_
 54 
 55     set from_cntrl_spec [split [$self get_option from_cntrl] "/"]
 56     set from_addr [lindex $from_cntrl_spec 0];
 57     set from_port [lindex $from_cntrl_spec 1];
 58     set from_ttl [lindex $from_cntrl_spec 2];
 59 
 60     set from_cntrl_obj_ [new GraphComm/Front/From $self [$self get_option comm_id] $from_addr $from_port $from_ttl];
 61 
 62     set to_cntrl_spec [split [$self get_option to_cntrl] "/"]
 63     set to_addr [lindex $to_cntrl_spec 0];
 64     set to_port [lindex $to_cntrl_spec 1];
 65     set to_ttl [lindex $to_cntrl_spec 2];
 66 
 67     $self instvar back_host_
 68     set back_host_ $to_addr;
 69 
 70     set to_cntrl_obj_ [new GraphComm/Front/To $self [$self get_option comm_id] $to_addr $to_port $to_ttl];
 71 
 72     $from_cntrl_obj_ install $to_cntrl_obj_
 73     $to_cntrl_obj_ install $from_cntrl_obj_
 74 }
 75 
 76 FX_Forward_Front instproc back_host {} {
 77     $self instvar back_host_;
 78 
 79     return $back_host_;
 80 }
 81 
 82 FX_Forward_Front instproc set_back_host {host} {
 83     $self instvar back_host_;
 84 
 85     puts "Setting back host to $host"
 86 
 87     set back_host_ $host;
 88 }
 89 
 90 FX_Forward_Front instproc init_resources {} {
 91     $self add_option network ip
 92     $self add_option mtu 1024
 93     $self add_option defaultTTL 32
 94     $self add_option sessionType rtpv2
 95     $self add_option maxVideoSessionBW 30000000
 96 
 97     set hname [exec hostname];
 98     set pid [pid];
 99 
100     $self add_option comm_id ${hname}.${pid};
101 }
102 
103 FX_Forward_Front instproc GenerateNewTunnelSpec {} {
104     $self instvar used_ports_;
105 
106     set new_port [expr (int(rand() * 10000)*2) + 5000];
107     while {[info exists used_ports_($new_port)]} {
108         set new_port [expr (int(rand() * 10000)*2) + 5000];
109     }
110     set used_ports_($new_port) 1;
111     return "[exec hostname]/$new_port"
112 }
113 
114 
115 Class GraphComm/Front -superclass GraphComm
116 
117 GraphComm/Front instproc init {app id addr port ttl} {
118     $self next $id $addr $port
119 
120     $self instvar app_
121 
122     set app_ $app;
123 
124     $self instvar dest_;
125 
126     set dest_ ""
127 }
128 
129 GraphComm/Front instproc install {dest} {
130     $self instvar dest_;
131 
132     set dest_ $dest;
133 }
134 
135 GraphComm/Front instproc recv_trigger_command {cmd} {
136     $self instvar dest_;
137 
138     if {$dest_ == ""} {
139         return;
140     }
141 
142     $dest_ send_trigger_command $cmd
143 }
144 
145 GraphComm/Front instproc recv_misc {cmd} {
146     $self instvar dest_;
147 
148     if {$dest_ == ""} {
149         return;
150     }
151 
152     $dest_ send_misc $cmd
153 }
154 
155 GraphComm/Front instproc recv_debug {data} {
156     $self instvar dest_;
157 
158     if {$dest_ == ""} {
159         return;
160     }
161 
162     $dest_ send_debug $data
163 }
164 
165 GraphComm/Front instproc new_input {new_name} {
166     $self instvar dest_;
167 
168     if {$dest_ == ""} {
169         return;
170     }
171     $self next $new_name
172 
173     $dest_ create_input $new_name
174 }
175 
176 GraphComm/Front instproc new_output {new_name} {
177     $self instvar dest_;
178 
179     if {$dest_ == ""} {
180         return;
181     }
182     $self next $new_name
183 
184     $dest_ create_output $new_name
185 }
186 
187 GraphComm/Front instproc new_parameter {new_name} {
188     $self instvar dest_;
189 
190     if {$dest_ == ""} {
191         return;
192     }
193     $self next $new_name
194 
195     $dest_ create_parameter $new_name
196 }
197 
198 GraphComm/Front instproc new_input_attribute {input_name attr_name} {
199     $self instvar dest_;
200 
201     if {$dest_ == ""} {
202         return;
203     }
204     $self next $input_name $attr_name
205 
206     $dest_ create_input_attr $input_name $attr_name
207 }
208 
209 GraphComm/Front instproc new_output_attribute {output_name attr_name} {
210     $self instvar dest_;
211 
212     if {$dest_ == ""} {
213         return;
214     }
215     $self next $output_name $attr_name
216 
217     $dest_ create_output_attr $output_name $attr_name
218 }
219 
220 GraphComm/Front instproc new_parameter_attribute {parameter_name attr_name} {
221     $self instvar dest_;
222 
223     if {$dest_ == ""} {
224         return;
225     }
226     $self next $parameter_name $attr_name
227 
228     $dest_ create_parameter_attr $parameter_name $attr_name
229 }
230 
231 GraphComm/Front instproc update_input_attr_value {input_name attr_name value} {
232     $self instvar dest_;
233 
234     if {$dest_ == ""} {
235         return;
236     }
237     $self next $input_name $attr_name $value
238 
239     $dest_ set_input_attr $input_name $attr_name $value
240 }
241 
242 GraphComm/Front instproc update_output_attr_value {output_name attr_name value} {
243     $self instvar dest_;
244 
245     if {$dest_ == ""} {
246         return;
247     }
248     $self next $output_name $attr_name $value
249 
250     $dest_ set_output_attr $output_name $attr_name $value
251 }
252 
253 GraphComm/Front instproc update_parameter_attr_value {parameter_name attr_name value} {
254     $self instvar dest_;
255 
256     if {$dest_ == ""} {
257         return;
258     }
259     $self next $parameter_name $attr_name $value
260 
261     $dest_ set_parameter_attr $parameter_name $attr_name $value
262 }
263 
264 GraphComm/Front instproc set_input_attr {input_name attr_name value} {
265     $self create_input $input_name
266     $self create_input_attr $input_name $attr_name
267     $self next $input_name $attr_name $value
268 }
269 
270 GraphComm/Front instproc set_output_attr {output_name attr_name value} {
271     $self create_output $output_name
272     $self create_output_attr $output_name $attr_name
273     $self next $output_name $attr_name $value
274 }
275 
276 GraphComm/Front instproc set_parameter_attr {parameter_name attr_name value} {
277     $self create_parameter $parameter_name
278     $self create_parameter_attr $parameter_name $attr_name
279     $self next $parameter_name $attr_name $value
280 }
281 
282 Class GraphComm/Front/From -superclass GraphComm/Front
283 
284 GraphComm/Front/From instproc update_input_attr_value {input_name attr_name value} {
285     $self instvar dest_;
286 
287     if {$dest_ == ""} {
288         return;
289     }
290 
291     $self instvar app_
292 
293     if {[$app_ back_host] == ""} {
294         return;
295     }
296 
297     if {$attr_name == "spec"} {
298         set split_spec [split $value "/"];
299         set addr [lindex $split_spec 0];
300         set port [lindex $split_spec 1];
301         set srcid [lindex $split_spec 2];
302 
303         $self instvar tunnels_
304         if {[info exists tunnels_($addr,$port)]} {
305             set fagent $tunnels_($addr,$port);
306             set tunnel_spec $tunnel_specs_($addr,$port);
307         } else {
308             set tunnel_spec [$app_ GenerateNewTunnelSpec];
309             set tunnel_port [lindex [split $tunnel_spec "/"] 1]
310             set fagent [new FAgent $app_ "${addr}/${port}" [$app_ back_host]/$tunnel_port];
311             set tunnels_($addr,$port) $fagent;
312             set tunnel_specs_($addr,$port) $tunnel_spec;
313         }
314         if {$srcid != "*"} {
315             $fagent install_src_callback $srcid "$self complete_input_setup $srcid $fagent $input_name $tunnel_spec"
316             return;
317         } else {
318             set value "${tunnel_spec}/*";
319         }
320     }
321     $self next $input_name $attr_name $value;
322 }
323 
324 GraphComm/Front/From instproc complete_input_setup {srcid fagent input_name tunnel_spec} {
325     set new_id [$fagent translate_srcid $srcid];
326 
327     $self instvar dest_;
328 
329     $dest_ set_input_attr $input_name spec "${tunnel_spec}/${new_id}"
330 }
331 
332 GraphComm/Front/From instproc update_output_attr_value {output_name attr_name value} {
333     $self instvar dest_;
334 
335     if {$dest_ == ""} {
336         return;
337     }
338 
339     $self instvar app_
340 
341     if {$attr_name == "spec"} {
342         $self instvar out_tunnels_
343         $self instvar out_tunnel_specs_
344 
345         if {[info exists out_tunnels_($value)]} {
346             set fagent $out_tunnels_($value);
347             set tunnel_spec $out_tunnel_specs_($value);
348         } else {
349             set tunnel_spec [$app_ GenerateNewTunnelSpec];
350             set fagent [new FAgent $app_ $tunnel_spec $value];
351             set out_tunnels_($value) $fagent;
352             set out_tunnel_specs_($value) $tunnel_spec;
353         }
354         set value $tunnel_spec
355     }
356     $self next $output_name $attr_name $value;
357 }
358 
359 
360 Class GraphComm/Front/To -superclass GraphComm/Front
361 
362 GraphComm/Front/To instproc recv_misc {cmd} {
363     if {[lindex $cmd 0] == "set_back_host"} {
364         $self instvar app_;
365 
366         $app_ set_back_host [lindex $cmd 1];
367     } else {
368         $self next $cmd;
369     }
370 }
371 
372 set app [new FX_Forward_Front $argv];
373 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.