From 3e19d39853c699c5f7e6ddcec8932a685ff67cb4 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Mon, 25 May 2026 08:21:46 -0400 Subject: [PATCH] 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. --- include/config.h.in | 1 + include/user/senseApiDesc.h | 41 +++-- smocore/body/body.cpp | 7 +- smocore/deviceManager/deviceManager.cpp | 50 +++--- .../include/cpsBoundary/stimBuffDeviceAReq.h | 160 ------------------ smocore/include/deviceManager/deviceManager.h | 5 +- .../include/stimBuffApis/stimBuffApiManager.h | 14 +- smocore/stimBuffApis/stimBuffApiManager.cpp | 130 ++++++++++---- stimBuffApis/xcbWindow/CMakeLists.txt | 3 +- stimBuffApis/xcbWindow/xcbWindow.cpp | 42 +++-- 10 files changed, 173 insertions(+), 280 deletions(-) delete mode 100644 smocore/include/cpsBoundary/stimBuffDeviceAReq.h diff --git a/include/config.h.in b/include/config.h.in index ed7e3ff..1c583bb 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -30,6 +30,7 @@ /* Common Libraries */ #cmakedefine CONFIG_LIB_XCBXORG_ENABLED +#cmakedefine CONFIG_LIB_LIVOXPROTO1_ENABLED #cmakedefine CONFIG_LIB_ALSA_ENABLED /* Stim Buff APIs */ diff --git a/include/user/senseApiDesc.h b/include/user/senseApiDesc.h index f0460a9..ff25586 100644 --- a/include/user/senseApiDesc.h +++ b/include/user/senseApiDesc.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #define CL_TARGET_OPENCL_VERSION 120 #include @@ -42,25 +42,24 @@ struct SmoThreadingModelDesc * * State management that's tied to a particular attachment spec should be * done on the ComponentThread for the thread that SMO provided in the - * attachDeviceReq call. + * attachDeviceCReq call. */ std::shared_ptr componentThread; }; -typedef std::function)> - sal_mlo_attachDeviceReqCbFn; -typedef std::function)> - sal_mlo_detachDeviceReqCbFn; +struct StimBuffDeviceOpResult +{ + bool success = false; + std::shared_ptr deviceSpec; +}; -typedef int (sal_mlo_initializeIndFn)(void); -typedef int (sal_mlo_finalizeIndFn)(void); -typedef void (sal_mlo_attachDeviceReqFn)( - const std::shared_ptr& desc, - const std::shared_ptr& componentThread, - sscl::cps::Callback cb); -typedef void (sal_mlo_detachDeviceReqFn)( - const std::shared_ptr& desc, - sscl::cps::Callback cb); +using sal_mlo_initializeCIndFn = sscl::co::ViralNonPostingInvoker(void); +using sal_mlo_finalizeCIndFn = sscl::co::ViralNonPostingInvoker(void); +using sal_mlo_attachDeviceCReqFn = sscl::co::ViralNonPostingInvoker( + const std::shared_ptr& desc, + const std::shared_ptr& componentThread); +using sal_mlo_detachDeviceCReqFn = sscl::co::ViralNonPostingInvoker( + const std::shared_ptr& desc); /** * @brief Hooks provided by Salmanoff to senseApi libraries. @@ -138,22 +137,22 @@ struct Sal_Mgmt_LibOps /* When Salmanoff loads a stim buff API lib, it calls this function to initialize * the lib. When this returns, the lib should be ready to attach devices. */ - sal_mlo_initializeIndFn *initializeInd; + sal_mlo_initializeCIndFn *initializeCInd; /* Salmanoff calls this to finalize the lib and free its internal * resources. When this returns, the lib should be ready to be unloaded. */ - sal_mlo_finalizeIndFn *finalizeInd; + sal_mlo_finalizeCIndFn *finalizeCInd; /* Salmanoff calls this to attach a device to the lib. When it returns, the * device should be attached and ready to present its stimbuff. */ - sal_mlo_attachDeviceReqFn *attachDeviceReq; + sal_mlo_attachDeviceCReqFn *attachDeviceCReq; // When this returns, the device should be detached. - sal_mlo_detachDeviceReqFn *detachDeviceReq; + sal_mlo_detachDeviceCReqFn *detachDeviceCReq; static bool sanityCheck(const Sal_Mgmt_LibOps &ops) { - if (!ops.initializeInd || !ops.finalizeInd - || !ops.attachDeviceReq || !ops.detachDeviceReq) + if (!ops.initializeCInd || !ops.finalizeCInd + || !ops.attachDeviceCReq || !ops.detachDeviceCReq) { return false; } diff --git a/smocore/body/body.cpp b/smocore/body/body.cpp index 23d67ed..d9ed455 100644 --- a/smocore/body/body.cpp +++ b/smocore/body/body.cpp @@ -55,8 +55,8 @@ BodyViralPostingInvoker Body::initializeCReq() std::cout << __func__ << ": About to initializeAllStimBuffApiLibs" << '\n'; } - stim_buff::StimBuffApiManager::getInstance() - .initializeAllStimBuffApiLibs(); + co_await stim_buff::StimBuffApiManager::getInstance() + .initializeAllStimBuffApiLibsCReq(); if (OptionParser::getOptions().verbose) { @@ -100,7 +100,8 @@ BodyViralPostingInvoker Body::finalizeCReq() << " sense devices." << "\n"; std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n"; - stim_buff::StimBuffApiManager::getInstance().finalizeAllStimBuffApiLibs(); + co_await stim_buff::StimBuffApiManager::getInstance() + .finalizeAllStimBuffApiLibsCReq(); std::cout << "Mrntt: About to unload all stim buff api libs." << "\n"; stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs(); diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index ecc8ed5..3a4db37 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -33,11 +32,6 @@ void assertMarionetteThread() } } -boost::asio::io_service &marionetteIoService() -{ - return mrntt::MrnttThreadTag::io_service(); -} - } // namespace DeviceManager::~DeviceManager() @@ -55,7 +49,7 @@ const std::string DeviceManager::stringifyDeviceSpecs(void) return oss.str(); } -mrntt::MrnttViralPostingInvoker +mrntt::MrnttViralPostingInvoker DeviceManager::attachStimBuffDeviceCReq( const std::shared_ptr& spec) { @@ -67,7 +61,7 @@ DeviceManager::attachStimBuffDeviceCReq( { std::cerr << "attachStimBuffDeviceCReq: No library found for API '" << spec->stimBuffApi << "'" << std::endl; - co_return cpsBoundary::StimBuffDeviceOpResult{false, spec}; + co_return stim_buff::StimBuffDeviceOpResult{false, spec}; } auto &lib = *libOpt.value(); @@ -76,15 +70,15 @@ DeviceManager::attachStimBuffDeviceCReq( { std::cerr << std::string(__func__) + ": Library is being destroyed" << " for API '" << spec->stimBuffApi << "'. Bailing out.\n"; - co_return cpsBoundary::StimBuffDeviceOpResult{false, spec}; + co_return stim_buff::StimBuffDeviceOpResult{false, spec}; } - if (!lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq) + if (!lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceCReq) { - std::cerr << std::string(__func__) + ": attachDeviceReq() is NULL " + std::cerr << std::string(__func__) + ": attachDeviceCReq() is NULL " "for library '" << lib.libraryPath << "'" << std::endl; - co_return cpsBoundary::StimBuffDeviceOpResult{false, spec}; + co_return stim_buff::StimBuffDeviceOpResult{false, spec}; } sscl::co::CoQutex::ReleaseHandle sbamGuard = @@ -114,14 +108,11 @@ DeviceManager::attachStimBuffDeviceCReq( << spec->deviceIdentifier << " to body thread" << "\n"; } - cpsBoundary::StimBuffDeviceOpResult result = co_await - cpsBoundary::AttachStimBuffDeviceAReq( - spec, lib, threadForAttachment, marionetteIoService()); - - co_return result; + co_return co_await lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceCReq( + spec, threadForAttachment); } -mrntt::MrnttViralPostingInvoker +mrntt::MrnttViralPostingInvoker DeviceManager::detachStimBuffDeviceCReq( const std::shared_ptr& spec) { @@ -133,7 +124,7 @@ DeviceManager::detachStimBuffDeviceCReq( { std::cerr << "detachStimBuffDeviceCReq: No library found for API '" << spec->stimBuffApi << "'" << std::endl; - co_return cpsBoundary::StimBuffDeviceOpResult{false, spec}; + co_return stim_buff::StimBuffDeviceOpResult{false, spec}; } auto &lib = *libOpt.value(); @@ -142,15 +133,15 @@ DeviceManager::detachStimBuffDeviceCReq( { std::cerr << std::string(__func__) + ": Library is being destroyed" << " for API '" << spec->stimBuffApi << "'. Bailing out.\n"; - co_return cpsBoundary::StimBuffDeviceOpResult{false, spec}; + co_return stim_buff::StimBuffDeviceOpResult{false, spec}; } - if (!lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceReq) + if (!lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceCReq) { - std::cerr << std::string(__func__) + ": detachDeviceReq() is NULL " + std::cerr << std::string(__func__) + ": detachDeviceCReq() is NULL " "for library '" << lib.libraryPath << "'" << std::endl; - co_return cpsBoundary::StimBuffDeviceOpResult{false, spec}; + co_return stim_buff::StimBuffDeviceOpResult{false, spec}; } sscl::co::CoQutex::ReleaseHandle sbamGuard = @@ -159,11 +150,8 @@ DeviceManager::detachStimBuffDeviceCReq( co_await lib.s.lock.getAcquireInvocationAndSuspensionPolicy(); sbamGuard.release(); - cpsBoundary::StimBuffDeviceOpResult result = co_await - cpsBoundary::DetachStimBuffDeviceAReq( - spec, lib, marionetteIoService()); - - co_return result; + co_return co_await lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceCReq( + spec); } mrntt::MrnttViralPostingInvoker @@ -243,7 +231,7 @@ DeviceManager::newDeviceAttachmentSpecIndCReq( true, existingDeviceRole, specPtr}; } - cpsBoundary::StimBuffDeviceOpResult attachResult = + stim_buff::StimBuffDeviceOpResult attachResult = co_await attachStimBuffDeviceCReq(specPtr); if (!attachResult.success) @@ -295,7 +283,7 @@ DeviceManager::removeDeviceAttachmentSpecCReq( } // Call detachStimBuffDeviceCReq first - only clean up metadata if this succeeds - cpsBoundary::StimBuffDeviceOpResult detachResult = + stim_buff::StimBuffDeviceOpResult detachResult = co_await detachStimBuffDeviceCReq(specPtr); if (!detachResult.success) @@ -473,7 +461,7 @@ DeviceManager::detachAllAttachedDeviceRolesCReq() sscl::co::Group group; std::vector< - mrntt::MrnttViralPostingInvoker> + mrntt::MrnttViralPostingInvoker> invokers; invokers.reserve(specsToDetach.size()); diff --git a/smocore/include/cpsBoundary/stimBuffDeviceAReq.h b/smocore/include/cpsBoundary/stimBuffDeviceAReq.h deleted file mode 100644 index 44a2c72..0000000 --- a/smocore/include/cpsBoundary/stimBuffDeviceAReq.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef STIM_BUFF_DEVICE_AREQ_H -#define STIM_BUFF_DEVICE_AREQ_H - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace smo { -namespace cpsBoundary { - -struct StimBuffDeviceOpResult -{ - bool success = false; - std::shared_ptr deviceSpec; -}; - -struct AttachStimBuffDeviceAReq -{ - struct AsyncState - { - std::atomic settled{false}; - StimBuffDeviceOpResult result; - std::coroutine_handle<> callerSchedHandle; - }; - - AttachStimBuffDeviceAReq( - const std::shared_ptr &spec, - stim_buff::StimBuffApiLib &lib, - const std::shared_ptr &threadForAttachment, - boost::asio::io_service &resumeIoService) - : asyncState(std::make_shared()), - resumeIoService(resumeIoService) - { - lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq( - spec, threadForAttachment, - {nullptr, - [asyncState = asyncState, &resumeIoService = resumeIoService]( - bool success, - std::shared_ptr deviceSpec) - { - asyncState->result = StimBuffDeviceOpResult{ - success, deviceSpec}; - - asyncState->settled.store( - true, std::memory_order_release); - - std::coroutine_handle<> handle = - asyncState->callerSchedHandle; - - if (!handle) { - return; - } - - boost::asio::post( - resumeIoService, - [handle]() { handle.resume(); }); - }}); - } - - bool await_ready() const noexcept - { - return asyncState->settled.load(std::memory_order_acquire); - } - - bool await_suspend(std::coroutine_handle<> callerSchedHandle) noexcept - { - if (asyncState->settled.load(std::memory_order_acquire)) { - return false; - } - - asyncState->callerSchedHandle = callerSchedHandle; - return true; - } - - StimBuffDeviceOpResult await_resume() noexcept - { - return asyncState->result; - } - - std::shared_ptr asyncState; - boost::asio::io_service &resumeIoService; -}; - -struct DetachStimBuffDeviceAReq -{ - struct AsyncState - { - std::atomic settled{false}; - StimBuffDeviceOpResult result; - std::coroutine_handle<> callerSchedHandle; - }; - - DetachStimBuffDeviceAReq( - const std::shared_ptr &spec, - stim_buff::StimBuffApiLib &lib, - boost::asio::io_service &resumeIoService) - : asyncState(std::make_shared()), - resumeIoService(resumeIoService) - { - lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceReq( - spec, - {nullptr, - [asyncState = asyncState, &resumeIoService = resumeIoService]( - bool success, - std::shared_ptr deviceSpec) - { - asyncState->result = StimBuffDeviceOpResult{ - success, deviceSpec}; - - asyncState->settled.store( - true, std::memory_order_release); - - std::coroutine_handle<> handle = - asyncState->callerSchedHandle; - - if (!handle) { - return; - } - - boost::asio::post( - resumeIoService, - [handle]() { handle.resume(); }); - }}); - } - - bool await_ready() const noexcept - { - return asyncState->settled.load(std::memory_order_acquire); - } - - bool await_suspend(std::coroutine_handle<> callerSchedHandle) noexcept - { - if (asyncState->settled.load(std::memory_order_acquire)) { - return false; - } - - asyncState->callerSchedHandle = callerSchedHandle; - return true; - } - - StimBuffDeviceOpResult await_resume() noexcept - { - return asyncState->result; - } - - std::shared_ptr asyncState; - boost::asio::io_service &resumeIoService; -}; - -} // namespace cpsBoundary -} // namespace smo - -#endif // STIM_BUFF_DEVICE_AREQ_H diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index 56a09a7..fb89ae1 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -59,11 +58,11 @@ public: mrntt::MrnttViralPostingInvoker removeDeviceAttachmentSpecCReq(const DeviceAttachmentSpec &spec); - mrntt::MrnttViralPostingInvoker + mrntt::MrnttViralPostingInvoker attachStimBuffDeviceCReq( const std::shared_ptr& spec); - mrntt::MrnttViralPostingInvoker + mrntt::MrnttViralPostingInvoker detachStimBuffDeviceCReq( const std::shared_ptr& spec); diff --git a/smocore/include/stimBuffApis/stimBuffApiManager.h b/smocore/include/stimBuffApis/stimBuffApiManager.h index 071a565..326019d 100644 --- a/smocore/include/stimBuffApis/stimBuffApiManager.h +++ b/smocore/include/stimBuffApis/stimBuffApiManager.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -44,15 +45,18 @@ public: const std::string& apiName); void unloadStimBuffApiLib(const std::string& libraryPath); - void initializeStimBuffApiLib(StimBuffApiLib& lib); - void finalizeStimBuffApiLib(StimBuffApiLib& lib); - void loadAllStimBuffApiLibsFromOptions( const std::shared_ptr& componentThread); void unloadAllStimBuffApiLibs(void); - void initializeAllStimBuffApiLibs(void); - void finalizeAllStimBuffApiLibs(void); + + body::BodyViralPostingInvoker initializeStimBuffApiLibCReq( + StimBuffApiLib &lib, bool acquireSbamLock); + body::BodyViralPostingInvoker finalizeStimBuffApiLibCReq( + StimBuffApiLib &lib, bool acquireSbamLock); + + body::BodyViralPostingInvoker initializeAllStimBuffApiLibsCReq(); + body::BodyViralPostingInvoker finalizeAllStimBuffApiLibsCReq(); std::string stringifyLibs() const; diff --git a/smocore/stimBuffApis/stimBuffApiManager.cpp b/smocore/stimBuffApis/stimBuffApiManager.cpp index 3cfcbc2..cb9003b 100644 --- a/smocore/stimBuffApis/stimBuffApiManager.cpp +++ b/smocore/stimBuffApis/stimBuffApiManager.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -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 +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 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 +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 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 +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 +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; } diff --git a/stimBuffApis/xcbWindow/CMakeLists.txt b/stimBuffApis/xcbWindow/CMakeLists.txt index f58f9e2..d022ebb 100644 --- a/stimBuffApis/xcbWindow/CMakeLists.txt +++ b/stimBuffApis/xcbWindow/CMakeLists.txt @@ -28,7 +28,8 @@ if(ENABLE_STIMBUFFAPI_xcbWindow) target_link_libraries(xcbWindow Boost::system Boost::log ${XCB_LIBRARIES} - attachmentSupport) + attachmentSupport + spinscale) # Install rules install(TARGETS xcbWindow diff --git a/stimBuffApis/xcbWindow/xcbWindow.cpp b/stimBuffApis/xcbWindow/xcbWindow.cpp index 34923ff..892a0ef 100644 --- a/stimBuffApis/xcbWindow/xcbWindow.cpp +++ b/stimBuffApis/xcbWindow/xcbWindow.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include "xcbWindow.h" @@ -214,7 +214,7 @@ AttachedWindow::~AttachedWindow() } // namespace xcb_window // SenseApi functions -static int xcbWindow_initializeInd(void) +static sscl::co::ViralNonPostingInvoker xcbWindow_initializeCInd(void) { if (!smoHooksPtr) { @@ -257,10 +257,10 @@ static int xcbWindow_initializeInd(void) ": Failed to get required function pointers from libxcbXorg"); } - return 0; + co_return 0; } -static int xcbWindow_finalizeInd(void) +static sscl::co::ViralNonPostingInvoker xcbWindow_finalizeCInd(void) { g_attachedWindows.clear(); @@ -271,14 +271,13 @@ static int xcbWindow_finalizeInd(void) xcbXorg.fns = { nullptr, nullptr, nullptr, nullptr, nullptr }; } - return 0; + co_return 0; } -static void xcbWindow_attachDeviceReq( +static sscl::co::ViralNonPostingInvoker +xcbWindow_attachDeviceCReq( const std::shared_ptr& desc, - const std::shared_ptr& componentThread, - sscl::cps::Callback cb - ) + const std::shared_ptr& componentThread) { // Not used yet, but may be used later. (void)componentThread; @@ -289,21 +288,19 @@ static void xcbWindow_attachDeviceReq( } catch (const std::exception& exc) { std::cerr << __func__ << ": Exception while attaching X11 window: " << exc.what() << "\n"; - cb.callbackFn(false, desc); - return; + co_return smo::stim_buff::StimBuffDeviceOpResult{false, desc}; } std::cout << __func__ << ": Attached X11 window:\n " << g_attachedWindows.back()->stringify() << "\n"; - cb.callbackFn(true, desc); + co_return smo::stim_buff::StimBuffDeviceOpResult{true, desc}; } -static void xcbWindow_detachDeviceReq( - const std::shared_ptr& spec, - sscl::cps::Callback cb - ) +static sscl::co::ViralNonPostingInvoker +xcbWindow_detachDeviceCReq( + const std::shared_ptr& spec) { auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(), [&spec](const std::unique_ptr& window) { @@ -316,15 +313,14 @@ static void xcbWindow_detachDeviceReq( std::cerr << __func__ << ": Device not found for detachment:\n" << spec->stringify() << "\n"; - cb.callbackFn(false, spec); - return; + co_return smo::stim_buff::StimBuffDeviceOpResult{false, spec}; } g_attachedWindows.erase(it); std::cout << __func__ << ": Detached X11 window device:\n" << spec->stringify() << "\n"; - cb.callbackFn(true, spec); + co_return smo::stim_buff::StimBuffDeviceOpResult{true, spec}; } // SenseApi descriptor @@ -332,10 +328,10 @@ static smo::stim_buff::StimBuffApiDesc xcbWindowApiDesc = { .name = "xcb", .exportedQualeIfaceApis = { { "visual-qualeiface" } }, .sal_mgmt_libOps = { - .initializeInd = xcbWindow_initializeInd, - .finalizeInd = xcbWindow_finalizeInd, - .attachDeviceReq = xcbWindow_attachDeviceReq, - .detachDeviceReq = xcbWindow_detachDeviceReq + .initializeCInd = xcbWindow_initializeCInd, + .finalizeCInd = xcbWindow_finalizeCInd, + .attachDeviceCReq = xcbWindow_attachDeviceCReq, + .detachDeviceCReq = xcbWindow_detachDeviceCReq } };