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:
@@ -38,20 +38,18 @@ static std::optional<std::string> findLibraryPath(
|
||||
|
||||
std::cerr << std::string(__func__) + ": library '"
|
||||
+ libraryPath + "' isn't in search bespoke search paths: ";
|
||||
for (const auto& path : searchPaths)
|
||||
{
|
||||
for (const auto& path : searchPaths) {
|
||||
std::cerr << path << " ";
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Trying to load " + libraryPath + " from system default search "
|
||||
"paths\n";
|
||||
std::cerr << "Trying to load " + libraryPath + " from system default "
|
||||
"search paths\n";
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
|
||||
{
|
||||
const CSenseApiDesc *libApiDesc;
|
||||
std::optional<std::string> fullPath = findLibraryPath(libraryPath);
|
||||
std::string resolvedPath = fullPath.value_or(libraryPath);
|
||||
|
||||
@@ -90,14 +88,7 @@ SenseApiLib& SenseApiManager::loadSenseApiLib(const std::string& libraryPath)
|
||||
+ libraryPath + "'");
|
||||
}
|
||||
|
||||
libApiDesc = func();
|
||||
if (!libApiDesc)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": getSenseApiDesc() returned NULL for "
|
||||
"library '" + libraryPath + "'");
|
||||
}
|
||||
|
||||
const SenseApiDesc &libApiDesc = func();
|
||||
auto lib = std::make_unique<SenseApiLib>(
|
||||
libraryPath, dlopen_handle.release(), func);
|
||||
lib->setSenseApiDesc(libApiDesc);
|
||||
@@ -173,24 +164,24 @@ std::string SenseApiManager::stringifyLibs() const
|
||||
|
||||
void SenseApiManager::initializeSenseApiLib(SenseApiLib& lib)
|
||||
{
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps->initializeInd)
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps.initializeInd)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": initializeInd() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
lib.senseApiDesc.sal_mgmt_libOps->initializeInd();
|
||||
lib.senseApiDesc.sal_mgmt_libOps.initializeInd();
|
||||
}
|
||||
|
||||
void SenseApiManager::finalizeSenseApiLib(SenseApiLib& lib)
|
||||
{
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps->finalizeInd)
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps.finalizeInd)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": finalizeInd() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
lib.senseApiDesc.sal_mgmt_libOps->finalizeInd();
|
||||
lib.senseApiDesc.sal_mgmt_libOps.finalizeInd();
|
||||
}
|
||||
|
||||
void SenseApiManager::initializeAllSenseApiLibs(void)
|
||||
@@ -207,7 +198,7 @@ void SenseApiManager::finalizeAllSenseApiLibs(void)
|
||||
}
|
||||
}
|
||||
|
||||
void SenseApiManager::attachSenseDevice(const SenseDeviceSpec& spec)
|
||||
void SenseApiManager::attachSenseDevice(const device::SenseDeviceSpec& spec)
|
||||
{
|
||||
auto libOpt = getSenseApiLibByApiName(spec.api);
|
||||
if (!libOpt)
|
||||
@@ -217,17 +208,16 @@ void SenseApiManager::attachSenseDevice(const SenseDeviceSpec& spec)
|
||||
+ spec.api + "'");
|
||||
}
|
||||
auto& lib = libOpt.value().get();
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps->attachDeviceReq)
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": attachDeviceReq() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
CSenseDeviceSpec cSpec(spec);
|
||||
lib.senseApiDesc.sal_mgmt_libOps->attachDeviceReq(&cSpec);
|
||||
lib.senseApiDesc.sal_mgmt_libOps.attachDeviceReq(&spec);
|
||||
}
|
||||
|
||||
void SenseApiManager::detachSenseDevice(const SenseDeviceSpec& spec)
|
||||
void SenseApiManager::detachSenseDevice(const device::SenseDeviceSpec& spec)
|
||||
{
|
||||
auto libOpt = getSenseApiLibByApiName(spec.api);
|
||||
if (!libOpt)
|
||||
@@ -237,26 +227,25 @@ void SenseApiManager::detachSenseDevice(const SenseDeviceSpec& spec)
|
||||
+ spec.api + "'");
|
||||
}
|
||||
auto& lib = libOpt.value().get();
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps->detachDeviceReq)
|
||||
if (!lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": detachDeviceReq() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
CSenseDeviceSpec cSpec(spec);
|
||||
lib.senseApiDesc.sal_mgmt_libOps->detachDeviceReq(&cSpec);
|
||||
lib.senseApiDesc.sal_mgmt_libOps.detachDeviceReq(&spec);
|
||||
}
|
||||
|
||||
void SenseApiManager::attachAllSenseDevicesFromSpecs(void)
|
||||
{
|
||||
for (const auto& spec : DeviceManager::senseDeviceSpecs) {
|
||||
for (const auto& spec : device::DeviceManager::senseDeviceSpecs) {
|
||||
attachSenseDevice(*spec);
|
||||
}
|
||||
}
|
||||
|
||||
void SenseApiManager::detachAllSenseDevices(void)
|
||||
{
|
||||
for (const auto& spec : DeviceManager::senseDeviceSpecs) {
|
||||
for (const auto& spec : device::DeviceManager::senseDeviceSpecs) {
|
||||
detachSenseDevice(*spec);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user