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