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
14 // @brief HLT DIM server implementation and dynamic access
17 #include "AliHLTLogging.h"
19 #include "TObjArray.h"
24 * @class AliHLTDimServer
25 * Implementation of a DIM server for HLT and the dynamic access to the
28 class AliHLTDimServer : public TNamed {
31 AliHLTDimServer(const char* servername);
34 /// Data type identifiers for services.
35 enum AliHLTDimServiceDataType{
36 kDataTypeUnknown = 0, /// initializer
37 kDataTypeCustom, /// Custom format maintained by the user.
38 kDataTypeInt, /// Integer type
39 kDataTypeFloat, /// Float type
40 kDataTypeString, /// String type
43 /// The service data field.
44 struct AliHLTDimServicePoint_t {
46 int iVal; /// integer value
47 float fVal; /// float value
48 void* strVal; /// string value, casted to string* before use
52 /** @class AliHLTDimService
53 * Base class for DIM services
55 class AliHLTDimService : public TNamed {
60 * Create a new service with a particular predefined type and name.
61 * \param type The type of the service
62 * \param servicename The name of the service.
64 AliHLTDimService(AliHLTDimServiceDataType type, const char* servicename);
67 * Create a new service with a particular custom type.
68 * \param type The type of the service as a string.
69 * The format parameter specifies the contents of the structure in the
70 * form T:N[;T:N]*[;T] where T is the item type: (I)nteger, (C)arachter,
71 * (L)ong, (S)hort, (F)loat, (D)ouble, X(tra long) and N is the number
72 * of such items. The type alone at the end means all following items
73 * are of the same type. Example: "I:3;F:2;C" means 3 Integers, 2 Floats
74 * and Characters until the end. The format parameter is used for
75 * communicating between different platforms.
76 * \param data Points to a buffer maintained by the user which stores the
77 * data to publish. This buffer must exist as long as the DIM service
78 * is registered and active.
79 * \param size The size of the data structure pointed to by data.
80 * \param servicename The name of the service.
82 AliHLTDimService(const char* type, void* data, int size, const char* servicename);
85 * Updates the DIM data point for custom data structures.
86 * i.e. This method should be used if the service was created with:
87 * AliHLTDimService(const char* type, void* data, int size, const char* servicename)
92 * Updates the DIM data point.
93 * This method should be used if the service was created with:
94 * AliHLTDimService(AliHLTDimServiceDataType type, const char* servicename)
95 * \param sp The new data point to publish via DIM.
97 void Update(const AliHLTDimServicePoint_t& sp);
99 AliHLTDimServiceDataType GetType() const {return fType;}
100 const char* GetTypeString() const { return fTypeString.Data(); }
101 void* GetLocation() {return fDataBuffer;}
102 int GetId() const {return fId;}
103 int SetId(int id) {fId=id;return id;}
104 void* GetDataBuffer() const { return fDataBuffer; }
105 int GetDataSize() const { return fDataSize; }
109 // Do not allow copying of this class
110 AliHLTDimService(const AliHLTDimService&);
111 AliHLTDimService& operator = (const AliHLTDimService&);
113 AliHLTDimServicePoint_t fData; /// the data point
114 AliHLTDimServiceDataType fType; /// type of this service
115 TString fTypeString; /// The string representing the service type.
116 void* fDataBuffer; /// Pointer to the data buffer.
117 int fDataSize; /// The size of the data buffer.
118 int fId; /// id of the service
121 /** @class AliHLTDimServiceFloat
122 * DIM service for a float value
124 class AliHLTDimServiceFloat : public AliHLTDimService {
126 AliHLTDimServiceFloat();
127 ~AliHLTDimServiceFloat();
129 void Update(float f) {
130 AliHLTDimServicePoint_t sp; sp.fVal=f; AliHLTDimService::Update(sp);
134 /** @class AliHLTDimServiceInt
135 * DIM service for a int value
137 class AliHLTDimServiceInt : public AliHLTDimService {
139 AliHLTDimServiceInt();
140 ~AliHLTDimServiceInt();
143 AliHLTDimServicePoint_t sp; sp.iVal=i; AliHLTDimService::Update(sp);
148 * Register a service.
149 * @param pService the service to be registered
151 int RegisterService(AliHLTDimService* pService);
155 * @param type type of the channel, see @ref ceServiceDataType
156 * @param name unique name of the service
157 * @return dim service object, needs to be cleaned by the caller
159 AliHLTDimService* CreateService(AliHLTDimServiceDataType type, const char* name);
162 * Create a group of services.
163 * The names are built from the basename and the number of services.
164 * @param type type of the channel
165 * @param basename base name of the services, the name might contain a '%d' sequence which is then
166 * replaced by the number, number is appended if no '%d' provided
167 * @param count number of services in this group, passed to the <i>update</i> and <i>set</i> function as parameter major
168 * @return TObjArray of AliHLTDimService objects, the array needs to be cleaned by the caller
170 TObjArray* CreateServiceGroup(AliHLTDimServiceDataType type, const char* basename, int count);
172 /// Update all services via the Dim channel
173 int UpdateServices();
176 /// load the dim library and function pointers
177 /// init dim (DNS and server name)
178 int Init(const char* dimNameServer);
190 enum AliHLTDimServerState_t {
191 // server is not started
193 // starting, will be changed by the server thread to kStateRunning
197 // set by the main thread and changed by the server thread before it terminates
203 int SetState(int state) {fState=state; return fState;}
205 int GetState() const {return fState;}
207 typedef void (*fctVoid)();
208 typedef int (*fctDisServiceCallback)( const char*);
209 typedef int (*fctDisAddService) ( const char* service,
213 fctDisServiceCallback cb,
215 typedef int (*fctDisRemoveService) ( unsigned int id);
216 typedef int (*fctDisUpdateService) ( unsigned int id);
217 typedef int (*fctDisCharArg) ( const char*);
218 typedef int (*fctDisNoArg) ( );
221 * @class AliHLTDimInterface
222 * Interface to the dim library
224 class AliHLTDimInterface : public AliHLTLogging {
226 AliHLTDimInterface();
227 ~AliHLTDimInterface();
229 /// load the dim library and function pointers
232 int DisAddService(const char* service, const char* type, void* buffer,
233 int size, fctDisServiceCallback cb, long int tag) const {
234 if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, cb, tag);
238 int DisAddService(const char* service, const char* type, void* buffer, int size) const {
239 if (fpDisAddService) return (*fpDisAddService)(service, type, buffer, size, NULL, 0);
243 int DisRemoveService(unsigned int id) const {
244 if (fpDisRemoveService) return (*fpDisRemoveService)(id);
248 int DisUpdateService(unsigned int id) const {
249 if (fpDisUpdateService) return (*fpDisUpdateService)(id);
253 int DisStartServing(const char *server) const {
254 if (fpDisStartServing) return (*fpDisStartServing)(server);
258 int DisStopServing() const {
259 if (fpDisStopServing) return (*fpDisStopServing)();
263 int DisSetDnsNode(const char *server) const {
264 if (fpDisSetDnsNode) return (*fpDisSetDnsNode)(server);
269 fctVoid FindSymbol(const char* library, const char* symbol) const;
271 fctDisAddService fpDisAddService; //! transient
272 fctDisRemoveService fpDisRemoveService; //! transient
273 fctDisUpdateService fpDisUpdateService; //! transient
274 fctDisCharArg fpDisStartServing; //! transient
275 fctDisNoArg fpDisStopServing; //! transient
276 fctDisCharArg fpDisSetDnsNode; //! transient
277 static const char* fgkDimLibraryName ; //!
278 static const char* fgkDisAddServiceSymbol; //!
279 static const char* fgkDisRemoveServiceSymbol; //!
280 static const char* fgkDisUpdateServiceSymbol; //!
281 static const char* fgkDisStartServingSymbol; //!
282 static const char* fgkDisStopServingSymbol; //!
283 static const char* fgkDisSetDnsNodeSymbol; //!
286 static AliHLTDimInterface* Interface();
289 /// copy constructor not permitted
290 AliHLTDimServer(const AliHLTDimServer&);
291 /// assignment operator not permitted
292 AliHLTDimServer& operator=(const AliHLTDimServer&);
294 /// entry point for the thread, param is pointer to object
295 static void* ServerLoop(void* param);
300 TObjArray fServices; //! list of services
301 int fState; //! state of the server
302 TThread* fpServerThread; //! thread
303 int fUpdatePeriod; //! update period for the DIM loop in ms
305 static AliHLTDimInterface* fgpInterface; //! the dim interface
307 ClassDef(AliHLTDimServer, 0)