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