]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponentHandler.h
component librarary unloading and handling of multiple loads fixed; documentation...
[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    * Unload a component shared library.
66    * All components will be de-registered.
67    * @param libraryPath  library name as specified to @ref LoadLibrary
68    * @return 0 if succeeded, neg. error code if failed
69    */
70   int UnloadLibrary( const char* libraryPath );
71
72   /**
73    * Schedule a component for registration.
74    * Full registration will be done after successfull loading of the shared
75    * library.
76    * @param pSample  a sample object of the component
77    * @return neg. error code if failed
78    */
79   int ScheduleRegister(AliHLTComponent* pSample );
80
81   /**
82    * Register a component.
83    * Registration is done by passing a sample object of the component to the
84    * handler. The object has to be valid during the whole runtime and should
85    * thus be a global object which is ONLY used for the purpose of registration.
86    * @param pSample  a sample object of the component
87    * @return neg. error code if failed
88    */
89   int RegisterComponent(AliHLTComponent* pSample );
90
91   /**
92    * Registers all scheduled components.
93    */
94   int RegisterScheduledComponents();
95
96   /**
97    * Deregister a component.
98    * @param componentID   ID of the component
99    * @return neg. error code if failed
100    */
101   int DeregisterComponent( const char* componentID );
102
103   /**
104    * Add standard components
105    * The standard components are part of the libHLTbase library and
106    * need therefore a special handling.
107    */
108   int AddStandardComponents();
109
110   /**
111    */
112   int DeleteStandardComponents();
113
114   /**
115    * Find the ID of a component with the given output data.
116    * @param dtype     data type descriptor
117    * @param prevType  can be used to iterate if there are multiple components
118    *                  with the same output data type.
119    * @return component id
120    */
121   //const char* FindComponentType( AliHLTComponentDataType dtype,
122   //                               const char* prevType = NULL )
123   //  { return NULL;}
124
125   /**
126    * Create a component of the given name (ID).
127    * The method tries to find a registerd component of id \em componentID and
128    * calls the \em Spawn method of the template component. After successful
129    * creation of a new object, the Init method is called in order to initialize
130    * the environment and the component arguments. <br>
131    * The environment is the same for all components, but each component can
132    * have an additional private parameter \em pEnvParam.<br>
133    * The component arguments consist of an array of strings and the array size
134    * in the usual manner of the main() function.
135    * @param componentID  ID of the component to create
136    * @param pEnvParam    environment parameter for the component
137    * @param argc         number of arguments in argv
138    * @param argv         argument array like in main()
139    * @param component    reference to receive the create component instance
140    * @return component pointer in component, neg. error code if failed
141    */
142   int CreateComponent( const char* componentID, void* pEnvParam, 
143                        int argc, const char** argv, AliHLTComponent*& component );
144
145   /**
146    * Create a component of the given name (ID).
147    * Introduced for backward compatibility.
148    * @param componentID  ID of the component to create
149    * @param pEnvParam    environment parameter for the component
150    * @param component    reference to receive the create component instance
151    * @return component pointer in component, neg. error code if failed
152    */
153   int CreateComponent( const char* componentID, void* pEnvParam, 
154                        AliHLTComponent*& component ) 
155     {
156     return CreateComponent( componentID, pEnvParam, 0, NULL, component );
157     }
158
159   /**
160    * Print registered components to stdout.
161    * @return none
162    */
163   void List();
164
165   /**
166    * Announce version and compilation info of the base library.
167    */
168   int AnnounceVersion();
169
170  protected:
171
172  private:
173   /**
174    * Find a component.
175    * @param componentID  ID of the component to find
176    * @return index, neg. error code if failed
177    */
178   int FindComponentIndex(const char* componentID);
179
180   /**
181    * Find a component.
182    * @param componentID  ID of the component to find
183    * @return descriptor
184    */
185   AliHLTComponent* FindComponent(const char* componentID);
186
187   /**
188    * Insert component to the list
189    * @param pSample      sample object of the component
190    * @return neg. error code if failed
191    */
192   int InsertComponent(AliHLTComponent* pSample);
193
194   /**
195    * Close all libraries.
196    * @return neg. error code if failed
197    */
198   int UnloadLibraries();
199
200   /**
201    * Compount descriptor for component libraries
202    */
203   struct AliHLTLibHandle {
204     AliHLTLibHandle() : handle(NULL), name(NULL) {}
205     /** dlopen handle */
206     void* handle;                                                  //! transient
207     /** name of the library, casted to TString* before use */
208     void* name;                                                    //! transient
209   };
210
211   /** list of registered components */
212   vector<AliHLTComponent*> fComponentList;                         // see above 
213   /** list of scheduled components */
214   vector<AliHLTComponent*> fScheduleList;                          // see above 
215   /** list of libraries */
216   vector<AliHLTLibHandle> fLibraryList;                            // see above 
217   /** running environment for the component */
218   AliHLTComponentEnvironment fEnvironment;                         // see above 
219   /** list of standard components */
220   vector<AliHLTComponent*> fStandardList;                          // see above 
221
222   ClassDef(AliHLTComponentHandler, 0);
223
224 };
225 #endif
226