SenseApiDesc,xcbWindow: port to sscl coro framework
SenseApiDesc's exported API now uses coro pointers instead of CPS fn pointers. * Do not build this version of SMO with the Livox drivers enabled, because SMO has been changed at the smocore level to use coros when calling into stimbuffAPI libs. But the Livox drivers haven't yet been ported from CPS to coros. xcbWindow has been ported to expose coros to SMO in its senseApiDesc exported iface.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <filesystem>
|
||||
#include <stimBuffApis/stimBuffApiManager.h>
|
||||
#include <stimBuffApis/stimBuffApiLib.h>
|
||||
#include <body/bodyThread.h>
|
||||
#include <componentThread.h>
|
||||
#include <opts.h>
|
||||
#include <user/senseApiDesc.h>
|
||||
#include <mind.h>
|
||||
@@ -17,6 +19,21 @@ namespace fs = std::filesystem;
|
||||
namespace smo {
|
||||
namespace stim_buff {
|
||||
|
||||
namespace {
|
||||
|
||||
void assertBodyThread()
|
||||
{
|
||||
auto self = sscl::ComponentThread::getSelf();
|
||||
if (self->id != SmoThreadId::BODY)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__)
|
||||
+ ": Must be executed on Body thread");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* @brief Searches for a library in predefined locations
|
||||
* @param libraryPath The name or path of the library to find
|
||||
@@ -269,49 +286,96 @@ std::string StimBuffApiManager::stringifyLibs() const
|
||||
return result;
|
||||
}
|
||||
|
||||
void StimBuffApiManager::initializeStimBuffApiLib(StimBuffApiLib& lib)
|
||||
body::BodyViralPostingInvoker<void>
|
||||
StimBuffApiManager::initializeStimBuffApiLibCReq(
|
||||
StimBuffApiLib &lib, bool acquireSbamLock)
|
||||
{
|
||||
/** FIXME:
|
||||
* When we eventually make this method async, this method should acquire
|
||||
* the StimBuffApiManager's main CRUD qutex.
|
||||
*/
|
||||
if (!lib.stimBuffApiDesc.sal_mgmt_libOps.initializeInd)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": initializeInd() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
lib.stimBuffApiDesc.sal_mgmt_libOps.initializeInd();
|
||||
assertBodyThread();
|
||||
|
||||
StimBuffApiManager &sbam = getInstance();
|
||||
std::optional<sscl::co::CoQutex::ReleaseHandle> sbamGuard;
|
||||
if (acquireSbamLock)
|
||||
{
|
||||
sbamGuard.emplace(
|
||||
co_await sbam.s.lock.getAcquireInvocationAndSuspensionPolicy());
|
||||
}
|
||||
|
||||
if (!lib.stimBuffApiDesc.sal_mgmt_libOps.initializeCInd)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": initializeCInd() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
|
||||
sscl::co::CoQutex::ReleaseHandle libGuard =
|
||||
co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
||||
|
||||
co_await lib.stimBuffApiDesc.sal_mgmt_libOps.initializeCInd();
|
||||
|
||||
co_return;
|
||||
}
|
||||
|
||||
void StimBuffApiManager::finalizeStimBuffApiLib(StimBuffApiLib& lib)
|
||||
body::BodyViralPostingInvoker<void>
|
||||
StimBuffApiManager::finalizeStimBuffApiLibCReq(
|
||||
StimBuffApiLib &lib, bool acquireSbamLock)
|
||||
{
|
||||
/** FIXME:
|
||||
* When we eventually make this method async, this flag should only be set
|
||||
* after acquiring the StimBuffApiManager's main CRUD qutex.
|
||||
*/
|
||||
lib.isBeingDestroyed.store(true);
|
||||
if (!lib.stimBuffApiDesc.sal_mgmt_libOps.finalizeInd)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": finalizeInd() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
lib.stimBuffApiDesc.sal_mgmt_libOps.finalizeInd();
|
||||
assertBodyThread();
|
||||
|
||||
StimBuffApiManager &sbam = getInstance();
|
||||
std::optional<sscl::co::CoQutex::ReleaseHandle> sbamGuard;
|
||||
if (acquireSbamLock)
|
||||
{
|
||||
sbamGuard.emplace(
|
||||
co_await sbam.s.lock.getAcquireInvocationAndSuspensionPolicy());
|
||||
}
|
||||
|
||||
lib.isBeingDestroyed.store(true);
|
||||
|
||||
if (!lib.stimBuffApiDesc.sal_mgmt_libOps.finalizeCInd)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": finalizeCInd() is NULL for library '"
|
||||
+ lib.libraryPath + "'");
|
||||
}
|
||||
|
||||
sscl::co::CoQutex::ReleaseHandle libGuard =
|
||||
co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
||||
|
||||
co_await lib.stimBuffApiDesc.sal_mgmt_libOps.finalizeCInd();
|
||||
|
||||
co_return;
|
||||
}
|
||||
|
||||
void StimBuffApiManager::initializeAllStimBuffApiLibs(void)
|
||||
body::BodyViralPostingInvoker<void>
|
||||
StimBuffApiManager::initializeAllStimBuffApiLibsCReq()
|
||||
{
|
||||
for (auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||
initializeStimBuffApiLib(*lib);
|
||||
}
|
||||
assertBodyThread();
|
||||
|
||||
StimBuffApiManager &sbam = getInstance();
|
||||
sscl::co::CoQutex::ReleaseHandle sbamGuard =
|
||||
co_await sbam.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
||||
|
||||
for (auto &lib : sbam.s.rsrc.stimBuffApiLibs) {
|
||||
co_await initializeStimBuffApiLibCReq(*lib, false);
|
||||
}
|
||||
|
||||
co_return;
|
||||
}
|
||||
|
||||
void StimBuffApiManager::finalizeAllStimBuffApiLibs(void)
|
||||
body::BodyViralPostingInvoker<void>
|
||||
StimBuffApiManager::finalizeAllStimBuffApiLibsCReq()
|
||||
{
|
||||
for (auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||
finalizeStimBuffApiLib(*lib);
|
||||
}
|
||||
assertBodyThread();
|
||||
|
||||
StimBuffApiManager &sbam = getInstance();
|
||||
sscl::co::CoQutex::ReleaseHandle sbamGuard =
|
||||
co_await sbam.s.lock.getAcquireInvocationAndSuspensionPolicy();
|
||||
|
||||
for (auto &lib : sbam.s.rsrc.stimBuffApiLibs) {
|
||||
co_await finalizeStimBuffApiLibCReq(*lib, false);
|
||||
}
|
||||
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user