diff --git a/smocore/include/senseApis/senseApiManager.h b/smocore/include/senseApis/senseApiManager.h index 8689327..12cf127 100644 --- a/smocore/include/senseApis/senseApiManager.h +++ b/smocore/include/senseApis/senseApiManager.h @@ -23,9 +23,9 @@ public: } SenseApiLib& loadSenseApiLib(const std::string& libraryPath); - std::optional> getSenseApiLib( + std::optional> getSenseApiLib( const std::string& libraryPath); - std::optional> getSenseApiLibByApiName( + std::optional> getSenseApiLibByApiName( const std::string& apiName); void unloadSenseApiLib(const std::string& libraryPath); @@ -53,7 +53,7 @@ private: SenseApiManager(const SenseApiManager&) = delete; SenseApiManager& operator=(const SenseApiManager&) = delete; - std::vector> senseApiLibs; + std::vector> senseApiLibs; public: static std::optional searchForLibInSmoSearchPaths( diff --git a/smocore/senseApis/senseApiManager.cpp b/smocore/senseApis/senseApiManager.cpp index dddaf1d..7bf11c1 100644 --- a/smocore/senseApis/senseApiManager.cpp +++ b/smocore/senseApis/senseApiManager.cpp @@ -122,43 +122,43 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath) } const SenseApiDesc &libApiDesc = func(salmanoffCallbacks); - auto lib = std::make_unique( + auto lib = std::make_shared( libraryPath, dlopen_handle.release(), func); lib->setSenseApiDesc(libApiDesc); - senseApiLibs.push_back(std::move(lib)); + senseApiLibs.push_back(lib); return *senseApiLibs.back(); } -std::optional> +std::optional> SenseApiManager::getSenseApiLib(const std::string& libraryPath) { auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(), - [&libPath = libraryPath](const std::unique_ptr& lib) { + [&libPath = libraryPath](const std::shared_ptr& lib) { return lib->libraryPath == libPath; } ); - if (it != senseApiLibs.end()) { return **it; } + if (it != senseApiLibs.end()) { return *it; } return std::nullopt; } -std::optional> +std::optional> SenseApiManager::getSenseApiLibByApiName(const std::string& apiName) { auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(), - [&apiName](const std::unique_ptr& lib) { + [&apiName](const std::shared_ptr& lib) { return lib->senseApiDesc.name == apiName; } ); - if (it != senseApiLibs.end()) { return **it; } + if (it != senseApiLibs.end()) { return *it; } return std::nullopt; } void SenseApiManager::unloadSenseApiLib(const std::string& libraryPath) { auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(), - [&lpath = libraryPath](const std::unique_ptr& lib) { + [&lpath = libraryPath](const std::shared_ptr& lib) { return lib->libraryPath == lpath; } ); @@ -242,7 +242,7 @@ void SenseApiManager::attachSenseDevice( std::string(__func__) + ": No library found for API '" + spec->api + "'"); } - auto& lib = libOpt.value().get(); + auto& lib = *libOpt.value(); if (!lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq) { throw std::runtime_error( @@ -263,7 +263,7 @@ void SenseApiManager::detachSenseDevice( std::string(__func__) + ": No library found for API '" + spec->api + "'"); } - auto& lib = libOpt.value().get(); + auto& lib = *libOpt.value(); if (!lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq) { throw std::runtime_error(