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.
15 #include "AliDCSValue.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)
46 class AliDCSMessage: public TObject {
66 kUnknownAliasDPName = 1,
67 kInvalidTimeRange = 2,
68 kInvalidBufferSize = 3,
77 AliDCSMessage(const char* buffer, UInt_t size);
82 void CreateRequestMessage(RequestType type,
83 UInt_t startTime, UInt_t endTime, const char* request);
85 void CreateMultiRequestMessage(RequestType type,
86 UInt_t startTime, UInt_t endTime);
88 void CreateCountMessage(UInt_t count);
90 void CreateResultSetMessage(AliSimpleValue::Type type);
92 void CreateErrorMessage(ErrorCode code, const char* errorString);
94 //void CreateNextMessage();
96 void DestroyMessage();
99 Bool_t SetRawHeader(const char* header);
101 void StoreToBuffer();
103 void LoadFromBuffer();
105 void DestroyBuffer();
108 Bool_t IsValid() const {return fType != kInvalid;};
110 UInt_t GetMessageSize() const {return fMessageSize;};
112 char* GetMessage() const {return fMessage;};
114 UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
116 char* GetBody() const {return fMessage + HEADER_SIZE;};
118 Type GetType() const {return fType;};
120 // RequestType and MultiReuqestType Message getters
121 RequestType GetRequestType() const;
123 UInt_t GetStartTime() const;
125 UInt_t GetEndTime() const;
127 TString GetRequestString() const;
129 // MultiRequestType Message getters and setters
130 void GetRequestStrings(TList& result) const;
132 Bool_t AddRequestString(const char* request);
134 void ClearRequestStrings();
136 // CountType Message getters
137 UInt_t GetCount() const;
139 // ResultSetType Message getters ans setters
140 AliSimpleValue::Type GetSimpleValueType() const;
142 UInt_t GetValueCount() const;
144 UInt_t GetValues(TList& result) const;
146 Bool_t AddValue(const AliDCSValue& value);
150 // ErrorType Message getters
151 ErrorCode GetErrorCode() const;
153 TString GetErrorString() const;
156 virtual void Print(Option_t* option = NULL) const;
158 static void PrintBuffer(const char* buf, UInt_t size, TString& output);
169 //Request message fields
170 RequestType fRequestType;
176 TString fRequestString;
178 //Count message fields
181 //ResultSet message fields
182 AliSimpleValue::Type fSimpleValueType;
186 //Error message fields
187 ErrorCode fErrorCode;
189 TString fErrorString;
191 //MultiRequest message fields
192 TList fRequestStrings;
195 // Message setter helpers
198 void StoreRequestMessage();
200 void StoreCountMessage();
202 void StoreResultSetMessage();
204 void StoreErrorMessage();
206 void StoreMultiRequestMessage();
208 //void StoreNextMessage();
211 Bool_t ValidateHeader(const char* buf);
213 void LoadRequestMessage();
215 void LoadCountMessage();
217 void LoadResultSetMessage();
219 void LoadErrorMessage();
221 void LoadMultiRequestMessage();
223 //void LoadNextMessage();
226 static void SetBool(char* buf, Bool_t val);
228 static void SetByte(char* buf, Char_t val);
230 static void SetUByte(char* buf, UChar_t val);
232 static void SetInt(char* buf, Int_t val);
234 static void SetUInt(char* buf, UInt_t val);
236 static void SetFloat(char* buf, Float_t val);
238 static Bool_t GetBool(const char* buf);
240 static Char_t GetByte(const char* buf);
242 static UChar_t GetUByte(const char* buf);
244 static Int_t GetInt(const char* buf);
246 static UInt_t GetUInt(const char* buf);
248 static Float_t GetFloat(const char* buf);
250 static TString GetString(const char* buf, Int_t maxLen);
253 ClassDef(AliDCSMessage, 0);