1 #ifndef ALI_DCS_MESSAGE_H
2 #define ALI_DCS_MESSAGE_H
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
10 // This class is a wrapper of AliDCSMessage.
11 // These are the messages which form AliDCSProtocol.
12 // Used by AliDCSClient to communicate with the DCS Amanda server
16 #include <TObjArray.h>
17 #include "AliDCSValue.h"
21 #define VERSION_OFFSET 2
23 #define BODY_SIZE_OFFSET 4
25 #define MAX_BODY_SIZE 500000
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)
32 #define REQUEST_STRINGS_OFFSET REQUEST_STRING_OFFSET
34 #define COUNT_OFFSET HEADER_SIZE
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)
41 #define ERROR_CODE_OFFSET HEADER_SIZE
42 #define UNKNOWN_DP_OFFSET HEADER_SIZE
43 #define ERROR_STRING_OFFSET (HEADER_SIZE + 1)
45 class AliDCSMessage: public TObject {
50 kCount = 2, // obsolete in protocol 2
67 kConnectionFailed = 1,
68 kUnexpectedPacketFormat = 2,
69 kDataRetrievingFailed = 3,
70 kUnsupportedProtocolVersion = 4,
77 AliDCSMessage(const char* buffer, UInt_t size);
78 virtual ~AliDCSMessage();
80 void CreateRequestMessage(RequestType type,
81 UInt_t startTime, UInt_t endTime, const char* request);
83 void CreateMultiRequestMessage(RequestType type,
84 UInt_t startTime, UInt_t endTime);
86 void CreateCountMessage(UInt_t count);
87 void CreateResultSetMessage(AliDCSValue::Type type);
88 void CreateErrorMessage(ErrorCode code, const char* errorString);
90 void CreateNextMessage();
92 void DestroyMessage();
95 Bool_t SetRawHeader(const char* header);
99 void LoadFromBuffer();
101 void DestroyBuffer();
104 Bool_t IsValid() const {return fType != kInvalid;};
106 UInt_t GetMessageSize() const {return fMessageSize;};
108 char* GetMessage() const {return fMessage;};
110 UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
112 char* GetBody() const {return fMessage + HEADER_SIZE;};
114 Type GetType() const {return fType;};
116 // RequestType and MultiReuqestType Message getters
117 RequestType GetRequestType() const;
119 UInt_t GetStartTime() const;
121 UInt_t GetEndTime() const;
123 TString GetRequestString() const;
125 // MultiRequestType Message getters and setters
126 void GetRequestStrings(TObjArray& result) const;
128 Bool_t AddRequestString(const char* request);
130 void ClearRequestStrings();
132 // CountType Message getters
133 UInt_t GetCount() const;
135 // ResultSetType Message getters ans setters
136 AliDCSValue::Type GetValueType() const;
138 Int_t GetOwnerIndex() const { return fOwnerIndex; }
140 UInt_t GetValueCount() const;
142 UInt_t GetValues(TObjArray* result) const;
144 Bool_t AddValue(AliDCSValue& value);
148 // ErrorType Message getters
149 ErrorCode GetErrorCode() const;
151 TString GetErrorString() const;
154 virtual void Print(Option_t* option = NULL) const;
156 static void PrintBuffer(const char* buf, UInt_t size, TString& output);
160 AliDCSMessage(const AliDCSMessage& other);
161 AliDCSMessage& operator= (const AliDCSMessage& other);
164 char* fMessage; // Array of bytes building the message
166 UInt_t fMessageSize; // Size of the message array
169 Type fType; // Message type (request, count...)
171 //Request message fields
172 RequestType fRequestType; // Type of request message
174 UInt_t fStartTime; // Start time of query
176 UInt_t fEndTime; // End time of query
178 TString fRequestString; // Request string
180 //Count message fields
181 UInt_t fCount; // count counter
183 //ResultSet message fields
184 Int_t fOwnerIndex; // owner index of this result
185 AliDCSValue::Type fValueType; // Simple value type
187 TObjArray* fValues; // array of received values
189 //Error message fields
190 ErrorCode fErrorCode; // error code
192 TString fErrorString; // error string
194 //MultiRequest message fields
195 TObjArray fRequestStrings; // multi request string array
198 // Message setter helpers
201 void StoreRequestMessage();
203 void StoreCountMessage();
205 void StoreResultSetMessage();
207 void StoreErrorMessage();
209 void StoreMultiRequestMessage();
211 void StoreNextMessage();
214 Bool_t ValidateHeader(const char* buf);
216 void LoadRequestMessage();
218 void LoadCountMessage();
220 void LoadResultSetMessage();
222 void LoadErrorMessage();
224 void LoadUnknownDPMessage();
226 void LoadMultiRequestMessage();
228 void LoadNextMessage();
230 void LoadHeartBeatMessage();
233 static void SetBool(char* buf, Bool_t val);
235 static void SetByte(char* buf, Char_t val);
237 static void SetUByte(char* buf, UChar_t val);
239 static void SetInt(char* buf, Int_t val);
241 static void SetUInt(char* buf, UInt_t val);
243 static void SetFloat(char* buf, Float_t val);
245 static Bool_t GetBool(const char* buf);
247 static Char_t GetByte(const char* buf);
249 static UChar_t GetUByte(const char* buf);
251 static Int_t GetInt(const char* buf);
253 static UInt_t GetUInt(const char* buf);
255 static Float_t GetFloat(const char* buf);
257 static TString GetString(const char* buf, Int_t maxLen);
260 ClassDef(AliDCSMessage, 0);