]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
added support for symbol lookup in dynamically loaded libraries; minor warning removed
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 20 Apr 2007 09:19:08 +0000 (09:19 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 20 Apr 2007 09:19:08 +0000 (09:19 +0000)
HLT/BASE/AliHLTComponentHandler.cxx
HLT/BASE/AliHLTComponentHandler.h
HLT/BASE/AliHLTSystem.cxx
HLT/BASE/AliHLTSystem.h

index de9410e36a1c0c3d98be33befdc11e9c5e351965..50aa238e3ca9bbd2f1d35b69106ed5058f728bdd 100644 (file)
@@ -259,37 +259,35 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
   if (libraryPath) {
     AliHLTComponent::SetGlobalComponentHandler(this);
     AliHLTLibHandle hLib;
+    const char* loadtype="";
 #ifdef HAVE_DLFCN_H
     // use interface to the dynamic linking loader
     hLib.handle=dlopen(libraryPath, RTLD_NOW);
+    loadtype="dlopen";
 #else
     // use ROOT dynamic loader
     // check if the library was already loaded, as Load returns
     // 'failure' if the library was already loaded
-    vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
-    while (element!=fLibraryList.end()) {
-      TString* name=reinterpret_cast<TString*>((*element).name);
-      if (name->CompareTo(libraryPath)==0) {
-       int* pRootHandle=reinterpret_cast<int*>((*element).handle);
+    AliHLTLibHandle* pLib=FindLibrary(libraryPath);
+    if (pLib) {
+       int* pRootHandle=reinterpret_cast<int*>(pLib->handle);
        (*pRootHandle)++;
        HLTDebug("instance %d of library %s loaded", (*pRootHandle), libraryPath);
        hLib.handle=pRootHandle;
-       break;
-      }
-      element++;
     }
     
     if (hLib.handle==NULL && gSystem->Load(libraryPath)==0) {
       int* pRootHandle=new int;
       if (pRootHandle) *pRootHandle=1;
       hLib.handle=pRootHandle;
-      HLTDebug("library %s loaded via gSystem", libraryPath);
+      //HLTDebug("library %s loaded via gSystem", libraryPath);
     }
+    loadtype="gSystem";
 #endif //HAVE_DLFCN_H
     if (hLib.handle!=NULL) {
       // create TString object to store library path and use pointer as handle 
       hLib.name=new TString(libraryPath);
-      HLTInfo("library %s loaded", libraryPath);
+      HLTInfo("library %s loaded (%s)", libraryPath, loadtype);
       fLibraryList.insert(fLibraryList.begin(), hLib);
       iResult=RegisterScheduledComponents();
     } else {
@@ -354,6 +352,37 @@ int AliHLTComponentHandler::UnloadLibraries()
   return iResult;
 }
 
+void* AliHLTComponentHandler::FindSymbol(const char* library, const char* symbol)
+{
+  // see header file for class documentation
+  AliHLTLibHandle* hLib=FindLibrary(library);
+  if (hLib==NULL) return NULL;
+  void* pFunc=NULL;
+#ifdef HAVE_DLFCN_H
+  pFunc=dlsym(hLib->handle, symbol);
+#else
+  TString* name=reinterpret_cast<TString*>(hLib->name);
+  pFunc=gSystem->DynFindSymbol(name->Data(), symbol);
+#endif
+  return pFunc;
+}
+
+AliHLTComponentHandler::AliHLTLibHandle* AliHLTComponentHandler::FindLibrary(const char* library)
+{
+  // see header file for class documentation
+  AliHLTLibHandle* hLib=NULL;
+  vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
+  while (element!=fLibraryList.end()) {
+    TString* name=reinterpret_cast<TString*>((*element).name);
+    if (name->CompareTo(library)==0) {
+      hLib=&(*element);
+      break;
+    }
+    element++;
+  }
+  return hLib;
+}
+
 int AliHLTComponentHandler::AddStandardComponents()
 {
   // see header file for class documentation
index ea3c4c4dfc3b40a1db3c44510753674aebb12811..f00314e8be113eb6327f889cbfa37022b88c414e 100644 (file)
@@ -61,6 +61,14 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   int LoadLibrary( const char* libraryPath );
 
+  /**
+   * 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.
@@ -208,6 +216,13 @@ class AliHLTComponentHandler : public AliHLTLogging {
     void* name;                                                    //! transient
   };
 
+  /**
+   * Find a specific library among the loaded libraries.
+   * @param library     library name/path
+   * @return pointer to AliHLTLibHandle
+   */
+  AliHLTLibHandle* FindLibrary(const char* library);
+
   /** list of registered components */
   vector<AliHLTComponent*> fComponentList;                         // see above 
   /** list of scheduled components */
index e316e71970f1fd67f0c2bcd7ec66ae3a7464d4ad..4c33d4173fc0011b417891f8d825b49ff7664fad 100644 (file)
@@ -411,6 +411,8 @@ int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
            pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
          }
          break;
+       default:
+         HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
        }
       }
     } else {
@@ -695,3 +697,9 @@ int AliHLTSystem::ClearStatusFlags(int flags)
   fState&=~flags;
   return fState;
 }
+
+void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
+{
+  if (fpComponentHandler==NULL) return NULL;
+  return fpComponentHandler->FindSymbol(library, symbol);
+}
index 70ca889c9df0d2df6141e89eb5c3781d54bb4178..7b9103ff606ca3da15194dfba96ff12dd320c399 100644 (file)
@@ -227,6 +227,14 @@ class AliHLTSystem : public AliHLTLogging {
    */
   int LoadComponentLibraries(const char* libs);
 
+  /**
+   * Find a symbol in a dynamically loaded library.
+   * @param library      library
+   * @param symbol       the symbol to find
+   * @return void pointer to function
+   */
+  void* FindDynamicSymbol(const char* library, const char* symbol);
+
   /**
    * Prepare the HLT system for running.
    * - module agents are requested to register configurations