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

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

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

  1 # source-sap.tcl --
  2 #
  3 #       Handles creation, and transmission, of a SAP announcement
  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 ProgramSource AnnounceListenManager Timer
 32 
 33 Class Timer/Adaptive/SAP -superclass Timer/Adaptive
 34 
 35 #alm is announcelistenmanager
 36 Timer/Adaptive/SAP public init { alm } {
 37         $self set alm_ $alm
 38         $self next
 39 }
 40 
 41 
 42 Timer/Adaptive/SAP private adapt {interval} {
 43         $self instvar alm_
 44         return [expr 1000*[$alm_ interval 1]]
 45 }
 46 
 47 
 48 # Used privately by ProgramSource/SAP/Isap.
 49 #--------------------------------------------------------------------------
 50 # Class:
 51 #   AnnounceListenManager/SAP/Isap
 52 # Description:
 53 #   An child of AnnounceListenManager/SAP. When an announcement is recieved,
 54 #   calls the recv method in ProgramSource/SAP/Isap to check the announcement.
 55 # ----------------------------------------------------------------------------
 56 Class AnnounceListenManager/SAP/Isap -superclass AnnounceListenManager/SAP
 57 
 58 #
 59 AnnounceListenManager/SAP/Isap public init {s mtu scope} {
 60         set ttl [$self get_option sapTTL]
 61         set spec "[$scope sapAddr]/none/$ttl"
 62         $self next $spec $mtu
 63 
 64         $self set bw_ [$scope bw]
 65         $self set s_ $s
 66         $self set avgsize_ 500
 67         $self set nsrcs_ 0
 68 }
 69 
 70 #
 71 AnnounceListenManager/SAP/Isap public destroy {} {
 72         $self next
 73 }
 74 
 75 #------------------------------------------------------------------------------
 76 #Method:
 77 # AnnounceListenManager/SAP/Isap recv_announcemnet
 78 #Description:
 79 # Calls on ProgramSource/SAP/Isap recv when an announcement is recieved
 80 #Parameters:
 81 # args -- the sap annoncement text
 82 #------------------------------------------------------------------------------
 83 AnnounceListenManager/SAP/Isap private recv_announcement args {
 84         $self instvar s_
 85         eval $s_ recv $self $args
 86 }
 87 
 88 
 89 AnnounceListenManager/SAP/Isap public sample_size {size} {
 90         $self instvar avgsize_
 91         set avgsize_ [expr $avgsize_ + ($size-$avgsize_)>>3]
 92 }
 93 
 94 
 95 AnnounceListenManager/SAP/Isap public incrnsrcs {n} {
 96         $self instvar nsrcs_
 97         incr nsrcs_ $n
 98 }
 99 
