receiver.tcl

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

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1