Eliminate the C FFI; Namespace lib API and DeviceManager

We decided to get rid of the C FFI for libs. It was becoming too intricate
and complicated. It was becoming a technical burden and expanding into
too much extra code. It's unfortunate, but we'll have to give up on getting
out-of-tree hot-loadable libraries the easy way.

It's possible to still do it with cross compilation or by keeping track
of the libstdc++ version that the running harikoff binary was compiled
against. Then we can ensure that our loadable lib code is linked against
that same libstdc++ code and this should ensure ABI stability.
This commit is contained in:
2025-01-13 21:57:11 -04:00
parent a4f96c8dfa
commit 09caf314f1
11 changed files with 197 additions and 377 deletions
+29 -41
View File
@@ -3,23 +3,25 @@
#include <stdexcept>
#include <memory>
#include <vector>
#include <user/senseDeviceSpec.h>
#include <user/senseApiDesc.h>
#include <xcb/xcb.h>
#include "xcbXorg.h"
class AttachedDevice {
public:
AttachedDevice(const CSenseDeviceSpec &spec) : deviceSpec(spec) {}
AttachedDevice(const hk::device::SenseDeviceSpec &spec)
: deviceSpec(spec)
{}
const CSenseDeviceSpec& getSpec() const {
const hk::device::SenseDeviceSpec& getSpec() const {
return deviceSpec;
}
private:
CSenseDeviceSpec deviceSpec;
hk::device::SenseDeviceSpec deviceSpec;
};
static std::vector<AttachedDevice> attachedDevices;
struct XcbConnectionInfo {
std::unique_ptr<xcb_connection_t, decltype(&xcb_disconnect)> connection;
int screenNumber;
@@ -29,44 +31,33 @@ struct XcbConnectionInfo {
};
static XcbConnectionInfo xcbConn;
static std::vector<AttachedDevice> attachedDevices;
static CExportedImplexorApiDesc xcbXorgExportedImplexorApis[] =
static hk::sense_api::sal_mlo_initializeIndFn xcbXorg_initializeInd;
static hk::sense_api::sal_mlo_finalizeIndFn xcbXorg_finalizeInd;
static hk::sense_api::sal_mlo_attachDeviceReqFn xcbXorg_attachDeviceReq;
static hk::sense_api::sal_mlo_detachDeviceReqFn xcbXorg_detachDeviceReq;
static hk::sense_api::SenseApiDesc xcbXorgApiDesc =
{
{
.name = "video-implexor"
.name = "xcb-xorg",
.exportedImplexorApis = { { "video-implexor" } },
.sal_mgmt_libOps = {
.initializeInd = xcbXorg_initializeInd,
.finalizeInd = xcbXorg_finalizeInd,
.attachDeviceReq = xcbXorg_attachDeviceReq,
.detachDeviceReq = xcbXorg_detachDeviceReq
}
};
static sal_mlo_initializeIndFn xcbXorg_initializeInd;
static sal_mlo_finalizeIndFn xcbXorg_finalizeInd;
static sal_mlo_attachDeviceReqFn xcbXorg_attachDeviceReq;
static sal_mlo_detachDeviceReqFn xcbXorg_detachDeviceReq;
extern HK_UNMANGLED hk::sense_api::getSenseApiDescFn
HK_GET_SENSE_API_DESC_FN_NAME;
static Csal_mgmt_libOps xcbXorgMgmtLibOps =
const hk::sense_api::SenseApiDesc &HK_GET_SENSE_API_DESC_FN_NAME(void)
{
.initializeInd = xcbXorg_initializeInd,
.finalizeInd = xcbXorg_finalizeInd,
.attachDeviceReq = xcbXorg_attachDeviceReq,
.detachDeviceReq = xcbXorg_detachDeviceReq
};
static CSenseApiDesc xcbXorgApiDesc =
{
.name = "xcb-xorg",
.numExportedImplexorApis = sizeof(xcbXorgExportedImplexorApis) /
sizeof(*xcbXorgExportedImplexorApis),
.exportedImplexorApis = xcbXorgExportedImplexorApis,
.sal_mgmt_libOps = &xcbXorgMgmtLibOps
};
extern HK_UNMANGLED getSenseApiDescFn HK_GET_SENSE_API_DESC_FN_NAME;
const CSenseApiDesc *HK_GET_SENSE_API_DESC_FN_NAME(void)
{
return &xcbXorgApiDesc;
return xcbXorgApiDesc;
}
static sal_mlo_initializeIndFn xcbXorg_initializeInd;
int xcbXorg_initializeInd(void)
{
xcbConn.connection.reset(
@@ -83,7 +74,6 @@ int xcbXorg_initializeInd(void)
return 0;
}
static sal_mlo_finalizeIndFn xcbXorg_finalizeInd;
int xcbXorg_finalizeInd(void)
{
if (!xcbConn.connection) {
@@ -94,22 +84,20 @@ int xcbXorg_finalizeInd(void)
return 0;
}
static sal_mlo_attachDeviceReqFn xcbXorg_attachDeviceReq;
int xcbXorg_attachDeviceReq(const CSenseDeviceSpec *const desc)
int xcbXorg_attachDeviceReq(const hk::device::SenseDeviceSpec *const desc)
{
attachedDevices.emplace_back(*desc);
std::ostringstream os;
for (const auto& device : attachedDevices) {
os << device.getSpec();
os << device.getSpec().stringify();
}
std::cout << __func__ << ": >>>> Attaching device spec: " << *desc << "\n"
std::cout << __func__ << ": >>>> Attaching device spec: " << desc->stringify() << "\n"
<< " >>>> Current attached devices:\n" << os.str();
return 0;
}
static sal_mlo_detachDeviceReqFn xcbXorg_detachDeviceReq;
int xcbXorg_detachDeviceReq(const CSenseDeviceSpec *const spec)
int xcbXorg_detachDeviceReq(const hk::device::SenseDeviceSpec *const spec)
{
auto it = std::remove_if(attachedDevices.begin(), attachedDevices.end(),
[spec](const AttachedDevice &device) {