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