Senselib FFI: Use devDesc object in SenseApiLib, also add per-device metadata to xcbXorg
We also had to write conversion constructors and so on to CSenseDeviceDesc. The technical debt that's being piled up from this C FFI is excessive. I think we'll end it here. API Libs will have to be written in C++ from now on. API Lib interfaces will be in C++. We'll use cross compilers to ensure stability for out-of-tree lib development.
This commit is contained in:
@@ -2,9 +2,24 @@
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <xcb/xcb.h>
|
||||
#include "xcbXorg.h"
|
||||
|
||||
class AttachedDevice {
|
||||
public:
|
||||
AttachedDevice(const CSenseDeviceSpec &spec) : deviceSpec(spec) {}
|
||||
|
||||
const CSenseDeviceSpec& getSpec() const {
|
||||
return deviceSpec;
|
||||
}
|
||||
|
||||
private:
|
||||
CSenseDeviceSpec deviceSpec;
|
||||
};
|
||||
|
||||
static std::vector<AttachedDevice> attachedDevices;
|
||||
|
||||
struct XcbConnectionInfo {
|
||||
std::unique_ptr<xcb_connection_t, decltype(&xcb_disconnect)> connection;
|
||||
int screenNumber;
|
||||
@@ -82,13 +97,25 @@ int xcbXorg_finalizeInd(void)
|
||||
static sal_mlo_attachDeviceReqFn xcbXorg_attachDeviceReq;
|
||||
int xcbXorg_attachDeviceReq(const CSenseDeviceSpec *const desc)
|
||||
{
|
||||
std::cout << __func__ << ": Attaching device spec: " << *desc << "\n";
|
||||
attachedDevices.emplace_back(*desc);
|
||||
|
||||
std::ostringstream os;
|
||||
for (const auto& device : attachedDevices) {
|
||||
os << device.getSpec();
|
||||
}
|
||||
std::cout << __func__ << ": >>>> Attaching device spec: " << *desc << "\n"
|
||||
<< " >>>> Current attached devices:\n" << os.str();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static sal_mlo_detachDeviceReqFn xcbXorg_detachDeviceReq;
|
||||
int xcbXorg_detachDeviceReq(const CSenseDeviceSpec *const spec)
|
||||
{
|
||||
std::cout << __func__ << "\n";
|
||||
auto it = std::remove_if(attachedDevices.begin(), attachedDevices.end(),
|
||||
[spec](const AttachedDevice &device) {
|
||||
return device.getSpec() == *spec;
|
||||
});
|
||||
attachedDevices.erase(it, attachedDevices.end());
|
||||
std::cout << __func__ << ": Detaching device spec\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user