transmitter.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  ### ### ### ######### ######### #########*/
00003 /** 
00004  * Transfer class. Sending of data.
00005  *#
00006  * Utilizes data source and connect components to handle the
00007  * general/common parts.
00008  */
00009 
00010 /*  ### ### ### ######### ######### #########*/
00011 /*  Requirements*/
00012 
00013 package require snit
00014 package require transfer::data::source ; /*  Data source*/
00015 package require transfer::connect      ; /*  Connection startup*/
00016 
00017 /*  ### ### ### ######### ######### #########*/
00018 /*  Implementation*/
00019 
00020 snit::type ::transfer::transmitter {
00021 
00022     /*  ### ### ### ######### ######### #########*/
00023     /*  API*/
00024 
00025     /*  Data source sub component*/
00026 
00027     delegate option -string   to source
00028     delegate option -channel  to source
00029     delegate option -file     to source
00030     delegate option -variable to source
00031     delegate option -size     to source
00032 
00033     /*  Connection management sub component*/
00034 
00035     delegate option -host        to conn
00036     delegate option -port        to conn
00037     delegate option -mode        to conn
00038     delegate option -translation to conn
00039     delegate option -encoding    to conn
00040     delegate option -eofchar     to conn
00041 
00042     /*  Transmitter configuration, and API*/
00043 
00044     option -command   {}
00045     option -blocksize 1024
00046 
00047     constructor {args} {}
00048 
00049     ret  start () {}
00050     ret  busy  () {}
00051 
00052     /*  ### ### ### ######### ######### #########*/
00053     /*  Implementation*/
00054 
00055     constructor {args} {
00056      source =  [::transfer::data::source ${selfns}::source]
00057      conn =    [::transfer::connect      ${selfns}::conn]
00058      busy =    0
00059 
00060     $self configurelist $args
00061     return
00062     }
00063 
00064     ret  start () {
00065     if {$busy} {
00066         return -code error "Object is busy"
00067     }
00068 
00069     if {![$source valid msg]} {
00070         return -code error $msg
00071     }
00072 
00073     if {$options(-command) eq ""} {
00074         return -code error "Completion callback is missing"
00075     }
00076 
00077     set busy 1
00078     return [$conn connect [mymethod Begin]]
00079     }
00080 
00081     ret  busy () {
00082     return $busy
00083     }
00084 
00085     /*  ### ### ### ######### ######### #########*/
00086     /*  Internal helper commands.*/
00087 
00088     ret  Begin (__ type sock) {
00089     # __ <=> conn
00090     $source transmit $sock \
00091         $options(-blocksize) \
00092         [mymethod Done $sock]
00093     return
00094     }
00095 
00096     ret  Done (type sock , type args) {
00097     # args is either (n),
00098     #             or (n errormessage)
00099 
00100     set busy 0
00101     close $sock
00102     $self Complete $args
00103     return
00104     }
00105 
00106     ret  Complete (type alist) {
00107     set     cmd $options(-command)
00108     lappend cmd $self
00109     foreach a $alist {lappend cmd $a}
00110 
00111     uplevel #0 $cmd
00112     return
00113 
00114     # 8.5: {*}$options(-command) {*}$alist
00115     }
00116 
00117     /*  ### ### ### ######### ######### #########*/
00118     /*  Data structures*/
00119 
00120     variable source
00121     variable conn
00122     variable busy
00123 
00124     /** 
00125      * ### ### ### ######### ######### #########
00126  */
00127 }
00128 
00129 /*  ### ### ### ######### ######### #########*/
00130 /*  Ready*/
00131 
00132 package provide transfer::transmitter 0.1
00133 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1