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:
2026-05-25 08:21:46 -04:00
parent b5fa20a2b8
commit 3e19d39853
10 changed files with 173 additions and 280 deletions
@@ -1,160 +0,0 @@
#ifndef STIM_BUFF_DEVICE_AREQ_H
#define STIM_BUFF_DEVICE_AREQ_H
#include <atomic>
#include <coroutine>
#include <memory>
#include <boost/asio/io_service.hpp>
#include <boost/asio/post.hpp>
#include <spinscale/cps/callback.h>
#include <stimBuffApis/stimBuffApiLib.h>
#include <user/deviceAttachmentSpec.h>
#include <user/senseApiDesc.h>
namespace smo {
namespace cpsBoundary {
struct StimBuffDeviceOpResult
{
bool success = false;
std::shared_ptr<device::DeviceAttachmentSpec> deviceSpec;
};
struct AttachStimBuffDeviceAReq
{
struct AsyncState
{
std::atomic<bool> settled{false};
StimBuffDeviceOpResult result;
std::coroutine_handle<> callerSchedHandle;
};
AttachStimBuffDeviceAReq(
const std::shared_ptr<device::DeviceAttachmentSpec> &spec,
stim_buff::StimBuffApiLib &lib,
const std::shared_ptr<sscl::ComponentThread> &threadForAttachment,
boost::asio::io_service &resumeIoService)
: asyncState(std::make_shared<AsyncState>()),
resumeIoService(resumeIoService)
{
lib.stimBuffApiDesc.sal_mgmt_libOps.attachDeviceReq(
spec, threadForAttachment,
{nullptr,
[asyncState = asyncState, &resumeIoService = resumeIoService](
bool success,
std::shared_ptr<device::DeviceAttachmentSpec> 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> asyncState;
boost::asio::io_service &resumeIoService;
};
struct DetachStimBuffDeviceAReq
{
struct AsyncState
{
std::atomic<bool> settled{false};
StimBuffDeviceOpResult result;
std::coroutine_handle<> callerSchedHandle;
};
DetachStimBuffDeviceAReq(
const std::shared_ptr<device::DeviceAttachmentSpec> &spec,
stim_buff::StimBuffApiLib &lib,
boost::asio::io_service &resumeIoService)
: asyncState(std::make_shared<AsyncState>()),
resumeIoService(resumeIoService)
{
lib.stimBuffApiDesc.sal_mgmt_libOps.detachDeviceReq(
spec,
{nullptr,
[asyncState = asyncState, &resumeIoService = resumeIoService](
bool success,
std::shared_ptr<device::DeviceAttachmentSpec> 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> asyncState;
boost::asio::io_service &resumeIoService;
};
} // namespace cpsBoundary
} // namespace smo
#endif // STIM_BUFF_DEVICE_AREQ_H