]>
Commit | Line | Data |
---|---|---|
30338a30 | 1 | //-*- Mode: C++ -*- |
f23a6e1a | 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 | ||
b22e91eb | 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 | */ | |
30338a30 | 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 | |
f23a6e1a | 22 | |
8ede8717 | 23 | #include <vector> |
5df0cbb9 | 24 | //#include "TObject.h" |
f23a6e1a | 25 | #include "AliHLTDataTypes.h" |
5ec8e281 | 26 | #include "AliHLTLogging.h" |
f23a6e1a | 27 | |
28 | class AliHLTComponent; | |
f3506ea2 | 29 | class AliHLTModuleAgent; |
f23a6e1a | 30 | struct AliHLTComponentEnvironment; |
8ede8717 | 31 | struct AliHLTComponentDataType; |
f23a6e1a | 32 | |
fa760045 | 33 | /** |
34 | * @class AliHLTComponentHandler | |
35 | * The component handler controls all the processing components available in | |
36 | * the system. It also controls the component shared libraries. | |
37 | * @ingroup alihlt_component | |
38 | */ | |
5ec8e281 | 39 | class AliHLTComponentHandler : public AliHLTLogging { |
f23a6e1a | 40 | public: |
fa760045 | 41 | /** standard constructor */ |
f23a6e1a | 42 | AliHLTComponentHandler(); |
3cde846d | 43 | /** constructor */ |
44 | AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv); | |
fa760045 | 45 | /** destructor */ |
f23a6e1a | 46 | virtual ~AliHLTComponentHandler(); |
47 | ||
b005ef92 | 48 | /** |
49 | * Create an instance from the global sigleton. | |
50 | * Instance has to be destroyed by the Destroy function | |
51 | */ | |
52 | static AliHLTComponentHandler* CreateHandler(); | |
53 | ||
54 | /** | |
55 | * Destroy an instance of the global singleton retrieved by | |
56 | * AliHLTComponentHandler::CreateHandler() | |
57 | */ | |
58 | int Destroy(); | |
59 | ||
dba03d72 | 60 | /** |
61 | * Library mode. | |
62 | * - kDynamic: library can be unloaded (unload forced at termination of the | |
63 | * handler | |
64 | * - kStatic: library persistent, once loaded it stays | |
65 | */ | |
66 | enum TLibraryMode {kDynamic, kStatic}; | |
67 | ||
fa760045 | 68 | /** |
69 | * Set the environment for the HLT framework. | |
70 | * The environment mainly consists of function pointers for the integration | |
71 | * of the HLT framework into a system like the PubSub online system or | |
72 | * AliRoot offline system. | |
73 | * @param pEnv pointer to @ref AliHLTComponentEnvironment structure | |
74 | * @return none | |
75 | */ | |
f23a6e1a | 76 | void SetEnvironment(AliHLTComponentEnvironment* pEnv); |
77 | ||
dba03d72 | 78 | /** |
79 | * Set library mode. | |
80 | * The mode effects all loaded libraries until another mode is set. | |
81 | * @param mode persistent library or not | |
7bcd6cad | 82 | * @return previous mode |
dba03d72 | 83 | */ |
84 | TLibraryMode SetLibraryMode(TLibraryMode mode); | |
85 | ||
fa760045 | 86 | /** |
87 | * Load a component shared library. | |
88 | * The component library needs to be loaded from the ComponentHanler in order | |
89 | * to automatically register all components in the library. | |
90 | * Registration is done by passing a sample object of the component to the | |
91 | * handler. The object has to be valid during the whole runtime and should | |
92 | * thus be a global object which is ONLY used for the purpose of registration. | |
93 | * This also ensures automatically registration at library load time. | |
f3506ea2 | 94 | * @param libraryPath const char string containing the library name/path |
95 | * @param bActivateAgents activate agents after loading (@ref ActivateAgents) | |
fa760045 | 96 | * @return 0 if succeeded, neg. error code if failed |
97 | */ | |
dba03d72 | 98 | int LoadLibrary( const char* libraryPath, int bActivateAgents=1); |
fa760045 | 99 | |
85f0cede | 100 | /** |
101 | * Find a symbol in a dynamically loaded library. | |
102 | * @param library library | |
103 | * @param symbol the symbol to find | |
104 | * @return void pointer to function | |
105 | */ | |
106 | void* FindSymbol(const char* library, const char* symbol); | |
107 | ||
fa760045 | 108 | /** |
109 | * Unload a component shared library. | |
a742f6f8 | 110 | * All components will be de-registered when the last instance of the |
111 | * library was unloaded. | |
fa760045 | 112 | * @param libraryPath library name as specified to @ref LoadLibrary |
113 | * @return 0 if succeeded, neg. error code if failed | |
114 | */ | |
f23a6e1a | 115 | int UnloadLibrary( const char* libraryPath ); |
116 | ||
fa760045 | 117 | /** |
118 | * Schedule a component for registration. | |
119 | * Full registration will be done after successfull loading of the shared | |
120 | * library. | |
121 | * @param pSample a sample object of the component | |
122 | * @return neg. error code if failed | |
f23a6e1a | 123 | */ |
f23a6e1a | 124 | int ScheduleRegister(AliHLTComponent* pSample ); |
125 | ||
fa760045 | 126 | /** |
127 | * Register a component. | |
128 | * Registration is done by passing a sample object of the component to the | |
129 | * handler. The object has to be valid during the whole runtime and should | |
130 | * thus be a global object which is ONLY used for the purpose of registration. | |
f3506ea2 | 131 | * @param pSample a sample object of the component |
fa760045 | 132 | * @return neg. error code if failed |
133 | */ | |
f3506ea2 | 134 | int RegisterComponent(AliHLTComponent* pSample); |
135 | ||
136 | /** | |
137 | * Add a component and leave control of the sample object to the handler. | |
138 | * Exactly the same functionality as @ref RegisterComponent but deletes | |
139 | * the sample object at clean-up of the handler. | |
140 | * @param pSample a sample object of the component | |
141 | * @return neg. error code if failed | |
142 | */ | |
143 | int AddComponent(AliHLTComponent* pSample); | |
f23a6e1a | 144 | |
9ce4bf4a | 145 | /** |
146 | * Registers all scheduled components. | |
147 | */ | |
148 | int RegisterScheduledComponents(); | |
149 | ||
fa760045 | 150 | /** |
151 | * Deregister a component. | |
152 | * @param componentID ID of the component | |
153 | * @return neg. error code if failed | |
154 | */ | |
155 | int DeregisterComponent( const char* componentID ); | |
f23a6e1a | 156 | |
9ce4bf4a | 157 | /** |
158 | * Add standard components | |
159 | * The standard components are part of the libHLTbase library and | |
160 | * need therefore a special handling. | |
161 | */ | |
162 | int AddStandardComponents(); | |
163 | ||
164 | /** | |
165 | */ | |
cbd84228 | 166 | int DeleteOwnedComponents(); |
9ce4bf4a | 167 | |
fa760045 | 168 | /** |
169 | * Find the ID of a component with the given output data. | |
170 | * @param dtype data type descriptor | |
171 | * @param prevType can be used to iterate if there are multiple components | |
172 | * with the same output data type. | |
173 | * @return component id | |
174 | */ | |
8ede8717 | 175 | //const char* FindComponentType( AliHLTComponentDataType dtype, |
fa760045 | 176 | // const char* prevType = NULL ) |
177 | // { return NULL;} | |
178 | ||
179 | /** | |
180 | * Create a component of the given name (ID). | |
c215072c | 181 | * The method tries to find a registerd component of id \em componentID and |
182 | * calls the \em Spawn method of the template component. After successful | |
183 | * creation of a new object, the Init method is called in order to initialize | |
184 | * the environment and the component arguments. <br> | |
2d7ff710 | 185 | * The environment is the same for all components, but each component can |
186 | * have an additional private parameter \em pEnvParam.<br> | |
c215072c | 187 | * The component arguments consist of an array of strings and the array size |
188 | * in the usual manner of the main() function. | |
fa760045 | 189 | * @param componentID ID of the component to create |
2d7ff710 | 190 | * @param pEnvParam environment parameter for the component |
db16520a | 191 | * @param argc number of arguments in argv |
fa760045 | 192 | * @param argv argument array like in main() |
193 | * @param component reference to receive the create component instance | |
b2065764 | 194 | * @param cdbPath optional CDB path |
db16520a | 195 | * @return component pointer in component, neg. error code if failed |
fa760045 | 196 | */ |
2d7ff710 | 197 | int CreateComponent( const char* componentID, void* pEnvParam, |
b2065764 | 198 | int argc, const char** argv, AliHLTComponent*& component, |
199 | const char* cdbPath=NULL); | |
fa760045 | 200 | |
201 | /** | |
202 | * Create a component of the given name (ID). | |
203 | * Introduced for backward compatibility. | |
204 | * @param componentID ID of the component to create | |
2d7ff710 | 205 | * @param pEnvParam environment parameter for the component |
fa760045 | 206 | * @param component reference to receive the create component instance |
db16520a | 207 | * @return component pointer in component, neg. error code if failed |
fa760045 | 208 | */ |
2d7ff710 | 209 | int CreateComponent( const char* componentID, void* pEnvParam, |
fa760045 | 210 | AliHLTComponent*& component ) |
211 | { | |
2d7ff710 | 212 | return CreateComponent( componentID, pEnvParam, 0, NULL, component ); |
fa760045 | 213 | } |
214 | ||
f3506ea2 | 215 | /** |
216 | * Check if a registered component has output data, e.g. is of type | |
217 | * kSource or kProcessor (see @ref AliHLTComponent::TComponentType). | |
218 | * @param componentID ID of the component to create | |
219 | * @return 1 if component has output data, 0 if not <br> | |
220 | * -ENOENT if component does not exist | |
221 | */ | |
222 | int HasOutputData( const char* componentID); | |
223 | ||
fa760045 | 224 | /** |
225 | * Print registered components to stdout. | |
226 | * @return none | |
f23a6e1a | 227 | */ |
228 | void List(); | |
fa760045 | 229 | |
230 | /** | |
231 | * Announce version and compilation info of the base library. | |
232 | */ | |
233 | int AnnounceVersion(); | |
234 | ||
f3506ea2 | 235 | /** |
236 | * Find a component. | |
237 | * @param componentID ID of the component to find | |
238 | * @return index, neg. error code if failed | |
239 | */ | |
240 | int FindComponentIndex(const char* componentID); | |
241 | ||
f23a6e1a | 242 | protected: |
f23a6e1a | 243 | |
244 | private: | |
298ef463 | 245 | /** copy constructor prohibited */ |
246 | AliHLTComponentHandler(const AliHLTComponentHandler&); | |
247 | /** assignment operator prohibited */ | |
248 | AliHLTComponentHandler& operator=(const AliHLTComponentHandler&); | |
249 | ||
fa760045 | 250 | /** |
251 | * Find a component. | |
252 | * @param componentID ID of the component to find | |
253 | * @return descriptor | |
254 | */ | |
f23a6e1a | 255 | AliHLTComponent* FindComponent(const char* componentID); |
256 | ||
fa760045 | 257 | /** |
258 | * Insert component to the list | |
259 | * @param pSample sample object of the component | |
260 | * @return neg. error code if failed | |
261 | */ | |
f23a6e1a | 262 | int InsertComponent(AliHLTComponent* pSample); |
263 | ||
fa760045 | 264 | /** |
265 | * Close all libraries. | |
266 | * @return neg. error code if failed | |
267 | */ | |
f23a6e1a | 268 | int UnloadLibraries(); |
269 | ||
c215072c | 270 | /** |
f3506ea2 | 271 | * Activate all module agents with this component handler. |
272 | * The function loops over all available module agents and activates | |
273 | * each agent with this component handler. During activation, the | |
274 | * dynamic component registration is carried out by the agents version | |
275 | * of @ref AliHLTModuleAgent::RegisterComponents | |
276 | * @param blackList array of agents which should be excluded | |
277 | * @param size array size | |
278 | */ | |
279 | int ActivateAgents(const AliHLTModuleAgent** blackList=NULL, int size=0); | |
280 | ||
281 | /** | |
282 | * Compound descriptor for component libraries | |
c215072c | 283 | */ |
284 | struct AliHLTLibHandle { | |
620fcee6 | 285 | AliHLTLibHandle() : fHandle(NULL), fName(NULL), fMode(kDynamic) {} |
c215072c | 286 | /** dlopen handle */ |
5df0cbb9 | 287 | void* fHandle; //! transient |
c215072c | 288 | /** name of the library, casted to TString* before use */ |
5df0cbb9 | 289 | void* fName; //! transient |
dba03d72 | 290 | /** library mode: kStatic means never unloaded */ |
291 | TLibraryMode fMode; //! transient | |
c215072c | 292 | }; |
293 | ||
85f0cede | 294 | /** |
295 | * Find a specific library among the loaded libraries. | |
296 | * @param library library name/path | |
297 | * @return pointer to AliHLTLibHandle | |
298 | */ | |
299 | AliHLTLibHandle* FindLibrary(const char* library); | |
300 | ||
a742f6f8 | 301 | /** |
302 | * Unload a component shared library. | |
303 | * All components will be de-registered when the last instance of the | |
304 | * library was unloaded. | |
305 | * @param handle handle to the library to unload | |
306 | * @return 0 if succeeded, neg. error code if failed | |
307 | */ | |
308 | int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle); | |
309 | ||
fa760045 | 310 | /** list of registered components */ |
70ed7d01 | 311 | vector<AliHLTComponent*> fComponentList; // see above |
fa760045 | 312 | /** list of scheduled components */ |
70ed7d01 | 313 | vector<AliHLTComponent*> fScheduleList; // see above |
fa760045 | 314 | /** list of libraries */ |
70ed7d01 | 315 | vector<AliHLTLibHandle> fLibraryList; // see above |
fa760045 | 316 | /** running environment for the component */ |
70ed7d01 | 317 | AliHLTComponentEnvironment fEnvironment; // see above |
f3506ea2 | 318 | /** list of owned components, deleted at termination of the handler */ |
319 | vector<AliHLTComponent*> fOwnedComponents; // see above | |
dba03d72 | 320 | /** library mode effects all loaded libraries until a new mode is set */ |
321 | TLibraryMode fLibraryMode; // see above | |
f23a6e1a | 322 | |
b005ef92 | 323 | /** the global singleton */ |
324 | static AliHLTComponentHandler* fgpInstance; //!transient | |
325 | /** number of used instances of the global singleton */ | |
326 | static int fgNofInstances; //!transient | |
327 | ||
328 | ClassDef(AliHLTComponentHandler, 1); | |
fa2e9b7c | 329 | |
fa760045 | 330 | }; |
f23a6e1a | 331 | #endif |
332 |