1 # application-specialfx.tcl --
2 #
3 # SDS app that provides interface to the Special FX functions
4 #
5 # Copyright (c) 2000-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 Application
32 import SSAC_Client
33 import CSdsService
34 import CServiceManager
35 import CService
36
37 Class CSpecialFxApplication -superclass Application
38
39 ##############################################################################
40 #
41 # CSpecialFxApplication instproc InitArgs { options } {
42 #
43 # Input:
44 # options - the options object
45 #
46 # Output:
47 # none
48 #
49 # Description:
50 # Registers all options before the command line argument is parsed
51 #
52 ##############################################################################
53 CSpecialFxApplication instproc InitArgs { options } {
54 # for the service discovery service
55 $options register_option -sa optServiceAddress
56 $options register_option -sp optServicePort
57 $options register_option -st optServiceTTL
58
59 # for the service discovery service
60 $options register_option -rp optComPort
61 }
62
63 ##############################################################################
64 #
65 # CSpecialFxApplication instproc InitResources { options } {
66 #
67 # Input:
68 # options - the options object
69 #
70 # Output:
71 # none
72 #
73 # Description:
74 # Gives defaults for options
75 #
76 ##############################################################################
77 CSpecialFxApplication instproc InitResources { options } {
78
79 # for the service discovery service
80 $options add_default optServiceAddress "224.4.6.8"
81 $options add_default optServicePort "12344"
82 $options add_default optServiceTTL "16"
83
84 # for the service discovery service
85 $options add_default optComPort "11412"
86 }
87
88
89 ##############################################################################
90 #
91 # CSpecialFxApplication instproc init { argv } {
92 #
93 # Input:
94 # argv - command line input
95 #
96 # Output:
97 # none
98 #
99 # Description:
100 # Constructor for the object.
101 #
102 ##############################################################################
103 CSpecialFxApplication instproc init { argv } {
104 $self next Replay
105
106
107 # Initiailization of options
108 set options [$self options]
109 $self InitArgs $options
110 $self InitResources $options
111 $options load_preferences "specialfx"
112 set argv [$options parse_args $argv]
113
114
115 # create the sds session object
116 set inetServiceAddr [$options get_option optServiceAddress]
117 set iServicePort [$options get_option optServicePort]
118 set iServiceTTL [$options get_option optServiceTTL]
119
120 $self instvar m_sdsService
121 set m_sdsService [new CSdsService $self $inetServiceAddr $iServicePort \
122 $iServicePort $iServiceTTL]
123
124 # setup the service objects
125 $self instvar m_serviceManager
126 $self instvar m_service
127
128 set iPort [$options get_option optComPort]
129 set m_serviceManager [new CServiceManager "ServiceApp" "SpecialFx" $iPort]
130 $m_serviceManager Attach $self
131
132 }
133
134 ##############################################################################
135 #
136 # CSpecialFxApplication public GetSdsServiceData { } {
137 #
138 # Input:
139 # none
140 #
141 # Output:
142 # the data that the will go out to the sds system
143 #
144 # Description:
145 # This is a callback function for the service discovery system. Need to
146 # return the data that will go out to the sds system. So far there are
147 # three fields with their values
148 #
149 ##############################################################################
150 CSpecialFxApplication public GetSdsServiceData { } {
151 set options [$self options]
152 set iComPort [$options get_option optComPort]
153 set hostname [exec hostname]
154
155 set location "Locationless"
156 set type "Special FX"
157
158 set data [list "UPDATE:" [concat $hostname $iComPort] \
159 [list [list "LOCATION:" $location] \
160 [list "TYPE:" $type]]]
161
162 return $data
163 }
164
165 ##############################################################################
166 #
167 # CSpecialFxApplication instproc NewConnection { service }
168 #
169 # Input:
170 # service - the new service that got connected
171 #
172 # Output:
173 # 1 - if handling this service
174 # 0 - otherwise
175 #
176 # Description:
177 # A call back function for the service manager. This function will be called
178 # when a new connection has just been noticed by the service manager
179 #
180 ##############################################################################
181 CSpecialFxApplication instproc NewConnection { service } {
182 $self instvar m_service
183
184 set m_service $service
185
186 # Add the service calls
187 $m_service MapMessage "SYN_SERVICE_IMAGE" $self SynServiceImage
188 $m_service MapMessage "GET_UI_WINDOW" $self GetUIWindow
189 $m_service MapMessage "START_FX" $self StartFx
190 $m_service MapMessage "CLOSE_LINK" $self CloseService
191
192 return 1
193 }
194
195 ##############################################################################
196 #
197 # CSpecialFxApplication 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 CSpecialFxApplication public SynServiceImage { service arguments } {
214 $service Send "SYN_SERVICE_IMAGE" "text SpecialFx"
215 }
216
217
218 ##############################################################################
219 #
220 # CSpecialFxApplication 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 CSpecialFxApplication public GetUIWindow { service arguments } {
238 set cmd ""
239
240 #################################################################
241 #
242 # Irene fill code here
243 #
244 #################################################################
245 append cmd "regsub -all -- {\\\.} \$winFrame {_} __name \n"
246
247 append cmd "frame \$winFrame.label \n"
248 append cmd "pack \$winFrame.label -side top -fill x -expand 1\n"
249
250 append cmd "label \$winFrame.label.label -text \"Please choose a SpecialFx:\" \n"
251 append cmd "pack \$winFrame.label.label -side left \n"
252
253 append cmd "frame \$winFrame.specialfx \n"
254 append cmd "pack \$winFrame.specialfx -side top -fill x -expand 1\n"
255
256 append cmd "global specialfx\$__name \n"
257 append cmd "set specialfx\$__name H261FadeSubprogram \n"
258
259 # Source 1 frames
260 append cmd "frame \$winFrame.source1 \n"
261 append cmd "label \$winFrame.source1.label -text \"SourceId 1:\" \n"
262 append cmd "menubutton \$winFrame.source1.choice -textvariable __source1 -menu \
263 \$winFrame.source1.choice.menu -relief raised\n"
264 append cmd "menu \$winFrame.source1.choice.menu \n"
265
266 # Source 2 frames
267 append cmd "frame \$winFrame.source2 \n"
268 append cmd "label \$winFrame.source2.label -text \"SourceId 2:\" \n"
269 append cmd "menubutton \$winFrame.source2.choice -textvariable __source2 -menu \
270 \$winFrame.source2.choice.menu -relief raised\n"
271 append cmd "menu \$winFrame.source2.choice.menu \n"
272
273 # Fading radio button
274 append cmd "radiobutton \$winFrame.specialfx.fade -variable specialfx\$__name \
275 -text Fading -value H261FadeSubprogram -command \"\$winFrame.source2.label configure \
276 -fg black; \$winFrame.source2.choice configure -state normal\" \n"
277 append cmd "pack \$winFrame.specialfx.fade -side top -fill x -expand 1\n"
278
279 # Titling radio button
280 append cmd "radiobutton \$winFrame.specialfx.title -variable specialfx\$__name \
281 -text Titling -value H261TitleSubprogram -command \"\$winFrame.source2.label configure \
282 -fg grey; \$winFrame.source2.choice configure -state disabled\" \n"
283 append cmd "pack \$winFrame.specialfx.title -side bottom -fill x -expand 1\n"
284
285 # Source Id 1
286 append cmd "global __source1 \n"
287 append cmd "global value_irene \n"
288 append cmd "set value_irene \[llength \$liSourceId\] \n"
289 append cmd "puts \"value is \$value_irene\n\" \n"
290 append cmd "if {\[llength \$liSourceId\] == 0} {\n"
291 append cmd "puts \"here \n\" \n"
292 append cmd "set __source1 \"N\/A\" \n"
293 append cmd "} else {\n"
294 append cmd "set __source1 \[lindex \$liSourceId 0\] \n"
295 append cmd "}\n"
296 append cmd "pack \$winFrame.source1 -side top -fill x -expand 1\n"
297 append cmd "pack \$winFrame.source1.label -side left -fill x -expand 1\n"
298
299 append cmd "pack \$winFrame.source1.choice -side right -fill x -expand 1\n"
300 append cmd "foreach item \$liSourceId { \n"
301 append cmd "\$winFrame.source1.choice.menu add radio -label \$item \
302 -variable __source1 \n"
303 append cmd "} \n"
304
305 # Source Id 2
306 append cmd "global __source2 \n"
307 append cmd "if {\[llength \$liSourceId\] == 0} {\n"
308 append cmd "set __source2 \"N\/A\" \n"
309 append cmd "} else {\n"
310 append cmd "set __source2 \[lindex \$liSourceId 0\] \n"
311 append cmd "}\n"
312 append cmd "pack \$winFrame.source2 -side top -fill x -expand 1\n"
313 append cmd "pack \$winFrame.source2.label -side left -fill x -expand 1\n"
314
315 append cmd "pack \$winFrame.source2.choice -side right -fill x -expand 1\n"
316 append cmd "foreach item \$liSourceId { \n"
317 append cmd "\$winFrame.source2.choice.menu add radio -label \$item \
318 -variable __source2 \n"
319 append cmd "} \n"
320
321
322 append cmd "frame \$winFrame.button \n"
323 append cmd "pack \$winFrame.button -side top -fill x -expand 1\n"
324
325 # Close button
326 append cmd "button \$winFrame.button.close -text Close \
327 -command \"destroy \$winFrame\" \n"
328 append cmd "pack \$winFrame.button.close -side right\n"
329
330 # Start button
331 append cmd "button \$winFrame.button.start -text Start \
332 -command \"global specialfx\$__name; global __source1; global __source2; destroy \$winFrame; \$service Send START_FX \\\"\$inetMStudioAddr \$iMStudioPort \$inetClientAddr \$iClientPort \\\$specialfx\$__name \\\$__source1 \\\$__source2 \\\\\\\"\\\{\$liSourceId\\\} \\\\\\\" \\\" \" \n"
333 append cmd "pack \$winFrame.button.start -side right\n"
334
335 $service Send "GET_UI_WINDOW" $cmd
336 }
337
338
339 ##############################################################################
340 #
341 # CSpecialFxApplication public StartFx { service arguments } {
342 #
343 # Input:
344 # service - the service that called this function
345 # arguments - the arguments associated with this call
346 #
347 # Output:
348 # none
349 #
350 # Description:
351 # This is called by the remote service client when it wants the start
352 # an effect
353 #
354 ##############################################################################
355 CSpecialFxApplication public StartFx { service arguments } {
356
357 # set up the arguments and launch the replay proxy
358 set strExec "dc-specialfxproxy-5.0b3"
359 append strExec " $arguments"
360
361 puts "strExec - $strExec"
362
363 if { [catch "eval exec $strExec &" pid] != 0 } {
364 puts "special effext got an error starting the proxy: check the path"
365 exit 0
366 }
367 }
368
369
370 ##############################################################################
371 #
372 # CSpecialFxApplication public CloseService { service arguments }
373 #
374 # Input:
375 # service - the service that called this function
376 # arguments - the arguments associated with this call
377 #
378 # Output:
379 # none
380 #
381 # Description:
382 # This is called by the remote service client closes the service link.
383 #
384 ##############################################################################
385 CSpecialFxApplication public CloseService { service arguments } {
386 exit
387 }
388
389
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.