1 # source-proxy.tcl --
2 #
3 # Defines mechanisms for using a proxy to transmit announcements.
4 #
5 # Copyright (c) 1998-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import ProgramSource TCP/Client
32
33 #
34 Class ProgramSource/Proxy -superclass { ProgramSource TCP/Client }
35
36 # FIXME spec shouldn't be necessary -- should do ERS
37 ProgramSource/Proxy public init {ui spec} {
38 #FIXME
39 $self set name_ "Proxy: $spec"
40
41 $self next $ui
42
43 # make sure no client caching is performed
44 $self instvar cache_
45 catch {unset cache_}
46
47 $self set buffer_ ""
48
49 # FIXME ERS goes here
50 $self connect $spec
51 }
52
53 #
54 ProgramSource/Proxy public destroy {} {
55 $self next
56 }
57
58 # Used to set the name of the tag for this program source in the
59 # user interface.
60 ProgramSource/Proxy public name {} {
61 return [$self set name_]
62 }
63
64 # FIXME
65 ProgramSource/Proxy public scopes {} {
66 return {}
67 }
68
69 #
70 ProgramSource/Proxy private connect {spec} {
71 # open tcp connection to the cache agent
72 set l [split $spec /]
73 set host [lindex $l 0]
74 set port [lindex $l 1]
75 $self open $host $port
76
77 # ask the cache agent to send programs
78 $self send "subscribe\n"
79 }
80
81 #
82 ProgramSource/Proxy public recv s {
83 $self instvar buffer_
84 append buffer_ "$s\n"
85
86 # look for blank line
87 if {[string trim $s] == ""} {
88 set i [string wordend $buffer_ 0]
89 set cmd [string trim [string range $buffer_ 0 $i]]
90 set data [string trim [string range $buffer_ $i end]]
91
92 switch $cmd {
93 "add" - "update" {
94 $self next $data
95 }
96
97 "remove" {
98 $self instvar progs_
99 if ![info exists progs_($data)] {
100 $self warn "got remove for nonexistent prog \"$data\""
101 } else {
102 $self remove $progs_($data)
103 }
104 }
105
106 default {
107 $self warn "got bogus command \"$cmd\""
108 }
109 }
110
111 set buffer_ ""
112 }
113 }
114
115 ProgramSource/Proxy public announce {msg scope} {
116 #FIXME
117 }
118
119 #FIXME need stop-announce
120
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.