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:
@@ -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
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <deviceManager/device.h>
|
||||
#include <deviceManager/deviceRole.h>
|
||||
#include <deviceManager/deviceReattacher.h>
|
||||
#include <cpsBoundary/stimBuffDeviceAReq.h>
|
||||
#include <marionette/marionetteThread.h>
|
||||
#include <spinscale/co/coQutex.h>
|
||||
#include <spinscale/multiOperationResultSet.h>
|
||||
@@ -59,11 +58,11 @@ public:
|
||||
mrntt::MrnttViralPostingInvoker<DeviceAttachmentIndResult>
|
||||
removeDeviceAttachmentSpecCReq(const DeviceAttachmentSpec &spec);
|
||||
|
||||
mrntt::MrnttViralPostingInvoker<cpsBoundary::StimBuffDeviceOpResult>
|
||||
mrntt::MrnttViralPostingInvoker<stim_buff::StimBuffDeviceOpResult>
|
||||
attachStimBuffDeviceCReq(
|
||||
const std::shared_ptr<DeviceAttachmentSpec>& spec);
|
||||
|
||||
mrntt::MrnttViralPostingInvoker<cpsBoundary::StimBuffDeviceOpResult>
|
||||
mrntt::MrnttViralPostingInvoker<stim_buff::StimBuffDeviceOpResult>
|
||||
detachStimBuffDeviceCReq(
|
||||
const std::shared_ptr<DeviceAttachmentSpec>& spec);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <functional>
|
||||
#include <stimBuffApis/stimBuffApiLib.h>
|
||||
#include <user/deviceAttachmentSpec.h>
|
||||
#include <body/bodyThread.h>
|
||||
#include <spinscale/co/coQutex.h>
|
||||
#include <spinscale/sharedResourceGroup.h>
|
||||
|
||||
@@ -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<sscl::ComponentThread>& componentThread);
|
||||
|
||||
void unloadAllStimBuffApiLibs(void);
|
||||
void initializeAllStimBuffApiLibs(void);
|
||||
void finalizeAllStimBuffApiLibs(void);
|
||||
|
||||
body::BodyViralPostingInvoker<void> initializeStimBuffApiLibCReq(
|
||||
StimBuffApiLib &lib, bool acquireSbamLock);
|
||||
body::BodyViralPostingInvoker<void> finalizeStimBuffApiLibCReq(
|
||||
StimBuffApiLib &lib, bool acquireSbamLock);
|
||||
|
||||
body::BodyViralPostingInvoker<void> initializeAllStimBuffApiLibsCReq();
|
||||
body::BodyViralPostingInvoker<void> finalizeAllStimBuffApiLibsCReq();
|
||||
|
||||
std::string stringifyLibs() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user