1 # application-rnswitch.tcl --
2 #
3 # SDS Service App that provides interface to switch the Real Networks
4 # output in the video matrix switch
5 #
6 # Copyright (c) 2000-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 import RTPApplication
33 import CSdsService
34 import CServiceManager
35 import CService
36 import DpClient
37
38 #
39 # Code for CRnSwitcherApplication
40 #
41
42 Class CRnSwitchApplication -superclass RTPApplication
43
44 CRnSwitchApplication instproc InitArgs { options } {
45 # for the service discovery service
46 $options register_option -sa optServiceAddress
47 $options register_option -sp optServicePort
48 $options register_option -st optServiceTTL
49
50 # for the service discovery service
51 $options register_option -rp optComPort
52
53 # for the amx info
54 $options register_option -amxaddr optAMXAddress
55 $options register_option -amxport optAMXPort
56 $options register_option -amxstate optAMXState
57 }
58
59 CRnSwitchApplication instproc InitResources { options } {
60 # for the service discovery service
61 $options add_default optServiceAddress "224.4.6.8"
62 $options add_default optServicePort "12344"
63 $options add_default optServiceTTL "16"
64
65 # for the service discovery service
66 $options add_default optComPort "11409"
67
68 # for the amx
69 $options add_default optAMXAddress "htsr.cs.berkeley.edu"
70 $options add_default optAMXPort "6901"
71 $options add_default optAMXState "speakerCamera"
72 }
73
74 CRnSwitchApplication instproc InitAMX { } {
75 $self instvar m_dpAMX
76 $self instvar m_szAMXState
77 set options [$self options]
78
79 set inetAMXAddr [$options get_option optAMXAddress]
80 set iAMXPort [$options get_option optAMXPort]
81 set m_szAMXState [$options get_option optAMXState]
82
83 set m_dpAMX [new DpClient $inetAMXAddr $iAMXPort]
84 $self AMXSwitch $m_szAMXState
85 }
86
87 CRnSwitchApplication instproc init { argv } {
88 $self next RnSwitcher
89
90 # set some member variables
91 $self instvar m_szAMXState
92 set m_szAMXState ""
93
94 # Initiailization of variables and resources.
95 set options [$self options]
96 $self InitArgs $options
97 $self InitResources $options
98 $options load_preferences "rtp rvc"
99 set argv [$options parse_args $argv]
100
101 # setup the amx stuff if we have to
102 $self InitAMX
103
104 # FIXME - this part is kind of messed up; it doesn't make sense
105 # there should be a --with-gui option or something like that
106 # if there is a GUI, then we have to use mash => if there is no
107 # GUI, we need to manually kill the default mash window
108
109 # create the sds if we don't have a ui else create the ui
110 if { $argv != "" } {
111
112 # create the sds session object
113 set inetServiceAddr [$options get_option optServiceAddress]
114 set iServicePort [$options get_option optServicePort]
115 set iServiceTTL [$options get_option optServiceTTL]
116
117 $self instvar m_sdsService
118 set m_sdsService [new CSdsService $self $inetServiceAddr \
119 $iServicePort $iServicePort $iServiceTTL]
120
121 # setup the service objects
122 $self instvar m_serviceManager
123 $self instvar m_service
124
125 set iPort [$options get_option optComPort]
126 set m_serviceManager [new CServiceManager "ServiceApp" "Service" $iPort]
127 $m_serviceManager Attach $self
128
129 set m_service ""
130
131 } else {
132 $self BuildUI
133 }
134 }
135
136 ##############################################################################
137 #
138 # CRnSwitchApplication instproc NewConnection { service } {
139 #
140 # Input:
141 # service - the new service that got connected
142 #
143 # Output:
144 # 1 - if handling this service
145 # 0 - otherwise
146 #
147 # Description:
148 # A call back function for the service manager. This function will be called
149 # when a new connection has just been noticed by the service manager
150 #
151 ##############################################################################
152 CRnSwitchApplication instproc NewConnection { service } {
153 $self instvar m_service
154
155 # check that we don't already have a connection that we're using
156 if { $m_service != "" } {
157 $service CloseLink
158 return 1
159 }
160
161 set m_service $service
162
163 # Add the service calls
164 $m_service MapMessage "SYN_SERVICE_IMAGE" $self SynServiceImage
165 $m_service MapMessage "GET_UI_WINDOW" $self GetUIWindow
166 $m_service MapMessage "AMX_SWITCH" $self RemoteAMXSwitch
167 $m_service MapMessage "CLOSE_LINK" $self CloseService
168
169 return 1
170 }
171
172 ##############################################################################
173 #
174 # CRnSwitchApplication instproc CloseService { service arguments }
175 #
176 # Input:
177 # service - the service object that called this function
178 # arguments - the arguments that are passed to this funct from remote caller
179 #
180 # Output:
181 # none
182 #
183 # Description:
184 # Need to close the service and allow other connections to be made
185 #
186 ##############################################################################
187 CRnSwitchApplication instproc CloseService { service arguments } {
188 $self instvar m_service
189 set m_service ""
190
191 exit
192 }
193
194
195 ##############################################################################
196 #
197 # CRnSwitchApplication public SynServiceImage { service arguments } {
198 #
199 # Input:
200 # service - the service that called this function
201 # arguments - the arguments associated with this call
202 #
203 # Output:
204 # none
205 #
206 # Description:
207 # This is called by the remote service client when it wants the image or text
208 # to display the service. The simple protocol goes as such:
209 # type type_dependent_arguments. The type could be text and it's argument
210 # the ascii of title. It could also be image and be a bitmap of the image
211 #
212 ##############################################################################
213 CRnSwitchApplication public SynServiceImage { service arguments } {
214 $service Send "SYN_SERVICE_IMAGE" "text RnSwitch"
215 }
216
217
218 ##############################################################################
219 #
220 # CRnSwitchApplication public GetUIWindow { service arguments }
221 #
222 # Input:
223 # service - the service that called this function
224 # arguments - the arguments associated with this call
225 #
226 # Output:
227 # none
228 #
229 # Description:
230 # This is called by the remote service client when it wants the code
231 # to make the window. It should send back the code to build the window.
232 # There are two things that are assumed to be set by the client. One is
233 # winFrame the window to draw into. Another is service, which is the
234 # m_service object to send back to yourself.
235 #
236 ##############################################################################
237 CRnSwitchApplication public GetUIWindow { service arguments } {
238 $self instvar m_szAMXState
239
240 set cmd ""
241
242 append cmd "regsub -all -- {\\\.} \$winFrame {_} __name \n"
243
244 # create the frame for the radio button
245 append cmd "frame \$winFrame.radioFrame -relief raised -borderwidth 2\n"
246 append cmd "pack \$winFrame.radioFrame -side top -fill both -expand 1 \n"
247
248 # now let's create the radio buttons
249 append cmd "global szAMXState\$__name \n"
250 append cmd "set szAMXState\$__name $m_szAMXState \n"
251
252 append cmd "set __lszSwitchItem \"\" \n"
253 append cmd "lappend __lszSwitchItem {Wide Camera} \n"
254 append cmd "lappend __lszSwitchItem wideCamera \n"
255 append cmd "lappend __lszSwitchItem {Speaker Camera} \n"
256 append cmd "lappend __lszSwitchItem speakerCamera \n"
257 append cmd "lappend __lszSwitchItem {Audience Camera} \n"
258 append cmd "lappend __lszSwitchItem audienceCamera \n"
259 append cmd "lappend __lszSwitchItem {Front PC} \n"
260 append cmd "lappend __lszSwitchItem frontPC \n"
261 append cmd "lappend __lszSwitchItem {Laptop} \n"
262 append cmd "lappend __lszSwitchItem laptop \n"
263 append cmd "lappend __lszSwitchItem Elmo \n"
264 append cmd "lappend __lszSwitchItem elmo \n"
265 append cmd "lappend __lszSwitchItem {Front VCR} \n"
266 append cmd "lappend __lszSwitchItem frontVCR \n"
267 append cmd "lappend __lszSwitchItem {Rack VCR} \n"
268 append cmd "lappend __lszSwitchItem rackVCR \n"
269 append cmd "lappend __lszSwitchItem Liveboard \n"
270 append cmd "lappend __lszSwitchItem liveboard \n"
271 append cmd "lappend __lszSwitchItem {MBone PC} \n"
272 append cmd "lappend __lszSwitchItem mbonePC \n"
273 append cmd "lappend __lszSwitchItem SGI \n"
274 append cmd "lappend __lszSwitchItem sgiPC \n"
275
276 append cmd "foreach {__szSwitchName __szSwitchValue} \
277 \$__lszSwitchItem { \n"
278 append cmd "frame \$winFrame.radioFrame.\$__szSwitchValue \n"
279 append cmd "pack \$winFrame.radioFrame.\$__szSwitchValue \
280 -side top -fill x -expand 1\n"
281
282 append cmd "radiobutton \$winFrame.radioFrame.\$__szSwitchValue.radio \
283 -text \"\$__szSwitchName\" -value \$__szSwitchValue \
284 -variable szAMXState\$__name \
285 -command \"\$service Send AMX_SWITCH \$__szSwitchValue\" \n"
286 append cmd "pack \$winFrame.radioFrame.\$__szSwitchValue.radio \
287 -side left \n"
288 append cmd "} \n"
289
290
291 # now put the close button in
292 append cmd "frame \$winFrame.command \n"
293 append cmd "pack \$winFrame.command -side top -fill x \n"
294
295 append cmd "button \$winFrame.command.closeButton -text Close \
296 -command \"destroy \$winFrame\" \n"
297 append cmd "pack \$winFrame.command.closeButton -side right \n"
298
299 append cmd "label \$winFrame.command.title -relief raised \
300 -text \"RnSwitcher\" \n"
301 append cmd "pack \$winFrame.command.title -side left -fill both -expand 1\n"
302
303
304 $service Send "GET_UI_WINDOW" $cmd
305 }
306
307 CRnSwitchApplication public RemoteAMXSwitch { service target } {
308 $self instvar m_service
309
310 # so the switch
311 $self AMXSwitch $target
312 }
313
314 CRnSwitchApplication public AMXSwitch { target } {
315 $self instvar m_dpAMX
316
317 # target is the input to the realNetworks feed
318 $m_dpAMX do matrix_switchVideoStream $target realNetworks
319 }
320
321 ##############################################################################
322 #
323 # CRnSwitchApplication public GetSdsServiceData { } {
324 #
325 # Input:
326 # none
327 #
328 # Output:
329 # the data that the will go out to the sds system
330 #
331 # Description:
332 # This is a callback function for the service discovery system. Need to
333 # return the data that will go out to the sds system. So far there are
334 # three fields with their values
335 #
336 ##############################################################################
337 CRnSwitchApplication public GetSdsServiceData { } {
338 $self instvar m_lConfig
339
340 set options [$self options]
341 set iComPort [$options get_option optComPort]
342 set hostname [exec hostname]
343
344 set location "Berkeley Soda 405"
345 set type "Real Networks Switcher"
346
347 set data [list "UPDATE:" [concat $hostname $iComPort] \
348 [list [list "LOCATION:" $location] \
349 [list "TYPE:" $type]]]
350
351 return $data
352 }
353
354
355 ##############################################################################
356 #
357 # CRnSwitchApplication public BuildUI { }
358 #
359 # Input:
360 # none
361 #
362 # Output:
363 # none
364 #
365 # Description:
366 # called to build the ui
367 #
368 ##############################################################################
369 CRnSwitchApplication public BuildUI { } {
370 $self GetUIWindow $self ""
371 }
372
373
374 ##############################################################################
375 #
376 # CRnSwitchApplication public Send { szMessage arguments }
377 #
378 # Input:
379 # szMessage - the message that is sent
380 # arguments - the arguments associated with this message
381 #
382 # Output:
383 # none
384 #
385 # Description:
386 # This function is used to immitate the Send of the CService object. When
387 # the user wishes to use this object as a non-service object, it will use
388 # this send instead of the one of in CService. In other words, we have
389 # the same functionality as before but instead of doing it with a remote
390 # client, do it locally.
391 #
392 ##############################################################################
393 CRnSwitchApplication public Send { szMessage arguments } {
394 switch -exact -- $szMessage {
395 "GET_UI_WINDOW" {
396 set service $self
397 destroy .top
398 set winFrame [frame .top]
399 pack $winFrame -fill both -expand 1
400
401 eval $arguments
402
403 # change the close button to exit the program
404 $winFrame.command.closeButton configure -command "exit"
405 }
406
407 "AMX_SWITCH" {
408 $self RemoteAMXSwitch $self $arguments
409 }
410 }
411 }
412
413
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.