1 # application-rvic-cl.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1998-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 RvicClientUI RendezvousManager
32
33 #
34 # application wrapper for RvicClientUI -- deal with cmd line
35 # args and spawn it appropriately
36 #
37 Class RvicClientApp -superclass Application
38
39
40 # start up a RvicClientUI. Three init styles:
41 # <br> 1) -ctrl `ctrl_addr_spec' -- attaches to server at
42 # `ctrl_addr_spec' directly
43 # <br> 2) -rendez `rendez_addr_spec' -- listens for any server on
44 # `rendez_addr_spec' and attaches to whatever is found
45 # <br> 3) -rendez `rendez_addr_spec' `session_addr_spec' -- attaches to
46 # a server connected to video session `session_addr_spec' by
47 # listening on `rendez_addr_spec'
48 #
49 RvicClientApp public init {argv} {
50 $self next rvicClient
51 $self instvar rvMgr_
52
53 set o [$self options]
54 $o register_option -rendez rendezSpec
55 $o register_option -ctrl ctrlSpec
56 #$o add_default rendezSpec 230.5.6.7/8888
57 set argv [$o parse_args $argv]
58
59 if {[llength $argv] > 1} {
60 $self show_usage
61 }
62
63
64 set ctrl [$self get_option ctrlSpec]
65 if {$ctrl == ""} {
66 # need to listen for and find ctrl address
67 set rendez [$self get_option rendezSpec]
68 if {$rendez == ""} {
69 $self show_usage
70 } else {
71 set rvMgr_ [new RendezvousManager $rendez]
72 set session_spec ""
73 if {[llength $argv] == 1} {
74 # the arg is the session address
75 # which this RvicClient wants to find a
76 # RvicServer for
77 set session_spec $argv
78 }
79 set ctrl [$self find_ctrl_addr $session_spec]
80 if {$ctrl == ""} {
81 puts "Error: Timeout occured: No RvicServer can be found"
82 exit
83 } else {
84 puts "RvicServer found at addr $ctrl... connecting."
85 }
86 }
87 }
88
89 set ui_ [new RvicClientUI "" $ctrl]
90
91 }
92
93 #
94 RvicClientApp private find_ctrl_addr {{session ""}} {
95 $self instvar rvMgr_ listen_timer_
96 if ![info exists listen_timer_] {set listen_timer_ 0}
97
98 set query "will-provide: & mash-object=RemoteVicApplication"
99 if {$session != ""} {
100 append query " & spec=$session"
101 }
102 set response [$rvMgr_ query $query]
103 if {$response == ""} {
104 if {$listen_timer_ > 12000} {
105 return ""
106 }
107 incr listen_timer_ 3000
108 puts "Can't find an RvicServer... still trying..."
109 update
110 after 3000
111 update
112 return [$self find_ctrl_addr $session]
113 } else {
114 unset listen_timer_
115 set ctrl [$response get_field ctrlspec]
116 return $ctrl
117 }
118 }
119
120
121 # print usage info and exit
122 RvicClientApp private show_usage {} {
123 global argv0
124 puts "Usage:"
125 puts " $argv0 -ctrl ctrl_addr_spec"
126 puts " $argv0 -rendez rendez_addr_spec"
127 puts " $argv0 -rendez rendez_addr_spec session_addr_spec"
128 set o [$self options]
129 foreach arg [$o arg_info] {
130 puts $arg
131 }
132 exit
133 }
134
135
136
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.