]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponentHandler.h
corrected compilation warnings
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponentHandler.h
1 //-*- Mode: C++ -*-
2 // @(#) $Id$
3
4 #ifndef ALIHLTCOMPONENTHANDLER_H
5 #define ALIHLTCOMPONENTHANDLER_H
6 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
7  * See cxx source for full Copyright notice                               */
8
9 /** @file   AliHLTComponentHandler.h
10     @author Matthias Richter, Timm Steinbeck
11     @date   
12     @brief  Global handling of HLT processing components
13     @note   The handler is part of the interface and both used in the
14             Online (PubSub) and Offline (AliRoot) context.
15                                                                           */
16
17 // see below for class documentation
18 // or
19 // refer to README to build package
20 // or
21 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
22
23 #include <vector>
24 //#include "TObject.h"
25 #include "AliHLTDataTypes.h"
26 #include "AliHLTLogging.h"
27
28 class AliHLTComponent;
29 struct AliHLTComponentEnvironment;
30 struct AliHLTComponentDataType;
31
32 /**
33  * @class AliHLTComponentHandler
34  * The component handler controls all the processing components available in
35  * the system. It also controls the component shared libraries.
36  * @ingroup alihlt_component
37  */
38 class AliHLTComponentHandler : public AliHLTLogging {
39  public:
40   /** standard constructor */
41   AliHLTComponentHandler();
42   /** constructor */
43   AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv);
44   /** destructor */
45   virtual ~AliHLTComponentHandler();
46
47   /**
48    * Set the environment for the HLT framework.
49    * The environment mainly consists of function pointers for the integration
50    * of the HLT framework into a system like the PubSub online system or
51    * AliRoot offline system.
52    * @param pEnv    pointer to @ref AliHLTComponentEnvironment structure
53    * @return none
54    */
55   void SetEnvironment(AliHLTComponentEnvironment* pEnv);
56
57   /**
58    * Load a component shared library.
59    * The component library needs to be loaded from the ComponentHanler in order
60    * to automatically register all components in the library.
61    * Registration is done by passing a sample object of the component to the
62    * handler. The object has to be valid during the whole runtime and should
63    * thus be a global object which is ONLY used for the purpose of registration.
64    * This also ensures automatically registration at library load time.
65    * @param libraryPath  const char string containing the library name/path
66    * @return 0 if succeeded, neg. error code if failed
67    */
68   int LoadLibrary( const char* libraryPath );
69
70   /**
71    * Find a symbol in a dynamically loaded library.
72    * @param library      library
73    * @param symbol       the symbol to find
74    * @return void pointer to function
75    */
76   void* FindSymbol(const char* library, const char* symbol);
77
78   /**
79    * Unload a component shared library.
80    * All components will be de-registered when the last instance of the
81    * library was unloaded.
82    * @param libraryPath  library name as specified to @ref LoadLibrary
83    * @return 0 if succeeded, neg. error code if failed
84    */
85   int UnloadLibrary( const char* libraryPath );
86
87   /**
88    * Schedule a component for registration.
89    * Full registration will be done after successfull loading of the shared
90    * library.
91    * @param pSample  a sample object of the component
92    * @return neg. error code if failed
93    */
94   int ScheduleRegister(AliHLTComponent* pSample );
95
96   /**
97    * Register a component.
98    * Registration is done by passing a sample object of the component to the
99    * handler. The object has to be valid during the whole runtime and should
100    * thus be a global object which is ONLY used for the purpose of registration.
101    * @param pSample  a sample object of the component
102    * @return neg. error code if failed
103    */
104   int RegisterComponent(AliHLTComponent* pSample );
105
106   /**
107    * Registers all scheduled components.
108    */
109   int RegisterScheduledComponents();
110
111   /**
112    * Deregister a component.
113    * @param componentID   ID of the component
114    * @return neg. error code if failed
115    */
116   int DeregisterComponent( const char* componentID );
117
118   /**
119    * Add standard components
120    * The standard components are part of the libHLTbase library and
121    * need therefore a special handling.
122    */
123   int AddStandardComponents();
124
125   /**
126    */
127   int DeleteStandardComponents();
128
129   /**
130    * Find the ID of a component with the given output data.
131    * @param dtype     data type descriptor
132    * @param prevType  can be used to iterate if there are multiple components
133    *                  with the same output data type.
134    * @return component id
135    */
136   //const char* FindComponentType( AliHLTComponentDataType dtype,
137   //                               const char* prevType = NULL )
138   //  { return NULL;}
139
140   /**
141    * Create a component of the given name (ID).
142    * The method tries to find a registerd component of id \em componentID and
143    * calls the \em Spawn method of the template component. After successful
144    * creation of a new object, the Init method is called in order to initialize
145    * the environment and the component arguments. <br>
146    * The environment is the same for all components, but each component can
147    * have an additional private parameter \em pEnvParam.<br>
148    * The component arguments consist of an array of strings and the array size
149    * in the usual manner of the main() function.
150    * @param componentID  ID of the component to create
151    * @param pEnvParam    environment parameter for the component
152    * @param argc         number of arguments in argv
153    * @param argv         argument array like in main()
154    * @param component    reference to receive the create component instance
155    * @return component pointer in component, neg. error code if failed
156    */
157   int CreateComponent( const char* componentID, void* pEnvParam, 
158                        int argc, const char** argv, AliHLTComponent*& component );
159
160   /**
161    * Create a component of the given name (ID).
162    * Introduced for backward compatibility.
163    * @param componentID  ID of the component to create
164    * @param pEnvParam    environment parameter for the component
165    * @param component    reference to receive the create component instance
166    * @return component pointer in component, neg. error code if failed
167    */
168   int CreateComponent( const char* componentID, void* pEnvParam, 
169                        AliHLTComponent*& component ) 
170     {
171     return CreateComponent( componentID, pEnvParam, 0, NULL, component );
172     }
173
174   /**
175    * Print registered components to stdout.
176    * @return none
177    */
178   void List();
179
180   /**
181    * Announce version and compilation info of the base library.
182    */
183   int AnnounceVersion();
184
185  protected:
186
187  private:
188   /** copy constructor prohibited */
189   AliHLTComponentHandler(const AliHLTComponentHandler&);
190   /** assignment operator prohibited */
191   AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
192
193   /**
194    * Find a component.
195    * @param componentID  ID of the component to find
196    * @return index, neg. error code if failed
197    */
198   int FindComponentIndex(const char* componentID);
199
200   /**
201    * Find a component.
202    * @param componentID  ID of the component to find
203    * @return descriptor
204    */
205   AliHLTComponent* FindComponent(const char* componentID);
206
207   /**
208    * Insert component to the list
209    * @param pSample      sample object of the component
210    * @return neg. error code if failed
211    */
212   int InsertComponent(AliHLTComponent* pSample);
213
214   /**
215    * Close all libraries.
216    * @return neg. error code if failed
217    */
218   int UnloadLibraries();
219
220   /**
221    * Compount descriptor for component libraries
222    */
223   struct AliHLTLibHandle {
224     AliHLTLibHandle() : fHandle(NULL), fName(NULL) {}
225     /** dlopen handle */
226     void* fHandle;                                                 //! transient
227     /** name of the library, casted to TString* before use */
228     void* fName;                                                   //! transient
229   };
230
231   /**
232    * Find a specific library among the loaded libraries.
233    * @param library     library name/path
234    * @return pointer to AliHLTLibHandle
235    */
236   AliHLTLibHandle* FindLibrary(const char* library);
237
238   /**
239    * Unload a component shared library.
240    * All components will be de-registered when the last instance of the
241    * library was unloaded.
242    * @param handle       handle to the library to unload
243    * @return 0 if succeeded, neg. error code if failed
244    */
245   int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle);
246
247   /** list of registered components */
248   vector<AliHLTComponent*> fComponentList;                         // see above 
249   /** list of scheduled components */
250   vector<AliHLTComponent*> fScheduleList;                          // see above 
251   /** list of libraries */
252   vector<AliHLTLibHandle> fLibraryList;                            // see above 
253   /** running environment for the component */
254   AliHLTComponentEnvironment fEnvironment;                         // see above 
255   /** list of standard components */
256   vector<AliHLTComponent*> fStandardList;                          // see above 
257
258   ClassDef(AliHLTComponentHandler, 0);
259
260 };
261 #endif
262