~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/indiva/services/isap/isap-application.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # application-isap.tcl --
  2 #
  3 #       Application class for isap. Creates remote indiva manager. Make, 
  4 #       remove, and update conference using remote indiva manager.
  5 #     
  6 #
  7 # Copyright (c) 1997-2002 The Regents of the University of California.
  8 # All rights reserved.
  9 #
 10 # Redistribution and use in source and binary forms, with or without
 11 # modification, are permitted provided that the following conditions are met:
 12 #
 13 # A. Redistributions of source code must retain the above copyright notice,
 14 #    this list of conditions and the following disclaimer.
 15 # B. Redistributions in binary form must reproduce the above copyright notice,
 16 #    this list of conditions and the following disclaimer in the documentation
 17 #    and/or other materials provided with the distribution.
 18 # C. Neither the names of the copyright holders nor the names of its
 19 #    contributors may be used to endorse or promote products derived from this
 20 #    software without specific prior written permission.
 21 #
 22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 23 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 25 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 26 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 28 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 30 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32 
 33 import AddressAllocator/SAP ProgramAnnouncer ErrorWindow Dp MashRemoteObject Application \
 34        ScopeZone Program ProgramSource ProgramSource/SAP/Isap 
 35 
 36 
 37 #----------------------------------------------------------------------------------
 38 # Class:
 39 #     IsapApplication
 40 #
 41 # Description:
 42 #   Application object for the Isap session announcement listening tool.
 43 #   Create remote indiva manager. Creates or update conference when session
 44 #   announcement is recieved. Check if conference with that name exist; if
 45 #   yes, append number to name and create conference.
 46 #
 47 # Members:
 48 #   manager_ -- remote indiva manager
 49 #   
 50 #----------------------------------------------------------------------------------
 51 
 52 Class IsapApplication -superclass Application
 53 
 54 #
 55 IsapApplication public init argv {
 56     $self next isap
 57     $self set nprogs_ 0
 58     global env
 59     if {![info exists env(HOME)]} {
 60         puts "Your HOME environment variable must be set."
 61         exit 1
 62     }
 63 
 64     set o [$self options]
 65     $self init_args $o
 66     $self init_resources $o
 67 
 68     set argv [$o parse_args $argv]
 69 
 70         # Source the user's hook file if it exists. The function
 71         # user_hook, which may be defined in this file, will be
 72         # called at the end of init.
 73         # no hookFile when initializing
 74         if {[$o get_option userhookFile] != ""} {
 75                 if {[file isfile [$o get_option userhookFile]] && \
 76                         [file readable [$o get_option userhookFile]]} {
 77                         source [$o get_option userhookFile]
 78                 } else {
 79                         puts stderr "Unable to source \"[$o get_option userhookFile]\". \ 
 80                         Not a file or not readable."
 81                 }
 82         }
 83 
 84     if {$argv!=""} {
 85         # no command line args for now
 86     }
 87     
 88     $self init_imgr
 89     $self init_local
 90     $self init_sap
 91     $self user_hook
 92 
 93 }
 94 
 95 IsapApplication instproc init_args o {
 96         $o register_option -u userhookFile
 97         $o register_option -sloc serviceLocation
 98         $o register_option -imgr imgr
 99 }
