1 # handler.tcl --
2 #
3 # This file defines classes that are responsible for
4 # launching services in Active Service Framework.
5 #
6 # Copyright (c) 1997-2002 The Regents of the University of California.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # A. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # B. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # C. Neither the names of the copyright holders nor the names of its
18 # contributors may be used to endorse or promote products derived from this
19 # software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #
32 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/hm/handler.tcl,v 1.53 2002/02/26 20:40:23 weitsang Exp $
33
34
35 import RTP/Video RTP/Audio SDPParser
36
37
38 set gwstr(video) VGW
39 set gwstr(sdp) SDGW
40 set gwstr(audio) AGW
41 set gwstr(mediaboard) MBGW
42 set gwstr(mb) MBGW
43 set gwstr(whiteboard) MBGW
44
45 Class GWHandler
46 Class GWHandler/RTPGW -superclass GWHandler
47 Class GWHandler/VGW -superclass { GWHandler/RTPGW RTP/Video }
48 Class GWHandler/AGW -superclass { GWHandler/RTPGW RTP/Audio }
49 Class GWHandler/MBGW -superclass GWHandler
50 Class GWHandler/SDGW -superclass GWHandler
51 Class GWHandler/Mars -superclass GWHandler
52 Class GWHandler/Aries -superclass GWHandler
53 Class GWHandler/FXTemp -superclass GWHandler
54 Class GWHandler/FXForwardBackEnd -superclass GWHandler
55 Class GWHandler/FXForwardFrontEnd -superclass GWHandler
56
57 Class ServiceCreator
58 Class ServiceCreator/MeGa -superclass ServiceCreator
59 Class ServiceCreator/Generic -superclass ServiceCreator
60 Class ServiceCreator/Mars -superclass ServiceCreator
61 Class ServiceCreator/Aries -superclass ServiceCreator
62 Class ServiceCreator/FXTemp -superclass ServiceCreator
63 Class ServiceCreator/FXForwardBackEnd -superclass ServiceCreator
64 Class ServiceCreator/FXForwardFrontEnd -superclass ServiceCreator
65
66 import ServiceCreator/MediaPad GWHandler/MediaPad
67 import ServiceCreator/Device GWHandler/Device
68
69 ServiceCreator instproc init { agent } {
70 $self next
71 $self set agent_ $agent
72 }
73
74 ServiceCreator/Generic instproc create_handler { srv_inst msg } {
75 $self instvar agent_
76 set h [new GWHandler $agent_ $srv_inst "" "" ""]
77 return $h
78 }
79
80 ServiceCreator/FXTemp instproc create_handler {srv_inst msg} {
81 $self instvar agent_
82 set h [new GWHandler/FXTemp $agent_ $srv_inst $msg]
83 return $h;
84 }
85
86 ServiceCreator/FXForwardBackEnd instproc create_handler {srv_inst msg} {
87 $self instvar agent_
88 set h [new GWHandler/FXForwardBackEnd $agent_ $srv_inst $msg]
89 return $h;
90 }
91
92 ServiceCreator/FXForwardFrontEnd instproc create_handler {srv_inst msg} {
93 $self instvar agent_
94 set h [new GWHandler/FXForwardFrontEnd $agent_ $srv_inst $msg]
95 return $h;
96 }
97
98 ServiceCreator/MeGa instproc init { agent } {
99 $self next $agent
100 $self set sdp_ [new SDPParser]
101 }
102
103 ServiceCreator/MeGa instproc destroy {} {
104 $self instvar sdp_
105 delete $sdp_
106 }
107
108
109 ServiceCreator/MeGa instproc create_handler { srv_inst msg } {
110 $self instvar sdp_ agent_
111 set msg [$sdp_ parse $msg]
112 set gspec [$msg set caddr_]
113
114 set media [$msg set allmedia_]
115 set fmt [$media set fmt_]
116 set mtype [$media set mediatype_]
117 set rport [$media set port_]
118
119 set clientaddr [$msg set createaddr_]
120
121 if [$msg have_field b] {
122 set bwval [$msg set bwval_]
123 } else {
124 # FIX THIS ###
125 set bwval "default"
126 }
127
128 # For unicast use client address and use rport. Otherwise, we pick
129 # the port and address.
130 set sport [$agent_ uniqport]
131 if { $rport != 0 } {
132 # unicast - use client recv port.
133 set laddr $clientaddr
134 } else {
135 # multicast - we pick the ports.
136 set rport $sport
137 set laddr [$agent_ pick_mcastaddr]
138 }
139
140 # insert 'none' for format into specs
141 set s [split $gspec /]
142 set gspec [lindex $s 0]/[lindex $s 1]/none/[lindex $s 2]
143 set lspec $laddr/$rport:$sport/none/1
144
145 global gwstr
146 if { $mtype == "video" } {
147 set lscuba [$msg have_attr localscuba]
148 set h [new GWHandler/VGW $agent_ $srv_inst $gspec $lspec $fmt \
149 $lscuba $bwval]
150 } else {
151 set s $gwstr($mtype)
152 set h [new GWHandler/$s $agent_ $srv_inst $gspec $lspec $fmt]
153 }
154 delete $msg
155 return $h
156 }
157
158
159 ServiceCreator/Mars instproc create_handler {srv_inst msg} {
160 $self instvar agent_
161
162 # extract filename
163 set h [new GWHandler/Mars $agent_ $srv_inst "" "" "" $msg]
164 return $h
165 }
166
167 ServiceCreator/Aries instproc create_handler {srv_inst msg} {
168 $self instvar agent_
169
170 # extract filename
171 set h [new GWHandler/Aries $agent_ $srv_inst "" "" "" $msg]
172 return $h
173 }
174
175
176
177 GWHandler instproc init { agent sname gspec lspec fmt } {
178 $self next
179
180 $self instvar agent_ sname_ gspec_ lspec_ link_
181 set agent_ $agent
182 set sname_ $sname
183 set gspec_ $gspec
184 set lspec_ $lspec
185 set link_ 0
186 set format_ null
187 }
188
189 GWHandler instproc exec { fname } {
190 $self instvar pid_ agent_ link_ gwctrl_
191
192 if $link_ {
193 $self instvar clientctrl_ bw_ ofmt_ gspec_ rportspec_
194
195 # take out the format
196 set s [split $gspec_ /]
197 set sspec [lindex $s 0]/[lindex $s 1]/[lindex $s 3]
198 set gspec_ none
199
200 set linkargs "-megactrl $gwctrl_ -megaclient $clientctrl_ -sbw $bw_ -ofmt $ofmt_ -sspec $sspec -rport $rportspec_"
201 } else {
202 set linkargs "-megactrl $gwctrl_"
203 }
204 set execargs "[$self execargs] $linkargs"
205
206 if { [$self get_option doFork] != "" } {
207 set targ ">& /dev/null"
208 } else {
209 set targ ""
210 }
211
212 set path [$self get_option execPath]
213 set execstr "$path/smash $fname $execargs"
214 if { [catch "eval exec [list $execstr] $targ &" pid_] != 0 } {
215 global errorCode
216 $agent_ log "hm: error in exec of '$execstr': $errorCode"
217 set pid_ -1
218 return -1
219 } else {
220 $agent_ log "$execstr"
221 }
222 return 0
223 }
224
225
226 GWHandler/FXTemp instproc init {agent srv_int msg} {
227 $self next $agent $srv_int "" "" "";
228
229 $self instvar client_args_;
230
231 set client_args_ $msg;
232 }
233
234 GWHandler/FXTemp instproc execargs {} {
235 $self instvar client_args_ sname_
236
237 return "$client_args_ -serv_inst $sname_"
238 }
239
240 GWHandler/FXForwardBackEnd instproc init {agent srv_int msg} {
241 $self next $agent $srv_int "" "" "";
242
243 $self instvar client_args_;
244
245 set client_args_ $msg;
246 }
247
248 GWHandler/FXForwardBackEnd instproc execargs {} {
249 $self instvar client_args_ sname_
250
251 return "$client_args_ -serv_inst $sname_"
252 }
253
254 GWHandler/FXForwardFrontEnd instproc init {agent srv_int msg} {
255 $self next $agent $srv_int "" "" "";
256
257 $self instvar client_args_;
258
259 set client_args_ $msg;
260 }
261
262 GWHandler/FXForwardFrontEnd instproc execargs {} {
263 $self instvar client_args_ sname_
264
265 return "$client_args_ -serv_inst $sname_"
266 }
267
268 GWHandler/RTPGW instproc destroy {} {
269 $self instvar agent_ cb_
270 if [info exists cb_] {
271 $agent_ close_cb $cb_
272 }
273
274 $self next
275 }
276
277 GWHandler/RTPGW instproc exec { script } {
278 $self instvar agent_ cb_
279 set cb_ [$agent_ open_cb $self]
280 $self init_callbacks
281
282 $self next $script
283 }
284
285 GWHandler/RTPGW instproc alive { info } {
286 $self instvar dstspec_
287 if ![info exists dstspec_] {
288 set dstspec_ 1
289 $self cb_init
290 update
291 }
292 }
293
294 GWHandler/RTPGW instproc init_callbacks {} {
295 $self next
296 $self instvar cb_
297 $cb_ register alive "$self alive"
298 $cb_ register activate "$self src_activate"
299 }
300
301 GWHandler/RTPGW instproc src_activate { info src args } {
302 }
303
304 GWHandler/AGW instproc cb_init {} {
305 $self instvar cb_ gspec_ lspec_ format_ dstspec_
306 $cb_ send cb_init
307 $cb_ send cb_sessions global=$gspec_!local=$lspec_
308 $cb_ send cb_set global RC 0
309 $cb_ send cb_set local RC 1
310 $cb_ send cb_set global txonly 1
311 $cb_ send cb_set local txonly 1
312
313 $cb_ send cb_set global ofmt $format_
314 $cb_ send cb_set local ofmt $format_
315 }
316
317
318 GWHandler/VGW instproc cb_init {} {
319 $self instvar cb_ gspec_ lspec_ format_ dstspec_ lscuba_
320 $cb_ send cb_init
321 $cb_ send cb_sessions global=$gspec_!local=$lspec_
322 if { $lscuba_ == "global" } {
323 $cb_ send cb_set global RC 1
324 } else {
325 $cb_ send cb_set global RC 0
326 }
327 $cb_ send cb_set local RC 1
328 if { $format_ == "null" } {
329 $cb_ send cb_set local txonly 1
330 }
331 $cb_ send cb_set global color 1
332 $cb_ send cb_set local color 1
333
334 $cb_ send cb_set global ofmt $format_
335 $cb_ send cb_set local ofmt $format_
336 $self instvar agent_ cb_
337 $agent_ log "DONE [$cb_ set channel_]"
338 }
339
340 GWHandler instproc cb_init {} {
341 }
342
343 GWHandler/VGW instproc init { agent sname gspec lspec fmt lscuba scubabw} {
344 $self next $agent $sname $gspec $lspec $fmt
345
346 $self instvar format_
347 set format_ [$self rtp_type $fmt]
348 if { $format_ == "" } {
349 set format_ null
350 }
351
352 $self instvar lscuba_
353 if { $lscuba } {
354 set lscuba_ local
355 } else {
356 set lscuba_ global
357 }
358 $self set gwname_ vgw
359 $self set scubabw_ $scubabw
360 }
361
362 GWHandler/AGW instproc init { agent sname gspec lspec fmt } {
363 $self next $agent $sname $gspec $lspec $fmt
364
365 $self instvar format_
366 set format_ [$self rtp_type $fmt]
367 if { $format_ == "" } {
368 set format_ null
369 }
370
371 $self set gwname_ agw
372 }
373
374 GWHandler/SDGW instproc init args {
375 eval $self next $args
376
377 $self set gwname_ sdgw
378 }
379
380 GWHandler/MBGW instproc init args {
381 eval $self next $args
382
383 $self set gwname_ mbgw
384 }
385
386 GWHandler instproc execargs {} {
387 return ""
388 }
389
390 GWHandler/VGW instproc execargs {} {
391 $self instvar cb_ sname_ lscuba_ scubabw_
392 set chan [$cb_ set channel_]
393
394 return "-scuba $lscuba_ -scubabw $scubabw_ -usemega $sname_ -I $chan"
395 }
396
397 GWHandler/AGW instproc execargs {} {
398 $self instvar cb_ sname_
399 set chan [$cb_ set channel_]
400
401 return "-usemega $sname_ -I $chan"
402 }
403
404 GWHandler/SDGW instproc execargs {} {
405 $self instvar sname_ gspec_ lspec_
406
407 return "-usemega $sname_ -gspec $gspec_ -lspec $lspec_"
408 }
409
410 GWHandler/MBGW instproc execargs {} {
411 $self instvar sname_ gspec_ lspec_
412
413 return "-usemega $sname_ -gspec $gspec_ -lspec $lspec_"
414 }
415
416 GWHandler/Mars instproc init {agent sname gspec lspec fmt ssd} {
417 $self next $agent $sname $gspec $lspec $fmt
418 $self instvar ssd_ serv_inst_
419
420 set ssd_ $ssd
421 set serv_inst_ $sname
422 }
423
424 GWHandler/Aries instproc init {agent sname gspec lspec fmt ssd} {
425 $self next $agent $sname $gspec $lspec $fmt
426 $self instvar ssd_ serv_inst_
427
428 set ssd_ $ssd
429 set serv_inst_ $sname
430 }
431 #
432 GWHandler/Mars instproc execargs {} {
433 $self instvar ssd_ serv_inst_ agent_
434
435 # check if we need a uniq port or not
436 set unicast_port [lindex [split [lindex [split $ssd_ \n] 4]] 1]
437 if { $unicast_port > 0 } {
438 set uniqport [$agent_ uniqport]
439 #FIXME:assume we will have at most 3 streams (audio + video + mb)
440 $agent_ uniqport
441 $agent_ uniqport
442 } else {
443 set uniqport 0
444 }
445
446 return "[list $ssd_] [list $serv_inst_] [list $uniqport]"
447 }
448
449
450 #
451 GWHandler/Aries instproc execargs {} {
452 $self instvar ssd_ serv_inst_
453
454 return "[list $ssd_] [list $serv_inst_]"
455 }
456
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.