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