]>
Commit | Line | Data |
---|---|---|
8ecd252f | 1 | //-*- Mode: C++ -*- |
2 | // $Id$ | |
3 | ||
4 | #ifndef ALIHLTDIMSERVER_H | |
5 | #define ALIHLTDIMSERVER_H | |
6 | ||
7 | //* This file is property of and copyright by the ALICE HLT Project * | |
8 | //* ALICE Experiment at CERN, All rights reserved. * | |
9 | //* See cxx source for full Copyright notice * | |
10 | ||
c7bdcc06 | 11 | // @file AliHLTDimServer.h |
12 | // @author Matthias Richter | |
13 | // @date 20010-03-10 | |
14 | // @brief HLT DIM server implementation and dynamic access | |
15 | // to DIM library | |
16 | ||
8ecd252f | 17 | #include "AliHLTLogging.h" |
18 | #include "TNamed.h" | |
19 | #include "TObjArray.h" | |
20 | ||
21 | class TThread; | |
22 | ||
23 | /** | |
24 | * @class AliHLTDimServer | |
25 | * Implementation of a DIM server for HLT and the dynamic access to the | |
26 | * DIM library. | |
27 | */ | |
28 | class AliHLTDimServer : public TNamed { | |
29 | public: | |
30 | AliHLTDimServer(); | |
31 | AliHLTDimServer(const char* servername); | |
32 | ~AliHLTDimServer(); | |
33 | ||
34 | /// Data type identifiers for services. | |
35 | enum AliHLTDimServiceDataType{ | |
36 | kDataTypeUnknown = 0, /// initializer | |
37 | kDataTypeInt, /// Integer type | |
38 | kDataTypeFloat, /// Float type | |
39 | kDataTypeString, /// String type | |
40 | }; | |
41 | ||
42 | /// The service data field. | |
43 | struct AliHLTDimServicePoint_t { | |
44 | union { | |
45 | int iVal; /// integer value | |
46 | float fVal; /// float value | |
47 | void* strVal; /// string value, casted to string* before use | |
48 | }; | |
49 | }; | |
50 | ||
51 | /** @class AliHLTDimService | |
52 | * Base class for DIM services | |
53 | */ | |
54 | class AliHLTDimService : public TNamed { | |
55 | public: | |
56 | AliHLTDimService(); | |
57 | AliHLTDimService(AliHLTDimServiceDataType type, const char* servicename); | |
58 | ||
c7bdcc06 | 59 | void Update(const AliHLTDimServicePoint_t& sp); |
8ecd252f | 60 | AliHLTDimServiceDataType GetType() const {return fType;} |
61 | void* GetLocation() {return &fData.iVal;} | |
62 | int GetId() const {return fId;} | |
63 | int SetId(int id) {fId=id;return id;} | |
64 | ||
65 | private: | |
66 | AliHLTDimServicePoint_t fData; /// the data point | |
67 | AliHLTDimServiceDataType fType; /// type of this service | |
68 | int fId; /// id of the service | |
69 | }; | |
70 | ||
71 | /** @class AliHLTDimServiceFloat | |
72 | * DIM service for a float value | |
73 | */ | |
74 | class AliHLTDimServiceFloat : public AliHLTDimService { | |
75 | public: | |
76 | AliHLTDimServiceFloat(); | |
77 | ~AliHLTDimServiceFloat(); | |
78 | ||
79 | void Update(float f) { | |
80 | AliHLTDimServicePoint_t sp; sp.fVal=f; AliHLTDimService::Update(sp); | |
81 | } | |
82 | }; | |
83 | ||
bdd7f6fd | 84 | /** @class AliHLTDimServiceInt |
85 | * DIM service for a int value | |
86 | */ | |
87 | class AliHLTDimServiceInt : public AliHLTDimService { | |
88 | public: | |
89 | AliHLTDimServiceInt(); | |
90 | ~AliHLTDimServiceInt(); | |
91 | ||
92 | void Update(int i) { | |
93 | AliHLTDimServicePoint_t sp; sp.iVal=i; AliHLTDimService::Update(sp); | |
94 | } | |
95 | }; | |
96 | ||
8ecd252f | 97 | /** |
98 | * Register a service. | |
99 | * @param pService the service to be registered | |
8ecd252f | 100 | */ |
101 | int RegisterService(AliHLTDimService* pService); | |
102 | ||
103 | /** | |
104 | * Create a service. | |
105 | * @param type type of the channel, see @ref ceServiceDataType | |
106 | * @param name unique name of the service | |
107 | * @return dim service object, needs to be cleaned by the caller | |
8ecd252f | 108 | */ |
109 | AliHLTDimService* CreateService(AliHLTDimServiceDataType type, const char* name); | |
110 | ||
111 | /** | |
112 | * Create a group of services. | |
113 | * The names are built from the basename and the number of services. | |
114 | * @param type type of the channel | |
115 | * @param basename base name of the services, the name might contain a '%d' sequence which is then | |
116 | * replaced by the number, number is appended if no '%d' provided | |
117 | * @param count number of services in this group, passed to the <i>update</i> and <i>set</i> function as parameter major | |
118 | * @return TObjArray of AliHLTDimService objects, the array needs to be cleaned by the caller | |
8ecd252f | 119 | */ |
120 | TObjArray* CreateServiceGroup(AliHLTDimServiceDataType type, const char* basename, int count); | |
121 | ||
122 | /// Update all services via the Dim channel | |
123 | int UpdateServices(); | |
124 | ||
125 | /// init the server | |
126 | /// load the dim library and function pointers | |
127 | /// init dim (DNS and server name) | |
128 | int Init(const char* dimNameServer); | |
129 | ||
130 | /// Reset | |
131 | int Reset(); | |
132 | ||
133 | /// start the server | |
134 | int Start(); | |
135 | ||
136 | /// stop the server | |
137 | int Stop(); | |
138 | ||
139 | protected: | |
140 | enum AliHLTDimServerState_t { | |
141 | // server is not started | |
142 | kStateOff = 0, | |
143 | // starting, will be changed by the server thread to kStateRunning | |
144 | kStateStarting, | |
145 | // server running | |
146 | kStateRunning, | |
147 | // set by the main thread and changed by the server thread before it terminates | |
148 | kStateStopping, | |
149 | // error | |
150 | kStateError | |
151 | }; | |
152 | ||
153 | int SetState(int state) {fState=state; return fState;} | |
154 | ||
c7bdcc06 | 155 | int GetState() const {return fState;} |
8ecd252f | 156 | |
157 | typedef void (*fctVoid)(); | |
158 | typedef int (*fctDisServiceCallback)( const char*); | |
159 | typedef int (*fctDisAddService) ( const char* service, | |
160 | const char* type, | |
161 | void* buffer, | |
162 | int size, | |
163 | fctDisServiceCallback cb, | |
164 | long int tag); | |
165 | typedef int (*fctDisRemoveService) ( unsigned int id); | |
166 | typedef int (*fctDisUpdateService) ( unsigned int id); | |
167 | typedef int (*fctDisCharArg) ( const char*); | |
168 | typedef int (*fctDisNoArg) ( ); | |
169 | ||
030da833 | 170 | /** |
171 | * @class AliHLTDimInterface | |
172 | * Interface to the dim library | |
173 | */ | |
8ecd252f | 174 | class AliHLTDimInterface : public AliHLTLogging { |
175 | public: | |
176 | AliHLTDimInterface(); | |
177 | ~AliHLTDimInterface(); | |
178 | ||
179 | /// load the dim library and function pointers | |
180 | int Init(); | |
181 | ||
182 | int DisAddService(const char* service, const char* type, void* buffer, | |
c7bdcc06 | 183 | int size, fctDisServiceCallback cb, long int tag) const { |
8ecd252f | 184 | if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, cb, tag); |
185 | return -ENODEV; | |
186 | } | |
187 | ||
c7bdcc06 | 188 | int DisAddService(const char* service, const char* type, void* buffer, int size) const { |
8ecd252f | 189 | if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, NULL, 0); |
190 | return -ENODEV; | |
191 | } | |
192 | ||
c7bdcc06 | 193 | int DisRemoveService(unsigned int id) const { |
8ecd252f | 194 | if (fpDisRemoveService) return (*fpDisRemoveService)(id); |
195 | return -ENODEV; | |
196 | } | |
197 | ||
c7bdcc06 | 198 | int DisUpdateService(unsigned int id) const { |
8ecd252f | 199 | if (fpDisUpdateService) return (*fpDisUpdateService)(id); |
200 | return -ENODEV; | |
201 | } | |
202 | ||
c7bdcc06 | 203 | int DisStartServing(const char *server) const { |
8ecd252f | 204 | if (fpDisStartServing) return (*fpDisStartServing)(server); |
205 | return -ENODEV; | |
206 | } | |
207 | ||
c7bdcc06 | 208 | int DisStopServing() const { |
8ecd252f | 209 | if (fpDisStopServing) return (*fpDisStopServing)(); |
210 | return -ENODEV; | |
211 | } | |
212 | ||
c7bdcc06 | 213 | int DisSetDnsNode(const char *server) const { |
8ecd252f | 214 | if (fpDisSetDnsNode) return (*fpDisSetDnsNode)(server); |
215 | return -ENODEV; | |
216 | } | |
217 | ||
218 | private: | |
219 | fctVoid FindSymbol(const char* library, const char* symbol) const; | |
220 | ||
221 | fctDisAddService fpDisAddService; //! transient | |
222 | fctDisRemoveService fpDisRemoveService; //! transient | |
223 | fctDisUpdateService fpDisUpdateService; //! transient | |
224 | fctDisCharArg fpDisStartServing; //! transient | |
225 | fctDisNoArg fpDisStopServing; //! transient | |
226 | fctDisCharArg fpDisSetDnsNode; //! transient | |
227 | static const char* fgkDimLibraryName ; //! | |
228 | static const char* fgkDisAddServiceSymbol; //! | |
229 | static const char* fgkDisRemoveServiceSymbol; //! | |
230 | static const char* fgkDisUpdateServiceSymbol; //! | |
231 | static const char* fgkDisStartServingSymbol; //! | |
232 | static const char* fgkDisStopServingSymbol; //! | |
233 | static const char* fgkDisSetDnsNodeSymbol; //! | |
234 | }; | |
235 | ||
236 | static AliHLTDimInterface* Interface(); | |
237 | ||
238 | private: | |
239 | /// copy constructor not permitted | |
240 | AliHLTDimServer(const AliHLTDimServer&); | |
241 | /// assignment operator not permitted | |
242 | AliHLTDimServer& operator=(const AliHLTDimServer&); | |
243 | ||
244 | /// entry point for the thread, param is pointer to object | |
245 | static void* ServerLoop(void* param); | |
246 | ||
247 | /// the server loop | |
248 | void* ServerLoop(); | |
249 | ||
250 | TObjArray fServices; //! list of services | |
251 | int fState; //! state of the server | |
252 | TThread* fpServerThread; //! thread | |
253 | int fUpdatePeriod; //! update period for the DIM loop in ms | |
254 | ||
255 | static AliHLTDimInterface* fgpInterface; //! the dim interface | |
256 | ||
257 | ClassDef(AliHLTDimServer, 0) | |
258 | }; | |
259 | #endif |