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