1 # application-replay.tcl --
2 #
3 # Stuff for building the window that is popped up when the director
4 # activates a Replay. It creates a replayproxy service to talk to MARS
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 Application
33 import SSAC_Client
34 import CSdsService
35 import CServiceManager
36 import CService
37
38 Class CReplayApplication -superclass Application
39
40 ##############################################################################
41 #
42 # CReplayApplication instproc InitArgs { options } {
43 #
44 # Input:
45 # options - the options object
46 #
47 # Output:
48 # none
49 #
50 # Description:
51 # Registers all options before the command line argument is parsed
52 #
53 ##############################################################################
54 CReplayApplication instproc InitArgs { options } {
55 # for the service discovery service
56 $options register_option -sa optServiceAddress
57 $options register_option -sp optServicePort
58 $options register_option -st optServiceTTL
59
60 # for the service discovery service
61 $options register_option -rp optComPort
62
63 # for the active services
64 $options register_option -sas optSpecAS
65 }
66
67 ##############################################################################
68 #
69 # CReplayApplication instproc InitResources { options } {
70 #
71 # Input:
72 # options - the options object
73 #
74 # Output:
75 # none
76 #
77 # Description:
78 # Gives defaults for options
79 #
80 ##############################################################################
81 CReplayApplication instproc InitResources { options } {
82
83 # for the service discovery service
84 $options add_default optServiceAddress "224.4.6.8"
85 $options add_default optServicePort "12344"
86 $options add_default optServiceTTL "16"
87
88 # for the service discovery service
89 $options add_default optComPort "11408"
90
91 # for the active services
92 $options add_default optSpecAS 224.4.5.24/50000/31
93 }
94
95
96 ##############################################################################
97 #
98 # CReplayApplication instproc init { argv } {
99 #
100 # Input:
101 # argv - command line input
102 #
103 # Output:
104 # none
105 #
106 # Description:
107 # Constructor for the object.
108 #
109 ##############################################################################
110 CReplayApplication instproc init { argv } {
111 $self next Replay
112
113
114 # Initiailization of options
115 set options [$self options]
116 $self InitArgs $options
117 $self InitResources $options
118 $options load_preferences "archival replay"
119 set argv [$options parse_args $argv]
120
121
122 # create the sds session object
123 set inetServiceAddr [$options get_option optServiceAddress]
124 set iServicePort [$options get_option optServicePort]
125 set iServiceTTL [$options get_option optServiceTTL]
126
127 $self instvar m_sdsService
128 set m_sdsService [new CSdsService $self $inetServiceAddr $iServicePort \
129 $iServicePort $iServiceTTL]
130
131 # setup the service objects
132 $self instvar m_serviceManager
133 $self instvar m_service
134
135 set iPort [$options get_option optComPort]
136 set m_serviceManager [new CServiceManager "ServiceApp" "Replay" $iPort]
137 $m_serviceManager Attach $self
138
139 }
140
141 ##############################################################################
142 #
143 # CReplayApplication public GetSdsServiceData { } {
144 #
145 # Input:
146 # none
147 #
148 # Output:
149 # the data that the will go out to the sds system
150 #
151 # Description:
152 # This is a callback function for the service discovery system. Need to
153 # return the data that will go out to the sds system. So far there are
154 # three fields with their values
155 #
156 ##############################################################################
157 CReplayApplication public GetSdsServiceData { } {
158 set options [$self options]
159 set iComPort [$options get_option optComPort]
160 set hostname [exec hostname]
161
162 set location "Locationless"
163 set type "Archive Replay"
164
165 set data [list "UPDATE:" [concat $hostname $iComPort] \
166 [list [list "LOCATION:" $location] \
167 [list "TYPE:" $type]]]
168
169 return $data
170 }
171
172 ##############################################################################
173 #
174 # CReplayApplication instproc NewConnection { service }
175 #
176 # Input:
177 # service - the new service that got connected
178 #
179 # Output:
180 # 1 - if handling this service
181 # 0 - otherwise
182 #
183 # Description:
184 # A call back function for the service manager. This function will be called
185 # when a new connection has just been noticed by the service manager
186 #
187 ##############################################################################
188 CReplayApplication instproc NewConnection { service } {
189 $self instvar m_service
190
191 set m_service $service
192
193 # Add the service calls
194 $m_service MapMessage "SYN_SERVICE_IMAGE" $self SynServiceImage
195 $m_service MapMessage "GET_UI_WINDOW" $self GetUIWindow
196 $m_service MapMessage "START_REPLAY" $self StartReplay
197 $m_service MapMessage "CLOSE_LINK" $self CloseService
198
199 return 1
200 }
201
202 ##############################################################################
203 #
204 # CReplayApplication public SynServiceImage { service arguments } {
205 #
206 # Input:
207 # service - the service that called this function
208 # arguments - the arguments associated with this call
209 #
210 # Output:
211 # none
212 #
213 # Description:
214 # This is called by the remote service client when it wants the image or text
215 # to display the service. The simple protocol goes as such:
216 # type type_dependent_arguments. The type could be text and it's argument
217 # the ascii of title. It could also be image and be a bitmap of the image
218 #
219 ##############################################################################
220 CReplayApplication public SynServiceImage { service arguments } {
221 $service Send "SYN_SERVICE_IMAGE" "text Replay"
222 }
223
224
225 ##############################################################################
226 #
227 # CReplayApplication public GetUIWindow { service arguments } {
228 #
229 # Input:
230 # service - the service that called this function
231 # arguments - the arguments associated with this call
232 #
233 # Output:
234 # none
235 #
236 # Description:
237 # This is called by the remote service client when it wants the code
238 # to make the window. It should send back the code to build the window.
239 # There are two things that are assumed to be set by the client. One is
240 # winFrame the window to draw into. Another is service, which is the
241 # m_service object to send back to yourself.
242 #
243 ##############################################################################
244 CReplayApplication public GetUIWindow { service arguments } {
245 set cmd ""
246
247 append cmd "regsub -all -- {\\\.} \$winFrame {_} __name \n"
248
249 append cmd "wm title \$winFrame \"Replay Manager\" \n"
250
251 append cmd "frame \$winFrame.catname\n"
252 append cmd "pack \$winFrame.catname -side top -fill x -expand 1\n"
253
254 append cmd "label \$winFrame.catname.label -text \"Archive Name:\" \n"
255 append cmd "pack \$winFrame.catname.label -side left \n"
256 append cmd "global catnameEntry\$__name \n"
257 append cmd "set catnameEntry\$__name \
258 \"/n/vid22/mars/cs298-5/opening/cat.ctg\" \n"
259
260 append cmd "entry \$winFrame.catname.entry \
261 -textvariable catnameEntry\$__name -relief sunken \n"
262 append cmd "pack \$winFrame.catname.entry -side right -fill x -expand 1 \n"
263
264 append cmd "frame \$winFrame.audioSession\n"
265 append cmd "pack \$winFrame.audioSession -side top -fill x -expand 1\n"
266
267 append cmd "label \$winFrame.audioSession.label -text \
268 \"Audio Session:\" \n"
269 append cmd "pack \$winFrame.audioSession.label -side left \n"
270 append cmd "global audioSessionEntry\$__name \n"
271 append cmd "set audioSessionEntry\$__name 233.0.25.02/22446\n"
272 append cmd "entry \$winFrame.audioSession.entry \
273 -textvariable audioSessionEntry\$__name -relief sunken \n"
274 append cmd "pack \$winFrame.audioSession.entry -side right \
275 -fill x -expand 1 \n"
276
277 # need to get the contact info and also options
278 append cmd "frame \$winFrame.command \n"
279 append cmd "pack \$winFrame.command -side top -fill x -expand 1\n"
280
281 append cmd "button \$winFrame.command.closeButton -text Close \
282 -command \"destroy \$winFrame\" \n"
283 append cmd "pack \$winFrame.command.closeButton -side right\n"
284
285 append cmd "button \$winFrame.command.startButton -text Start \
286 -command \"global catnameEntry\$__name; global audioSessionEntry\__name; \$service Send START_REPLAY \\\"\$inetMStudioAddr \$iMStudioPort \$inetClientAddr \$iClientPort \\\$catnameEntry\$__name \\\$audioSessionEntry\$__name \\\" \"\n"
287 append cmd "pack \$winFrame.command.startButton -side right\n"
288
289 $service Send "GET_UI_WINDOW" $cmd
290 }
291
292
293 ##############################################################################
294 #
295 # CReplayApplication public StartReplay { service arguments } {
296 #
297 # Input:
298 # service - the service that called this function
299 # arguments - the arguments associated with this call
300 #
301 # Output:
302 # none
303 #
304 # Description:
305 # This is called by the remote service client when it wants the start the
306 # replay.
307 #
308 ##############################################################################
309 CReplayApplication public StartReplay { service arguments } {
310
311 # set up the arguments and launch the replay proxy
312 set options [$self options]
313 set specAS [$options get_option optSpecAS]
314
315 # set strExec "dc-replayproxy-5.0b3"
316 set strExec "dc-replayproxy"
317
318 append strExec " -sas $specAS $arguments"
319
320 # puts "strExec - $strExec"
321
322 if { [catch "eval exec $strExec &" pid] != 0 } {
323 puts "replay got an error starting the proxy: check the path"
324 exit 0
325 }
326 }
327
328
329 ##############################################################################
330 #
331 # CReplayApplication public CloseService { service arguments }
332 #
333 # Input:
334 # service - the service that called this function
335 # arguments - the arguments associated with this call
336 #
337 # Output:
338 # none
339 #
340 # Description:
341 # This is called by the remote service client closes the service link.
342 #
343 ##############################################################################
344 CReplayApplication public CloseService { service arguments } {
345 exit
346 }
347
348
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.