1 # session-dc.tcl --
2 #
3 # Stuff for talking to the SDS using SRM.
4 #
5 # Copyright (c) 2000-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 SRMv2_Session
32 import SRMv2_Source
33 import Timer/Periodic
34
35
36 #
37 # Code for CDcSession
38 #
39
40 Class CDcSession -superclass {SRMv2_Session Timer/Periodic}
41 #
42 # CDcSession constructor
43 #
44 # input: inetAddr - a string with the internet address
45 # iSPort - sending port
46 # iRPort - receiving port
47 #
48
49 CDcSession instproc init {inetAddr iSPort iRPort iTTL} {
50 $self next $inetAddr $iSPort $iRPort $iTTL
51
52 # initialize some member variables
53 $self instvar m_cmdUpdate
54 $self instvar m_data
55
56 set m_cmdUpdate {}
57 set m_data {}
58
59 # create the one and only source object
60 $self instvar m_DcSource
61 $self instvar m_cidQuery
62
63 set m_DcSource [new SRMv2_Source $self ]
64
65 # set the source info
66 $m_DcSource app_info { "DC Service Source" }
67
68 # create some default containers
69 set m_cidQuery [$m_DcSource calloc 0 "Query"]
70 }
71
72 #
73 # CDcSession instproc UpdateInfo { cmdUpdate }
74 # the command that should be evaluated when the session gets new information
75 # from the service discovery service.
76 #
77 # input: cmdUpdate - the command to perform
78 #
79 CDcSession instproc UpdateInfo { cmdUpdate } {
80 $self instvar m_cmdUpdate
81
82 set m_cmdUpdate $cmdUpdate
83 }
84
85 CDcSession instproc StartQuery {} {
86 # Ok now let's set the timer to go off periodically
87 # when the timer goes off it will call timeout
88 $self start 500
89
90 # I don't want to wait 1 sec so call to get it now
91 $self instvar m_DcSource
92 $self instvar m_cidQuery
93
94 set data "QUERY_REQUEST:"
95 $m_DcSource send $m_cidQuery $data
96 }
97
98 #
99 # CDcSession instproc srm_recv { src cid seqno data }
100 #
101 # Get all the information from the query and then stick
102 # it into a structure to be delivered to an ui which will
103 # represent it in some way
104 #
105 # input: same as the srm_rec of SRMv2_Session object
106 #
107 CDcSession instproc srm_recv { src cid seqno data } {
108 if {[lindex $data 0] == "QUERY_RESPONSE:"} {
109 $self instvar m_data
110
111 # take out the QUERY_REPONSE: header
112 set data [lrange $data 1 end]
113
114 # update the data file and send an update if applicable
115 if { $m_data != $data } {
116 $self instvar m_cmdUpdate
117
118 set m_data $data
119 eval "$m_cmdUpdate"
120 }
121 }
122 }
123
124 #
125 # CDcSession public srm_read_adu { src cid seqno } {
126 #
127 # don't repair any loses
128 #
129 # input: same as the srm_rec of SRMv2_Session object
130 #
131 CDcSession instproc srm_read_adu { src cid seqno } {
132 # no recovery mechanism
133 }
134
135 #
136 # CDcSession public srm_should_recover { src cid sseq eseq } {
137 #
138 # don't repair any losses
139 #
140 # input: same as the srm_rec of SRMv2_Session object
141 #
142 CDcSession instproc srm_should_recover { src cid sseq eseq } {
143 return 0
144 }
145
146 #
147 # CDcSession instproc timeout {} {
148 #
149 # time out periodically sends to the sds that it's alive and active
150 #
151 # input: same as the srm_rec of SRMv2_Session object
152 #
153 CDcSession instproc timeout {} {
154 $self instvar m_DcSource
155 $self instvar m_cidQuery
156
157 set data "QUERY_REQUEST:"
158 $m_DcSource send $m_cidQuery $data
159 }
160
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.