]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponentHandler.h
- improvements in AliHLTFilePublisher/Writer
[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 typedef void* AliHLTLibHandle;
27
28 /**
29  * @class AliHLTComponentHandler
30  * The component handler controls all the processing components available in
31  * the system. It also controls the component shared libraries.
32  * @ingroup alihlt_component
33  */
34 class AliHLTComponentHandler : public AliHLTLogging {
35  public:
36   /** standard constructor */
37   AliHLTComponentHandler();
38   /** constructor */
39   AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv);
40   /** destructor */
41   virtual ~AliHLTComponentHandler();
42
43   /**
44    * Set the environment for the HLT framework.
45    * The environment mainly consists of function pointers for the integration
46    * of the HLT framework into a system like the PubSub online system or
47    * AliRoot offline system.
48    * @param pEnv    pointer to @ref AliHLTComponentEnvironment structure
49    * @return none
50    */
51   void SetEnvironment(AliHLTComponentEnvironment* pEnv);
52
53   /**
54    * Load a component shared library.
55    * The component library needs to be loaded from the ComponentHanler in order
56    * to automatically register all components in the library.
57    * Registration is done by passing a sample object of the component to the
58    * handler. The object has to be valid during the whole runtime and should
59    * thus be a global object which is ONLY used for the purpose of registration.
60    * This also ensures automatically registration at library load time.
61    * @param libraryPath  const char string containing the library name/path
62    * @return 0 if succeeded, neg. error code if failed
63    */
64   int LoadLibrary( const char* libraryPath );
65
66   /**
67    * Unload a component shared library.
68    * All components will be de-registered.
69    * @param libraryPath  library name as specified to @ref LoadLibrary
70    * @return 0 if succeeded, neg. error code if failed
71    */
72   int UnloadLibrary( const char* libraryPath );
73
74   /**
75    * Schedule a component for registration.
76    * Full registration will be done after successfull loading of the shared
77    * library.
78    * @param pSample  a sample object of the component
79    * @return neg. error code if failed
80    */
81   int ScheduleRegister(AliHLTComponent* pSample );
82
83   /**
84    * Register a component.
85    * Registration is done by passing a sample object of the component to the
86    * handler. The object has to be valid during the whole runtime and should
87    * thus be a global object which is ONLY used for the purpose of registration.
88    * @param pSample  a sample object of the component
89    * @return neg. error code if failed
90    */
91   int RegisterComponent(AliHLTComponent* pSample );
92
93   /**
94    * Registers all scheduled components.
95    */
96   int RegisterScheduledComponents();
97
98   /**
99    * Deregister a component.
100    * @param componentID   ID of the component
101    * @return neg. error code if failed
102    */
103   int DeregisterComponent( const char* componentID );
104
105   /**
106    * Add standard components
107    * The standard components are part of the libHLTbase library and
108    * need therefore a special handling.
109    */
110   int AddStandardComponents();
111
112   /**
113    */
114   int DeleteStandardComponents();
115
116   /**
117    * Find the ID of a component with the given output data.
118    * @param dtype     data type descriptor
119    * @param prevType  can be used to iterate if there are multiple components
120    *                  with the same output data type.
121    * @return component id
122    */
123   //const char* FindComponentType( AliHLTComponentDataType dtype,
124   //                               const char* prevType = NULL )
125   //  { return NULL;}
126
127   /**
128    * Create a component of the given name (ID).
129    * The method tries to find a registerd component of id \em componentID and calls
130    * the \em Spawn method of the template component. After successful creation of
131    * a new object, the Init method is called in order to initialize the environment
132    * and the component arguments. <br>
133    * The environment is the same for all components, but each component can
134    * have an additional private parameter \em pEnvParam.<br>
135    * The component arguments consist of an array of strings and the array size in the
136    * usual manner of the main() function.
137    * @param componentID  ID of the component to create
138    * @param pEnvParam    environment parameter for the component
139    * @param argc         number of arguments in argv
140    * @param argv         argument array like in main()
141    * @param component    reference to receive the create component instance
142    * @return component pointer in component, neg. error code if failed
143    */
144   int CreateComponent( const char* componentID, void* pEnvParam, 
145                        int argc, const char** argv, AliHLTComponent*& component );
146
147   /**
148    * Create a component of the given name (ID).
149    * Introduced for backward compatibility.
150    * @param componentID  ID of the component to create
151    * @param pEnvParam    environment parameter for the component
152    * @param component    reference to receive the create component instance
153    * @return component pointer in component, neg. error code if failed
154    */
155   int CreateComponent( const char* componentID, void* pEnvParam, 
156                        AliHLTComponent*& component ) 
157     {
158     return CreateComponent( componentID, pEnvParam, 0, NULL, component );
159     }
160
161   /**
162    * Print registered components to stdout.
163    * @return none
164    */
165   void List();
166
167   /**
168    * Announce version and compilation info of the base library.
169    */
170   int AnnounceVersion();
171
172  protected:
173
174  private:
175   /**
176    * Find a component.
177    * @param componentID  ID of the component to find
178    * @return index, neg. error code if failed
179    */
180   int FindComponentIndex(const char* componentID);
181
182   /**
183    * Find a component.
184    * @param componentID  ID of the component to find
185    * @return descriptor
186    */
187   AliHLTComponent* FindComponent(const char* componentID);
188
189   /**
190    * Insert component to the list
191    * @param pSample      sample object of the component
192    * @return neg. error code if failed
193    */
194   int InsertComponent(AliHLTComponent* pSample);
195
196   /**
197    * Close all libraries.
198    * @return neg. error code if failed
199    */
200   int UnloadLibraries();
201
202   /** list of registered components */
203   vector<AliHLTComponent*> fComponentList;
204   /** list of scheduled components */
205   vector<AliHLTComponent*> fScheduleList;
206   /** list of libraries */
207   vector<AliHLTLibHandle> fLibraryList;
208   /** running environment for the component */
209   AliHLTComponentEnvironment fEnvironment;
210   /** list of standard components */
211   vector<AliHLTComponent*> fStandardList;  
212
213   ClassDef(AliHLTComponentHandler, 0);
214
215 };
216 #endif
217