1 # dc-service.tcl --
2 #
3 # Contains CServiceManager and CService, building blocks of DC
4 # Service Discovery Service.
5 #
6 # Copyright (c) 2000-2002 The Regents of the University of California.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # A. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # B. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # C. Neither the names of the copyright holders nor the names of its
18 # contributors may be used to endorse or promote products derived from this
19 # software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 import CLinkManager
33 import CLink
34
35 Class CServiceManager -superclass CLinkManager
36
37 CServiceManager public init { szType szAttribute iPort } {
38 $self next $iPort
39
40 $self instvar m_szType
41 $self instvar m_szAttribute
42
43 set m_szType $szType
44 set m_szAttribute $szAttribute
45 }
46
47
48 CServiceManager private NewConnection { newSocket inetAddr iPort } {
49 $self instvar m_lAttach
50 $self instvar m_lService
51 $self instvar m_szType
52 $self instvar m_szAttribute
53
54 # send out this service manager's type and attribute
55 puts $newSocket "$m_szType"
56 puts $newSocket "$m_szAttribute"
57 flush $newSocket
58
59 # get the remote service's type and attribute
60 set szType [gets $newSocket]
61 set szAttribute [gets $newSocket]
62
63 # create the new service with the socket
64 set service [new CService $newSocket $inetAddr $iPort $szType $szAttribute]
65
66 # now go through the list of attached objects and see if anyone wants it
67 foreach attach $m_lAttach {
68 set result [$attach NewConnection $service]
69 if { $result != 0 } {
70 return
71 }
72 }
73
74 # ok no one want's it so stick into a list and maybe some will want it
75 # later
76 lappend m_lService $service
77 }
78
79 CServiceManager instproc NewService { inetRemoteAddr iRemotePort \
80 { szType "" } { szAttribute "" } } {
81 $self instvar m_szType
82 $self instvar m_szAttribute
83
84 # first create the new socket
85 if {[catch {socket $inetRemoteAddr $iRemotePort} sock]} {
86 error "CServiceManager: NewService couldn't connect to ${inetRemoteAddr}/${iRemotePort}"
87 }
88
89 # check that the socket is good
90 if { $sock <= 0 } {
91 error "CServiceManager: NewService couldn't connect to ${inetRemoteAddr}/${iRemotePort}"
92 }
93
94 # get the remote service's type and attribute
95 set szRemoteType [gets $sock]
96 set szRemoteAttribute [gets $sock]
97
98 # send out this service manager's type and attribute
99 if { $szType == "" && $szAttribute == "" } {
100 set szType $m_szType
101 set szAttribute $m_szAttribute
102 }
103
104 puts $sock "$szType"
105 puts $sock "$szAttribute"
106 flush $sock
107
108 set service [new CService $sock $inetRemoteAddr $iRemotePort \
109 $szRemoteType $szRemoteAttribute]
110
111 return $service
112 }
113
114
115
116
117
118 Class CService -superclass CLink
119 # CService friend CServiceManager
120
121 CService private init { sock inetAddr iPort szType szAttribute } {
122 $self next $sock
123
124 $self instvar m_szType
125 $self instvar m_szAttribute
126
127 set m_szType $szType
128 set m_szAttribute $szAttribute
129 }
130
131
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.