100 
101 IsapApplication instproc init_resources o {
102     $o load_preferences "isap"
103 
104     # defaults
105     global env
106     $o add_default cachedir [file join $env(HOME) .mash isap-cache]
107     $o add_default cacheWriteInterval 300
108     $o add_default useSAP 1
109     $o add_default SAPaddress 224.2.127.254
110     $o add_default SAPport 9875
111     
112     
113     $o add_default sapZones 224.2.128.0/17,239.255.0.0/16
114     $o add_default sapTTL 255
115 
116     $o add_default alarmLead 300
117 
118     set filename [file join $env(HOME) .mash isap-apps.tcl]
119     if {![file exists $filename]} {
120         set filename {}
121     }
122     
123     $o add_default appFiles $filename
124     $o add_default imgr "[info hostname]:9500"
125 
126 }
127 
128 #------------------------------------------------------------------------
129 # Method:
130 #  IsapApplication init_imgr
131 # Description:
132 #  creates remote indiva manager
133 #------------------------------------------------------------------------
134 IsapApplication instproc init_imgr {}  {
135     if { [$self get_option imgr] == "" } {
136         puts "No indiva host manager"
137         exit
138     }
139     set list [split [$self get_option imgr] :]
140         set host [lindex $list 0]
141         set port [lindex $list 1]
142     if {[catch {dp_MakeRPCClient $host $port} imgr_rpc]} {
143         puts "WARNING: unable to connect to indiva manager at $host:$port"
144         puts "$imgr_rpc"
145         exit
146     }
147     # Create a remote IndivaManager object.
148     $self instvar manager_
149     set manager_ [new MashRemoteObject $imgr_rpc new IndivaManager]
150 }
151 
152 IsapApplication instproc init_sap {} {
153     # instantiate SAP source
154     
155     #Object has an method to see if this particular object use certain parameters r
156     if ![$self yesno useSAP] {
157         return
158     }
159     # FIXME this should eventually use an automatic mechanism
160     #     (e.g., MZAP - draft-ietf-mboned-mzap) to discover
161     #     what scope zones are present.
162     #
163     # FIXME Also need a simple way to figure out SAP bandwidth
164     set zones {}
165     foreach zone [split [$self get_option sapZones] ","] {
166         lappend zones [new ScopeZone $zone]
167     }
168     
169     set s [eval new ProgramSource/SAP/Isap $self $zones]
170     # eventually this may change to use AddressAllocator/MDHCP
171     # or /AAP or something else.
172 
173     #creates an allocator to see if any address conflicts show up
174     $self instvar allocator_
175     set allocator_ [new AddressAllocator/SAP $s]
176 
177     #
178     #used to announce messages
179     $self instvar announcer_
180     set announcer_ [new ProgramAnnouncer $s]
181 
182     $self instvar sources_
183     lappend sources_ $s
184 }
185 
186 IsapApplication instproc addsource { ps } {
187     puts "isap::addsource([$ps info class]:$ps)"
188 }
189 
190 #---------------------------------------------------------------------
191 # Method:
192 #   IsapApplication addprog
193 # Description:
194 #   Add the new announcement programs to indiva manager by creating a
195 #   new conference. Calls conf_name to create a name for this conference.
196 # Arguments:
197 #   ps -- not used
198 #   p -- the program that contains the session announcement messages
199 #----------------------------------------------------------------------
200 IsapApplication instproc addprog { ps p } {
201     $self instvar manager_
202     set msgs "-sdp"
203     foreach m [$p set msgs_] {
204         lappend msgs [$m set msgtext_]
205     }
206     set name [$self conf_name $p]
207     puts $name
208     if { [catch {$manager_ mkcon $name $msgs} error] } {
209         puts stderr "Can't create conference; $error"
210         return
211     }
212 }
213 
214 #-----------------------------------------------------------------------
215 # Method: 
216 #   IsapApplication removeprog
217 # Description:
218 #   Removes the conference created by indiva manager when conference no
219 #   longer exists.
220 # Arguments:
221 #   ps -- not used
222 #   p -- the program that contains information about this conference
223 #-------------------------------------------------------------------------
224 IsapApplication instproc removeprog { ps p } {
225     $self instvar manager_ 
226     $self instvar conf_names
227     set unique_key [$p unique_key]
228     set name $conf_names(unique_key)
229     if { [catch {$manager_ mkcon "$name\.con"} error] } {
230         puts stderr "Can't remove conference; $error"
231         return
232     }
233     unset $conf_names(unique_key)
234 }
235 
236 IsapApplication instproc updateprog { ps p } {
237     $self removeprog $ps $p 
238     $self addprog $ps $p 
239 }
240 
241 IsapApplication instproc exit {} {
242     $self instvar sources_ 
243     foreach s $sources_ {
244         $s shutdown
245     }
246     exit
247 }
248 
249 #--------------------------------------------------------------------
250 # Method:
251 #   IsapApplication conf_name
252 # Description:
253 #   Checks if a conference with session name already exist. If no append
254 #   0 to the session name and set it as the conference name. If yes, keep
255 #   checking until we find a number to append such that the conference 
256 #   name is not one that is already being used.
257 # Arguments:
258 #   p -- the program that contains the SAP announcement
259 #------------------------------------------------------------------------
260 IsapApplication instproc conf_name { p } {
261     $self instvar manager_ 
262     $self instvar conf_names
263     set unique_key [$p unique_key]      
264     set conf_name [split [string trim [$p field_value s] .]]
265     set conf_name [split $conf_name ": /"]
266     set conf_name [join [join [join $conf_name]] _]
267     set conf_name "/bmrc/Conferences/$conf_name"
268     if { ![$manager_ exists $conf_name\.con] } {
269         set conf_names($unique_key) $conf_name
270         return $conf_name
271     }
272     for { set i 1 } { 1 } { incr i } {
273         if { ![$manager_ exists $conf_name\_$i\.con] } {
274             set conf_names($unique_key) $conf_name\-$i
275             return $conf_name\_$i
276         }
277     }
278 }
279 
280 
281 
282 
283 
284 
285 
286 
287 
288 
289 
290 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.