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:
@@ -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
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef X11_XCB_API_H
|
||||
#define X11_XCB_API_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class X11XcbApi
|
||||
{
|
||||
public:
|
||||
X11XcbApi(const std::string& displayName);
|
||||
~X11XcbApi();
|
||||
|
||||
void addDevice(const std::string& deviceSpec);
|
||||
void removeDevice(const std::string& deviceSpec);
|
||||
void addAllDevicesFromSpecs(const std::vector<std::string>& deviceSpecs);
|
||||
|
||||
private:
|
||||
std::string displayName;
|
||||
std::vector<std::shared_ptr<DeviceManager::SensorDeviceSpec>> deviceSpecs;
|
||||
// Add other necessary members and methods
|
||||
};
|
||||
|
||||
#endif // X11_XCB_API_H
|
||||
Reference in New Issue
Block a user