source: tol/tolsh/tolsh.vfs/lib/tcllib1.10/transfer/transmitter.tcl

devel
Last change on this file was 8597867d, checked in by Jorge Pérez <josp.jorge@…>, 16 years ago

closes #976, se incluye tcllib1.10, base64 debe eliminarse del raiz de lib ya que esta incluido en tcllib

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2556 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 2.6 KB
Line 
1# -*- tcl -*-
2# ### ### ### ######### ######### #########
3##
4# Transfer class. Sending of data.
5##
6# Utilizes data source and connect components to handle the
7# general/common parts.
8
9# ### ### ### ######### ######### #########
10## Requirements
11
12package require snit
13package require transfer::data::source ; # Data source
14package require transfer::connect      ; # Connection startup
15
16# ### ### ### ######### ######### #########
17## Implementation
18
19snit::type ::transfer::transmitter {
20
21    # ### ### ### ######### ######### #########
22    ## API
23
24    ## Data source sub component
25
26    delegate option -string   to source
27    delegate option -channel  to source
28    delegate option -file     to source
29    delegate option -variable to source
30    delegate option -size     to source
31
32    ## Connection management sub component
33
34    delegate option -host        to conn
35    delegate option -port        to conn
36    delegate option -mode        to conn
37    delegate option -translation to conn
38    delegate option -encoding    to conn
39    delegate option -eofchar     to conn
40
41    ## Transmitter configuration, and API
42
43    option -command   {}
44    option -blocksize 1024
45
46    constructor {args} {}
47
48    method start {} {}
49    method busy  {} {}
50
51    # ### ### ### ######### ######### #########
52    ## Implementation
53
54    constructor {args} {
55        set source [::transfer::data::source ${selfns}::source]
56        set conn   [::transfer::connect      ${selfns}::conn]
57        set busy   0
58
59        $self configurelist $args
60        return
61    }
62
63    method start {} {
64        if {$busy} {
65            return -code error "Object is busy"
66        }
67
68        if {![$source valid msg]} {
69            return -code error $msg
70        }
71
72        if {$options(-command) eq ""} {
73            return -code error "Completion callback is missing"
74        }
75
76        set busy 1
77        return [$conn connect [mymethod Begin]]
78    }
79
80    method busy {} {
81        return $busy
82    }
83
84    # ### ### ### ######### ######### #########
85    ## Internal helper commands.
86
87    method Begin {__ sock} {
88        # __ <=> conn
89        $source transmit $sock \
90                $options(-blocksize) \
91                [mymethod Done $sock]
92        return
93    }
94
95    method Done {sock args} {
96        # args is either (n),
97        #             or (n errormessage)
98
99        set busy 0
100        close $sock
101        $self Complete $args
102        return
103    }
104
105    method Complete {alist} {
106        set     cmd $options(-command)
107        lappend cmd $self
108        foreach a $alist {lappend cmd $a}
109
110        uplevel #0 $cmd
111        return
112
113        # 8.5: {*}$options(-command) {*}$alist
114    }
115
116    # ### ### ### ######### ######### #########
117    ## Data structures
118
119    variable source
120    variable conn
121    variable busy
122
123    ##
124    # ### ### ### ######### ######### #########
125}
126
127# ### ### ### ######### ######### #########
128## Ready
129
130package provide transfer::transmitter 0.1
Note: See TracBrowser for help on using the repository browser.