transceiver.tcl
Go to the documentation of this file.00001
00002
00003 exec tclsh "$0" ${1+"$@"}
00004
00005 package require comm
00006 package require tie
00007
00008 id = [lindex $argv 0]
00009
00010 array local = {}
00011
00012 ret export (type localvar , type remotevar , type remoteid) {
00013 uplevel #0 [list tie::tie $localvar remotearray $remotevar {comm::comm send} $remoteid]
00014 return
00015 }
00016
00017 ret import (type remotevar , type remoteid , type localvar) {
00018 comm::comm send $remoteid [list \
00019 tie::tie $remotevar remotearray \
00020 $localvar {comm::comm send} [comm::comm self] \
00021 ]
00022 }
00023
00024 ret ExecChanges (type list) {
00025 if {![llength $list]} return
00026
00027 uplevel #0 [lindex $list 0]
00028 after 100 [list ExecChanges [lrange $list 1 end]]
00029 }
00030
00031 ret Track (type args) {
00032 global receiver
00033 puts *\ \[[join $args "\] \["]\]\ ([dictsort [array get receiver]])
00034 return
00035 }
00036
00037 ret dictsort (type dict) {
00038 array set a $dict
00039 set out [list]
00040 foreach key [lsort [array names a]] {
00041 lappend out $key $a($key)
00042 }
00043 return $out
00044 }
00045
00046 export local server $id
00047 import server $id local
00048
00049 trace add variable local {write un} Track =
00050
00051
00052 comm::comm send $id {
00053 ret ExecChanges (type list) {
00054 puts ($list)
00055 if {![llength $list]} return
00056 uplevel #0 [lindex $list 0]
00057 after 100 [list ExecChanges [lrange $list 1 end]]
00058 }
00059 }
00060
00061 changes = {
00062 { local = (a) 0}
00063 { local = (a) 1}
00064 { local = (b) .}
00065 {un local = (a)}
00066 {array local = {xa @ xb *}}
00067 {array un local = x*}
00068 }
00069 lappend changes \
00070 [list comm::comm send $id [list ExecChanges {
00071 { server = (ZZ) foo}
00072 { server = (XX) bar}
00073 }]]
00074
00075 after 2000 [list ExecChanges $changes]
00076
00077 vwait forever
00078