]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponentHandler.h
moved AliHLTModulePreprocessor to base library and introduced abstract interface...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponentHandler.h
index ea3c4c4dfc3b40a1db3c44510753674aebb12811..b653173cc4f0ab5466bda9ebc842d4efb2ae8460 100644 (file)
@@ -1,3 +1,4 @@
+//-*- Mode: C++ -*-
 // @(#) $Id$
 
 #ifndef ALIHLTCOMPONENTHANDLER_H
     @note   The handler is part of the interface and both used in the
             Online (PubSub) and Offline (AliRoot) context.
                                                                           */
-   
+
+// see below for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
 
 #include <vector>
-#include "TObject.h"
+//#include "TObject.h"
 #include "AliHLTDataTypes.h"
 #include "AliHLTLogging.h"
 
 class AliHLTComponent;
+class AliHLTModuleAgent;
 struct AliHLTComponentEnvironment;
 struct AliHLTComponentDataType;
 
@@ -38,6 +45,14 @@ class AliHLTComponentHandler : public AliHLTLogging {
   /** destructor */
   virtual ~AliHLTComponentHandler();
 
+  /**
+   * Library mode.
+   * - kDynamic: library can be unloaded (unload forced at termination of the
+   *             handler
+   * - kStatic:  library persistent, once loaded it stays
+   */
+  enum TLibraryMode {kDynamic, kStatic};
+
   /**
    * Set the environment for the HLT framework.
    * The environment mainly consists of function pointers for the integration
@@ -48,6 +63,14 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   void SetEnvironment(AliHLTComponentEnvironment* pEnv);
 
+  /**
+   * Set library mode.
+   * The mode effects all loaded libraries until another mode is set.
+   * @param mode             persistent library or not
+   * @return previous mode
+   */
+  TLibraryMode SetLibraryMode(TLibraryMode mode);
+
   /**
    * Load a component shared library.
    * The component library needs to be loaded from the ComponentHanler in order
@@ -56,14 +79,24 @@ class AliHLTComponentHandler : public AliHLTLogging {
    * handler. The object has to be valid during the whole runtime and should
    * thus be a global object which is ONLY used for the purpose of registration.
    * This also ensures automatically registration at library load time.
-   * @param libraryPath  const char string containing the library name/path
+   * @param libraryPath      const char string containing the library name/path
+   * @param bActivateAgents  activate agents after loading (@ref ActivateAgents)
    * @return 0 if succeeded, neg. error code if failed
    */
-  int LoadLibrary( const char* libraryPath );
+  int LoadLibrary( const char* libraryPath, int bActivateAgents=1);
+
+  /**
+   * Find a symbol in a dynamically loaded library.
+   * @param library      library
+   * @param symbol       the symbol to find
+   * @return void pointer to function
+   */
+  void* FindSymbol(const char* library, const char* symbol);
 
   /**
    * Unload a component shared library.
-   * All components will be de-registered.
+   * All components will be de-registered when the last instance of the
+   * library was unloaded.
    * @param libraryPath  library name as specified to @ref LoadLibrary
    * @return 0 if succeeded, neg. error code if failed
    */
@@ -83,10 +116,19 @@ class AliHLTComponentHandler : public AliHLTLogging {
    * Registration is done by passing a sample object of the component to the
    * handler. The object has to be valid during the whole runtime and should
    * thus be a global object which is ONLY used for the purpose of registration.
-   * @param pSample  a sample object of the component
+   * @param pSample   a sample object of the component
+   * @return neg. error code if failed
+   */
+  int RegisterComponent(AliHLTComponent* pSample);
+
+  /**
+   * Add a component and leave control of the sample object to the handler.
+   * Exactly the same functionality as @ref RegisterComponent but deletes
+   * the sample object at clean-up of the handler.
+   * @param pSample   a sample object of the component
    * @return neg. error code if failed
    */
-  int RegisterComponent(AliHLTComponent* pSample );
+  int AddComponent(AliHLTComponent* pSample);
 
   /**
    * Registers all scheduled components.
@@ -109,7 +151,7 @@ class AliHLTComponentHandler : public AliHLTLogging {
 
   /**
    */
-  int DeleteStandardComponents();
+  int DeleteOwnedComponents();
 
   /**
    * Find the ID of a component with the given output data.
@@ -156,6 +198,15 @@ class AliHLTComponentHandler : public AliHLTLogging {
     return CreateComponent( componentID, pEnvParam, 0, NULL, component );
     }
 
+  /**
+   * Check if a registered component has output data, e.g. is of type
+   * kSource or kProcessor (see @ref AliHLTComponent::TComponentType).
+   * @param componentID  ID of the component to create
+   * @return 1 if component has output data, 0 if not                 <br>
+   *         -ENOENT     if component does not exist
+   */
+  int HasOutputData( const char* componentID);
+
   /**
    * Print registered components to stdout.
    * @return none
@@ -167,9 +218,6 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   int AnnounceVersion();
 
- protected:
-
- private:
   /**
    * Find a component.
    * @param componentID  ID of the component to find
@@ -177,6 +225,14 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   int FindComponentIndex(const char* componentID);
 
+ protected:
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTComponentHandler(const AliHLTComponentHandler&);
+  /** assignment operator prohibited */
+  AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
+
   /**
    * Find a component.
    * @param componentID  ID of the component to find
@@ -198,16 +254,45 @@ class AliHLTComponentHandler : public AliHLTLogging {
   int UnloadLibraries();
 
   /**
-   * Compount descriptor for component libraries
+   * Activate all module agents with this component handler.
+   * The function loops over all available module agents and activates
+   * each agent with this component handler. During activation, the
+   * dynamic component registration is carried out by the agents version
+   * of @ref AliHLTModuleAgent::RegisterComponents
+   * @param blackList     array of agents which should be excluded
+   * @param size          array size
+   */
+  int ActivateAgents(const AliHLTModuleAgent** blackList=NULL, int size=0);
+
+  /**
+   * Compound descriptor for component libraries
    */
   struct AliHLTLibHandle {
-    AliHLTLibHandle() : handle(NULL), name(NULL) {}
+    AliHLTLibHandle() : fHandle(NULL), fName(NULL), fMode(kDynamic) {}
     /** dlopen handle */
-    void* handle;                                                  //! transient
+    void* fHandle;                                                 //! transient
     /** name of the library, casted to TString* before use */
-    void* name;                                                    //! transient
+    void* fName;                                                   //! transient
+    /** library mode: kStatic means never unloaded */
+    TLibraryMode fMode;                                            //! transient
   };
 
+  /**
+   * Find a specific library among the loaded libraries.
+   * @param library     library name/path
+   * @return pointer to AliHLTLibHandle
+   */
+  AliHLTLibHandle* FindLibrary(const char* library);
+
+  /**
+   * Unload a component shared library.
+   * All components will be de-registered when the last instance of the
+   * library was unloaded.
+   * @param handle       handle to the library to unload
+   * @return 0 if succeeded, neg. error code if failed
+   */
+  int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle);
+
   /** list of registered components */
   vector<AliHLTComponent*> fComponentList;                         // see above 
   /** list of scheduled components */
@@ -216,8 +301,10 @@ class AliHLTComponentHandler : public AliHLTLogging {
   vector<AliHLTLibHandle> fLibraryList;                            // see above 
   /** running environment for the component */
   AliHLTComponentEnvironment fEnvironment;                         // see above 
-  /** list of standard components */
-  vector<AliHLTComponent*> fStandardList;                          // see above 
+  /** list of owned components, deleted at termination of the handler */
+  vector<AliHLTComponent*> fOwnedComponents;                       // see above 
+  /** library mode effects all loaded libraries until a new mode is set */
+  TLibraryMode fLibraryMode;                                       // see above 
 
   ClassDef(AliHLTComponentHandler, 0);