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 ERROR_STRING_OFFSET (HEADER_SIZE + 1)
44 class AliDCSMessage: public TObject {
64 kUnknownAliasDPName = 1,
65 kInvalidTimeRange = 2,
66 kInvalidBufferSize = 3,
75 AliDCSMessage(const char* buffer, UInt_t size);
76 virtual ~AliDCSMessage();
78 void CreateRequestMessage(RequestType type,
79 UInt_t startTime, UInt_t endTime, const char* request);
81 void CreateMultiRequestMessage(RequestType type,
82 UInt_t startTime, UInt_t endTime);
84 void CreateCountMessage(UInt_t count);
85 void CreateResultSetMessage(AliDCSValue::Type type);
86 void CreateErrorMessage(ErrorCode code, const char* errorString);
88 void CreateNextMessage();
90 void DestroyMessage();
93 Bool_t SetRawHeader(const char* header);
97 void LoadFromBuffer();
102 Bool_t IsValid() const {return fType != kInvalid;};
104 UInt_t GetMessageSize() const {return fMessageSize;};
106 char* GetMessage() const {return fMessage;};
108 UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
110 char* GetBody() const {return fMessage + HEADER_SIZE;};
112 Type GetType() const {return fType;};
114 // RequestType and MultiReuqestType Message getters
115 RequestType GetRequestType() const;
117 UInt_t GetStartTime() const;
119 UInt_t GetEndTime() const;
121 TString GetRequestString() const;
123 // MultiRequestType Message getters and setters
124 void GetRequestStrings(TObjArray& result) const;
126 Bool_t AddRequestString(const char* request);
128 void ClearRequestStrings();
130 // CountType Message getters
131 UInt_t GetCount() const;
133 // ResultSetType Message getters ans setters
134 AliDCSValue::Type GetValueType() const;
136 Int_t GetOwnerIndex() const { return fOwnerIndex; }
138 UInt_t GetValueCount() const;
140 UInt_t GetValues(TObjArray* result) const;
142 Bool_t AddValue(AliDCSValue& value);
146 // ErrorType Message getters
147 ErrorCode GetErrorCode() const;
149 TString GetErrorString() const;
152 virtual void Print(Option_t* option = NULL) const;
154 static void PrintBuffer(const char* buf, UInt_t size, TString& output);
158 AliDCSMessage(const AliDCSMessage& other);
159 AliDCSMessage& operator= (const AliDCSMessage& other);
162 char* fMessage; // Array of bytes building the message
164 UInt_t fMessageSize; // Size of the message array
167 Type fType; // Message type (request, count...)
169 //Request message fields
170 RequestType fRequestType; // Type of request message
172 UInt_t fStartTime; // Start time of query
174 UInt_t fEndTime; // End time of query
176 TString fRequestString; // Request string
178 //Count message fields
179 UInt_t fCount; // count counter
181 //ResultSet message fields
182 Int_t fOwnerIndex; // owner index of this result
183 AliDCSValue::Type fValueType; // Simple value type
185 TObjArray* fValues; // array of received values
187 //Error message fields
188 ErrorCode fErrorCode; // error code
190 TString fErrorString; // error string
192 //MultiRequest message fields
193 TObjArray fRequestStrings; // multi request string array
196 // Message setter helpers
199 void StoreRequestMessage();
201 void StoreCountMessage();
203 void StoreResultSetMessage();
205 void StoreErrorMessage();
207 void StoreMultiRequestMessage();
209 void StoreNextMessage();
212 Bool_t ValidateHeader(const char* buf);
214 void LoadRequestMessage();
216 void LoadCountMessage();
218 void LoadResultSetMessage();
220 void LoadErrorMessage();
222 void LoadMultiRequestMessage();
224 void LoadNextMessage();
227 static void SetBool(char* buf, Bool_t val);
229 static void SetByte(char* buf, Char_t val);
231 static void SetUByte(char* buf, UChar_t val);
233 static void SetInt(char* buf, Int_t val);
235 static void SetUInt(char* buf, UInt_t val);
237 static void SetFloat(char* buf, Float_t val);
239 static Bool_t GetBool(const char* buf);
241 static Char_t GetByte(const char* buf);
243 static UChar_t GetUByte(const char* buf);
245 static Int_t GetInt(const char* buf);
247 static UInt_t GetUInt(const char* buf);
249 static Float_t GetFloat(const char* buf);
251 static TString GetString(const char* buf, Int_t maxLen);
254 ClassDef(AliDCSMessage, 0);