1 # application-dc.tcl --
2 #
3 # Base of the DC app. Contains a service manager for talking to the
4 # SDS. Creates UI and parses command line options.
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 Observer
34 import WidgetResourceInitializer
35 import FontInitializer
36 import DcBroadcastAgent
37 import DcStudioAgent
38 import CDcUI
39 import CServiceManager
40 import CService
41 import CDcSession
42 import DcApi
43
44 #-----------------------------------------------------------------------------
45 # Class:
46 # DcObserver
47 #
48 # Description:
49 # This is an observer that gets attached to the StudioAgent, and
50 # get notified when events happen. In particular, we are interested
51 # in format change events (trigger_format{}).
52 #
53 # Members:
54 # ui_ -- the CDcUI object.
55 # agent_ -- the DcStudioAgent we are attached to.
56 #-----------------------------------------------------------------------------
57 Class DcObserver -superclass Observer
58
59 #-----------------------------------------------------------------------------
60 # Method:
61 # DcObserver init
62 #
63 # Arguments:
64 # ui -- the CDcUI object.
65 # agent -- the DcStudioAgent we are attached to.
66 #
67 # Description:
68 # Initialize members.
69 #-----------------------------------------------------------------------------
70 DcObserver instproc init {ui agent} {
71 $self next
72 $self instvar agent_ ui_
73
74 set agent_ $agent
75 set ui_ $ui
76 }
77
78
79 #-----------------------------------------------------------------------------
80 # Method:
81 # DcObserver trigger_format
82 # DcObserver decoder_changed
83 #
84 # Arguments:
85 # src -- the Source/RTP object whose format has changed.
86 #
87 # Description:
88 # 1. Tell the agent to "reactivate" the $src (removes old decoder,
89 # creates new decoder, set the source of the decoder). 2. Tell the
90 # UI to reattach the source (set the targets of the decoder to
91 # various renderers).
92 #
93 #-----------------------------------------------------------------------------
94 DcObserver instproc trigger_format {src} {
95 $self instvar agent_ ui_
96 $agent_ reactivate $src
97 $ui_ reattach $src
98 }
99
100 DcObserver instproc decoder_changed {src} {
101 $self instvar agent_ ui_
102 $agent_ reactivate $src
103 $ui_ reattach $src
104 }
105
106
107 #-----------------------------------------------------------------------------
108 # Class:
109 # DcApplication
110 #
111 # Description:
112 # Main application class that is responsible for creating everything
113 # else.
114 #
115 # Members:
116 # sds_session_ -- The session for SDS protocol.
117 # bcast_agent_ -- The VideoAgent responsible for broadcast session.
118 # studio_agent_ -- The VideoAgent responsible for studio session.
119 # service_mgr_ -- The service manager object for managing connections
120 # to services.
121 # ui_ -- The DcUI object that encapsulates all the UI
122 # components of this application.
123 #
124 #-----------------------------------------------------------------------------
125 Class DcApplication -superclass RTPApplication
126
127 DcApplication instproc init { framePath argv } {
128 $self next "dc"
129
130 # Initialization of variables and resources.
131 set options [$self options]
132 $self init_arguments $options
133 $self init_resources $options
134 $options load_preferences "rtp dc"
135 set argv [$options parse_args $argv]
136 $self check_rtp_sdes
137
138 # create the discovery service session
139 $self instvar sds_session_
140 set addr [$options get_option optServiceAddress]
141 set port [$options get_option optServicePort]
142 set ttl [$options get_option optServiceTTL]
143 set sds_session_ [new CDcSession $addr $port $port $ttl]
144 $sds_session_ StartQuery
145
146 # create the broadcast agent
147 $self instvar bcast_agent_
148 set addr [$options get_option optBroadcastAddress]
149 set port [$options get_option optBroadcastPort]
150 set ttl [$options get_option optBroadcastTTL]
151 set bcast_agent_ [new DcBroadcastAgent $self $addr $port $ttl]
152 puts "BroadCast to $addr/$port/$ttl"
153
154 # create the Studio agent
155 $self instvar studio_agent_
156 set addr [$options get_option optMStudioAddress]
157 set port [$options get_option optMStudioPort]
158 set ttl [$options get_option optMStudioTTL]
159 set studio_agent_ [new DcStudioAgent $self $addr $port $ttl \
160 [$bcast_agent_ get_switcher]]
161
162 # create the service manager
163 $self instvar service_mgr_
164 if {[catch {new CServiceManager "ClientApp" "DC" 0} service_mgr_]} {
165 puts "ERROR: dc: unable to create service manager."
166 puts "$service_mgr_"
167 exit
168 }
169 $service_mgr_ Attach $self
170
171 # the ui stuff here
172 $self instvar ui_
173 set ui_ [new CDcUI $self]
174 $ui_ build_ui $framePath
175
176 $studio_agent_ attach [new DcObserver $ui_ $studio_agent_]
177
178 # by this time the UI has been built, so we can init the API object
179 $self instvar dcapi_
180 set apiPort [$options get_option apiPort]
181 set dcapi_ [new DcApi $self $ui_ $apiPort]
182 }
183
184 DcApplication instproc init_arguments { options } {
185 $options register_option -t defaultTTL
186 $options register_option -r remoteHosts
187
188 # for Media Studio Session
189 $options register_option -ma optMStudioAddress
190 $options register_option -mp optMStudioPort
191 $options register_option -mt optMStudioTTL
192
193 # for Broadcast Session
194 $options register_option -ba optBroadcastAddress
195 $options register_option -bp optBroadcastPort
196 $options register_option -bt optBroadcastTTL
197
198 # for the service discovery service
199 $options register_option -sa optServiceAddress
200 $options register_option -sp optServicePort
201 $options register_option -st optServiceTTL
202
203 # for remote communcation
204 $options register_option -cp optComPort
205
206 # for the RPC Api server
207 $options register_option -apip apiPort
208 }
209
210 DcApplication instproc init_resources { options } {
211
212 new WidgetResourceInitializer
213 new FontInitializer [$self options]
214
215 # for Media Studio Session
216 $options add_default optMStudioAddress "224.1.2.3"
217 $options add_default optMStudioPort "12344"
218 $options add_default optMStudioTTL "4"
219
220 # for Broadcast Session
221 $options add_default optBroadcastAddress "224.1.2.4"
222 $options add_default optBroadcastPort "12344"
223 $options add_default optBroadcastTTL "8"
224
225 # for the service discovery service
226 $options add_default optServiceAddress "224.4.6.8"
227 $options add_default optServicePort "12344"
228 $options add_default optServiceTTL "16"
229
230 # for remote communcation
231 $options add_default optComPort "12344"
232
233 # for the RPC Api server
234 $options add_default apiPort "6907"
235 }
236
237
238 DcApplication instproc destroy { } {
239 $self instvar service_mgr_
240 delete $service_mgr_
241 }
242
243 #---------------------------------------------------------------------------
244 #
245 # Method:
246 # DcApplication NewConnection
247 #
248 # Arguments:
249 # service -- the newly connected service object
250 #
251 # Description:
252 # This is a callback function for the service manager.
253 # It will be called whenever a new connection is made
254 # The service will have attributes to it that will
255 # indicate which agent object it should go to.
256 #
257 #---------------------------------------------------------------------------
258 DcApplication public NewConnection { service } {
259 set szType [$service set m_szType]
260
261 switch -exact -- $szType {
262 VideoService {
263 $self instvar ui_
264 set uiThumbnailFrame [$ui_ set m_uiThumbnailFrame]
265 $uiThumbnailFrame NewConnection $service
266 }
267 }
268 }
269
270
271 #---------------------------------------------------------------------------
272 # Method:
273 # DcApplication get_studio_agent
274 # DcApplication get_bcast_agent
275 # DcApplication get_sds_session
276 #
277 # Description:
278 # Return the studio agent, broadcast agent and SDS session respectively.
279 #---------------------------------------------------------------------------
280 DcApplication instproc get_studio_agent {} {
281 $self instvar studio_agent_
282 return $studio_agent_
283 }
284 DcApplication instproc get_bcast_agent {} {
285 $self instvar bcast_agent_
286 return $bcast_agent_
287 }
288 DcApplication instproc get_sds_session {} {
289 $self instvar sds_session_
290 return $sds_session_
291 }
292
293
294 #---------------------------------------------------------------------------
295 # Method:
296 # DcApplication new_service
297 #
298 # Description:
299 # Call the service manager to create a new service for $addr/$port. The
300 # new service is returned.
301 #---------------------------------------------------------------------------
302 DcApplication instproc new_service {addr port} {
303 $self instvar service_mgr_
304 if {[catch {$service_mgr_ NewService $addr $port} service]} {
305 puts stderr "WARNING: unable to connect to service at $addr/$port"
306 return ""
307 } else {
308 return $service
309 }
310 }
311
312 #---------------------------------------------------------------------------
313 # Method:
314 # DcApplication get_service_spec
315 #
316 # Description:
317 # Ask the service manager to return textual information about
318 # the current socket.
319 #---------------------------------------------------------------------------
320 DcApplication instproc get_service_spec {} {
321 $self instvar service_mgr_
322 return [$service_mgr_ GetSpec]
323 }
324
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.