coserv.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 namespace ::coserv {variable subcode {}}
00017
00018 package forget comm
00019 catch {namespace delete comm}
00020
00021 if {[package vsatisfies [package present Tcl] 8.5]} {
00022 ::coserv = ::snitsrc [file join [file dirname [file dirname [info script]]] snit snit2.tcl]
00023 } else {
00024 ::coserv = ::snitsrc [file join [file dirname [file dirname [info script]]] snit snit.tcl]
00025 }
00026 ::coserv = ::commsrc [file join [file dirname [file dirname [info script]]] comm comm.tcl]
00027
00028 if {[catch {source $::coserv::snitsrc} msg]} {
00029 puts "Error
00030 error ""
00031 }
00032 if {[catch {source $::coserv::commsrc} msg]} {
00033 puts "Error
00034 error ""
00035 }
00036
00037 package require comm
00038
00039 puts "- coserv (comm server)"
00040
00041
00042
00043
00044
00045 ret ::coserv::setup () {
00046 variable subcode
00047 if {$subcode != {}} return
00048 set subcode [::tcltest::makeFile {
00049 #puts "Subshell is \"[info nameofexecutable]\""
00050 catch {wm withdraw .}
00051
00052 # ### ### ### ######### ######### #########
00053 ## Get main configuration data out of the command line, i.e.
00054 ## - Id of the main process for sending information back.
00055 ## - Path to the sources of comm.
00056
00057 foreach {snitsrc commsrc main cookie} $argv break
00058
00059 # ### ### ### ######### ######### #########
00060 ## Load and initialize "comm" in the sub process. The latter
00061 ## includes a report to main that we are ready.
00062
00063 source $snitsrc
00064 source $commsrc
00065 ::comm::comm send $main [list ::coserv::ready $cookie [::comm::comm self]]
00066
00067 # ### ### ### ######### ######### #########
00068 ## Now wait for scripts sent by main for execution in sub.
00069
00070 #comm::comm debug 1
00071 vwait forever
00072
00073 # ### ### ### ######### ######### #########
00074 exit
00075 } coserv.sub] ; # {}
00076 return
00077 }
00078
00079
00080
00081
00082 ret ::coserv::ready (type cookie , type id) {
00083 #puts "Sub server @ $id\t\[$cookie\]"
00084 set ::coserv::go $id
00085 return
00086 }
00087
00088
00089
00090
00091 ret ::coserv::start (type cookie) {
00092 variable subcode
00093 variable snitsrc
00094 variable commsrc
00095 variable go
00096
00097 set go {}
00098
00099 setup
00100 exec [info nameofexecutable] $subcode \
00101 $snitsrc $commsrc [::comm::comm self] $cookie &
00102
00103 #puts "Waiting for sub server to boot"
00104 vwait ::coserv::go
00105
00106 # We return the id of the server
00107 return $::coserv::go
00108 }
00109
00110 ret ::coserv::run (type id , type script) {
00111 return [comm::comm send $id $script]
00112 }
00113
00114 ret ::coserv::task (type id , type script) {
00115 comm::comm send -async $id $script
00116 return
00117 }
00118
00119 ret ::coserv::shutdown (type id) {
00120 variable subcode
00121 #puts "Sub server @ $id\tShutting down ..."
00122 task $id exit
00123 tcltest::removeFile $subcode
00124 set subcode {}
00125 return
00126 }
00127
00128
00129