Debian Codegraph @

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

raw
1 /*===========================================================================
2 FILE:
3 ProtocolRequest.h
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 protocol 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 // Pragmas
43 //---------------------------------------------------------------------------
44 #pragma once
45
46 //---------------------------------------------------------------------------
47 // Include Files
48 //---------------------------------------------------------------------------
49 #include "ProtocolBuffer.h"
50
51 //---------------------------------------------------------------------------
52 // Forward Declarations
53 //---------------------------------------------------------------------------
54 class cProtocolNotification;
55
56 //---------------------------------------------------------------------------
57 // Definitions
58 //---------------------------------------------------------------------------
59
60 // Default protocol request timeout
61 extern const ULONG DEFAULT_REQ_TIMEOUT;
62
63 // Minimum and maximum allowable timeout values (in milliseconds)
64 extern const ULONG MIN_REQ_TIMEOUT;
65 extern const ULONG MAX_REQ_TIMEOUT;
66
67 // Minimum number of attempts a request can be scheduled for
68 extern const ULONG MIN_REQ_ATTEMPTS;
69
70 // Value to indicate that a request is to be sent out indefinately
71 extern const ULONG INFINITE_REQS;
72
73 // Minimum/default amount of time between repeated requests (in milliseconds)
74 extern const ULONG MIN_REQ_FREQUENCY;
75 extern const ULONG DEFAULT_REQ_FREQUENCY;
76
77 /*=========================================================================*/
78 // Struct sProtocolRequest
79 //
80 // Structure to represent a generic request packet, including all the
81 // information needed to schedule the request, send the request, and
82 // (optionally) reschedule the request for another TX/RX attempt
83 //
84 // The default parameters schedule an immediate request (indicated by
85 // passing in '0' for the schedule parameter) to be sent once with
86 // the default timeout value
87 /*=========================================================================*/
88 struct sProtocolRequest : public sProtocolBuffer
89 {
90 public:
91 // Parameterized constructor
92 sProtocolRequest(
93 sSharedBuffer * pBuffer,
94 ULONG schedule = 0,
95 ULONG timeout = DEFAULT_REQ_TIMEOUT,
96 ULONG requests = MIN_REQ_ATTEMPTS,
97 ULONG frequency = DEFAULT_REQ_FREQUENCY,
98 cProtocolNotification * pNotifier = 0 );
99
100 // Parameterized constructor (notification with defaults)
101 sProtocolRequest(
102 sSharedBuffer * pBuffer,
103 cProtocolNotification * pNotifier );
104
105 // Copy constructor
106 sProtocolRequest( const sProtocolRequest & req );
107
108 // Destructor
109 virtual ~sProtocolRequest();
110
111 // (Inline) Get schedule value (value is in milliseconds)
112 ULONG GetSchedule() const
113 {
114 return mSchedule;
115 };
116
117 // (Inline) Get timeout value
118 ULONG GetTimeout() const
119 {
120 return mTimeout;
121 };
122
123 // (Inline) Get requests value
124 ULONG GetRequests() const
125 {
126 return mRequests;
127 };
128
129 // (Inline) Get frequency value (value is in milliseconds)
130 ULONG GetFrequency() const
131 {
132 return mFrequency;
133 };
134
135 const cProtocolNotification * GetNotifier() const
136 {
137 return mpNotifier;
138 };
139
140 // (Inline) Set auxiliary data
141 void SetAuxiliaryData(
142 const BYTE * pData,
143 ULONG dataSz )
144 {
145 mpAuxData = pData;
146 mAuxDataSize = dataSz;
147 };
148
149 // (Inline) Get auxiliary data
150 const BYTE * GetAuxiliaryData( ULONG & dataSz ) const
151 {
152 dataSz = mAuxDataSize;
153 return mpAuxData;
154 };
155
156 // (Inline) Set TX only flag
157 void SetTXOnly()
158 {
159 mbTXOnly = true;
160 };
161
162 // (Inline) Get TX only flag
163 bool IsTXOnly() const
164 {
165 return mbTXOnly;
166 };
167
168 protected:
169 /* Schedule (approximately when to send the initial request) */
170 ULONG mSchedule;
171
172 /* Timeout value for receiving a response */
173 ULONG mTimeout;
174
175 /* Number of requests to schedule (must be at least one) */
176 ULONG mRequests;
177
178 /* Frequency (approximately how long to wait before next request) */
179 ULONG mFrequency;
180
181 /* Notification object */
182 cProtocolNotification * mpNotifier;
183
184 /* Auxiliary data */
185 const BYTE * mpAuxData;
186
187 /* Auxilary data size */
188 ULONG mAuxDataSize;
189
190 /* TX only (i.e. do not wait for a response) ? */
191 bool mbTXOnly;
192 };
193