]>
Commit | Line | Data |
---|---|---|
73abe331 | 1 | #ifndef ALI_DCS_MESSAGE_H |
2 | #define ALI_DCS_MESSAGE_H | |
3 | ||
4 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * See cxx source for full Copyright notice */ | |
6 | ||
7 | /* $Id$ */ | |
8 | ||
9 | // | |
10 | // This class is a wrapper of AliDCSMessage. | |
11 | // These are the messages which form AliDCSProtocol. | |
12 | // | |
13 | ||
14 | ||
15 | #include "AliDCSValue.h" | |
16 | ||
17 | #include <TString.h> | |
d477ad88 | 18 | #include <TObjArray.h> |
73abe331 | 19 | |
20 | #define HEADER_SIZE 8 | |
21 | #define ID_OFFSET 0 | |
22 | #define VERSION_OFFSET 2 | |
23 | #define TYPE_OFFSET 3 | |
24 | #define BODY_SIZE_OFFSET 4 | |
25 | ||
26 | #define MAX_BODY_SIZE 40000 | |
27 | ||
28 | #define REQUEST_TYPE_OFFSET HEADER_SIZE | |
29 | #define START_TIME_OFFSET (HEADER_SIZE + 1) | |
30 | #define END_TIME_OFFSET (HEADER_SIZE + 5) | |
31 | #define REQUEST_STRING_OFFSET (HEADER_SIZE + 9) | |
32 | ||
33 | #define REQUEST_STRINGS_OFFSET REQUEST_STRING_OFFSET | |
34 | ||
35 | #define COUNT_OFFSET HEADER_SIZE | |
36 | ||
37 | #define SVT_OFFSET HEADER_SIZE | |
38 | #define VALUE_COUNT_OFFSET (HEADER_SIZE + 1) | |
39 | #define VALUES_OFFSET (HEADER_SIZE + 5) | |
40 | ||
41 | #define ERROR_CODE_OFFSET HEADER_SIZE | |
42 | #define ERROR_STRING_OFFSET (HEADER_SIZE + 1) | |
43 | ||
44 | ||
45 | ||
46 | class AliDCSMessage: public TObject { | |
47 | public: | |
48 | enum Type { | |
49 | kInvalid = 0, | |
50 | kRequest = 1, | |
51 | kCount = 2, | |
52 | kResultSet = 3, | |
53 | kError = 4, | |
54 | kMultiRequest = 5 | |
55 | // kNext = 6 | |
56 | }; | |
57 | ||
58 | enum RequestType { | |
59 | kNoneType = 0, | |
60 | kAlias = 1, | |
61 | kDPName = 2 | |
62 | }; | |
63 | ||
64 | enum ErrorCode { | |
65 | kNoneError = 0, | |
66 | kUnknownAliasDPName = 1, | |
67 | kInvalidTimeRange = 2, | |
68 | kInvalidBufferSize = 3, | |
69 | kInvalidRequest = 4, | |
70 | kUnsupportedType = 5, | |
71 | kUnknownError = 255 | |
72 | }; | |
73 | ||
74 | ||
75 | AliDCSMessage(); | |
76 | ||
77 | AliDCSMessage(const char* buffer, UInt_t size); | |
78 | ||
79 | ~AliDCSMessage(); | |
80 | ||
81 | ||
82 | void CreateRequestMessage(RequestType type, | |
83 | UInt_t startTime, UInt_t endTime, const char* request); | |
84 | ||
85 | void CreateMultiRequestMessage(RequestType type, | |
86 | UInt_t startTime, UInt_t endTime); | |
87 | ||
88 | void CreateCountMessage(UInt_t count); | |
89 | ||
90 | void CreateResultSetMessage(AliSimpleValue::Type type); | |
91 | ||
92 | void CreateErrorMessage(ErrorCode code, const char* errorString); | |
93 | ||
94 | //void CreateNextMessage(); | |
95 | ||
96 | void DestroyMessage(); | |
97 | ||
98 | ||
99 | Bool_t SetRawHeader(const char* header); | |
100 | ||
101 | void StoreToBuffer(); | |
102 | ||
103 | void LoadFromBuffer(); | |
104 | ||
105 | void DestroyBuffer(); | |
106 | ||
107 | ||
108 | Bool_t IsValid() const {return fType != kInvalid;}; | |
109 | ||
110 | UInt_t GetMessageSize() const {return fMessageSize;}; | |
111 | ||
112 | char* GetMessage() const {return fMessage;}; | |
113 | ||
114 | UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;}; | |
115 | ||
116 | char* GetBody() const {return fMessage + HEADER_SIZE;}; | |
117 | ||
118 | Type GetType() const {return fType;}; | |
119 | ||
120 | // RequestType and MultiReuqestType Message getters | |
121 | RequestType GetRequestType() const; | |
122 | ||
123 | UInt_t GetStartTime() const; | |
124 | ||
125 | UInt_t GetEndTime() const; | |
126 | ||
127 | TString GetRequestString() const; | |
128 | ||
129 | // MultiRequestType Message getters and setters | |
d477ad88 | 130 | void GetRequestStrings(TObjArray& result) const; |
73abe331 | 131 | |
132 | Bool_t AddRequestString(const char* request); | |
133 | ||
134 | void ClearRequestStrings(); | |
135 | ||
136 | // CountType Message getters | |
137 | UInt_t GetCount() const; | |
138 | ||
139 | // ResultSetType Message getters ans setters | |
140 | AliSimpleValue::Type GetSimpleValueType() const; | |
141 | ||
142 | UInt_t GetValueCount() const; | |
143 | ||
d477ad88 | 144 | UInt_t GetValues(TObjArray& result) const; |
73abe331 | 145 | |
146 | Bool_t AddValue(const AliDCSValue& value); | |
147 | ||
148 | void ClearValues(); | |
149 | ||
150 | // ErrorType Message getters | |
151 | ErrorCode GetErrorCode() const; | |
152 | ||
153 | TString GetErrorString() const; | |
154 | ||
155 | ||
156 | virtual void Print(Option_t* option = NULL) const; | |
157 | ||
158 | static void PrintBuffer(const char* buf, UInt_t size, TString& output); | |
159 | ||
160 | private: | |
161 | ||
162 | char* fMessage; | |
163 | ||
164 | UInt_t fMessageSize; | |
165 | ||
166 | ||
167 | Type fType; | |
168 | ||
169 | //Request message fields | |
170 | RequestType fRequestType; | |
171 | ||
172 | UInt_t fStartTime; | |
173 | ||
174 | UInt_t fEndTime; | |
175 | ||
176 | TString fRequestString; | |
177 | ||
178 | //Count message fields | |
179 | UInt_t fCount; | |
180 | ||
181 | //ResultSet message fields | |
182 | AliSimpleValue::Type fSimpleValueType; | |
183 | ||
d477ad88 | 184 | TObjArray fValues; |
73abe331 | 185 | |
186 | //Error message fields | |
187 | ErrorCode fErrorCode; | |
188 | ||
189 | TString fErrorString; | |
190 | ||
191 | //MultiRequest message fields | |
d477ad88 | 192 | TObjArray fRequestStrings; |
73abe331 | 193 | |
194 | ||
195 | // Message setter helpers | |
196 | void StoreHeader(); | |
197 | ||
198 | void StoreRequestMessage(); | |
199 | ||
200 | void StoreCountMessage(); | |
201 | ||
202 | void StoreResultSetMessage(); | |
203 | ||
204 | void StoreErrorMessage(); | |
205 | ||
206 | void StoreMultiRequestMessage(); | |
207 | ||
208 | //void StoreNextMessage(); | |
209 | ||
210 | ||
211 | Bool_t ValidateHeader(const char* buf); | |
212 | ||
213 | void LoadRequestMessage(); | |
214 | ||
215 | void LoadCountMessage(); | |
216 | ||
217 | void LoadResultSetMessage(); | |
218 | ||
219 | void LoadErrorMessage(); | |
220 | ||
221 | void LoadMultiRequestMessage(); | |
222 | ||
223 | //void LoadNextMessage(); | |
224 | ||
225 | // Buffer helpers | |
226 | static void SetBool(char* buf, Bool_t val); | |
227 | ||
228 | static void SetByte(char* buf, Char_t val); | |
229 | ||
230 | static void SetUByte(char* buf, UChar_t val); | |
231 | ||
232 | static void SetInt(char* buf, Int_t val); | |
233 | ||
234 | static void SetUInt(char* buf, UInt_t val); | |
235 | ||
236 | static void SetFloat(char* buf, Float_t val); | |
237 | ||
238 | static Bool_t GetBool(const char* buf); | |
239 | ||
240 | static Char_t GetByte(const char* buf); | |
241 | ||
242 | static UChar_t GetUByte(const char* buf); | |
243 | ||
244 | static Int_t GetInt(const char* buf); | |
245 | ||
246 | static UInt_t GetUInt(const char* buf); | |
247 | ||
248 | static Float_t GetFloat(const char* buf); | |
249 | ||
250 | static TString GetString(const char* buf, Int_t maxLen); | |
251 | ||
252 | ||
253 | ClassDef(AliDCSMessage, 0); | |
254 | }; | |
255 | ||
256 | #endif |