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
+5 -69
View File
@@ -11,59 +11,6 @@
namespace hk {
namespace sense_api {
/* C++ version of the C struct above, which Harikoff uses to manage the
* lib and connect implexors to it.
*/
class SenseApiDesc
{
public:
class ExportedImplexorApiDesc
{
public:
ExportedImplexorApiDesc(const CExportedImplexorApiDesc& cDesc)
// The caller should sanity check before calling this constructor.
: name(cDesc.name)
{}
const std::string name;
};
public:
SenseApiDesc() = default;
SenseApiDesc(const CSenseApiDesc& cDesc)
// The caller should sanity check before calling this constructor.
: name(cDesc.name),
sal_mgmt_libOps(cDesc.sal_mgmt_libOps)
{
for (uint32_t i = 0; i < cDesc.numExportedImplexorApis; ++i)
{
if (!CExportedImplexorApiDesc_sanityCheck(
&cDesc.exportedImplexorApis[i]))
{
throw std::runtime_error(
"Sanity check failed for exported implexor API descriptor");
}
exportedImplexorApis.push_back(
ExportedImplexorApiDesc(cDesc.exportedImplexorApis[i]));
}
}
std::string name;
// These are the implexors whose APIs this lib exports.
std::vector<ExportedImplexorApiDesc> exportedImplexorApis;
Csal_mgmt_libOps* sal_mgmt_libOps;
std::string stringify() const {
std::string result = "Name: " + name + "\n";
result += "Exported Implexor APIs:\n";
for (const auto& api : exportedImplexorApis) {
result += " - " + api.name + "\n";
}
return result;
}
};
class SenseApiLib
{
private:
@@ -86,27 +33,16 @@ public:
HK_GET_SENSE_API_DESC_FN_NAME(descFn)
{}
void setSenseApiDesc(const CSenseApiDesc* desc)
void setSenseApiDesc(const SenseApiDesc &desc)
{
if (!CSenseApiDesc_sanityCheck(desc) ||
!Csal_mgmt_libOps_sanityCheck(desc->sal_mgmt_libOps))
if (!SenseApiDesc::sanityCheck(desc))
{
throw std::runtime_error(
std::string(__func__) + ": Sanity check failed for sense API "
"descriptor in library '" + libraryPath + "'");
}
for (uint32_t i = 0; i < desc->numExportedImplexorApis; ++i)
{
if (!CExportedImplexorApiDesc_sanityCheck(
&desc->exportedImplexorApis[i]))
{
throw std::runtime_error(
std::string(__func__) + ": Sanity check failed for "
"exported implexor API descriptor in library '"
+ libraryPath + "'");
}
}
new (&senseApiDesc) SenseApiDesc(*desc); // Placement new
senseApiDesc = desc;
}
public:
@@ -119,7 +55,7 @@ public:
/**
* @brief Every sense API lib is required to provide a function that returns
* a CSenseApiDesc struct. This struct states which API the lib uses to
* a SenseApiDesc struct. This struct states which API the lib uses to
* connect Harikoff to the sense provider it supports.
*
* This getter function should be visible to dlsym() so that Harikoff can
+2 -2
View File
@@ -38,8 +38,8 @@ public:
void finalizeAllSenseApiLibs(void);
void attachAllSenseDevicesFromSpecs(void);
void attachSenseDevice(const SenseDeviceSpec& spec);
void detachSenseDevice(const SenseDeviceSpec& spec);
void attachSenseDevice(const device::SenseDeviceSpec& spec);
void detachSenseDevice(const device::SenseDeviceSpec& spec);
void detachAllSenseDevices(void);
std::string stringifyLibs() const;