SenseApis: Define descriptors exported by libs
This commit is contained in:
@@ -7,63 +7,35 @@
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <senseApis/senseApiLib.h>
|
||||
|
||||
struct SenseApiInstance {
|
||||
int a;
|
||||
|
||||
bool operator==(const SenseApiInstance& other) const {
|
||||
return a == other.a;
|
||||
}
|
||||
};
|
||||
|
||||
class SenseApiLib {
|
||||
public:
|
||||
std::string libraryPath;
|
||||
std::unique_ptr<void, decltype(&dlclose)> handle;
|
||||
|
||||
SenseApiLib(const std::string& path)
|
||||
: libraryPath(path), handle(nullptr, &dlclose) {}
|
||||
};
|
||||
namespace hk {
|
||||
namespace sense_api {
|
||||
|
||||
class SenseApiManager {
|
||||
public:
|
||||
static SenseApiManager& getInstance()
|
||||
{
|
||||
static SenseApiManager instance
|
||||
{
|
||||
#ifdef CONFIG_SENSEAPI_FOO
|
||||
"builtinApi1",
|
||||
#endif
|
||||
#ifdef CONFIG_SENSEAPI_BAR
|
||||
"builtinApi2",
|
||||
#endif
|
||||
// X11 XCB is always built-in.
|
||||
"x11-xcb"
|
||||
};
|
||||
|
||||
static SenseApiManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void registerSenseApi(const SenseApiInstance& apiInstance);
|
||||
void unregisterSenseApi(const SenseApiInstance& apiInstance);
|
||||
|
||||
SenseApiLib& loadSenseApiLib(const std::string& libraryPath);
|
||||
std::optional<std::reference_wrapper<SenseApiLib>> getSenseApiLib(
|
||||
const std::string& libraryPath);
|
||||
void unloadSenseApiLib(const std::string& libraryPath);
|
||||
|
||||
private:
|
||||
SenseApiManager() = delete;
|
||||
SenseApiManager(std::initializer_list<std::string> builtinApis)
|
||||
: builtinSenseApis(builtinApis) {}
|
||||
SenseApiManager() = default;
|
||||
~SenseApiManager() = default;
|
||||
|
||||
SenseApiManager(const SenseApiManager&) = delete;
|
||||
SenseApiManager& operator=(const SenseApiManager&) = delete;
|
||||
|
||||
std::vector<std::unique_ptr<SenseApiInstance>> senseApiInstances;
|
||||
std::vector<std::unique_ptr<SenseApiLib>> senseApiLibs;
|
||||
const std::vector<std::string> builtinSenseApis;
|
||||
};
|
||||
|
||||
} // namespace sense_api
|
||||
} // namespace hk
|
||||
|
||||
#endif // SENSE_API_MANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user