Belle II Software development
DynamicLoader.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include "daq/slc/system/DynamicLoader.h"
9#include "daq/slc/system/DynamicLoadException.h"
10
11#include <dlfcn.h>
12
13using namespace Belle2;
14
15DynamicLoader::~DynamicLoader()
16{
17}
18
19void DynamicLoader::close()
20{
21 if (m_handle != NULL) {
22 dlclose(m_handle);
23 m_handle = NULL;
24 }
25}
26
27void* DynamicLoader::open(const std::string& lib_path)
28{
29 void* handle = dlopen(lib_path.c_str(), RTLD_LAZY);
30 if (!handle) {
31 throw (DynamicLoadException("dlopen: %s", dlerror()));
32 }
33 m_handle = handle;
34 return handle;
35}
36
37void* DynamicLoader::load(const std::string& funcname)
38{
39 char* error = NULL;
40 void* func = dlsym(m_handle, funcname.c_str());
41 if ((error = dlerror()) != NULL) {
42 throw (DynamicLoadException("dlopen: %s", error));
43 }
44 return func;
45}
Abstract base class for different kinds of events.