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

Open Mash Cross Reference
mash/tcl/srmv2/bt-srmv2.tcl

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

  1 # bt-srmv2.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 Class BulkTransfer -superclass { Application }
 32 
 33 BulkTransfer instproc init { ab logfile peakrate {dirname ""}} {
 34         $self next bulk_transfer
 35         $self configure
 36         $self init-net $ab $logfile $peakrate
 37         $self instvar receiver_ pending_
 38 
 39         set pending_ ""
 40         if {$dirname != ""} {
 41                 foreach filename [glob "$dirname/*.tcl"] {
 42                         $self read-file $filename
 43                 }
 44                 set receiver_ 0
 45         } else {
 46 #               puts "Receiver"
 47                 set receiver_ 1
 48         }
 49 }
 50 
 51 BulkTransfer instproc configure {  } {
 52         $self instvar options_ blksz_ cwd_ root_
 53 
 54         set cwd_ [string trimright [pwd] "/"]
 55 
 56         set config [new Configuration]
 57         $self set options_ $config
 58 
 59         set root_ "/var/tmp/mftp/"
 60         set blksz_ 1000
 61 }
 62 
 63 BulkTransfer instproc init-net { ab logfile rate } {
 64         $self instvar srmv2_ options_
 65 
 66         set ab [$options_ parse_args $ab]
 67         set srmv2_(manager) [new SRMv2_Manager/Text $ab]
 68         set srmv2_(session) [$srmv2_(manager) set session_]
 69         $srmv2_(session) log-file $logfile
 70         $srmv2_(session) peak-rate $rate
 71         $srmv2_(session) c1_ 2.0
 72         $srmv2_(session) c2_ 0.0
 73 
 74         $srmv2_(session) set-manager $srmv2_(manager)
 75         $srmv2_(manager) session $srmv2_(session)
 76         $srmv2_(session) start-announce
 77         $srmv2_(manager) application $self
 78 }
 79 
 80 BulkTransfer instproc select-file { } {
 81 #       set f [Dialog transient FileDialog]
 82 #       return $f
 83         return "/usr/home/mccanne/suchi/srmv2/mash/tcl/srmv2/session-srmv2.tcl"
 84 }
 85 
 86 # Application simply hands SRMv2 a humungous file.
 87 BulkTransfer instproc read-file { filename } {
 88         $self instvar srmv2_ blksz_ cwd_
 89         $self instvar cid_ flen_ ss_
 90 
 91         set source [$srmv2_(session) local-source]
 92         set comps [split $filename "/"]
 93         set cid 0
 94         for {set i 0} {$i < [llength $comps]} {incr i} {
 95                 set cid [$source calloc $cid [lindex $comps $i]]
 96         }
 97 #       puts "read-file $filename"
 98         if {$filename != ""} {
 99                 set ss 0
100                 set flen [file size $filename]
101                 set cid_($filename) $cid
102                 set flen_($filename) $flen
103                 set ss_($filename) $ss
104                 $self enqueue $filename $ss 0 [expr $flen -1]
105                 incr ss
106         }
107 }
108 
109 BulkTransfer instproc enqueue {aduname seqno ss es} {
110         $self instvar pending_ srmv2_ cid_
111         set qlen [llength $pending_]
112         set aduname [string trimleft $aduname "/"]
113         set idx [lsearch -exact $pending_ "$aduname,$seqno,$ss,$es"]
114         if {$idx < 0} {
115 #               puts "Enqueue $aduname $seqno $ss $es"
116                 set pending_ [lappend pending_ "$aduname,$seqno,$ss,$es"]
117         }
118         # If the pending queue is empty, wake up the
119         # SRMv2 session to set a timer, and call us back.
120         if {$qlen == 0} {
121 #               puts "\n @@@ req-send aduname $aduname \n"
122                 $srmv2_(session) req-send $cid_($aduname) $seqno $ss $es
123         }
124 }
125 
126 # This application ignores 'seqno'
127 BulkTransfer instproc handle {nm seqno blk} {
128         $self instvar root_
129         if {$nm == "/map"} {
130                 return
131         }
132 #       puts "$nm ::"
133         set filename "$root_/$nm"
134         set index [string last "/" $filename]
135         set dir [string range $filename 0 [expr $index-1]]
136         set fname [string range $filename [expr $index+1] end]
137         exec mkdir -p $dir
138         set fd [open $filename w]
139         puts -nonewline $fd $blk
140         close $fd
141 }
142 
143 BulkTransfer instproc reada { nm seqno } {
144         # This application ignores 'seqno'
145         $self instvar receiver_ pending_ cid_ flen_ ss_ srmv2_
146         if {$nm == "/map"} {
147                 return
148         }
149         if {$receiver_ == 0} {
150                 set nm [string trimleft $nm /]
151                 set idx [lsearch -glob $pending_ "$nm,*"]
152                 set request ""
153                 if {$idx >= 0} {
154                         set request [lindex $pending_ $idx]
155                         set pending_ [lreplace $pending_ $idx $idx]
156                 }
157                 # If there is a next ADU in the pending queue,
158                 # schedule it for transmission.
159                 if {[llength $pending_] > 0} {
160                         set nxt [split [lindex $pending_ 0] ","]
161                         set filename [string trimleft [lindex $nxt 0] /]
162                         set seqno [lindex $nxt 1]
163                         set ss [lindex $nxt 2]
164                         set es [lindex $nxt 3]
165                         if {$filename != ""} {
166 #                               puts "\n **** ($nm) req-send aduname $filename $ss-$es\n"
167                                 $srmv2_(session) req-send $cid_($filename) $seqno \
168                                                 $ss $es
169                         }
170                 }
171                 set filename "[pwd]/$nm"
172                 set index [string last "/" $filename]
173                 set dir [string range $filename 0 [expr $index-1]]
174                 set fname [string range $filename [expr $index+1] end]
175                 set fd [open $filename r]
176                 set data [read $fd]
177                 close $fd
178                 return $data
179         } else {
180                 return ""
181         }
182 }
183 
184 
185 BulkTransfer instproc recover { nm start end } {
186         # This example simply ignore 'start' and 'end'
187         # ADU sequence numbers.
188         if [string match *Remote*.tcl $nm] {
189                 return 0
190         } else {
191                 return 1
192         }
193 }
194 
195 

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