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 40000
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 SVT_OFFSET HEADER_SIZE
37 #define VALUE_COUNT_OFFSET (HEADER_SIZE + 1)
38 #define VALUES_OFFSET (HEADER_SIZE + 5)
40 #define ERROR_CODE_OFFSET HEADER_SIZE
41 #define ERROR_STRING_OFFSET (HEADER_SIZE + 1)
43 class AliDCSMessage: public TObject {
63 kUnknownAliasDPName = 1,
64 kInvalidTimeRange = 2,
65 kInvalidBufferSize = 3,
74 AliDCSMessage(const char* buffer, UInt_t size);
76 virtual ~AliDCSMessage();
79 void CreateRequestMessage(RequestType type,
80 UInt_t startTime, UInt_t endTime, const char* request);
82 void CreateMultiRequestMessage(RequestType type,
83 UInt_t startTime, UInt_t endTime);
85 void CreateCountMessage(UInt_t count);
87 void CreateResultSetMessage(AliDCSValue::Type type);
89 void CreateErrorMessage(ErrorCode code, const char* errorString);
91 //void CreateNextMessage();
93 void DestroyMessage();
96 Bool_t SetRawHeader(const char* header);
100 void LoadFromBuffer();
102 void DestroyBuffer();
105 Bool_t IsValid() const {return fType != kInvalid;};
107 UInt_t GetMessageSize() const {return fMessageSize;};
109 char* GetMessage() const {return fMessage;};
111 UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
113 char* GetBody() const {return fMessage + HEADER_SIZE;};
115 Type GetType() const {return fType;};
117 // RequestType and MultiReuqestType Message getters
118 RequestType GetRequestType() const;
120 UInt_t GetStartTime() const;
122 UInt_t GetEndTime() const;
124 TString GetRequestString() const;
126 // MultiRequestType Message getters and setters
127 void GetRequestStrings(TObjArray& result) const;
129 Bool_t AddRequestString(const char* request);
131 void ClearRequestStrings();
133 // CountType Message getters
134 UInt_t GetCount() const;
136 // ResultSetType Message getters ans setters
137 AliDCSValue::Type GetValueType() const;
139 UInt_t GetValueCount() const;
141 UInt_t GetValues(TObjArray& result) const;
143 Bool_t AddValue(const AliDCSValue& value);
147 // ErrorType Message getters
148 ErrorCode GetErrorCode() const;
150 TString GetErrorString() const;
153 virtual void Print(Option_t* option = NULL) const;
155 static void PrintBuffer(const char* buf, UInt_t size, TString& output);
159 AliDCSMessage(const AliDCSMessage& other);
160 AliDCSMessage& operator= (const AliDCSMessage& other);
163 char* fMessage; // Array of bytes building the message
165 UInt_t fMessageSize; // Size of the message array
168 Type fType; // Message type (request, count...)
170 //Request message fields
171 RequestType fRequestType; // Type of request message
173 UInt_t fStartTime; // Start time of query
175 UInt_t fEndTime; // End time of query
177 TString fRequestString; // Request string
179 //Count message fields
180 UInt_t fCount; // count counter
182 //ResultSet message fields
183 AliDCSValue::Type fValueType; // Simple value type
185 // TODO this has to be a pointer
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);