100 
101 AnnounceListenManager/SAP/Isap public interval {rand} {
102         $self instvar avgsize_ nsrcs_ bw_
103 
104         set i [expr 8 * $avgsize_ * $nsrcs_ / $bw_]
105         if {$rand != 0} {
106                 # random in U[2/3,4/3] as per SAP spec
107                 set r1 [expr [random]/double(0x7fffffff)]
108                 set r2 [expr ($r1*2.0/3.0) + 2.0/3.0]
109                 set i [expr int($i*$r2)]
110         }
111         #FIXME
112         if {$i < 5} {
113                 set i 5
114         }
115         return $i
116 }
117 
118 
119 AnnounceListenManager/SAP/Isap public start {msg} {
120         $self instvar nsrcs_
121         incr nsrcs_
122         $self timer $msg [new Timer/Adaptive/SAP $self]
123         $self next $msg
124 }
125 
126 
127 AnnounceListenManager/SAP/Isap private send_announcement {msg} {
128         set text [$msg set msgtext_]
129         $self sample_size [string length $text]
130         $self announce $text
131 }
132 
133 
134 # Retrieves program descriptions via the Session Announcement
135 # Protocol (SAP).
136 Class ProgramSource/SAP/Isap -superclass ProgramSource
137 #---------------------------------------------------------------------
138 # Class:
139 #   ProgramSource/SAP/Isap
140 # Description:
141 #   Initializes a new object.  <i>ui</i> is passed on to
142 #   ProgramSource::init.  <i>bw</i> is the aggregate bandwidth
143 #   allocate to the SAP channel (which is used for determining
144 #   the timeout interval as well as for announcing new programs).
145 #   <i>args</i> contains a list of  multicast scope zones
146 #   (e.g., 224.2.128.0/17 for global sap) within which this
147 #   object should listen for SAP announcements.
148 #----------------------------------------------------------------------
149 ProgramSource/SAP/Isap public init {ui args} { 
150         $self next $ui
151  
152         $self instvar scopes_ addrs_ cache_ announce_file_
153         set scopes_ {}
154         set addrs_ {}
155         foreach scope $args {
156                 lappend scopes_ $scope
157                 set al [new AnnounceListenManager/SAP/Isap $self 2048 $scope]
158                 lappend addrs_ $al
159         }
160         #FIXME need a way to disable this
161         set dir [$self get_option cachedir]
162         if {![info exists cache_] && $dir != ""} {
163                 set o [$self options]
164                 set addr [$o get_option SAPaddress]
165                 set cache_ [file join $dir global-$addr]
166         }
167         $self readcache
168         set write_interval [$self get_option cacheWriteInterval]
169         if {$write_interval != ""} {$self periodic-writecache $write_interval }
170 
171         #FIXME
172 #       set a [lindex $addrs_ 0]
173 #       if {$a == ""} {
174 #               set announce_file_ ""
175 #       } else {
176 #               set if [[$a set snet_] interface]
177 #               set announce_file_ [file join $dir announce-$if]
178 #       }
179 #
180 #       if [file readable $announce_file_] {
181 #               $self instvar sdp_
182 #
183 #               set fp [open $announce_file_ r]
184 #               set msgs [$sdp_ parse [read $fp]]
185 #               close $fp
186 #
187 #               file delete $announce_file_
188 #
189 #               foreach m $msgs {
190 #                       set p [new Program $m]
191 #                       $self announce $p
192 #               }
193 #       }
194 }
195 
196 #---------------------------------------------------------------------
197 #Method:
198 # ProgramSource/SAP/Isap displayNames
199 #Description:
200 # Print the name of all the programs that has been recieved
201 #---------------------------------------------------------------------
202 ProgramSource/SAP/Isap instproc displayNames {} {
203         $self instvar progs_
204         foreach x [array names progs_] {
205                 puts $x
206         }
207 }
208 
209 #
210 ProgramSource/SAP/Isap public destroy {} {
211         $self next
212         $self instvar addrs_
213         foreach a $addrs_ { delete $a }
214 }
215 
216 # Used to set the name of the tag for this program source in the
217 # user interface.
218 ProgramSource/SAP/Isap public name {} {
219         return "SAP: Global"
220 }
221 
222 #-----------------------------------------------------------------------
223 #Method:
224 # ProgramSource/SAP/Isap scopes
225 #Description:
226 # Returns the list of scopes this object knows about
227 #-----------------------------------------------------------------------
228 ProgramSource/SAP/Isap public scopes {} {
229         return [$self set scopes_]
230 }
231 #----------------------------------------------------------------------
232 # Method:
233 #  ProgramSource/SAP/Isap recv
234 # Description:
235 #  Called by an AnnounceListenManager/SAP/Isap object when an
236 #  announcement is received.  Invokes ProgramSource::recv
237 #  and then sets a timeout on this announcement.
238 #------------------------------------------------------------------------
239 
240 ProgramSource/SAP/Isap public recv {child addr port data size} {
241         # keep nsrcs_ array up to date for this child by watching the
242         # change in the size of the progs_ array when the message is
243         # processed.
244         $self instvar progs_
245         set old [array size progs_]
246         set objs [$self next $data]
247         $child incrnsrcs [expr [array size progs_] - $old]
248 
249         # update average announcement size
250         $child sample_size $size
251 
252         # set timeouts
253         $self instvar progs_ timeouts_
254         foreach o $objs {
255                 # calculate timeout with a minimum of 30 mins as per sap spec
256                 set t [expr 10 * [$child interval 0]]
257                 if {$t < 1800} { set t 1800 }
258                 $self timeout $o $t
259         }
260 }
261 
262 # hack since tcl expr can't do unsigned comparison
263 ProgramSource/SAP/Isap private timestamp-gt {a b} {
264         if {$b == 0} { return 1 }
265         if {$a > 0 && $b < 0} { return 0 }
266         return [expr $a > $b]
267 }
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 

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