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"
18 #include "AliSimpleValue.h"
22 #define VERSION_OFFSET 2
24 #define BODY_SIZE_OFFSET 4
26 #define MAX_BODY_SIZE 40000
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)
33 #define REQUEST_STRINGS_OFFSET REQUEST_STRING_OFFSET
35 #define COUNT_OFFSET HEADER_SIZE
37 #define SVT_OFFSET HEADER_SIZE
38 #define VALUE_COUNT_OFFSET (HEADER_SIZE + 1)
39 #define VALUES_OFFSET (HEADER_SIZE + 5)
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);
77 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);
88 void CreateResultSetMessage(AliSimpleValue::Type type);
90 void CreateErrorMessage(ErrorCode code, const char* errorString);
92 //void CreateNextMessage();
94 void DestroyMessage();
97 Bool_t SetRawHeader(const char* header);
101 void LoadFromBuffer();
103 void DestroyBuffer();
106 Bool_t IsValid() const {return fType != kInvalid;};
108 UInt_t GetMessageSize() const {return fMessageSize;};
110 char* GetMessage() const {return fMessage;};
112 UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
114 char* GetBody() const {return fMessage + HEADER_SIZE;};
116 Type GetType() const {return fType;};
118 // RequestType and MultiReuqestType Message getters
119 RequestType GetRequestType() const;
121 UInt_t GetStartTime() const;
123 UInt_t GetEndTime() const;
125 TString GetRequestString() const;
127 // MultiRequestType Message getters and setters
128 void GetRequestStrings(TObjArray& result) const;
130 Bool_t AddRequestString(const char* request);
132 void ClearRequestStrings();
134 // CountType Message getters
135 UInt_t GetCount() const;
137 // ResultSetType Message getters ans setters
138 AliSimpleValue::Type GetSimpleValueType() const;
140 UInt_t GetValueCount() const;
142 UInt_t GetValues(TObjArray& result) const;
144 Bool_t AddValue(const 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 AliSimpleValue::Type fSimpleValueType; // Simple value type
186 TObjArray fValues; // array of received values
188 //Error message fields
189 ErrorCode fErrorCode; // error code
191 TString fErrorString; // error string
193 //MultiRequest message fields
194 TObjArray fRequestStrings; // multi request string array
197 // Message setter helpers
200 void StoreRequestMessage();
202 void StoreCountMessage();
204 void StoreResultSetMessage();
206 void StoreErrorMessage();
208 void StoreMultiRequestMessage();
210 //void StoreNextMessage();
213 Bool_t ValidateHeader(const char* buf);
215 void LoadRequestMessage();
217 void LoadCountMessage();
219 void LoadResultSetMessage();
221 void LoadErrorMessage();
223 void LoadMultiRequestMessage();
225 //void LoadNextMessage();
228 static void SetBool(char* buf, Bool_t val);
230 static void SetByte(char* buf, Char_t val);
232 static void SetUByte(char* buf, UChar_t val);
234 static void SetInt(char* buf, Int_t val);
236 static void SetUInt(char* buf, UInt_t val);
238 static void SetFloat(char* buf, Float_t val);
240 static Bool_t GetBool(const char* buf);
242 static Char_t GetByte(const char* buf);
244 static UChar_t GetUByte(const char* buf);
246 static Int_t GetInt(const char* buf);
248 static UInt_t GetUInt(const char* buf);
250 static Float_t GetFloat(const char* buf);
252 static TString GetString(const char* buf, Int_t maxLen);
255 ClassDef(AliDCSMessage, 0);