diff --git a/hcore/include/senseApis/senseApiLib.h b/hcore/include/senseApis/senseApiLib.h index abf075c..0e1e1f1 100644 --- a/hcore/include/senseApis/senseApiLib.h +++ b/hcore/include/senseApis/senseApiLib.h @@ -64,12 +64,23 @@ public: class SenseApiLib { +private: + friend class SenseApiManager; + struct DlCloser + { + void operator()(void* handle) const + { + if (handle) { + dlclose(handle); + } + } + }; + public: SenseApiLib( const std::string& path, void *_dlopen_handle, getSenseApiDescFn *descFn) : libraryPath(path), - dlopen_handle( - _dlopen_handle, reinterpret_cast(&dlclose)), + dlopen_handle(_dlopen_handle, DlCloser()), HK_GET_SENSE_API_DESC_FN_NAME(descFn) {} @@ -98,7 +109,7 @@ public: public: std::string libraryPath; - std::unique_ptr dlopen_handle; + std::unique_ptr dlopen_handle; /* UNIMPLEMENTED: API-specific cmdline options. These affect this specific * sense api lib's behaviour globally. */ diff --git a/hcore/include/senseApis/senseApiManager.h b/hcore/include/senseApis/senseApiManager.h index 919b1a4..ca690fe 100644 --- a/hcore/include/senseApis/senseApiManager.h +++ b/hcore/include/senseApis/senseApiManager.h @@ -12,7 +12,8 @@ namespace hk { namespace sense_api { -class SenseApiManager { +class SenseApiManager +{ public: static SenseApiManager& getInstance() { diff --git a/hcore/senseApis/senseApiManager.cpp b/hcore/senseApis/senseApiManager.cpp index 7a306e0..d171e05 100644 --- a/hcore/senseApis/senseApiManager.cpp +++ b/hcore/senseApis/senseApiManager.cpp @@ -12,14 +12,6 @@ namespace fs = std::filesystem; namespace hk { namespace sense_api { -struct DlCloser { - void operator()(void* handle) const { - if (handle) { - dlclose(handle); - } - } -}; - static std::optional findLibraryPath( const std::string& libraryPath) { @@ -64,7 +56,7 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath) // Clear any existing error dlerror(); - auto dlopen_handle = std::unique_ptr( + auto dlopen_handle = std::unique_ptr( dlopen(resolvedPath.c_str(), RTLD_LAZY)); if (!dlopen_handle && fullPath.has_value()) {