4 #ifndef ALIHLTDIMSERVER_H
5 #define ALIHLTDIMSERVER_H
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 *
11 /** @file AliHLTDimServer.h
12 @author Matthias Richter
16 #include "AliHLTLogging.h"
18 #include "TObjArray.h"
23 * @class AliHLTDimServer
24 * Implementation of a DIM server for HLT and the dynamic access to the
27 class AliHLTDimServer : public TNamed {
30 AliHLTDimServer(const char* servername);
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
41 /// The service data field.
42 struct AliHLTDimServicePoint_t {
44 int iVal; /// integer value
45 float fVal; /// float value
46 void* strVal; /// string value, casted to string* before use
50 /** @class AliHLTDimService
51 * Base class for DIM services
53 class AliHLTDimService : public TNamed {
56 AliHLTDimService(AliHLTDimServiceDataType type, const char* servicename);
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;}
65 AliHLTDimServicePoint_t fData; /// the data point
66 AliHLTDimServiceDataType fType; /// type of this service
67 int fId; /// id of the service
70 /** @class AliHLTDimServiceFloat
71 * DIM service for a float value
73 class AliHLTDimServiceFloat : public AliHLTDimService {
75 AliHLTDimServiceFloat();
76 ~AliHLTDimServiceFloat();
78 void Update(float f) {
79 AliHLTDimServicePoint_t sp; sp.fVal=f; AliHLTDimService::Update(sp);
83 /** @class AliHLTDimServiceInt
84 * DIM service for a int value
86 class AliHLTDimServiceInt : public AliHLTDimService {
88 AliHLTDimServiceInt();
89 ~AliHLTDimServiceInt();
92 AliHLTDimServicePoint_t sp; sp.iVal=i; AliHLTDimService::Update(sp);
98 * @param pService the service to be registered
99 * @ingroup rcu_ce_base_services
101 int RegisterService(AliHLTDimService* pService);
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
108 * @ingroup rcu_ce_base_services
110 AliHLTDimService* CreateService(AliHLTDimServiceDataType type, const char* name);
113 * Create a group of services.
114 * The names are built from the basename and the number of services.
115 * @param type type of the channel
116 * @param basename base name of the services, the name might contain a '%d' sequence which is then
117 * replaced by the number, number is appended if no '%d' provided
118 * @param count number of services in this group, passed to the <i>update</i> and <i>set</i> function as parameter major
119 * @return TObjArray of AliHLTDimService objects, the array needs to be cleaned by the caller
120 * @ingroup rcu_ce_base_services
122 TObjArray* CreateServiceGroup(AliHLTDimServiceDataType type, const char* basename, int count);
124 /// Update all services via the Dim channel
125 int UpdateServices();
128 /// load the dim library and function pointers
129 /// init dim (DNS and server name)
130 int Init(const char* dimNameServer);
142 enum AliHLTDimServerState_t {
143 // server is not started
145 // starting, will be changed by the server thread to kStateRunning
149 // set by the main thread and changed by the server thread before it terminates
155 int SetState(int state) {fState=state; return fState;}
157 int GetState() {return fState;}
159 typedef void (*fctVoid)();
160 typedef int (*fctDisServiceCallback)( const char*);
161 typedef int (*fctDisAddService) ( const char* service,
165 fctDisServiceCallback cb,
167 typedef int (*fctDisRemoveService) ( unsigned int id);
168 typedef int (*fctDisUpdateService) ( unsigned int id);
169 typedef int (*fctDisCharArg) ( const char*);
170 typedef int (*fctDisNoArg) ( );
173 * @class AliHLTDimInterface
174 * Interface to the dim library
176 class AliHLTDimInterface : public AliHLTLogging {
178 AliHLTDimInterface();
179 ~AliHLTDimInterface();
181 /// load the dim library and function pointers
184 int DisAddService(const char* service, const char* type, void* buffer,
185 int size, fctDisServiceCallback cb, long int tag) {
186 if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, cb, tag);
190 int DisAddService(const char* service, const char* type, void* buffer, int size) {
191 if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, NULL, 0);
195 int DisRemoveService(unsigned int id) {
196 if (fpDisRemoveService) return (*fpDisRemoveService)(id);
200 int DisUpdateService(unsigned int id) {
201 if (fpDisUpdateService) return (*fpDisUpdateService)(id);
205 int DisStartServing(const char *server) {
206 if (fpDisStartServing) return (*fpDisStartServing)(server);
210 int DisStopServing() {
211 if (fpDisStopServing) return (*fpDisStopServing)();
215 int DisSetDnsNode(const char *server) {
216 if (fpDisSetDnsNode) return (*fpDisSetDnsNode)(server);
221 fctVoid FindSymbol(const char* library, const char* symbol) const;
223 fctDisAddService fpDisAddService; //! transient
224 fctDisRemoveService fpDisRemoveService; //! transient
225 fctDisUpdateService fpDisUpdateService; //! transient
226 fctDisCharArg fpDisStartServing; //! transient
227 fctDisNoArg fpDisStopServing; //! transient
228 fctDisCharArg fpDisSetDnsNode; //! transient
229 static const char* fgkDimLibraryName ; //!
230 static const char* fgkDisAddServiceSymbol; //!
231 static const char* fgkDisRemoveServiceSymbol; //!
232 static const char* fgkDisUpdateServiceSymbol; //!
233 static const char* fgkDisStartServingSymbol; //!
234 static const char* fgkDisStopServingSymbol; //!
235 static const char* fgkDisSetDnsNodeSymbol; //!
238 static AliHLTDimInterface* Interface();
241 /// copy constructor not permitted
242 AliHLTDimServer(const AliHLTDimServer&);
243 /// assignment operator not permitted
244 AliHLTDimServer& operator=(const AliHLTDimServer&);
246 /// entry point for the thread, param is pointer to object
247 static void* ServerLoop(void* param);
252 TObjArray fServices; //! list of services
253 int fState; //! state of the server
254 TThread* fpServerThread; //! thread
255 int fUpdatePeriod; //! update period for the DIM loop in ms
257 static AliHLTDimInterface* fgpInterface; //! the dim interface
259 ClassDef(AliHLTDimServer, 0)