]> git.uio.no Git - u/mrichter/AliRoot.git/blame - SHUTTLE/AliDCSMessage.h
Generator for ISAJET events (A. Bogdanov)
[u/mrichter/AliRoot.git] / SHUTTLE / AliDCSMessage.h
CommitLineData
73abe331 1#ifndef ALI_DCS_MESSAGE_H
2#define ALI_DCS_MESSAGE_H
3
4/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6
7/* $Id$ */
8
9//
10// This class is a wrapper of AliDCSMessage.
11// These are the messages which form AliDCSProtocol.
58bc3020 12// Used by AliDCSClient to communicate with the DCS Amanda server
73abe331 13//
14
73abe331 15#include <TString.h>
d477ad88 16#include <TObjArray.h>
58bc3020 17#include "AliDCSValue.h"
73abe331 18
19#define HEADER_SIZE 8
20#define ID_OFFSET 0
21#define VERSION_OFFSET 2
22#define TYPE_OFFSET 3
23#define BODY_SIZE_OFFSET 4
24
25#define MAX_BODY_SIZE 40000
26
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)
31
32#define REQUEST_STRINGS_OFFSET REQUEST_STRING_OFFSET
33
34#define COUNT_OFFSET HEADER_SIZE
35
36#define SVT_OFFSET HEADER_SIZE
37#define VALUE_COUNT_OFFSET (HEADER_SIZE + 1)
38#define VALUES_OFFSET (HEADER_SIZE + 5)
39
40#define ERROR_CODE_OFFSET HEADER_SIZE
41#define ERROR_STRING_OFFSET (HEADER_SIZE + 1)
42
73abe331 43class AliDCSMessage: public TObject {
44public:
45 enum Type {
46 kInvalid = 0,
47 kRequest = 1,
48 kCount = 2,
49 kResultSet = 3,
50 kError = 4,
51 kMultiRequest = 5
52// kNext = 6
53 };
54
55 enum RequestType {
56 kNoneType = 0,
57 kAlias = 1,
58 kDPName = 2
59 };
60
61 enum ErrorCode {
62 kNoneError = 0,
63 kUnknownAliasDPName = 1,
64 kInvalidTimeRange = 2,
65 kInvalidBufferSize = 3,
66 kInvalidRequest = 4,
67 kUnsupportedType = 5,
68 kUnknownError = 255
69 };
70
71
72 AliDCSMessage();
73
74 AliDCSMessage(const char* buffer, UInt_t size);
75
58bc3020 76 virtual ~AliDCSMessage();
73abe331 77
78
79 void CreateRequestMessage(RequestType type,
80 UInt_t startTime, UInt_t endTime, const char* request);
81
82 void CreateMultiRequestMessage(RequestType type,
83 UInt_t startTime, UInt_t endTime);
84
85 void CreateCountMessage(UInt_t count);
86
45a493ce 87 void CreateResultSetMessage(AliDCSValue::Type type);
73abe331 88
89 void CreateErrorMessage(ErrorCode code, const char* errorString);
90
91 //void CreateNextMessage();
92
93 void DestroyMessage();
94
95
96 Bool_t SetRawHeader(const char* header);
97
98 void StoreToBuffer();
99
100 void LoadFromBuffer();
101
102 void DestroyBuffer();
103
104
105 Bool_t IsValid() const {return fType != kInvalid;};
106
107 UInt_t GetMessageSize() const {return fMessageSize;};
108
109 char* GetMessage() const {return fMessage;};
110
111 UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
112
113 char* GetBody() const {return fMessage + HEADER_SIZE;};
114
115 Type GetType() const {return fType;};
116
117 // RequestType and MultiReuqestType Message getters
118 RequestType GetRequestType() const;
119
120 UInt_t GetStartTime() const;
121
122 UInt_t GetEndTime() const;
123
124 TString GetRequestString() const;
125
126 // MultiRequestType Message getters and setters
d477ad88 127 void GetRequestStrings(TObjArray& result) const;
73abe331 128
129 Bool_t AddRequestString(const char* request);
130
131 void ClearRequestStrings();
132
133 // CountType Message getters
134 UInt_t GetCount() const;
135
136 // ResultSetType Message getters ans setters
45a493ce 137 AliDCSValue::Type GetValueType() const;
73abe331 138
139 UInt_t GetValueCount() const;
140
d477ad88 141 UInt_t GetValues(TObjArray& result) const;
73abe331 142
143 Bool_t AddValue(const AliDCSValue& value);
144
145 void ClearValues();
146
147 // ErrorType Message getters
148 ErrorCode GetErrorCode() const;
149
150 TString GetErrorString() const;
151
152
153 virtual void Print(Option_t* option = NULL) const;
154
155 static void PrintBuffer(const char* buf, UInt_t size, TString& output);
156
157private:
158
58bc3020 159 AliDCSMessage(const AliDCSMessage& other);
160 AliDCSMessage& operator= (const AliDCSMessage& other);
161
162
163 char* fMessage; // Array of bytes building the message
73abe331 164
58bc3020 165 UInt_t fMessageSize; // Size of the message array
73abe331 166
167
58bc3020 168 Type fType; // Message type (request, count...)
73abe331 169
170 //Request message fields
58bc3020 171 RequestType fRequestType; // Type of request message
73abe331 172
58bc3020 173 UInt_t fStartTime; // Start time of query
73abe331 174
58bc3020 175 UInt_t fEndTime; // End time of query
73abe331 176
58bc3020 177 TString fRequestString; // Request string
73abe331 178
179 //Count message fields
58bc3020 180 UInt_t fCount; // count counter
73abe331 181
182 //ResultSet message fields
45a493ce 183 AliDCSValue::Type fValueType; // Simple value type
73abe331 184
e090413b 185 // TODO this has to be a pointer
58bc3020 186 TObjArray fValues; // array of received values
73abe331 187
188 //Error message fields
58bc3020 189 ErrorCode fErrorCode; // error code
73abe331 190
58bc3020 191 TString fErrorString; // error string
73abe331 192
193 //MultiRequest message fields
58bc3020 194 TObjArray fRequestStrings; // multi request string array
73abe331 195
196
197 // Message setter helpers
198 void StoreHeader();
199
200 void StoreRequestMessage();
201
202 void StoreCountMessage();
203
204 void StoreResultSetMessage();
205
206 void StoreErrorMessage();
207
208 void StoreMultiRequestMessage();
209
210 //void StoreNextMessage();
211
212
213 Bool_t ValidateHeader(const char* buf);
214
215 void LoadRequestMessage();
216
217 void LoadCountMessage();
218
219 void LoadResultSetMessage();
220
221 void LoadErrorMessage();
222
223 void LoadMultiRequestMessage();
224
225 //void LoadNextMessage();
226
227 // Buffer helpers
228 static void SetBool(char* buf, Bool_t val);
229
230 static void SetByte(char* buf, Char_t val);
231
232 static void SetUByte(char* buf, UChar_t val);
233
234 static void SetInt(char* buf, Int_t val);
235
236 static void SetUInt(char* buf, UInt_t val);
237
238 static void SetFloat(char* buf, Float_t val);
239
240 static Bool_t GetBool(const char* buf);
241
242 static Char_t GetByte(const char* buf);
243
244 static UChar_t GetUByte(const char* buf);
245
246 static Int_t GetInt(const char* buf);
247
248 static UInt_t GetUInt(const char* buf);
249
250 static Float_t GetFloat(const char* buf);
251
252 static TString GetString(const char* buf, Int_t maxLen);
253
254
255 ClassDef(AliDCSMessage, 0);
256};
257
258#endif