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 */
8 /** @file AliHLTComponentHandler.h
9 @author Matthias Richter, Timm Steinbeck
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.
18 //#include "TObject.h"
19 #include "AliHLTDataTypes.h"
20 #include "AliHLTLogging.h"
22 class AliHLTComponent;
23 struct AliHLTComponentEnvironment;
24 struct AliHLTComponentDataType;
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
32 class AliHLTComponentHandler : public AliHLTLogging {
34 /** standard constructor */
35 AliHLTComponentHandler();
37 AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv);
38 /** not a valid copy constructor, defined according to effective C++ style */
39 AliHLTComponentHandler(const AliHLTComponentHandler&);
40 /** not a valid assignment op, but defined according to effective C++ style */
41 AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
43 virtual ~AliHLTComponentHandler();
46 * Set the environment for the HLT framework.
47 * The environment mainly consists of function pointers for the integration
48 * of the HLT framework into a system like the PubSub online system or
49 * AliRoot offline system.
50 * @param pEnv pointer to @ref AliHLTComponentEnvironment structure
53 void SetEnvironment(AliHLTComponentEnvironment* pEnv);
56 * Load a component shared library.
57 * The component library needs to be loaded from the ComponentHanler in order
58 * to automatically register all components in the library.
59 * Registration is done by passing a sample object of the component to the
60 * handler. The object has to be valid during the whole runtime and should
61 * thus be a global object which is ONLY used for the purpose of registration.
62 * This also ensures automatically registration at library load time.
63 * @param libraryPath const char string containing the library name/path
64 * @return 0 if succeeded, neg. error code if failed
66 int LoadLibrary( const char* libraryPath );
69 * Find a symbol in a dynamically loaded library.
70 * @param library library
71 * @param symbol the symbol to find
72 * @return void pointer to function
74 void* FindSymbol(const char* library, const char* symbol);
77 * Unload a component shared library.
78 * All components will be de-registered when the last instance of the
79 * library was unloaded.
80 * @param libraryPath library name as specified to @ref LoadLibrary
81 * @return 0 if succeeded, neg. error code if failed
83 int UnloadLibrary( const char* libraryPath );
86 * Schedule a component for registration.
87 * Full registration will be done after successfull loading of the shared
89 * @param pSample a sample object of the component
90 * @return neg. error code if failed
92 int ScheduleRegister(AliHLTComponent* pSample );
95 * Register a component.
96 * Registration is done by passing a sample object of the component to the
97 * handler. The object has to be valid during the whole runtime and should
98 * thus be a global object which is ONLY used for the purpose of registration.
99 * @param pSample a sample object of the component
100 * @return neg. error code if failed
102 int RegisterComponent(AliHLTComponent* pSample );
105 * Registers all scheduled components.
107 int RegisterScheduledComponents();
110 * Deregister a component.
111 * @param componentID ID of the component
112 * @return neg. error code if failed
114 int DeregisterComponent( const char* componentID );
117 * Add standard components
118 * The standard components are part of the libHLTbase library and
119 * need therefore a special handling.
121 int AddStandardComponents();
125 int DeleteStandardComponents();
128 * Find the ID of a component with the given output data.
129 * @param dtype data type descriptor
130 * @param prevType can be used to iterate if there are multiple components
131 * with the same output data type.
132 * @return component id
134 //const char* FindComponentType( AliHLTComponentDataType dtype,
135 // const char* prevType = NULL )
139 * Create a component of the given name (ID).
140 * The method tries to find a registerd component of id \em componentID and
141 * calls the \em Spawn method of the template component. After successful
142 * creation of a new object, the Init method is called in order to initialize
143 * the environment and the component arguments. <br>
144 * The environment is the same for all components, but each component can
145 * have an additional private parameter \em pEnvParam.<br>
146 * The component arguments consist of an array of strings and the array size
147 * in the usual manner of the main() function.
148 * @param componentID ID of the component to create
149 * @param pEnvParam environment parameter for the component
150 * @param argc number of arguments in argv
151 * @param argv argument array like in main()
152 * @param component reference to receive the create component instance
153 * @return component pointer in component, neg. error code if failed
155 int CreateComponent( const char* componentID, void* pEnvParam,
156 int argc, const char** argv, AliHLTComponent*& component );
159 * Create a component of the given name (ID).
160 * Introduced for backward compatibility.
161 * @param componentID ID of the component to create
162 * @param pEnvParam environment parameter for the component
163 * @param component reference to receive the create component instance
164 * @return component pointer in component, neg. error code if failed
166 int CreateComponent( const char* componentID, void* pEnvParam,
167 AliHLTComponent*& component )
169 return CreateComponent( componentID, pEnvParam, 0, NULL, component );
173 * Print registered components to stdout.
179 * Announce version and compilation info of the base library.
181 int AnnounceVersion();
188 * @param componentID ID of the component to find
189 * @return index, neg. error code if failed
191 int FindComponentIndex(const char* componentID);
195 * @param componentID ID of the component to find
198 AliHLTComponent* FindComponent(const char* componentID);
201 * Insert component to the list
202 * @param pSample sample object of the component
203 * @return neg. error code if failed
205 int InsertComponent(AliHLTComponent* pSample);
208 * Close all libraries.
209 * @return neg. error code if failed
211 int UnloadLibraries();
214 * Compount descriptor for component libraries
216 struct AliHLTLibHandle {
217 AliHLTLibHandle() : fHandle(NULL), fName(NULL) {}
219 void* fHandle; //! transient
220 /** name of the library, casted to TString* before use */
221 void* fName; //! transient
225 * Find a specific library among the loaded libraries.
226 * @param library library name/path
227 * @return pointer to AliHLTLibHandle
229 AliHLTLibHandle* FindLibrary(const char* library);
232 * Unload a component shared library.
233 * All components will be de-registered when the last instance of the
234 * library was unloaded.
235 * @param handle handle to the library to unload
236 * @return 0 if succeeded, neg. error code if failed
238 int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle);
240 /** list of registered components */
241 vector<AliHLTComponent*> fComponentList; // see above
242 /** list of scheduled components */
243 vector<AliHLTComponent*> fScheduleList; // see above
244 /** list of libraries */
245 vector<AliHLTLibHandle> fLibraryList; // see above
246 /** running environment for the component */
247 AliHLTComponentEnvironment fEnvironment; // see above
248 /** list of standard components */
249 vector<AliHLTComponent*> fStandardList; // see above
251 ClassDef(AliHLTComponentHandler, 0);