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

Open Mash Cross Reference
mash/tcl/nsdr/application-nsdr.tcl

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

  1 # application-nsdr.tcl --
  2 #
  3 #       Primary tcl file for nsdr.  Defines defaults and assembles GUI.
  4 #
  5 # Copyright (c) 1997-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 ErrorWindow NsdrUI UserApplication \
 32     ScopeZone Program ProgramSource ProgramSource/SAP \
 33     ProgramSource/SAP/MeGa ProgramSource/Proxy \
 34     AddressAllocator/SAP ProgramAnnouncer
 35 
 36 # Application object for the Nsdr session directory tool.
 37 # Takes care of random stuff not handled by the other application
 38 # components.
 39 Class NsdrApplication -superclass Application
 40 
 41 #
 42 NsdrApplication public init argv {
 43 
 44     $self next nsdr
 45 
 46     global env
 47     if {![info exists env(HOME)]} {
 48         new ErrorWindow {Your HOME environment variable must be set.}
 49         exit 1
 50     }
 51 
 52     label .label
 53     set defaultLabelFont [.label cget -font]
 54     destroy .label
 55 
 56     set o [$self options]
 57     $self init_args $o
 58     $self init_resources $o
 59     set argv [$o parse_args $argv]
 60 
 61         # Source the user's hook file if it exists. The function
 62         # user_hook, which may be defined in this file, will be
 63         # called at the end of init.
 64         if {[$o get_option userhookFile] != ""} {
 65                 if {[file isfile [$o get_option userhookFile]] && \
 66                         [file readable [$o get_option userhookFile]]} {
 67                         source [$o get_option userhookFile]
 68                 } else {
 69                         puts stderr "Unable to source \"[$o get_option userhookFile]\". Not a file or not readable."
 70                 }
 71         }
 72 
 73     if {$argv!=""} {
 74         set dst [split $argv /]
 75         set n [llength $dst]
 76         if { $n < 2 } {
 77             $self fatal "must specify both address and port in the form addr/port ($s)"
 78         }
 79         set addr [lindex $dst 0]
 80         set port [lindex $dst 1]
 81         set firstchar [string index $addr 0]
 82         if [string match \[a-zA-Z\] $firstchar] {
 83             set s [gethostbyname $addr]
 84             if { $s == "" } {
 85                 $self fatal "cannot lookup host name: $addr"
 86             }
 87             set addr $s
 88         }
 89         if { ![string match \[0-9\]* $port] || $port >= 65536 } {
 90             $self fatal "illegal port '$port'"
 91         }
 92         set octets [split $addr .]
 93         set n [llength $octets]
 94         if { $n != 4 } {
 95             puts "invalid address (not IP4)"
 96             $self fatal "invalid address (not IP4)"
 97         }
 98         set first 1
 99         foreach octet $octets {
100             if {$first == 1} {
101                 if {$octet <224 || $octet >239} {
102                     puts "not in class D multicast"
103                     $self fatal "not in class D multicast"
104                 }
105                 set first 0
106             } else {
107                 if {$octet <0 || $octet>255} {
108                     puts "invalid addr: not 8-byte"
109                     $self fatal "invalid addr: not 8-byte"
110                 }
111             }
112         }
113         $o add_default SAPaddress $addr
114         $o add_default SAPport $port
115     }
116 
117     # nsdr takes a while to start up so we'll give the user some feedback.
118     wm withdraw .
119     toplevel .startup
120     wm title .startup [winfo name .]
121     label .startup.label -text {Starting up...} -font $defaultLabelFont
122     pack .startup.label -fill both -expand true
123     update
124 
125     $self init_local
126     # $self init_confbus
127 
128     UserApplication init_apps
129     $self init_ui
130     $self init_sap
131     $self init_proxy
132     $self init_mega
133 
134     $self instvar ui_
135     if {[llength [$ui_ set sources_]] == 0} {
136         puts stderr "No program sources..."
137         exit 1
138     }
139 
140     $self user_hook
141 
142     destroy .startup
143     wm deiconify .
144 }
145 
146 NsdrApplication instproc init_args o {
147         $o register_option -a extraAppFiles
148         $o register_option -u userhookFile
149         $o register_option -usemega megaAddrs
150         $o register_option -sloc serviceLocation
151         $o register_option -sapAdr SAPaddress
152         $o register_option -sapPrt SAPport
153         $o register_boolean_option -simple simpleInterface
154         foreach a "SAP Mega Scuba Proxy" {
155                 $o register_boolean_option -use$a use$a
156                 $o register_boolean_option -no$a use$a 0
157         }
158 }
159 
160 NsdrApplication instproc init_resources o {
161     $o load_preferences "nsdr"
162 
163     # defaults
164     global env
165     $o add_default cachedir [file join $env(HOME) .mash nsdr-cache]
166     $o add_default cacheWriteInterval 300
167     $o add_default useSAP 1
168     $o add_default SAPaddress 224.2.127.254
169     $o add_default SAPport 9875
170 
171     $o add_default sapZones 224.2.128.0/17,239.255.0.0/16
172     $o add_default sapTTL 255
173 
174     $o add_default useProxy 0
175     $o add_default proxyLocation quimby.cs.berkeley.edu/12000
176     $o add_default useProxyAnnouncer 0
177 
178     $o add_default simpleInterface 0
179     $o add_default alarmLead 300
180     $o add_default webbrowser xm
181     $o add_default unifiedVic 0
182 
183     set filename [file join $env(HOME) .mash nsdr-apps.tcl]
184     if {![file exists $filename]} {
185         set filename {}
186     }
187     $o add_default appFiles $filename
188 
189     # mega/scuba defaults
190     $o add_default useMega 0
191     $o add_default megaBW 128000
192     $o add_default megaStartupBW 64000
193     $o add_default megaMaxBW 128000
194     $o add_default asCtrl 224.4.5.24/50000/31
195     $o add_default asCtrlBW 20000
196     $o add_default serviceLocation static:sdgw
197 
198     # font stuff (largely stolen from vic)
199     $o add_default foundry adobe
200     set foundry [$o get_option foundry]
201     set helv10 [$self search_font $foundry helvetica medium 10 r]
202     set helv10b [$self search_font $foundry helvetica bold 10 r]
203     set helv10o [$self search_font $foundry helvetica bold 10 o]
204     set helv12b [$self search_font $foundry helvetica bold 12 r]
205     set times14 [$self search_font $foundry times medium 14 r]
206 
207     $o add_default medfont $helv12b
208     $o add_default smallfont $helv10b
209     $o add_default entryFont $helv10
210     $o add_default helpFont $times14
211 
212     option add *Font [$self get_option medfont] startupFile
213     option add *Button.Font [$self get_option smallfont] startupFile
214     option add *Checkbutton.Font [$self get_option smallfont] startupFile
215     option add *Label.Font [$self get_option smallfont] startupFile
216     option add *Listbox.Font [$self get_option smallfont] startupFile
217     option add *Menu.Font [$self get_option smallfont] startupFile
218     option add *Menubutton.Font [$self get_option smallfont] startupFile
219     option add *Message.Font [$self get_option smallfont] startupFile
220     option add *Entry.Font [$self get_option entryFont] startupFile
221 
222     option add *Entry.Background white
223     option add *padX 2
224     option add *padY 2
225 
226     set name [$self get_option nsdrName]
227     set phone [$self get_option nsdrPhone]
228     if {$name == "" || $phone == ""} {
229         $self run_resource_dialog $name $phone
230     }
231 }
232 
233 NsdrApplication private run_resource_dialog {name phone} {
234     set w .form
235     frame $w
236 
237     frame $w.msg -relief ridge
238     label $w.msg.label -font [$self get_option medfont] \
239         -wraplength 4i -justify left \
240         -text "Please specify values for the following resources. \
241 These strings will identify you and give your phone number in \
242 outgoing session announcements that you create.  The values you \
243 enter will be saved in ~/.mash/prefs so you will not have to \
244 re-enter them." -relief ridge
245     pack $w.msg.label -padx 6 -pady 6
246     pack $w.msg -side top
247 
248     foreach i {name phone} {
249         frame $w.$i -bd 2
250         entry $w.$i.entry -relief sunken
251         label $w.$i.label -width 10 -anchor e
252         pack $w.$i.label -side left
253         pack $w.$i.entry -side left -fill x -expand 1 -padx 8
254     }
255     if {"[$self get_option rtpName]" != ""} {
256         $w.name.entry insert end [$self get_option rtpName]
257     }
258     $w.name.label config -text Name:
259     $w.phone.label config -text Phone:
260     pack $w.msg -pady 10
261     pack $w.name $w.phone -side top -fill x
262 
263     frame $w.buttons
264     button $w.buttons.accept -text Accept -command "set dialogDone 1"
265     button $w.buttons.dismiss -text Quit -command "set dialogDone -1"
266     pack $w.buttons.accept $w.buttons.dismiss -side left \
267         -expand 1 -padx 20 -pady 10
268     pack $w.buttons
269     pack $w -padx 10
270 
271     global dialogDone
272     while { 1 } {
273         set dialogDone 0
274         focus $w.name.entry
275         tkwait variable dialogDone
276         if {$dialogDone < 0} {
277             exit 0
278         }
279         set name [string trim [$w.name.entry get]]
280         if { [string length $name] <= 3 } {
281             new ErrorWindow "please enter a reasonable name"
282             continue
283         }
284         set phone [string trim [$w.phone.entry get]]
285         #FIXME
286         if { [string length $phone] <= 10} {
287             new ErrorWindow "please enter a complete phone number"
288             continue
289         }
290         break
291     }
292 
293     $self add_option nsdrName $name
294     $self add_option nsdrPhone $phone
295 
296     global env
297         set mash [file join $env(HOME) .mash]
298     if {![file exists $mash]} {
299         file mkdir $mash
300     }
301     set f [open [file join $mash prefs-nsdr] a+ 0644]
302     puts $f "nsdrName: $name"
303     puts $f "nsdrPhone: $phone"
304     close $f
305 
306     unset dialogDone
307     pack forget $w
308     destroy $w
309 }
310 
311 NsdrApplication instproc init_ui {} {
312     pack [frame .f] -fill both -expand yes
313     $self set ui_ [new NsdrUI .f $self]
314     wm geometry . 300x500
315     wm protocol . WM_DELETE_WINDOW "$self exit"
316 }
317 
318 NsdrApplication instproc init_sap {} {
319     # instantiate SAP source
320     if ![$self yesno useSAP] {
321         return
322     }
323 
324     # FIXME this should eventually use an automatic mechanism
325     #     (e.g., MZAP - draft-ietf-mboned-mzap) to discover
326     #     what scope zones are present.
327     #
328     # FIXME Also need a simple way to figure out SAP bandwidth
329     set zones {}
330     foreach zone [split [$self get_option sapZones] ","] {
331         lappend zones [new ScopeZone $zone]
332     }
333 
334     $self instvar ui_
335     set s [eval new ProgramSource/SAP $ui_ $zones]
336 
337     # eventually this may change to use AddressAllocator/MDHCP
338     # or /AAP or something else.
339     $self instvar allocator_
340     set allocator_ [new AddressAllocator/SAP $s]
341 
342     #
343     $self instvar announcer_
344     set announcer_ [new ProgramAnnouncer $s]
345 
346     $self instvar sources_
347     lappend sources_ $s
348 }
349 
350 NsdrApplication private init_proxy {} {
351     if ![$self yesno useProxy] {
352         return
353     }
354 
355     #FIXME needs lots of work
356     $self instvar sources_ ui_
357     set spec [$self get_option proxyLocation]
358     lappend sources_ [new ProgramSource/Proxy $ui_ $spec]
359 }
360 
361 NsdrApplication instproc init_mega {} {
362     if { [$self get_option megaAddrs] != "" } {
363         $self instvar source_ ui_
364         foreach addr [split [$self get_option megaAddrs] ","] {
365             # FIXME this is only the unicast case.  Need the multicast case.
366             set s [new ProgramSource/SAP/MeGa $ui_ $addr]
367 
368             $self instvar sources_
369             lappend sources_ $s
370         }
371     }
372 }
373 
374 NsdrApplication instproc gourl {url} {
375     set browser [$self get_option webbrowser]
376     catch {exec $browser $url &}
377 }
378 
379 NsdrApplication instproc exit {} {
380     $self instvar sources_
381     foreach s $sources_ {
382         $s shutdown
383     }
384     exit
385 }
386 

~ [ 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.