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

Open Mash Cross Reference
mash/tcl/degas/degasclient/alm-degas-client.tcl

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

  1 import AnnounceListenManager
  2 
  3 Class AnnounceListenManager/DegasClient -superclass {AnnounceListenManager}
  4 
  5 
  6 #------------------------------------------------------------------

  7 # AnnouceListenManager/DegasClient::init

  8 #

  9 # purpose : Constructor for a AnnouceListenManager/DegasClient obj

 10 # input   : spec - Specifies where the ALM should announce and listen.

 11 #                  Format is <ipaddr>/<port> or <port>.

 12 #           mtu  - Maximum size of a message.  A buffer of this size

 13 #                  will be allocated for storing message.

 14 # output  : none

 15 #------------------------------------------------------------------

 16 
 17 AnnounceListenManager/DegasClient public init {agent controller spec mtu} {
 18     
 19     $self next $spec $mtu
 20 
 21     # member : prog_filename_ 

 22     # specifies the filename of the program to submit to 

 23     # the server to run.

 24 
 25     $self instvar prog_filename_
 26     set prog_filename_ ""
 27 
 28     # member : announcement_ 

 29     # stores the message to announce to the server.

 30 
 31     $self instvar announcement_
 32     set announcement_ ""
 33 
 34     # member : after_id_

 35     # this is the id of the current pending "after" event.

 36     # It can be used to cancel a scheduled announcement.

 37     
 38     $self instvar after_id_
 39     set after_id_ 0
 40 
 41     $self instvar agent_
 42     set agent_ $agent
 43 
 44     $self instvar controller_
 45     set controller_ $controller
 46 
 47         $self timer "DCP client action request" [new Timer/Periodic 5]
 48         $self start "DCP client action request"
 49 }
 50 
 51 
 52 #------------------------------------------------------------------

 53 # AnnouceListenManager/DegasClient::recv_announcement

 54 #

 55 # purpose : This is called whenever an announcement is received.

 56 # input   : addr - the ip address where this message is from.

 57 #           port - the port where this message is from

 58 #           m    - the announcement message itself

 59 #           l    - length of the message.

 60 # output  : none

 61 #------------------------------------------------------------------

 62 
 63 AnnounceListenManager/DegasClient private recv_announcement {addr port m l} {
 64     $self log "recv announcement from $addr $port {$m}"
 65     # Check magic word.

 66     set magic_word [lindex $m 0]
 67     if {$magic_word != "DCP"} {
 68         # This message is not for me.

 69         return
 70     }
 71 
 72     # Check message type (from server ? or client ?)

 73     set type [lindex $m 1]
 74     set m [lrange $m 2 end]
 75     if {$type == "server"} {
 76         $self handle_server_message $addr $port $m
 77     } elseif {$type == "client"} {
 78         $self handle_client_message $addr $port $m
 79     }
 80 }
 81 
 82 
 83 #------------------------------------------------------------------

 84 # AnnounceListenManager/DegasClient::handle_client_message

 85 #

 86 # purpose : Handle message received from other client.  Do nothing

 87 #           for now.  Not sure if we care what other clients is 

 88 #           saying.

 89 # input   : addr,port - the client that announce this message.

 90 #           m - the message itself.

 91 # output  : none

 92 #------------------------------------------------------------------

 93 
 94 AnnounceListenManager/DegasClient private handle_client_message {addr port m} {
 95     return
 96 }
 97 
 98 
 99 #------------------------------------------------------------------

100 # AnnounceListenManager/DegasClient::handle_server_message

101 #

102 # purpose : Handle message received from server.  

103 # input   : addr,port - the client that announce this message.

104 #           m - the message itself.

105 # output  : none

106 #------------------------------------------------------------------

107 
108 AnnounceListenManager/DegasClient private handle_server_message {addr port m} {
109 
110     set key [lindex $m 0]
111     switch $key {
112         "service" {
113             $self instvar snet_
114             set service_addr [lindex $m 1]
115             set service_port [lindex $m 2]
116             set my_addr [localaddr]
117             set my_port [$snet_ localsport]
118             if {$service_addr == $my_addr && $service_port == $my_port} {
119                 $self instvar agent_
120                 $self instvar controller_
121                 set in_session_spec [lindex $m 3]
122                 $agent_ reset [new AddressBlock $in_session_spec]
123 #                               set log [open client.log a]

124 #                               puts $log "receiving from $in_session_spec"

125 #                               close $log

126                 $controller_ open $addr [lindex $m 4]
127             }
128             $self stop
129         }
130     }
131 }
132 
133 
134 #------------------------------------------------------------------

