SenseApis: New senseApiManager and X11XcbApi

Still fleshing these out but ultimately senseApiMgr will manage
sense apis, and the X11XcbApi is where we'll connect to Xcb and
read the screen.
This commit is contained in:
2025-01-08 06:26:36 -04:00
parent f594d29a2d
commit fe3f911db4
8 changed files with 248 additions and 2 deletions
+69
View File
@@ -0,0 +1,69 @@
#ifndef SENSE_API_MANAGER_H
#define SENSE_API_MANAGER_H
#include <config.h>
#include <memory>
#include <vector>
#include <string>
#include <optional>
#include <functional>
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) {}
};
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"
};
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(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;
};
#endif // SENSE_API_MANAGER_H