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