File: transceiver.tcl

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (76 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env tclsh
## -*- tcl -*-

package require comm
package require tie

set id [lindex $argv 0]

array set local {}

proc export {localvar remotevar remoteid} {
    uplevel #0 [list tie::tie $localvar remotearray $remotevar {comm::comm send} $remoteid]
    return
}

proc import {remotevar remoteid localvar} {
    comm::comm send $remoteid [list \
	    tie::tie $remotevar remotearray \
	    $localvar {comm::comm send} [comm::comm self] \
	 ]
}

proc ExecChanges {list} {
    if {![llength $list]} return

    uplevel #0 [lindex $list 0]
    after 100 [list ExecChanges [lrange $list 1 end]]
}

proc Track {args} {
    global receiver
    puts *\ \[[join $args "\] \["]\]\ ([dictsort [array get receiver]])
    return
}

proc dictsort {dict} {
    array set a $dict
    set out [list]
    foreach key [lsort [array names a]] {
	lappend out $key $a($key)
    }
    return $out
}

export local server $id
import server $id local

trace add variable local {write unset} Track


comm::comm send $id {
    proc ExecChanges {list} {
	puts ($list)
	if {![llength $list]} return
	uplevel #0 [lindex $list 0]
	after 100 [list ExecChanges [lrange $list 1 end]]
    }
}

set changes {
    {set local(a) 0}
    {set local(a) 1}
    {set local(b) .}
    {unset local(a)}
    {array set local {xa @ xb *}}
    {array unset local x*}
}
lappend changes \
	[list comm::comm send $id [list ExecChanges {
    {set server(ZZ) foo}
    {set server(XX) bar}
}]]

after 2000 [list ExecChanges $changes]

vwait forever