Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Core/ProtocolRequest.cpp

raw
1 /*===========================================================================
2 FILE:
3 ProtocolRequest.cpp
4
5 DESCRIPTION:
6 Generic protocol request/command related structures and
7 affliated methods, these structures are used by clients of
8 the protocol server to specify outgoing requests
9
10 PUBLIC CLASSES AND METHODS:
11 sProtocolRequest
12
13 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17 * Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 * Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22 * Neither the name of Code Aurora Forum nor
23 the names of its contributors may be used to endorse or promote
24 products derived from this software without specific prior written
25 permission.
26
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 POSSIBILITY OF SUCH DAMAGE.
39 ===========================================================================*/
40
41 //---------------------------------------------------------------------------
42 // Include Files
43 //---------------------------------------------------------------------------
44 #include "StdAfx.h"
45
46 #include "ProtocolRequest.h"
47 #include "ProtocolNotification.h"
48 #include "ProtocolServer.h"
49
50 //---------------------------------------------------------------------------
51 // Definitions
52 //---------------------------------------------------------------------------
53
54 // Default protocol request timeout
55 const ULONG DEFAULT_REQ_TIMEOUT = 1000;
56
57 // Minimum and maximum allowable timeout values (in milliseconds)
58 const ULONG MIN_REQ_TIMEOUT = 100;
59 const ULONG MAX_REQ_TIMEOUT = 300000;
60
61 // Minimum number of attempts a request can be scheduled for
62 const ULONG MIN_REQ_ATTEMPTS = 1;
63
64 // Value to indicate that a request is to be sent out indefinately
65 const ULONG INFINITE_REQS = 0xFFFFFFFF;
66
67 // Minimum/default amount of time between repeated requests (in milliseconds)
68 const ULONG MIN_REQ_FREQUENCY = 10;
69 const ULONG DEFAULT_REQ_FREQUENCY = 100;
70
71 /*=========================================================================*/
72 // sProtocolRequest Methods
73 /*=========================================================================*/
74
75 /*===========================================================================
76 METHOD:
77 sProtocolRequest
78
79 DESCRIPTION:
80 Parameterized constructor
81
82 PARAMETERS:
83 pBuffer [ I ] - Shareable buffer representing the request (must be
84 valid)
85
86 schedule [ I ] - When (from now, in milliseconds) to send the first
87 request, this isn't a hard value as the request is
88 only guaranteed to go out after this time elapses
89
90 timeout [ I ] - Milliseconds to wait for a response to an individual
91 request before declaring a timeout. Regardless of
92 what is passed in the timeout value used will be
93 between MIN/MAX_REQ_TIMEOUT
94
95 requests [ I ] - Number of request attempts to make, this isn't a
96 retry count rather this value is used to specify
97 repeating requests. Regardless of what is passed in
98 the requests value used will be at least
99 MIN_REQ_ATTEMPTS
100
101 frequency [ I ] - If the 'requests' value is greater than the
102 MIN_REQ_ATTEMPTS than this represents the amount of
103 time to wait between requests (from the completion of
104 the last request attempt, in milliseconds), again this
105 isn't a hard value. Regardless of what is passed in
106 the frequency value used will be at least
107 MIN_REQ_FREQUENCY
108
109 pNotifier [ I ] - Status notification mechanism (may be 0)
110
111
112 RETURN VALUE:
113 None
114 ===========================================================================*/
115 sProtocolRequest::sProtocolRequest(
116 sSharedBuffer * pBuffer,
117 ULONG schedule,
118 ULONG timeout,
119 ULONG requests,
120 ULONG frequency,
121 cProtocolNotification * pNotifier )
122 : sProtocolBuffer( pBuffer ),
123 mSchedule( schedule ),
124 mTimeout( DEFAULT_REQ_TIMEOUT ),
125 mRequests( MIN_REQ_ATTEMPTS ),
126 mFrequency( DEFAULT_REQ_FREQUENCY ),
127 mpNotifier( 0 ),
128 mpAuxData( 0 ),
129 mAuxDataSize( 0 ),
130 mbTXOnly( false )
131 {
132 // Constrain requested timeout to allowable range
133 if (timeout < MIN_REQ_TIMEOUT)
134 {
135 timeout = MIN_REQ_TIMEOUT;
136 }
137
138 if (timeout > MAX_REQ_TIMEOUT)
139 {
140 timeout = MAX_REQ_TIMEOUT;
141 }
142
143 mTimeout = timeout;
144
145 // Constrain request attempts
146 if (requests >= MIN_REQ_ATTEMPTS)
147 {
148 mRequests = requests;
149 }
150
151 // Constrain frequency
152 if (frequency >= MIN_REQ_FREQUENCY)
153 {
154 mFrequency = frequency;
155 }
156
157 // Clone notifier?
158 if (pNotifier != 0)
159 {
160 mpNotifier = pNotifier->Clone();
161 }
162 }
163
164 /*===========================================================================
165 METHOD:
166 sProtocolRequest
167
168 DESCRIPTION:
169 Parameterized constructor (notification with defaults)
170
171 PARAMETERS:
172 pBuffer [ I ] - Shareable buffer representing the request (must be
173 valid)
174
175 pNotifier [ I ] - Status notification mechanism (may be 0)
176
177
178 RETURN VALUE:
179 None
180 ===========================================================================*/
181 sProtocolRequest::sProtocolRequest(
182 sSharedBuffer * pBuffer,
183 cProtocolNotification * pNotifier )
184 : sProtocolBuffer( pBuffer ),
185 mSchedule( 0 ),
186 mTimeout( DEFAULT_REQ_TIMEOUT ),
187 mRequests( MIN_REQ_ATTEMPTS ),
188 mFrequency( DEFAULT_REQ_FREQUENCY ),
189 mpNotifier( pNotifier ),
190 mpAuxData( 0 ),
191 mAuxDataSize( 0 ),
192 mbTXOnly( false )
193 {
194 // Clone notifier?
195 if (pNotifier != 0)
196 {
197 mpNotifier = pNotifier->Clone();
198 }
199
200 Validate();
201 }
202
203 /*===========================================================================
204 METHOD:
205 sProtocolRequest
206
207 DESCRIPTION:
208 Copy constructor
209
210 PARAMETERS:
211 req [ I ] - Request to copy
212
213 RETURN VALUE:
214 None
215 ===========================================================================*/
216 sProtocolRequest::sProtocolRequest( const sProtocolRequest & req )
217 : sProtocolBuffer( req ),
218 mSchedule( req.mSchedule ),
219 mTimeout( req.mTimeout ),
220 mRequests( req.mRequests ),
221 mFrequency( req.mFrequency ),
222 mpNotifier( 0 ),
223 mpAuxData( req.mpAuxData ),
224 mAuxDataSize( req.mAuxDataSize ),
225 mbTXOnly( req.mbTXOnly )
226 {
227 // Clone notifier?
228 if (req.mpNotifier != 0)
229 {
230 mpNotifier = req.mpNotifier->Clone();
231 }
232
233 Validate();
234 }
235
236 /*===========================================================================
237 METHOD:
238 ~sProtocolRequest
239
240 DESCRIPTION:
241 Destructor
242
243 RETURN VALUE:
244 None
245 ===========================================================================*/
246 sProtocolRequest::~sProtocolRequest()
247 {
248 // Delete cloned notifier?
249 if (mpNotifier != 0)
250 {
251 delete mpNotifier;
252 mpNotifier = 0;
253 }
254 }