1 # agent-megafor.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1997-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 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/megafor/agent-megafor.tcl,v 1.22 2002/02/03 04:27:42 lim Exp $
32
33 import AnnounceListenManager/AS MeGa AnnounceListenManager/AS/SSG SDPParser
34
35 # FIXME This file still needs restructuring
36 # Agent class for the megafor application, which allows clients without multicast to connect to AS1
37 # Author: Elan Amir
38 # Status: alpha
39 Class MeGaForAgent
40
41 MeGaForAgent instproc init { } {
42 $self next
43 $self instvar gwal_ cliental_ clientnets_ conf_ sdp_
44 set sdp_ [new SDPParser]
45
46 set f [$self get_option megaConfFile]
47 set bw [$self get_option asCtrlBW]
48 if { [file exists $f] } {
49 $self parse_conffile $f
50 set megaspec $conf_(gwctrl)
51 } else {
52 set megaspec [$self get_option asCtrl]
53 }
54 $self instvar gwal_ cliental_ altype_
55 # Each type of established service has a separate control channel port.
56 # Others use the generic -megactrl port. We create these gateways so
57 # that messages from established servents will be available for
58 # forwarding to clients
59 foreach m { generic audio video sdp mb } {
60 set spec [MeGa ctrlchan $m $megaspec]
61 set al [new AnnounceListenManager/AS/SSG $self $spec $bw]
62 set altype_($al) gw
63 set gwal_($m) $al
64 #$al start 0
65 }
66
67 if [info exists conf_(clientctrl)] {
68 set clientctrl $conf_(clientctrl)
69 foreach m { generic audio video sdp mb } {
70 set spec [MeGa ctrlchan $m $clientctrl]
71 set bw $conf_($m,bw)
72 set al [new AnnounceListenManager/AS/SSG \
73 $self $spec $bw]
74 set altype_($al) client
75 set cliental_($m) $al
76 #$al start 0
77 }
78 } else {
79 # FIXME
80 set port [$self get_option defaultSSGPort]
81 set al [new AnnounceListenManager/AS/SSG $self $port $bw]
82 set altype_($al) client
83 }
84
85 }
86
87 MeGaForAgent instproc parse_conffile { f } {
88 set fd [open $f r]
89 if { $fd < 0 } {
90 return
91 }
92 $self instvar conf_ app_
93 while { [gets $fd line] > 0 } {
94 set kw [lindex $line 0]
95 switch $kw {
96 link {
97 $self add_option link yes
98 set conf_(gwctrl) [lindex $line 1]
99 set conf_(clientctrl) [lindex $line 2]
100 }
101 leaf {
102 set conf_(gwctrl) [lindex $line 1]
103 }
104 media {
105 set mtype [lindex $line 1]
106 set conf_($mtype,bw) [lindex $line 2]
107 set conf_($mtype,ofmt) [lindex $line 3]
108 }}
109 }
110 close $fd
111 }
112
113 # This method added by Angie so that we don't have to sdp parse
114 # messages in order to find out what media type, and therefor port
115 # mapping they should be on. The whole concept of different port
116 # numbers for different services needs to be rethought.
117
118 MeGaForAgent private port_mapping {srv_loc} {
119
120 # FIXME hack! This only works if srv_loc is urn:something
121 set ind [string first : $srv_loc]
122 set servent [string range $srv_loc [incr ind] end]
123 puts "SERVENT $servent"
124 switch $servent {
125 vgw {
126 return video
127 }
128 agw {
129 return audio
130 }
131 mbgw {
132 return mb
133 }
134 sdgw {
135 return sdp
136 }
137 default {
138 return generic
139 }
140 }
141 }
142
143
144 #
145 MeGaForAgent instproc recv_msg { al atype aspec addr srv_name srv_loc srv_inst ssg_port msg } {
146 $self instvar gwal_ cliental_ clientnets_ msgq_ altype_
147
148 set o "ASCP v[AnnounceListenManager/AS version]"
149 set n $atype
150 set o $o\n$n
151 set n $aspec
152 set o $o\n$n
153 set n $srv_name
154 set o $o\n$n
155 set n $srv_loc
156 set o $o\n$n
157 set n $srv_inst
158 set o $o\n$n
159 set n $ssg_port
160 set o $o\n$n
161 set n $msg
162 set o $o\n$n
163
164
165 if { $altype_($al) == "client" } {
166 # FIXME Forward all client-side announcements
167
168 if ![info exists clientnets_($aspec:$srv_loc)] {
169 set spec $addr/$ssg_port:0/1
170 puts "^^^^^^^^^^^^^^^ creating an ALM for $spec"
171 # set bw [$msg attr_value linkbw]
172 # FIXME
173 set bw [expr 0.05*128000]
174 set cnet [new AnnounceListenManager/AS/SSG \
175 $self $spec $bw $srv_inst]
176 #$cnet start 0
177 set clientnets_($aspec:$srv_loc) $cnet
178 }
179 # FIXME this only works if srv_loc is urn:something !
180 set mtype [$self port_mapping $srv_loc]
181 $self instvar gwal_
182 $gwal_($mtype) announce $o
183 } else {
184 # Gateway-side announcements
185 set cnets [array names clientnets_]
186 foreach cspec $cnets {
187 set cnet $clientnets_($cspec)
188 if { $srv_inst == [$cnet set srv_inst_] } {
189 # Client has expressed interest in this
190 # session - queue the message text.
191 $cnet enqueue $aspec:$srv_loc $o
192 }
193 }
194 }
195
196 }
197
198 MeGaForAgent instproc unregister { aspec } {
199 $self instvar clientnets_
200 if [info exists clientnets_($aspec)] {
201 set cnet $clientnets_($aspec)
202 delete $cnet
203 unset clientnets_($aspec)
204 } else {
205 # A gateway got unregistered -- notify all the client handlers
206 set cnets [array names clientnets_]
207 foreach cspec $cnets {
208 set cnet $clientnets_($cspec)
209 $cnet remove_agent $aspec
210 }
211 }
212 }
213
214 MeGaForAgent instproc destroy {} {
215 $self instvar gwal_ cliental_ clientnets_
216 foreach m { generic sdp video audio mb } {
217 delete $gwal_($m)
218 delete $cliental_($m)
219 }
220 set aspecs [array names clientnets_]
221 foreach aspec $aspecs {
222 delete $clientnets_($aspec)
223 }
224
225 $self next
226 }
227
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.