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