SenseApis: Define descriptors exported by libs
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <optional>
|
||||
#include <senseApis/senseApiManager.h>
|
||||
#include <senseApis/senseApiLib.h>
|
||||
|
||||
std::vector<std::unique_ptr<SenseApiLib>> senseApiLibs;
|
||||
std::vector<std::unique_ptr<SenseApiInstance>> senseApiInstances;
|
||||
namespace hk {
|
||||
namespace sense_api {
|
||||
|
||||
SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
|
||||
{
|
||||
@@ -29,8 +29,8 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
|
||||
return *senseApiLibs.back();
|
||||
}
|
||||
|
||||
std::optional<std::reference_wrapper<SenseApiLib>> SenseApiManager::getSenseApiLib(
|
||||
const std::string& libraryPath)
|
||||
std::optional<std::reference_wrapper<SenseApiLib>>
|
||||
SenseApiManager::getSenseApiLib(const std::string& libraryPath)
|
||||
{
|
||||
auto it = std::find_if(senseApiLibs.begin(), senseApiLibs.end(),
|
||||
[&libPath = libraryPath](const std::unique_ptr<SenseApiLib>& lib) {
|
||||
@@ -60,39 +60,5 @@ void SenseApiManager::unloadSenseApiLib(const std::string& libraryPath)
|
||||
<< libraryPath << '\n';
|
||||
}
|
||||
|
||||
void SenseApiManager::registerSenseApi(const SenseApiInstance& apiInstance)
|
||||
{
|
||||
auto it = std::find_if(
|
||||
senseApiInstances.begin(), senseApiInstances.end(),
|
||||
[&apiInstance](const std::unique_ptr<SenseApiInstance>& instance) {
|
||||
return const_cast<const SenseApiInstance&>(*instance) == apiInstance;
|
||||
}
|
||||
);
|
||||
|
||||
if (it != senseApiInstances.end())
|
||||
{
|
||||
std::cerr << std::string(__func__)
|
||||
+ ": Sense API Instance already registered.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
senseApiInstances.push_back(std::make_unique<SenseApiInstance>(apiInstance));
|
||||
}
|
||||
|
||||
void SenseApiManager::unregisterSenseApi(const SenseApiInstance& apiInstance)
|
||||
{
|
||||
auto it = std::find_if(
|
||||
senseApiInstances.begin(), senseApiInstances.end(),
|
||||
[&apiInstance](const std::unique_ptr<SenseApiInstance>& instance) {
|
||||
return const_cast<const SenseApiInstance&>(*instance) == apiInstance;
|
||||
}
|
||||
);
|
||||
|
||||
if (it == senseApiInstances.end())
|
||||
{
|
||||
std::cerr << std::string(__func__) + ": Sense API Instance not found.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
senseApiInstances.erase(it);
|
||||
}
|
||||
} // namespace sense_api
|
||||
} // namespace hk
|
||||
|
||||
Reference in New Issue
Block a user