Belle II Software  release-05-01-25
DynamicLoader.cc
1 #include "daq/slc/system/DynamicLoader.h"
2 #include "daq/slc/system/DynamicLoadException.h"
3 
4 #include <dlfcn.h>
5 
6 using namespace Belle2;
7 
8 DynamicLoader::~DynamicLoader()
9 {
10 }
11 
12 void DynamicLoader::close()
13 {
14  if (m_handle != NULL) {
15  dlclose(m_handle);
16  m_handle = NULL;
17  }
18 }
19 
20 void* DynamicLoader::open(const std::string& lib_path)
21 {
22  void* handle = dlopen(lib_path.c_str(), RTLD_LAZY);
23  if (!handle) {
24  throw (DynamicLoadException("dlopen: %s", dlerror()));
25  }
26  m_handle = handle;
27  return handle;
28 }
29 
30 void* DynamicLoader::load(const std::string& funcname)
31 {
32  char* error = NULL;
33  void* func = dlsym(m_handle, funcname.c_str());
34  if ((error = dlerror()) != NULL) {
35  throw (DynamicLoadException("dlopen: %s", error));
36  }
37  return func;
38 }
Belle2::DynamicLoadException
Definition: DynamicLoadException.h:12
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19