135 # AnnounceListenManager/DegasClient::create_annoucement

136 #

137 # purpose : Create a new message.  This message can then be send

138 #           by calling "announce".

139 # input   : 

140 # return  : A new message of the following format :

141 #           {

142 #               DCP

143 #               client

144 #               input_session_spec   <addr>/<port>/<ttl>

145 #               control_channel_port <port>

146 #               sources              <list of sources>

147 #               max_num_of_sources   <int> or "*"

148 #               init_callback        <program>

149 #               recv_frame_callback  <program>

150 #               new_source_callback  <program>

151 #               del_source_callback  <program>

152 #               destroy_callback     <program>

153 #           }

154 #           This message is read from file whose filename is specified 

155 #           with -df option or entered from GUI.

156 #------------------------------------------------------------------

157 
158 AnnounceListenManager/DegasClient public create_announcement {} {
159     $self instvar prog_filename_
160     $self instvar announcement_
161 
162     if {$announcement_ == ""} {
163             if {$prog_filename_ == ""} {
164                     puts stderr "no program filename specified. quiting."
165                     exit
166             }
167             set f [open $prog_filename_ r]
168             set announcement_ [$self parse_degas_program $f]
169     close $f
170     }
171     return $announcement_
172 }
173 
174 
175 #------------------------------------------------------------------

176 # AnnouceListenManager/DegasClient::run

177 #

178 # purpose : Start the AnnounceListenManager.  This simply calls

179 #           create_announcement and annouce repeatedly, with

180 #           period seconds between them.

181 # input   : period - Interval between two announcements.

182 # return  : none

183 #------------------------------------------------------------------

184 
185 AnnounceListenManager/DegasClient public run {period} {
186     $self instvar after_id_
187     $self instvar announcement_
188 
189     puts stderr "announcing"
190         $self announce "$announcement_"
191     set cmd "
192         $self announce \{$announcement_\}
193         $self run $period
194         "
195         set after_id_ [after $period $cmd]
196 }
197 
198 
199 #------------------------------------------------------------------

200 # AnnouceListenManager/DegasClient::stop

201 #

202 # purpose : Stop the AnnounceListenManager.  This simply calls

203 #           cancelled the current scheduled announcement.

204 # input   : none

205 # return  : none

206 #------------------------------------------------------------------

207 
208 AnnounceListenManager/DegasClient public stop {} {
209     $self instvar after_id_
210 
211     if {[info exists after_id_]} {
212         after cancel $after_id_ 
213     } else {
214         puts stderr "ALM is not running."
215     }
216 }
217 
218 
219 #------------------------------------------------------------------

220 # AnnounceListenManager/DegasClient::log

221 #

222 # purpose : create a log message of the server.  This can be either

223 #           to the screen or to a file.

224 # input   : msg - a message to log

225 # output  : none

226 #------------------------------------------------------------------

227 
228 AnnounceListenManager/DegasClient private log {msg} {
229 #    set log [open LOGFILE a+]

230 #    puts $log "$msg"

231 #    close $log

232 }
233 
234 
235 #------------------------------------------------------------------

236 # AnnounceListenManager/DegasClient::parse_degas_program

237 #

238 # purpose : parse the degas program given the file.  this function

239 #           basically remove the comments and add the header for 

240 #           announcement.

241 # input   : file - the file that contains the program

242 # output  : a list of strings that represents the content of the 

243 #           program.  

244 #------------------------------------------------------------------

245 
246 AnnounceListenManager/DegasClient private parse_degas_program {f} {
247     set result "DCP\nclient\naction new\n"
248     while {![eof $f]} {
249         set line [gets $f]
250         if {![regexp {^[\ \t]*#.*} $line]} {
251             append result "$line\n"
252         } else {
253         }
254     }
255     return $result
256 }
257 

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