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);
85 * @param pService the service to be registered
86 * @ingroup rcu_ce_base_services
88 int RegisterService(AliHLTDimService* pService);
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
97 AliHLTDimService* CreateService(AliHLTDimServiceDataType type, const char* name);
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
109 TObjArray* CreateServiceGroup(AliHLTDimServiceDataType type, const char* basename, int count);
111 /// Update all services via the Dim channel
112 int UpdateServices();
115 /// load the dim library and function pointers
116 /// init dim (DNS and server name)
117 int Init(const char* dimNameServer);
129 enum AliHLTDimServerState_t {
130 // server is not started
132 // starting, will be changed by the server thread to kStateRunning
136 // set by the main thread and changed by the server thread before it terminates
142 int SetState(int state) {fState=state; return fState;}
144 int GetState() {return fState;}
146 typedef void (*fctVoid)();
147 typedef int (*fctDisServiceCallback)( const char*);
148 typedef int (*fctDisAddService) ( const char* service,
152 fctDisServiceCallback cb,
154 typedef int (*fctDisRemoveService) ( unsigned int id);
155 typedef int (*fctDisUpdateService) ( unsigned int id);
156 typedef int (*fctDisCharArg) ( const char*);
157 typedef int (*fctDisNoArg) ( );
159 /// @class AliHLTDimInterface Interface to the dim library
160 class AliHLTDimInterface : public AliHLTLogging {
162 AliHLTDimInterface();
163 ~AliHLTDimInterface();
165 /// load the dim library and function pointers
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);
174 int DisAddService(const char* service, const char* type, void* buffer, int size) {
175 if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, NULL, 0);
179 int DisRemoveService(unsigned int id) {
180 if (fpDisRemoveService) return (*fpDisRemoveService)(id);
184 int DisUpdateService(unsigned int id) {
185 if (fpDisUpdateService) return (*fpDisUpdateService)(id);
189 int DisStartServing(const char *server) {
190 if (fpDisStartServing) return (*fpDisStartServing)(server);
194 int DisStopServing() {
195 if (fpDisStopServing) return (*fpDisStopServing)();
199 int DisSetDnsNode(const char *server) {
200 if (fpDisSetDnsNode) return (*fpDisSetDnsNode)(server);
205 fctVoid FindSymbol(const char* library, const char* symbol) const;
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; //!
222 static AliHLTDimInterface* Interface();
225 /// copy constructor not permitted
226 AliHLTDimServer(const AliHLTDimServer&);
227 /// assignment operator not permitted
228 AliHLTDimServer& operator=(const AliHLTDimServer&);
230 /// entry point for the thread, param is pointer to object
231 static void* ServerLoop(void* param);
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
241 static AliHLTDimInterface* fgpInterface; //! the dim interface
243 ClassDef(AliHLTDimServer, 0)