]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliDCSMessage.h
Record changes.
[u/mrichter/AliRoot.git] / SHUTTLE / 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 #include "AliSimpleValue.h"
19
20 #define HEADER_SIZE 8
21 #define ID_OFFSET 0
22 #define VERSION_OFFSET 2
23 #define TYPE_OFFSET 3
24 #define BODY_SIZE_OFFSET 4
25
26 #define MAX_BODY_SIZE 40000
27
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)
32
33 #define REQUEST_STRINGS_OFFSET REQUEST_STRING_OFFSET
34
35 #define COUNT_OFFSET HEADER_SIZE
36
37 #define SVT_OFFSET HEADER_SIZE
38 #define VALUE_COUNT_OFFSET (HEADER_SIZE + 1)
39 #define VALUES_OFFSET (HEADER_SIZE + 5)
40
41 #define ERROR_CODE_OFFSET HEADER_SIZE
42 #define ERROR_STRING_OFFSET (HEADER_SIZE + 1)
43
44 class AliDCSMessage: public TObject {
45 public:
46         enum Type {
47                 kInvalid = 0,
48                 kRequest = 1,
49                 kCount = 2,
50                 kResultSet = 3,
51                 kError = 4,
52                 kMultiRequest = 5
53 //              kNext = 6
54         };
55
56         enum RequestType {
57                 kNoneType = 0,
58                 kAlias = 1,
59                 kDPName = 2     
60         };
61
62         enum ErrorCode {
63                 kNoneError = 0,
64                 kUnknownAliasDPName = 1,
65                 kInvalidTimeRange = 2,
66                 kInvalidBufferSize = 3,
67                 kInvalidRequest = 4,
68                 kUnsupportedType = 5,
69                 kUnknownError = 255
70         };
71
72
73         AliDCSMessage();
74
75         AliDCSMessage(const char* buffer, UInt_t size);
76
77         virtual ~AliDCSMessage();
78
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
88         void CreateResultSetMessage(AliSimpleValue::Type type); 
89
90         void CreateErrorMessage(ErrorCode code, const char* errorString);
91         
92         //void CreateNextMessage();
93
94         void DestroyMessage();
95
96
97         Bool_t SetRawHeader(const char* header);
98
99         void StoreToBuffer();
100
101         void LoadFromBuffer();
102
103         void DestroyBuffer();
104
105
106         Bool_t IsValid() const {return fType != kInvalid;};
107
108         UInt_t GetMessageSize() const {return fMessageSize;};
109
110         char* GetMessage() const {return fMessage;};
111
112         UInt_t GetBodySize() const {return fMessageSize - HEADER_SIZE;};
113
114         char* GetBody() const {return fMessage + HEADER_SIZE;};
115
116         Type GetType() const {return fType;};
117
118          // RequestType and MultiReuqestType Message getters
119         RequestType GetRequestType() const;
120
121         UInt_t GetStartTime() const;
122
123         UInt_t GetEndTime() const;
124
125         TString GetRequestString() const;
126
127         // MultiRequestType Message getters and setters
128         void GetRequestStrings(TObjArray& result) const;
129
130         Bool_t AddRequestString(const char* request);
131
132         void ClearRequestStrings();
133
134         // CountType Message getters            
135         UInt_t GetCount() const;
136
137         // ResultSetType Message getters ans setters       
138         AliSimpleValue::Type GetSimpleValueType() const;
139
140         UInt_t GetValueCount() const;
141
142         UInt_t GetValues(TObjArray& result) const;
143
144         Bool_t AddValue(const 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         AliSimpleValue::Type fSimpleValueType; // Simple value type
185
186         TObjArray fValues;              // array of received values
187         
188         //Error message fields
189         ErrorCode fErrorCode;           // error code
190         
191         TString fErrorString;           // error string
192
193         //MultiRequest message fields
194         TObjArray fRequestStrings;      // multi request string array
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