Libspinscale: Initial top-level SMO port to coroutine framework
We haven't ported everything. Just the top-level methods. We'll dig in to the leaf stuff later. Surprisingly, this all went without any real difficulties. Runs like a charm on first try.
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <user/senseApiDesc.h>
|
#include <user/senseApiDesc.h>
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
@@ -74,7 +74,7 @@ std::optional<std::shared_ptr<Device>> DeviceManager::getDevice(
|
|||||||
|
|
||||||
// GetOrCreateDeviceReq nested class implementation
|
// GetOrCreateDeviceReq nested class implementation
|
||||||
class DeviceManager::GetOrCreateDeviceReq
|
class DeviceManager::GetOrCreateDeviceReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<
|
: public sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
livoxProto1_getOrCreateDeviceReqCbFn>
|
livoxProto1_getOrCreateDeviceReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -86,8 +86,8 @@ public:
|
|||||||
GetOrCreateDeviceReq(
|
GetOrCreateDeviceReq(
|
||||||
DeviceManager& mgr,
|
DeviceManager& mgr,
|
||||||
std::shared_ptr<Device> device,
|
std::shared_ptr<Device> device,
|
||||||
sscl::Callback<livoxProto1_getOrCreateDeviceReqCbFn> cb)
|
sscl::cps::Callback<livoxProto1_getOrCreateDeviceReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<
|
: sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
livoxProto1_getOrCreateDeviceReqCbFn>(std::move(cb)),
|
livoxProto1_getOrCreateDeviceReqCbFn>(std::move(cb)),
|
||||||
deviceManager(mgr), pendingDevice(device)
|
deviceManager(mgr), pendingDevice(device)
|
||||||
{}
|
{}
|
||||||
@@ -132,7 +132,7 @@ void DeviceManager::getOrCreateDeviceReq(
|
|||||||
int commandTimeoutMs, int retryDelayMs,
|
int commandTimeoutMs, int retryDelayMs,
|
||||||
const std::string& smoIp, uint8_t smoSubnetNbits,
|
const std::string& smoIp, uint8_t smoSubnetNbits,
|
||||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
||||||
sscl::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback)
|
sscl::cps::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback)
|
||||||
{
|
{
|
||||||
// Validate smoIp format using Boost.Asio IPv4 validation
|
// Validate smoIp format using Boost.Asio IPv4 validation
|
||||||
if (!smoIp.empty() && !comms::isValidIPv4(smoIp))
|
if (!smoIp.empty() && !comms::isValidIPv4(smoIp))
|
||||||
@@ -179,7 +179,7 @@ void DeviceManager::getOrCreateDeviceReq(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DeviceManager::DestroyDeviceReq
|
class DeviceManager::DestroyDeviceReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<
|
: public sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
livoxProto1_destroyDeviceReqCbFn>
|
livoxProto1_destroyDeviceReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -190,8 +190,8 @@ public:
|
|||||||
DestroyDeviceReq(
|
DestroyDeviceReq(
|
||||||
DeviceManager& mgr,
|
DeviceManager& mgr,
|
||||||
std::shared_ptr<Device> device,
|
std::shared_ptr<Device> device,
|
||||||
sscl::Callback<livoxProto1_destroyDeviceReqCbFn> cb)
|
sscl::cps::Callback<livoxProto1_destroyDeviceReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<
|
: sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
livoxProto1_destroyDeviceReqCbFn>(std::move(cb)),
|
livoxProto1_destroyDeviceReqCbFn>(std::move(cb)),
|
||||||
deviceManager(mgr), pendingDevice(device)
|
deviceManager(mgr), pendingDevice(device)
|
||||||
{}
|
{}
|
||||||
@@ -220,7 +220,7 @@ public:
|
|||||||
|
|
||||||
void DeviceManager::destroyDeviceReq(
|
void DeviceManager::destroyDeviceReq(
|
||||||
std::shared_ptr<Device> dev,
|
std::shared_ptr<Device> dev,
|
||||||
sscl::Callback<livoxProto1_destroyDeviceReqCbFn> callback
|
sscl::cps::Callback<livoxProto1_destroyDeviceReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "broadcastListener.h"
|
#include "broadcastListener.h"
|
||||||
#include "udpCommandDemuxer.h"
|
#include "udpCommandDemuxer.h"
|
||||||
#include "livoxProto1.h"
|
#include "livoxProto1.h"
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
|
|
||||||
namespace livoxProto1 {
|
namespace livoxProto1 {
|
||||||
|
|
||||||
@@ -29,11 +29,11 @@ public:
|
|||||||
int commandTimeoutMs, int retryDelayMs,
|
int commandTimeoutMs, int retryDelayMs,
|
||||||
const std::string& smoIp, uint8_t smoSubnetNbits,
|
const std::string& smoIp, uint8_t smoSubnetNbits,
|
||||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
||||||
sscl::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback);
|
||||||
|
|
||||||
void destroyDeviceReq(
|
void destroyDeviceReq(
|
||||||
std::shared_ptr<Device> device,
|
std::shared_ptr<Device> device,
|
||||||
sscl::Callback<livoxProto1_destroyDeviceReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_destroyDeviceReqCbFn> callback);
|
||||||
|
|
||||||
std::optional<std::shared_ptr<Device>> getDevice(
|
std::optional<std::shared_ptr<Device>> getDevice(
|
||||||
const std::string &deviceIdentifier);
|
const std::string &deviceIdentifier);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
@@ -124,15 +124,15 @@ Device::~Device()
|
|||||||
* This class manages the overall device connection process including handshake and heartbeat setup
|
* This class manages the overall device connection process including handshake and heartbeat setup
|
||||||
*/
|
*/
|
||||||
class Device::ConnectReq
|
class Device::ConnectReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<Device::connectReqCbFn>
|
: public sscl::cps::NonPostedAsynchronousContinuation<Device::connectReqCbFn>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Device& device;
|
Device& device;
|
||||||
boost::asio::deadline_timer delayTimer;
|
boost::asio::deadline_timer delayTimer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectReq(Device& dev, sscl::Callback<Device::connectReqCbFn> cb)
|
ConnectReq(Device& dev, sscl::cps::Callback<Device::connectReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<Device::connectReqCbFn>(
|
: sscl::cps::NonPostedAsynchronousContinuation<Device::connectReqCbFn>(
|
||||||
std::move(cb)), device(dev),
|
std::move(cb)), device(dev),
|
||||||
delayTimer(dev.componentThread->getIoService())
|
delayTimer(dev.componentThread->getIoService())
|
||||||
{}
|
{}
|
||||||
@@ -216,7 +216,7 @@ public:
|
|||||||
{ callOriginalCallback(false); }
|
{ callOriginalCallback(false); }
|
||||||
};
|
};
|
||||||
|
|
||||||
void Device::connectReq(sscl::Callback<Device::connectReqCbFn> callback)
|
void Device::connectReq(sscl::cps::Callback<Device::connectReqCbFn> callback)
|
||||||
{
|
{
|
||||||
// Create the connection request object to hold state and callbacks
|
// Create the connection request object to hold state and callbacks
|
||||||
auto request = std::make_shared<ConnectReq>(*this, std::move(callback));
|
auto request = std::make_shared<ConnectReq>(*this, std::move(callback));
|
||||||
@@ -233,7 +233,7 @@ void Device::connectReq(sscl::Callback<Device::connectReqCbFn> callback)
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Device::ConnectToKnownDeviceReq
|
class Device::ConnectToKnownDeviceReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<
|
: public sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
Device::connectToKnownDeviceReqCbFn>
|
Device::connectToKnownDeviceReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -241,8 +241,8 @@ public:
|
|||||||
std::string deviceIP;
|
std::string deviceIP;
|
||||||
std::shared_ptr<livoxProto1::comms::DiscoveredDevice> deviceInfo;
|
std::shared_ptr<livoxProto1::comms::DiscoveredDevice> deviceInfo;
|
||||||
|
|
||||||
ConnectToKnownDeviceReq(Device& dev, sscl::Callback<Device::connectToKnownDeviceReqCbFn> cb)
|
ConnectToKnownDeviceReq(Device& dev, sscl::cps::Callback<Device::connectToKnownDeviceReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<
|
: sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
Device::connectToKnownDeviceReqCbFn>(std::move(cb)), device(dev)
|
Device::connectToKnownDeviceReqCbFn>(std::move(cb)), device(dev)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ public:
|
|||||||
* broadcastListener.
|
* broadcastListener.
|
||||||
*/
|
*/
|
||||||
void Device::connectToKnownDeviceReq(
|
void Device::connectToKnownDeviceReq(
|
||||||
sscl::Callback<Device::connectToKnownDeviceReqCbFn> callback
|
sscl::cps::Callback<Device::connectToKnownDeviceReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Create the connection request object to hold state and callbacks
|
// Create the connection request object to hold state and callbacks
|
||||||
@@ -336,7 +336,7 @@ void Device::connectToKnownDeviceReq(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Device::ConnectByDeviceIdentifierReq
|
class Device::ConnectByDeviceIdentifierReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<
|
: public sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
Device::connectByDeviceIdentifierReqCbFn>
|
Device::connectByDeviceIdentifierReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -344,8 +344,8 @@ public:
|
|||||||
std::string deviceIP;
|
std::string deviceIP;
|
||||||
|
|
||||||
ConnectByDeviceIdentifierReq(
|
ConnectByDeviceIdentifierReq(
|
||||||
Device& dev, sscl::Callback<Device::connectByDeviceIdentifierReqCbFn> cb)
|
Device& dev, sscl::cps::Callback<Device::connectByDeviceIdentifierReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<
|
: sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
Device::connectByDeviceIdentifierReqCbFn>(
|
Device::connectByDeviceIdentifierReqCbFn>(
|
||||||
std::move(cb)), device(dev)
|
std::move(cb)), device(dev)
|
||||||
{}
|
{}
|
||||||
@@ -370,7 +370,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Device::connectByDeviceIdentifierReq(
|
void Device::connectByDeviceIdentifierReq(
|
||||||
sscl::Callback<Device::connectByDeviceIdentifierReqCbFn> callback
|
sscl::cps::Callback<Device::connectByDeviceIdentifierReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
@@ -419,13 +419,13 @@ void Device::connectByDeviceIdentifierReq(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Device::ExecuteHandshakeReq
|
class Device::ExecuteHandshakeReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<
|
: public sscl::cps::NonPostedAsynchronousContinuation<
|
||||||
Device::executeHandshakeReqCbFn>
|
Device::executeHandshakeReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend void Device::executeHandshakeReq(
|
friend void Device::executeHandshakeReq(
|
||||||
const std::string& deviceIP,
|
const std::string& deviceIP,
|
||||||
sscl::Callback<Device::executeHandshakeReqCbFn> callback);
|
sscl::cps::Callback<Device::executeHandshakeReqCbFn> callback);
|
||||||
|
|
||||||
enum class SocketState
|
enum class SocketState
|
||||||
{
|
{
|
||||||
@@ -459,8 +459,8 @@ public:
|
|||||||
Device& dev, const std::string& deviceIP,
|
Device& dev, const std::string& deviceIP,
|
||||||
std::shared_ptr<boost::asio::posix::stream_descriptor>
|
std::shared_ptr<boost::asio::posix::stream_descriptor>
|
||||||
&cmdEndpointFdDesc,
|
&cmdEndpointFdDesc,
|
||||||
sscl::Callback<Device::executeHandshakeReqCbFn> cb)
|
sscl::cps::Callback<Device::executeHandshakeReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<Device::executeHandshakeReqCbFn>(
|
: sscl::cps::NonPostedAsynchronousContinuation<Device::executeHandshakeReqCbFn>(
|
||||||
std::move(cb)),
|
std::move(cb)),
|
||||||
device(dev), deviceIP(deviceIP),
|
device(dev), deviceIP(deviceIP),
|
||||||
cmdEndpointFdDesc(cmdEndpointFdDesc),
|
cmdEndpointFdDesc(cmdEndpointFdDesc),
|
||||||
@@ -753,7 +753,7 @@ private:
|
|||||||
|
|
||||||
void Device::executeHandshakeReq(
|
void Device::executeHandshakeReq(
|
||||||
const std::string& deviceIP,
|
const std::string& deviceIP,
|
||||||
sscl::Callback<Device::executeHandshakeReqCbFn> callback
|
sscl::cps::Callback<Device::executeHandshakeReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Get the command endpoint from the UdpCommandDemuxer
|
// Get the command endpoint from the UdpCommandDemuxer
|
||||||
@@ -803,7 +803,7 @@ void Device::executeHandshakeReq(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::disconnectReq(sscl::Callback<Device::disconnectReqCbFn> callback)
|
void Device::disconnectReq(sscl::cps::Callback<Device::disconnectReqCbFn> callback)
|
||||||
{
|
{
|
||||||
// Stop heartbeat first
|
// Stop heartbeat first
|
||||||
stopHeartbeat();
|
stopHeartbeat();
|
||||||
@@ -1331,7 +1331,7 @@ std::optional<std::string> Device::getSmoIp(const std::string& deviceIP)
|
|||||||
// Base class for both enable and disable pcloud data requests
|
// Base class for both enable and disable pcloud data requests
|
||||||
template<typename CallbackType>
|
template<typename CallbackType>
|
||||||
class EnDisablePcloudDataReq
|
class EnDisablePcloudDataReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<CallbackType>
|
: public sscl::cps::NonPostedAsynchronousContinuation<CallbackType>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class SocketState
|
enum class SocketState
|
||||||
@@ -1362,8 +1362,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
EnDisablePcloudDataReq(
|
EnDisablePcloudDataReq(
|
||||||
Device& dev,
|
Device& dev,
|
||||||
sscl::Callback<CallbackType> cb)
|
sscl::cps::Callback<CallbackType> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<CallbackType>(std::move(cb)),
|
: sscl::cps::NonPostedAsynchronousContinuation<CallbackType>(std::move(cb)),
|
||||||
device(dev),
|
device(dev),
|
||||||
timeoutTimer(device.componentThread->getIoService())
|
timeoutTimer(device.componentThread->getIoService())
|
||||||
{}
|
{}
|
||||||
@@ -1608,11 +1608,11 @@ class Device::EnablePcloudDataReq
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend void Device::enablePcloudDataReq(
|
friend void Device::enablePcloudDataReq(
|
||||||
sscl::Callback<Device::enablePcloudDataReqCbFn> callback);
|
sscl::cps::Callback<Device::enablePcloudDataReqCbFn> callback);
|
||||||
|
|
||||||
EnablePcloudDataReq(
|
EnablePcloudDataReq(
|
||||||
Device& dev,
|
Device& dev,
|
||||||
sscl::Callback<Device::enablePcloudDataReqCbFn> cb)
|
sscl::cps::Callback<Device::enablePcloudDataReqCbFn> cb)
|
||||||
: EnDisablePcloudDataReq<Device::enablePcloudDataReqCbFn>(dev, std::move(cb))
|
: EnDisablePcloudDataReq<Device::enablePcloudDataReqCbFn>(dev, std::move(cb))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -1643,11 +1643,11 @@ class Device::DisablePcloudDataReq
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend void Device::disablePcloudDataReq(
|
friend void Device::disablePcloudDataReq(
|
||||||
sscl::Callback<Device::disablePcloudDataReqCbFn> callback);
|
sscl::cps::Callback<Device::disablePcloudDataReqCbFn> callback);
|
||||||
|
|
||||||
DisablePcloudDataReq(
|
DisablePcloudDataReq(
|
||||||
Device& dev,
|
Device& dev,
|
||||||
sscl::Callback<Device::disablePcloudDataReqCbFn> cb)
|
sscl::cps::Callback<Device::disablePcloudDataReqCbFn> cb)
|
||||||
: EnDisablePcloudDataReq<Device::disablePcloudDataReqCbFn>(
|
: EnDisablePcloudDataReq<Device::disablePcloudDataReqCbFn>(
|
||||||
dev, std::move(cb))
|
dev, std::move(cb))
|
||||||
{}
|
{}
|
||||||
@@ -1675,7 +1675,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Device::enablePcloudDataReq(
|
void Device::enablePcloudDataReq(
|
||||||
sscl::Callback<Device::enablePcloudDataReqCbFn> callback
|
sscl::cps::Callback<Device::enablePcloudDataReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto request = std::make_shared<EnablePcloudDataReq>(
|
auto request = std::make_shared<EnablePcloudDataReq>(
|
||||||
@@ -1702,7 +1702,7 @@ void Device::enablePcloudDataReq(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Device::disablePcloudDataReq(
|
void Device::disablePcloudDataReq(
|
||||||
sscl::Callback<Device::disablePcloudDataReqCbFn> callback
|
sscl::cps::Callback<Device::disablePcloudDataReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto request = std::make_shared<DisablePcloudDataReq>(
|
auto request = std::make_shared<DisablePcloudDataReq>(
|
||||||
@@ -1858,7 +1858,7 @@ void Device::unregisterUdpCommandHandler(
|
|||||||
|
|
||||||
// SetReturnModeReq continuation class
|
// SetReturnModeReq continuation class
|
||||||
class Device::SetReturnModeReq
|
class Device::SetReturnModeReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<Device::setReturnModeReqCbFn>
|
: public sscl::cps::NonPostedAsynchronousContinuation<Device::setReturnModeReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class SocketState
|
enum class SocketState
|
||||||
@@ -1890,12 +1890,12 @@ public:
|
|||||||
public:
|
public:
|
||||||
friend void Device::setReturnModeReq(
|
friend void Device::setReturnModeReq(
|
||||||
uint8_t returnMode,
|
uint8_t returnMode,
|
||||||
sscl::Callback<Device::setReturnModeReqCbFn> callback);
|
sscl::cps::Callback<Device::setReturnModeReqCbFn> callback);
|
||||||
|
|
||||||
SetReturnModeReq(
|
SetReturnModeReq(
|
||||||
Device& dev, uint8_t mode,
|
Device& dev, uint8_t mode,
|
||||||
sscl::Callback<Device::setReturnModeReqCbFn> cb)
|
sscl::cps::Callback<Device::setReturnModeReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<Device::setReturnModeReqCbFn>(
|
: sscl::cps::NonPostedAsynchronousContinuation<Device::setReturnModeReqCbFn>(
|
||||||
std::move(cb)),
|
std::move(cb)),
|
||||||
device(dev), returnMode(mode),
|
device(dev), returnMode(mode),
|
||||||
timeoutTimer(device.componentThread->getIoService())
|
timeoutTimer(device.componentThread->getIoService())
|
||||||
@@ -2107,7 +2107,7 @@ public:
|
|||||||
|
|
||||||
// GetReturnModeReq continuation class
|
// GetReturnModeReq continuation class
|
||||||
class Device::GetReturnModeReq
|
class Device::GetReturnModeReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<Device::getReturnModeReqCbFn>
|
: public sscl::cps::NonPostedAsynchronousContinuation<Device::getReturnModeReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class SocketState
|
enum class SocketState
|
||||||
@@ -2137,12 +2137,12 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
friend void Device::getReturnModeReq(
|
friend void Device::getReturnModeReq(
|
||||||
sscl::Callback<Device::getReturnModeReqCbFn> callback);
|
sscl::cps::Callback<Device::getReturnModeReqCbFn> callback);
|
||||||
|
|
||||||
GetReturnModeReq(
|
GetReturnModeReq(
|
||||||
Device& dev,
|
Device& dev,
|
||||||
sscl::Callback<Device::getReturnModeReqCbFn> cb)
|
sscl::cps::Callback<Device::getReturnModeReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<Device::getReturnModeReqCbFn>(
|
: sscl::cps::NonPostedAsynchronousContinuation<Device::getReturnModeReqCbFn>(
|
||||||
std::move(cb)),
|
std::move(cb)),
|
||||||
device(dev),
|
device(dev),
|
||||||
timeoutTimer(device.componentThread->getIoService())
|
timeoutTimer(device.componentThread->getIoService())
|
||||||
@@ -2351,7 +2351,7 @@ public:
|
|||||||
|
|
||||||
void Device::setReturnModeReq(
|
void Device::setReturnModeReq(
|
||||||
uint8_t returnMode,
|
uint8_t returnMode,
|
||||||
sscl::Callback<Device::setReturnModeReqCbFn> callback
|
sscl::cps::Callback<Device::setReturnModeReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto request = std::make_shared<SetReturnModeReq>(
|
auto request = std::make_shared<SetReturnModeReq>(
|
||||||
@@ -2378,7 +2378,7 @@ void Device::setReturnModeReq(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Device::getReturnModeReq(
|
void Device::getReturnModeReq(
|
||||||
sscl::Callback<Device::getReturnModeReqCbFn> callback
|
sscl::cps::Callback<Device::getReturnModeReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto request = std::make_shared<GetReturnModeReq>(
|
auto request = std::make_shared<GetReturnModeReq>(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <spinscale/spinLock.h>
|
#include <spinscale/spinLock.h>
|
||||||
|
|
||||||
// Custom hash function for std::pair<uint8_t, uint8_t>
|
// Custom hash function for std::pair<uint8_t, uint8_t>
|
||||||
@@ -163,20 +163,20 @@ public:
|
|||||||
getReturnModeReqCbFn;
|
getReturnModeReqCbFn;
|
||||||
|
|
||||||
// Async connection methods
|
// Async connection methods
|
||||||
void connectReq(sscl::Callback<connectReqCbFn> callback);
|
void connectReq(sscl::cps::Callback<connectReqCbFn> callback);
|
||||||
void connectToKnownDeviceReq(
|
void connectToKnownDeviceReq(
|
||||||
sscl::Callback<connectToKnownDeviceReqCbFn> callback);
|
sscl::cps::Callback<connectToKnownDeviceReqCbFn> callback);
|
||||||
void connectByDeviceIdentifierReq(
|
void connectByDeviceIdentifierReq(
|
||||||
sscl::Callback<connectByDeviceIdentifierReqCbFn> callback);
|
sscl::cps::Callback<connectByDeviceIdentifierReqCbFn> callback);
|
||||||
void executeHandshakeReq(
|
void executeHandshakeReq(
|
||||||
const std::string& deviceIP,
|
const std::string& deviceIP,
|
||||||
sscl::Callback<executeHandshakeReqCbFn> callback);
|
sscl::cps::Callback<executeHandshakeReqCbFn> callback);
|
||||||
void disconnectReq(sscl::Callback<disconnectReqCbFn> callback);
|
void disconnectReq(sscl::cps::Callback<disconnectReqCbFn> callback);
|
||||||
void enablePcloudDataReq(sscl::Callback<enablePcloudDataReqCbFn> callback);
|
void enablePcloudDataReq(sscl::cps::Callback<enablePcloudDataReqCbFn> callback);
|
||||||
void disablePcloudDataReq(sscl::Callback<disablePcloudDataReqCbFn> callback);
|
void disablePcloudDataReq(sscl::cps::Callback<disablePcloudDataReqCbFn> callback);
|
||||||
void setReturnModeReq(
|
void setReturnModeReq(
|
||||||
uint8_t returnMode, sscl::Callback<setReturnModeReqCbFn> callback);
|
uint8_t returnMode, sscl::cps::Callback<setReturnModeReqCbFn> callback);
|
||||||
void getReturnModeReq(sscl::Callback<getReturnModeReqCbFn> callback);
|
void getReturnModeReq(sscl::cps::Callback<getReturnModeReqCbFn> callback);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
comms::DiscoveredDevice discoveredDevice;
|
comms::DiscoveredDevice discoveredDevice;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <boostAsioLinkageFix.h>
|
#include <boostAsioLinkageFix.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||||
#include "livoxProto1.h"
|
#include "livoxProto1.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
@@ -16,7 +16,7 @@ void livoxProto1_getOrCreateDeviceReq(
|
|||||||
int commandTimeoutMs, int retryDelayMs,
|
int commandTimeoutMs, int retryDelayMs,
|
||||||
const std::string& smoIp, uint8_t smoSubnetNbits,
|
const std::string& smoIp, uint8_t smoSubnetNbits,
|
||||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
||||||
sscl::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback
|
sscl::cps::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Get the global DeviceManager instance
|
// Get the global DeviceManager instance
|
||||||
@@ -39,7 +39,7 @@ void livoxProto1_getOrCreateDeviceReq(
|
|||||||
|
|
||||||
void livoxProto1_destroyDeviceReq(
|
void livoxProto1_destroyDeviceReq(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_destroyDeviceReqCbFn> callback
|
sscl::cps::Callback<livoxProto1_destroyDeviceReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto& protoState = livoxProto1::getProtoState();
|
auto& protoState = livoxProto1::getProtoState();
|
||||||
@@ -67,7 +67,7 @@ void livoxProto1_exit(void)
|
|||||||
|
|
||||||
void livoxProto1_device_enablePcloudDataReq(
|
void livoxProto1_device_enablePcloudDataReq(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_device_enablePcloudDataReqCbFn> callback
|
sscl::cps::Callback<livoxProto1_device_enablePcloudDataReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!device)
|
if (!device)
|
||||||
@@ -81,7 +81,7 @@ void livoxProto1_device_enablePcloudDataReq(
|
|||||||
|
|
||||||
void livoxProto1_device_disablePcloudDataReq(
|
void livoxProto1_device_disablePcloudDataReq(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_device_disablePcloudDataReqCbFn> callback
|
sscl::cps::Callback<livoxProto1_device_disablePcloudDataReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!device)
|
if (!device)
|
||||||
@@ -95,7 +95,7 @@ void livoxProto1_device_disablePcloudDataReq(
|
|||||||
|
|
||||||
void livoxProto1_device_getReturnModeReq(
|
void livoxProto1_device_getReturnModeReq(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_device_getReturnModeReqCbFn> callback
|
sscl::cps::Callback<livoxProto1_device_getReturnModeReqCbFn> callback
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!device)
|
if (!device)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
@@ -64,30 +64,30 @@ typedef void livoxProto1_getOrCreateDeviceReqFn(
|
|||||||
int commandTimeoutMs, int retryDelayMs,
|
int commandTimeoutMs, int retryDelayMs,
|
||||||
const std::string& smoIp, uint8_t smoSubnetNbits,
|
const std::string& smoIp, uint8_t smoSubnetNbits,
|
||||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
||||||
sscl::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback);
|
||||||
|
|
||||||
typedef std::function<void(bool success)> livoxProto1_destroyDeviceReqCbFn;
|
typedef std::function<void(bool success)> livoxProto1_destroyDeviceReqCbFn;
|
||||||
typedef void livoxProto1_destroyDeviceReqFn(
|
typedef void livoxProto1_destroyDeviceReqFn(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_destroyDeviceReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_destroyDeviceReqCbFn> callback);
|
||||||
|
|
||||||
typedef std::function<void(bool success)>
|
typedef std::function<void(bool success)>
|
||||||
livoxProto1_device_enablePcloudDataReqCbFn;
|
livoxProto1_device_enablePcloudDataReqCbFn;
|
||||||
typedef void livoxProto1_device_enablePcloudDataReqFn(
|
typedef void livoxProto1_device_enablePcloudDataReqFn(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_device_enablePcloudDataReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_device_enablePcloudDataReqCbFn> callback);
|
||||||
|
|
||||||
typedef std::function<void(bool success)>
|
typedef std::function<void(bool success)>
|
||||||
livoxProto1_device_disablePcloudDataReqCbFn;
|
livoxProto1_device_disablePcloudDataReqCbFn;
|
||||||
typedef void livoxProto1_device_disablePcloudDataReqFn(
|
typedef void livoxProto1_device_disablePcloudDataReqFn(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_device_disablePcloudDataReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_device_disablePcloudDataReqCbFn> callback);
|
||||||
|
|
||||||
typedef std::function<void(bool success, uint8_t returnMode)>
|
typedef std::function<void(bool success, uint8_t returnMode)>
|
||||||
livoxProto1_device_getReturnModeReqCbFn;
|
livoxProto1_device_getReturnModeReqCbFn;
|
||||||
typedef void livoxProto1_device_getReturnModeReqFn(
|
typedef void livoxProto1_device_getReturnModeReqFn(
|
||||||
std::shared_ptr<livoxProto1::Device> device,
|
std::shared_ptr<livoxProto1::Device> device,
|
||||||
sscl::Callback<livoxProto1_device_getReturnModeReqCbFn> callback);
|
sscl::cps::Callback<livoxProto1_device_getReturnModeReqCbFn> callback);
|
||||||
|
|
||||||
typedef std::shared_ptr<boost::asio::posix::stream_descriptor>
|
typedef std::shared_ptr<boost::asio::posix::stream_descriptor>
|
||||||
livoxProto1_getPcloudDataFdDescFn(void);
|
livoxProto1_getPcloudDataFdDescFn(void);
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
Ok. We're extending the DAPS language to support specifying at most 1 postrin and at most 1 negtrin for each DAP spec. I.e: we'll no longer treat negtrins/postrins as their own qualeifaceapis attached to a deviceselector, but rather now negtrins and postrins will be attached to the nontrins they are triggered by. So looking at avia0.dapss:
|
||||||
|
|
||||||
|
```
|
||||||
|
// This line will be entirely deleted:
|
||||||
|
+edev|avia0|postrin(
|
||||||
|
from-stimbuff=pcloudAmbience|
|
||||||
|
interest-pc=85|
|
||||||
|
passband-count-lt-val=8
|
||||||
|
)
|
||||||
|
|livoxGen1()|livoxProto1(SMO_IP)|3JEDK380010Z39||
|
||||||
|
|
||||||
|
// And this one will be deleted too:
|
||||||
|
+edev|avia0|negtrin(
|
||||||
|
from-stimbuff=pcloudAmbience|
|
||||||
|
interest-pc=85|distraction-pc=90|intolerable-pc=95|
|
||||||
|
passband-count-gt-val=120
|
||||||
|
)
|
||||||
|
|livoxGen1()|livoxProto1(SMO_IP)|3JEDK380010Z39
|
||||||
|
|
||||||
|
// And this line will be modified from:
|
||||||
|
+edev|avia0|pcloudAmbience()|livoxGen1()|livoxProto1(SMO_IP)|3JEDK380010Z39||
|
||||||
|
|
||||||
|
// To:
|
||||||
|
+edev|avia0| postrin(interest-pc=85)| negtrin(interest-pc=85) |pcloudAmbience(passband-count-lt-val=8|passband-count-gt-val=120)|livoxGen1()|livoxProto1(SMO_IP)|3JEDK380010Z39||
|
||||||
|
```
|
||||||
|
|
||||||
|
So we're adding the ability to spec intrins on nontrin stimbuffs. Any DAP spec can declare 0 or 1 negtrin and 0 or 1 postrin. These must be declared before the first qualeIfaceApi.
|
||||||
|
|
||||||
|
Modify the current DAP spec lex/yacc files to support thissyntax; as well as the current DeviceAttachmentSpec struct type too. And update the current stimbuff devices if they use the current postrin/negtrin parameters. Let them look for these new postrin and negtrin specs and their params instead. For the official language-level spec, you can use these names for the new specifiers:
|
||||||
|
|
||||||
|
```
|
||||||
|
sensor-type|dev-identifier|postrin-spec(postrin-params)|negtrin-spec(negtrin-params)|quale-iface-api(quale-iface-api-params)|stim-buff-api(api-params)|provider(provider-params)|dev-selector
|
||||||
|
```
|
||||||
|
|
||||||
|
NB: The postrin and negtrin spec have no ordering requirement with respect to one another. They are only ordered with respect to the other specifiers in the DAP specs -- i.e: again, they must precede the qualeIfaceApi specifier. So the negtrin may appear before the postrin; and vice versa.
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <preprocessor.h>
|
#include <preprocessor.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <spinscale/componentThread.h>
|
#include <spinscale/componentThread.h>
|
||||||
#define CL_TARGET_OPENCL_VERSION 120
|
#define CL_TARGET_OPENCL_VERSION 120
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
@@ -57,10 +57,10 @@ typedef int (sal_mlo_finalizeIndFn)(void);
|
|||||||
typedef void (sal_mlo_attachDeviceReqFn)(
|
typedef void (sal_mlo_attachDeviceReqFn)(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
||||||
sscl::Callback<sal_mlo_attachDeviceReqCbFn> cb);
|
sscl::cps::Callback<sal_mlo_attachDeviceReqCbFn> cb);
|
||||||
typedef void (sal_mlo_detachDeviceReqFn)(
|
typedef void (sal_mlo_detachDeviceReqFn)(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
const std::shared_ptr<device::DeviceAttachmentSpec>& desc,
|
||||||
sscl::Callback<sal_mlo_detachDeviceReqCbFn> cb);
|
sscl::cps::Callback<sal_mlo_detachDeviceReqCbFn> cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Hooks provided by Salmanoff to senseApi libraries.
|
* @brief Hooks provided by Salmanoff to senseApi libraries.
|
||||||
|
|||||||
+1
-1
Submodule libspinscale updated: b6eb502e56...a14d622eaf
@@ -7,6 +7,7 @@ add_library(smocore STATIC
|
|||||||
mind.cpp
|
mind.cpp
|
||||||
mindComponent.cpp
|
mindComponent.cpp
|
||||||
componentThread.cpp
|
componentThread.cpp
|
||||||
|
componentThreadTags.cpp
|
||||||
opts.cpp
|
opts.cpp
|
||||||
|
|
||||||
# Body
|
# Body
|
||||||
|
|||||||
+28
-119
@@ -1,15 +1,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
|
||||||
#include <spinscale/asynchronousLoop.h>
|
|
||||||
#include <spinscale/callback.h>
|
|
||||||
#include <spinscale/callableTracer.h>
|
|
||||||
#include <spinscale/puppetApplication.h>
|
|
||||||
#include <body/body.h>
|
#include <body/body.h>
|
||||||
|
#include <body/bodyThread.h>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
|
#include <deviceManager/deviceManager.h>
|
||||||
#include <mind.h>
|
#include <mind.h>
|
||||||
#include <stimBuffApis/stimBuffApiManager.h>
|
#include <stimBuffApis/stimBuffApiManager.h>
|
||||||
#include <deviceManager/deviceManager.h>
|
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace body {
|
namespace body {
|
||||||
@@ -19,26 +16,8 @@ Body::Body(Mind &parent, const std::shared_ptr<sscl::PuppetThread> &thread)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class Body::InitializeReq
|
BodyViralPostingInvoker<bool> Body::initializeCReq()
|
||||||
: public sscl::PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
InitializeReq(
|
|
||||||
sscl::PuppetApplication &parent,
|
|
||||||
const std::shared_ptr<sscl::ComponentThread> &caller,
|
|
||||||
sscl::Callback<bodyLifetimeMgmtOpCbFn> callback)
|
|
||||||
: sscl::PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(caller, callback),
|
|
||||||
parent(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
|
||||||
sscl::PuppetApplication &parent;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void initializeReq1_posted(
|
|
||||||
[[maybe_unused]] std::shared_ptr<InitializeReq> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
auto self = sscl::ComponentThread::getSelf();
|
||||||
if (self->id != SmoThreadId::BODY)
|
if (self->id != SmoThreadId::BODY)
|
||||||
{
|
{
|
||||||
@@ -57,12 +36,12 @@ public:
|
|||||||
* Body instead since it's meant to handle device-management operations.
|
* Body instead since it's meant to handle device-management operations.
|
||||||
*/
|
*/
|
||||||
// Upcast to Mind to access Mind-specific members
|
// Upcast to Mind to access Mind-specific members
|
||||||
Mind &mind = static_cast<Mind&>(context->parent);
|
Mind &mind = static_cast<Mind&>(parent);
|
||||||
stim_buff::StimBuffApiManager::getInstance()
|
stim_buff::StimBuffApiManager::getInstance()
|
||||||
.loadAllStimBuffApiLibsFromOptions(mind.body.thread);
|
.loadAllStimBuffApiLibsFromOptions(mind.body.thread);
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
* Consider body::initializeReq to have been called if even one of its
|
* Consider body::initializeCReq to have been called if even one of its
|
||||||
* operations was executed at all, whether successfully or
|
* operations was executed at all, whether successfully or
|
||||||
* unsuccessfully.
|
* unsuccessfully.
|
||||||
*/
|
*/
|
||||||
@@ -81,41 +60,22 @@ public:
|
|||||||
|
|
||||||
if (OptionParser::getOptions().verbose)
|
if (OptionParser::getOptions().verbose)
|
||||||
{
|
{
|
||||||
std::cout << __func__ << ": About to attachAllSenseDevicesFromSpecs"
|
std::cout << __func__ << ": About to attachAllUnattachedDevicesFromCmdline"
|
||||||
<< '\n';
|
<< '\n';
|
||||||
}
|
}
|
||||||
device::DeviceManager::getInstance()
|
|
||||||
.attachAllUnattachedDevicesFromCmdlineReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&InitializeReq::initializeReq2,
|
|
||||||
context.get(), context,
|
|
||||||
std::placeholders::_1)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeReq2(
|
sscl::MultiOperationResultSet attachResults = co_await
|
||||||
[[maybe_unused]] std::shared_ptr<InitializeReq> context,
|
device::DeviceManager::getInstance()
|
||||||
sscl::AsynchronousLoop &results
|
.attachAllUnattachedDevicesFromCmdlineCReq();
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: attached "
|
std::cout << "Mrntt: attached "
|
||||||
<< results.nSucceeded << " of " << results.nTotal
|
<< attachResults.nSucceeded << " of " << attachResults.nTotal
|
||||||
<< " sense devices." << "\n";
|
<< " sense devices." << "\n";
|
||||||
|
|
||||||
callOriginalCb(results.nSucceeded > 0);
|
co_return attachResults.nSucceeded > 0;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
class Body::FinalizeReq
|
BodyViralPostingInvoker<bool> Body::finalizeCReq()
|
||||||
: public InitializeReq
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
using InitializeReq::InitializeReq;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void finalizeReq1_posted(
|
|
||||||
[[maybe_unused]] std::shared_ptr<FinalizeReq> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
auto self = sscl::ComponentThread::getSelf();
|
||||||
if (self->id != SmoThreadId::BODY)
|
if (self->id != SmoThreadId::BODY)
|
||||||
{
|
{
|
||||||
@@ -123,80 +83,29 @@ public:
|
|||||||
+ ": Must be executed on Body thread");
|
+ ": Must be executed on Body thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Mrntt: About to detach all sense devices." << "\n";
|
|
||||||
device::DeviceManager::getInstance().detachAllAttachedDeviceRoles(
|
|
||||||
{context, std::bind(
|
|
||||||
&FinalizeReq::finalizeReq2,
|
|
||||||
context.get(), context,
|
|
||||||
std::placeholders::_1)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void finalizeReq2(
|
|
||||||
[[maybe_unused]] std::shared_ptr<FinalizeReq> context,
|
|
||||||
sscl::AsynchronousLoop &results
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: Successfully detached "
|
|
||||||
<< results.nSucceeded << " of " << results.nTotal
|
|
||||||
<< " sense devices." << "\n";
|
|
||||||
|
|
||||||
std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n";
|
|
||||||
stim_buff::StimBuffApiManager::getInstance().finalizeAllStimBuffApiLibs();
|
|
||||||
|
|
||||||
std::cout << "Mrntt: About to unload all stim buff api libs." << "\n";
|
|
||||||
stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs();
|
|
||||||
callOriginalCb(results.nSucceeded == results.nTotal);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void Body::initializeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback)
|
|
||||||
{
|
|
||||||
auto mrntt = sscl::ComponentThread::getSelf();
|
|
||||||
|
|
||||||
if (mrntt->id != SmoThreadId::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": Must be invoked by Mrntt thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto request = std::make_shared<InitializeReq>(
|
|
||||||
parent, mrntt, callback);
|
|
||||||
|
|
||||||
thread->getIoService().post(
|
|
||||||
STC(std::bind(
|
|
||||||
&InitializeReq::initializeReq1_posted,
|
|
||||||
request.get(), request)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Body::finalizeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback)
|
|
||||||
{
|
|
||||||
auto mrntt = sscl::ComponentThread::getSelf();
|
|
||||||
|
|
||||||
if (mrntt->id != SmoThreadId::MRNTT)
|
|
||||||
{
|
|
||||||
std::cerr << __func__ << ": Must be invoked by Mrntt thread"
|
|
||||||
<< std::endl;
|
|
||||||
callback.callbackFn(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upcast to Mind to access Mind-specific members
|
// Upcast to Mind to access Mind-specific members
|
||||||
Mind &mind = static_cast<Mind&>(parent);
|
Mind &mind = static_cast<Mind&>(parent);
|
||||||
if (!mind.bodyComponentInitialized)
|
if (!mind.bodyComponentInitialized)
|
||||||
{
|
{
|
||||||
std::cout << "Mrntt: Body component not initialized. "
|
std::cout << "Mrntt: Body component not initialized. "
|
||||||
<< "Skipping finalization." << "\n";
|
<< "Skipping finalization." << "\n";
|
||||||
callback.callbackFn(true);
|
co_return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto request = std::make_shared<FinalizeReq>(
|
std::cout << "Mrntt: About to detach all sense devices." << "\n";
|
||||||
parent, mrntt, callback);
|
sscl::MultiOperationResultSet detachResults = co_await
|
||||||
|
device::DeviceManager::getInstance().detachAllAttachedDeviceRolesCReq();
|
||||||
|
std::cout << "Mrntt: Successfully detached "
|
||||||
|
<< detachResults.nSucceeded << " of " << detachResults.nTotal
|
||||||
|
<< " sense devices." << "\n";
|
||||||
|
|
||||||
thread->getIoService().post(
|
std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n";
|
||||||
STC(std::bind(
|
stim_buff::StimBuffApiManager::getInstance().finalizeAllStimBuffApiLibs();
|
||||||
&FinalizeReq::finalizeReq1_posted,
|
|
||||||
request.get(), request)));
|
std::cout << "Mrntt: About to unload all stim buff api libs." << "\n";
|
||||||
|
stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs();
|
||||||
|
|
||||||
|
co_return detachResults.nSucceeded == detachResults.nTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace body
|
} // namespace body
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <body/bodyThread.h>
|
||||||
|
#include <componentThread.h>
|
||||||
|
#include <director/directorThread.h>
|
||||||
|
#include <marionette/marionette.h>
|
||||||
|
#include <marionette/marionetteThread.h>
|
||||||
|
#include <mind.h>
|
||||||
|
#include <simulator/simulatorThread.h>
|
||||||
|
#include <subconsciousThread.h>
|
||||||
|
#include <world/worldThread.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace mrntt {
|
||||||
|
|
||||||
|
boost::asio::io_service &MrnttThreadTag::io_service() noexcept
|
||||||
|
{
|
||||||
|
return thread->getIoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mrntt
|
||||||
|
|
||||||
|
namespace body {
|
||||||
|
|
||||||
|
boost::asio::io_service &BodyThreadTag::io_service()
|
||||||
|
{
|
||||||
|
if (!mind::globalMind) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"BodyThreadTag: globalMind not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mind::globalMind->body.thread->getIoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace body
|
||||||
|
|
||||||
|
namespace director {
|
||||||
|
|
||||||
|
boost::asio::io_service &DirectorThreadTag::io_service()
|
||||||
|
{
|
||||||
|
if (!mind::globalMind) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"DirectorThreadTag: globalMind not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mind::globalMind->director.thread->getIoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace director
|
||||||
|
|
||||||
|
namespace simulator {
|
||||||
|
|
||||||
|
boost::asio::io_service &SimulatorThreadTag::io_service()
|
||||||
|
{
|
||||||
|
if (!mind::globalMind) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"SimulatorThreadTag: globalMind not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mind::globalMind->canvas.thread->getIoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace simulator
|
||||||
|
|
||||||
|
boost::asio::io_service &SubconsciousThreadTag::io_service()
|
||||||
|
{
|
||||||
|
if (!mind::globalMind) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"SubconsciousThreadTag: globalMind not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mind::globalMind->subconscious.thread->getIoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::asio::io_service &WorldThreadTag::io_service()
|
||||||
|
{
|
||||||
|
if (!mind::globalMind) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"WorldThreadTag: globalMind not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mind::globalMind->world.thread->getIoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace smo
|
||||||
@@ -33,23 +33,27 @@ std::string DeviceManager::readDapSpecFile(const std::string& filename)
|
|||||||
void DeviceManager::collateAllDapSpecs(void)
|
void DeviceManager::collateAllDapSpecs(void)
|
||||||
{
|
{
|
||||||
OptionParser &options = OptionParser::getOptions();
|
OptionParser &options = OptionParser::getOptions();
|
||||||
allDapSpecs = options.dapSpecs;
|
DeviceManager &dm = getInstance();
|
||||||
|
dm.s.rsrc.allDapSpecs = options.dapSpecs;
|
||||||
|
|
||||||
for (const auto& file : options.dapSpecFiles)
|
for (const auto& file : options.dapSpecFiles)
|
||||||
{
|
{
|
||||||
std::string fileContent = readDapSpecFile(file);
|
std::string fileContent = readDapSpecFile(file);
|
||||||
if (!allDapSpecs.empty()) {
|
if (!dm.s.rsrc.allDapSpecs.empty()) {
|
||||||
allDapSpecs += "||";
|
dm.s.rsrc.allDapSpecs += "||";
|
||||||
}
|
}
|
||||||
allDapSpecs += fileContent;
|
dm.s.rsrc.allDapSpecs += fileContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::parseAllDapSpecs(void)
|
void DeviceManager::parseAllDapSpecs(void)
|
||||||
{
|
{
|
||||||
|
DeviceManager &dm = getInstance();
|
||||||
auto file_deleter = [](FILE* f) { if (f) fclose(f); };
|
auto file_deleter = [](FILE* f) { if (f) fclose(f); };
|
||||||
std::unique_ptr<FILE, decltype(file_deleter)> input(
|
std::unique_ptr<FILE, decltype(file_deleter)> input(
|
||||||
fmemopen((void*)allDapSpecs.c_str(), allDapSpecs.size(), "r"),
|
fmemopen(
|
||||||
|
(void*)dm.s.rsrc.allDapSpecs.c_str(),
|
||||||
|
dm.s.rsrc.allDapSpecs.size(), "r"),
|
||||||
file_deleter);
|
file_deleter);
|
||||||
|
|
||||||
if (!input)
|
if (!input)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ interoceptor_spec:
|
|||||||
*static_cast<smo::device::InteroceptorDevAttachmentSpec *>($3));
|
*static_cast<smo::device::InteroceptorDevAttachmentSpec *>($3));
|
||||||
|
|
||||||
spec->sensorType = $1;
|
spec->sensorType = $1;
|
||||||
smo::device::DeviceManager::commandLineDASpecs.push_back(*spec);
|
smo::device::DeviceManager::getInstance().s.rsrc.commandLineDASpecs.push_back(*spec);
|
||||||
|
|
||||||
delete $3;
|
delete $3;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ extrospector_spec:
|
|||||||
*static_cast<smo::device::ExtrospectorDevAttachmentSpec *>($3));
|
*static_cast<smo::device::ExtrospectorDevAttachmentSpec *>($3));
|
||||||
|
|
||||||
spec->sensorType = $1;
|
spec->sensorType = $1;
|
||||||
smo::device::DeviceManager::commandLineDASpecs.push_back(*spec);
|
smo::device::DeviceManager::getInstance().s.rsrc.commandLineDASpecs.push_back(*spec);
|
||||||
|
|
||||||
delete $3;
|
delete $3;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,20 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <spinscale/callback.h>
|
|
||||||
#include <deviceManager/deviceReattacher.h>
|
#include <deviceManager/deviceReattacher.h>
|
||||||
#include <deviceManager/deviceManager.h>
|
#include <deviceManager/deviceManager.h>
|
||||||
|
#include <marionette/marionetteThread.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace device {
|
namespace device {
|
||||||
|
|
||||||
static void reattachmentCb(sscl::AsynchronousLoop& results)
|
namespace {
|
||||||
{
|
|
||||||
if (results.nTotal == 0) { return; }
|
|
||||||
|
|
||||||
std::cout << "DeviceReattacher: Successfully reattached "
|
constexpr unsigned int reattachInFlightStaleThresholdMultiplier = 4;
|
||||||
<< results.nSucceeded << " of " << results.nTotal << " devices"
|
|
||||||
<< std::endl;
|
} // namespace
|
||||||
}
|
|
||||||
|
|
||||||
DeviceReattacher::DeviceReattacher(
|
DeviceReattacher::DeviceReattacher(
|
||||||
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread)
|
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread)
|
||||||
@@ -25,6 +23,22 @@ timer(ioThread->getIoService())
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mrntt::MrnttNonViralPostingInvoker DeviceReattacher::reattachKnownListCReq(
|
||||||
|
[[maybe_unused]] std::exception_ptr &exceptionPtr,
|
||||||
|
[[maybe_unused]] std::function<void()> callback)
|
||||||
|
{
|
||||||
|
sscl::MultiOperationResultSet results = co_await
|
||||||
|
parent.attachAllUnattachedDevicesFromKnownListCReq();
|
||||||
|
if (results.nTotal > 0)
|
||||||
|
{
|
||||||
|
std::cout << "DeviceReattacher: Successfully reattached "
|
||||||
|
<< results.nSucceeded << " of " << results.nTotal
|
||||||
|
<< " devices" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
co_return;
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceReattacher::start()
|
void DeviceReattacher::start()
|
||||||
{
|
{
|
||||||
shouldContinue = true;
|
shouldContinue = true;
|
||||||
@@ -36,6 +50,14 @@ void DeviceReattacher::stop()
|
|||||||
{
|
{
|
||||||
sscl::SpinLock::Guard lock(shouldContinueLock);
|
sscl::SpinLock::Guard lock(shouldContinueLock);
|
||||||
shouldContinue = false;
|
shouldContinue = false;
|
||||||
|
reattachOpInFlight = false;
|
||||||
|
/** EXPLANATION:
|
||||||
|
* Do not call reattachCReqInvoker.reset() here. Forcibly destroying
|
||||||
|
* the invoker would tear down an in-flight reattach coroutine frame
|
||||||
|
* mid-operation. During normal program teardown the optional (and
|
||||||
|
* its invoker) are destroyed with the rest of the binary anyway; leave
|
||||||
|
* a running reattach time to finish if shutdown races with it.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
@@ -56,6 +78,21 @@ void DeviceReattacher::scheduleNextTimeout()
|
|||||||
std::bind(&DeviceReattacher::onTimeout, this, std::placeholders::_1));
|
std::bind(&DeviceReattacher::onTimeout, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceReattacher::holdReattachCReq()
|
||||||
|
{
|
||||||
|
reattachOpInFlight = true;
|
||||||
|
lastReattachReqTimestamp = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
reattachCReqInvoker.reset();
|
||||||
|
reattachCReqInvoker.emplace(reattachKnownListCReq(
|
||||||
|
reattachLifetimeExceptionPtr,
|
||||||
|
[this]()
|
||||||
|
{
|
||||||
|
sscl::SpinLock::Guard lock(shouldContinueLock);
|
||||||
|
reattachOpInFlight = false;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceReattacher::onTimeout(const boost::system::error_code& error)
|
void DeviceReattacher::onTimeout(const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
// Timer was cancelled, which is expected when stopping
|
// Timer was cancelled, which is expected when stopping
|
||||||
@@ -75,9 +112,32 @@ void DeviceReattacher::onTimeout(const boost::system::error_code& error)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto staleThreshold = std::chrono::milliseconds(
|
||||||
|
reattachInFlightStaleThresholdMultiplier
|
||||||
|
* CONFIG_MRNTT_DEVMGR_REATTACHER_PERIOD_MS);
|
||||||
|
|
||||||
// Attempt to reattach all unattached devices from the known list
|
// Attempt to reattach all unattached devices from the known list
|
||||||
parent.attachAllUnattachedDevicesFromKnownListReq(
|
if (!reattachOpInFlight)
|
||||||
{ nullptr, reattachmentCb});
|
{
|
||||||
|
holdReattachCReq();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto elapsedSinceLastReattachReq =
|
||||||
|
std::chrono::steady_clock::now() - lastReattachReqTimestamp;
|
||||||
|
|
||||||
|
if (elapsedSinceLastReattachReq >= staleThreshold)
|
||||||
|
{
|
||||||
|
std::cerr << "DeviceReattacher: Reattach op still in flight after "
|
||||||
|
<< std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
elapsedSinceLastReattachReq).count()
|
||||||
|
<< "ms (threshold "
|
||||||
|
<< staleThreshold.count()
|
||||||
|
<< "ms); forcing a new reattach request."
|
||||||
|
<< std::endl;
|
||||||
|
holdReattachCReq();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Schedule the next timeout
|
// Schedule the next timeout
|
||||||
scheduleNextTimeout();
|
scheduleNextTimeout();
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
#include <spinscale/puppetApplication.h>
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
#include <mindComponent.h>
|
#include <mindComponent.h>
|
||||||
#include <functional>
|
#include <body/bodyThread.h>
|
||||||
#include <spinscale/callback.h>
|
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
|
|
||||||
@@ -20,13 +19,8 @@ public:
|
|||||||
Body(Mind &parent, const std::shared_ptr<sscl::PuppetThread> &thread);
|
Body(Mind &parent, const std::shared_ptr<sscl::PuppetThread> &thread);
|
||||||
~Body() = default;
|
~Body() = default;
|
||||||
|
|
||||||
typedef std::function<void(bool)> bodyLifetimeMgmtOpCbFn;
|
BodyViralPostingInvoker<bool> initializeCReq();
|
||||||
void initializeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback);
|
BodyViralPostingInvoker<bool> finalizeCReq();
|
||||||
void finalizeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback);
|
|
||||||
|
|
||||||
private:
|
|
||||||
class InitializeReq;
|
|
||||||
class FinalizeReq;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace body
|
} // namespace body
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef SMO_BODY_THREAD_H
|
||||||
|
#define SMO_BODY_THREAD_H
|
||||||
|
|
||||||
|
#include <boost/asio/io_service.hpp>
|
||||||
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postingPromise.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace body {
|
||||||
|
|
||||||
|
struct BodyThreadTag
|
||||||
|
{
|
||||||
|
static boost::asio::io_service &io_service();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using BodyPostingPromise =
|
||||||
|
sscl::co::TaggedPostingPromise<T, BodyThreadTag>;
|
||||||
|
|
||||||
|
using BodyNonViralPostingInvoker =
|
||||||
|
sscl::co::NonViralPostingInvoker<BodyPostingPromise>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using BodyViralPostingInvoker =
|
||||||
|
sscl::co::ViralPostingInvoker<BodyPostingPromise, T>;
|
||||||
|
|
||||||
|
} // namespace body
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // SMO_BODY_THREAD_H
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <deviceManager/deviceRole.h>
|
#include <deviceManager/deviceRole.h>
|
||||||
#include <spinscale/qutex.h>
|
#include <spinscale/co/coQutex.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace device {
|
namespace device {
|
||||||
@@ -15,8 +15,9 @@ namespace device {
|
|||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Device(const std::string& identifier)
|
explicit Device(const std::string& identifier)
|
||||||
: deviceIdentifier(identifier), qutex("Device-" + identifier)
|
: deviceIdentifier(identifier),
|
||||||
|
qutex("Device-" + identifier)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string stringify() const
|
std::string stringify() const
|
||||||
@@ -33,7 +34,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
std::string deviceIdentifier;
|
std::string deviceIdentifier;
|
||||||
std::vector<std::shared_ptr<DeviceRole>> deviceRoles;
|
std::vector<std::shared_ptr<DeviceRole>> deviceRoles;
|
||||||
sscl::Qutex qutex;
|
sscl::co::CoQutex qutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace device
|
} // namespace device
|
||||||
|
|||||||
@@ -7,15 +7,16 @@
|
|||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <functional>
|
|
||||||
#include <user/senseApiDesc.h>
|
#include <user/senseApiDesc.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
|
||||||
#include <deviceManager/device.h>
|
#include <deviceManager/device.h>
|
||||||
#include <deviceManager/deviceRole.h>
|
#include <deviceManager/deviceRole.h>
|
||||||
#include <deviceManager/deviceReattacher.h>
|
#include <deviceManager/deviceReattacher.h>
|
||||||
#include <spinscale/callback.h>
|
#include <cpsBoundary/stimBuffDeviceAReq.h>
|
||||||
#include <spinscale/qutex.h>
|
#include <marionette/marionetteThread.h>
|
||||||
|
#include <spinscale/co/coQutex.h>
|
||||||
|
#include <spinscale/multiOperationResultSet.h>
|
||||||
|
#include <spinscale/sharedResourceGroup.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace device {
|
namespace device {
|
||||||
@@ -25,6 +26,13 @@ class DeviceReattacher;
|
|||||||
class DeviceManager
|
class DeviceManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct DeviceAttachmentIndResult
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
std::shared_ptr<DeviceRole> deviceRole;
|
||||||
|
std::shared_ptr<DeviceAttachmentSpec> deviceSpec;
|
||||||
|
};
|
||||||
|
|
||||||
static DeviceManager& getInstance()
|
static DeviceManager& getInstance()
|
||||||
{
|
{
|
||||||
static DeviceManager instance;
|
static DeviceManager instance;
|
||||||
@@ -45,74 +53,55 @@ public:
|
|||||||
|
|
||||||
static const std::string stringifyDeviceSpecs(void);
|
static const std::string stringifyDeviceSpecs(void);
|
||||||
|
|
||||||
typedef std::function<void(
|
mrntt::MrnttViralPostingInvoker<DeviceAttachmentIndResult>
|
||||||
bool success, std::shared_ptr<DeviceRole> deviceRole,
|
newDeviceAttachmentSpecIndCReq(const DeviceAttachmentSpec &spec);
|
||||||
std::shared_ptr<DeviceAttachmentSpec> deviceSpec)>
|
|
||||||
newDeviceAttachmentSpecIndCbFn;
|
|
||||||
typedef std::function<void(
|
|
||||||
bool success, std::shared_ptr<DeviceAttachmentSpec> deviceSpec)>
|
|
||||||
removeDeviceAttachmentSpecReqCbFn;
|
|
||||||
|
|
||||||
void newDeviceAttachmentSpecInd(
|
mrntt::MrnttViralPostingInvoker<DeviceAttachmentIndResult>
|
||||||
const DeviceAttachmentSpec &spec,
|
removeDeviceAttachmentSpecCReq(const DeviceAttachmentSpec &spec);
|
||||||
sscl::Callback<newDeviceAttachmentSpecIndCbFn> callback);
|
|
||||||
void removeDeviceAttachmentSpecReq(
|
|
||||||
const DeviceAttachmentSpec &spec,
|
|
||||||
sscl::Callback<removeDeviceAttachmentSpecReqCbFn> callback);
|
|
||||||
|
|
||||||
// Device attachment/detachment methods moved from SenseApiManager
|
mrntt::MrnttViralPostingInvoker<cpsBoundary::StimBuffDeviceOpResult>
|
||||||
typedef stim_buff::sal_mlo_attachDeviceReqCbFn attachStimBuffDeviceReqCbFn;
|
attachStimBuffDeviceCReq(
|
||||||
typedef stim_buff::sal_mlo_detachDeviceReqCbFn detachStimBuffDeviceReqCbFn;
|
const std::shared_ptr<DeviceAttachmentSpec>& spec);
|
||||||
|
|
||||||
void attachStimBuffDeviceReq(
|
mrntt::MrnttViralPostingInvoker<cpsBoundary::StimBuffDeviceOpResult>
|
||||||
const std::shared_ptr<DeviceAttachmentSpec>& spec,
|
detachStimBuffDeviceCReq(
|
||||||
sscl::Callback<attachStimBuffDeviceReqCbFn> cb);
|
const std::shared_ptr<DeviceAttachmentSpec>& spec);
|
||||||
void detachStimBuffDeviceReq(
|
|
||||||
const std::shared_ptr<DeviceAttachmentSpec>& spec,
|
|
||||||
sscl::Callback<detachStimBuffDeviceReqCbFn> cb);
|
|
||||||
|
|
||||||
typedef std::function<void(sscl::AsynchronousLoop &results)>
|
mrntt::MrnttViralPostingInvoker<sscl::MultiOperationResultSet>
|
||||||
attachAllUnattachedDevicesFromReqCbFn;
|
attachAllUnattachedDevicesFromCReq(
|
||||||
typedef std::function<void(sscl::AsynchronousLoop &results)>
|
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs);
|
||||||
detachAllAttachedDeviceRolesCbFn;
|
|
||||||
|
|
||||||
void attachAllUnattachedDevicesFromReq(
|
mrntt::MrnttViralPostingInvoker<sscl::MultiOperationResultSet>
|
||||||
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
|
attachAllUnattachedDevicesFromKnownListCReq();
|
||||||
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
|
|
||||||
void attachAllUnattachedDevicesFromKnownListReq(
|
mrntt::MrnttViralPostingInvoker<sscl::MultiOperationResultSet>
|
||||||
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
|
attachAllUnattachedDevicesFromCmdlineCReq();
|
||||||
void attachAllUnattachedDevicesFromCmdlineReq(
|
|
||||||
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
|
mrntt::MrnttViralPostingInvoker<sscl::MultiOperationResultSet>
|
||||||
void detachAllAttachedDeviceRoles(
|
detachAllAttachedDeviceRolesCReq();
|
||||||
sscl::Callback<detachAllAttachedDeviceRolesCbFn> cb);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceManager()
|
DeviceManager()
|
||||||
: qutex("DeviceManager"), deviceReattacher(nullptr)
|
: s("DeviceManager")
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~DeviceManager();
|
~DeviceManager();
|
||||||
DeviceManager(const DeviceManager&) = delete;
|
DeviceManager(const DeviceManager&) = delete;
|
||||||
DeviceManager& operator=(const DeviceManager&) = delete;
|
DeviceManager& operator=(const DeviceManager&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
sscl::Qutex qutex;
|
struct Resources
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<DeviceAttachmentSpec>> deviceAttachmentSpecs;
|
||||||
|
std::vector<std::shared_ptr<Device>> devices;
|
||||||
|
std::vector<std::shared_ptr<DeviceRole>> attachedDeviceRoles;
|
||||||
|
std::vector<DeviceAttachmentSpec> commandLineDASpecs;
|
||||||
std::string allDapSpecs;
|
std::string allDapSpecs;
|
||||||
static std::vector<std::shared_ptr<DeviceAttachmentSpec>>
|
};
|
||||||
deviceAttachmentSpecs;
|
sscl::SharedResourceGroup<sscl::co::CoQutex, Resources> s;
|
||||||
static std::vector<std::shared_ptr<Device>> devices;
|
|
||||||
static std::vector<std::shared_ptr<DeviceRole>> attachedDeviceRoles;
|
|
||||||
static std::vector<DeviceAttachmentSpec> commandLineDASpecs;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<DeviceReattacher> deviceReattacher;
|
std::unique_ptr<DeviceReattacher> deviceReattacher;
|
||||||
|
|
||||||
class NewDeviceAttachmentSpecInd;
|
|
||||||
class RemoveDeviceAttachmentSpecReq;
|
|
||||||
class AttachStimBuffDeviceReq;
|
|
||||||
typedef AttachStimBuffDeviceReq DetachStimBuffDeviceReq;
|
|
||||||
class AttachAllUnattachedDevicesFromReq;
|
|
||||||
class AttachAllUnattachedDevicesFromKnownListReq;
|
|
||||||
class DetachAllAttachedDeviceRoles;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace device
|
} // namespace device
|
||||||
|
|||||||
@@ -3,8 +3,14 @@
|
|||||||
|
|
||||||
#include <boostAsioLinkageFix.h>
|
#include <boostAsioLinkageFix.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
|
#include <marionette/marionetteThread.h>
|
||||||
|
#include <spinscale/multiOperationResultSet.h>
|
||||||
#include <spinscale/spinLock.h>
|
#include <spinscale/spinLock.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
@@ -20,7 +26,6 @@ public:
|
|||||||
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread);
|
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread);
|
||||||
~DeviceReattacher() = default;
|
~DeviceReattacher() = default;
|
||||||
|
|
||||||
// Non-copyable
|
|
||||||
DeviceReattacher(const DeviceReattacher&) = delete;
|
DeviceReattacher(const DeviceReattacher&) = delete;
|
||||||
DeviceReattacher& operator=(const DeviceReattacher&) = delete;
|
DeviceReattacher& operator=(const DeviceReattacher&) = delete;
|
||||||
|
|
||||||
@@ -31,12 +36,21 @@ public:
|
|||||||
private:
|
private:
|
||||||
void scheduleNextTimeout();
|
void scheduleNextTimeout();
|
||||||
void onTimeout(const boost::system::error_code& error);
|
void onTimeout(const boost::system::error_code& error);
|
||||||
|
void holdReattachCReq();
|
||||||
|
|
||||||
|
mrntt::MrnttNonViralPostingInvoker reattachKnownListCReq(
|
||||||
|
std::exception_ptr &exceptionPtr,
|
||||||
|
std::function<void()> callback);
|
||||||
|
|
||||||
DeviceManager &parent;
|
DeviceManager &parent;
|
||||||
std::shared_ptr<sscl::ComponentThread> ioThread;
|
std::shared_ptr<sscl::ComponentThread> ioThread;
|
||||||
sscl::SpinLock shouldContinueLock;
|
sscl::SpinLock shouldContinueLock;
|
||||||
bool shouldContinue;
|
bool shouldContinue;
|
||||||
boost::asio::deadline_timer timer;
|
boost::asio::deadline_timer timer;
|
||||||
|
std::exception_ptr reattachLifetimeExceptionPtr;
|
||||||
|
std::optional<mrntt::MrnttNonViralPostingInvoker> reattachCReqInvoker;
|
||||||
|
bool reattachOpInFlight = false;
|
||||||
|
std::chrono::steady_clock::time_point lastReattachReqTimestamp{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace device
|
} // namespace device
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef SMO_DIRECTOR_THREAD_H
|
||||||
|
#define SMO_DIRECTOR_THREAD_H
|
||||||
|
|
||||||
|
#include <boost/asio/io_service.hpp>
|
||||||
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postingPromise.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace director {
|
||||||
|
|
||||||
|
struct DirectorThreadTag
|
||||||
|
{
|
||||||
|
static boost::asio::io_service &io_service();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using DirectorPostingPromise =
|
||||||
|
sscl::co::TaggedPostingPromise<T, DirectorThreadTag>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using DirectorViralPostingInvoker =
|
||||||
|
sscl::co::ViralPostingInvoker<DirectorPostingPromise, T>;
|
||||||
|
|
||||||
|
} // namespace director
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // SMO_DIRECTOR_THREAD_H
|
||||||
@@ -4,9 +4,12 @@
|
|||||||
#include <boost/asio/signal_set.hpp>
|
#include <boost/asio/signal_set.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
|
#include <marionette/marionetteThread.h>
|
||||||
|
|
||||||
namespace sscl {
|
namespace sscl {
|
||||||
|
|
||||||
@@ -26,11 +29,17 @@ public:
|
|||||||
{}
|
{}
|
||||||
~MarionetteComponent() = default;
|
~MarionetteComponent() = default;
|
||||||
|
|
||||||
public:
|
void holdInitializeCReq(std::function<void()> completion);
|
||||||
typedef std::function<void(bool)> mrnttLifetimeMgmtOpCbFn;
|
void holdFinalizeCReq(std::function<void()> completion);
|
||||||
void initializeReq(sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback);
|
|
||||||
void finalizeReq(sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback);
|
MrnttNonViralPostingInvoker initializeCReq(
|
||||||
// Intentionally doesn't take a callback.
|
std::exception_ptr &exceptionPtr,
|
||||||
|
std::function<void()> callback);
|
||||||
|
|
||||||
|
MrnttNonViralPostingInvoker finalizeCReq(
|
||||||
|
std::exception_ptr &exceptionPtr,
|
||||||
|
std::function<void()> callback);
|
||||||
|
|
||||||
void exceptionInd();
|
void exceptionInd();
|
||||||
|
|
||||||
void handleLoopExceptionHook() override;
|
void handleLoopExceptionHook() override;
|
||||||
@@ -47,11 +56,14 @@ protected:
|
|||||||
void handleTryBlock1UnknownException() override;
|
void handleTryBlock1UnknownException() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class MrnttLifetimeMgmtOp;
|
|
||||||
class TerminationEvent;
|
|
||||||
|
|
||||||
std::unique_ptr<boost::asio::signal_set> signals;
|
std::unique_ptr<boost::asio::signal_set> signals;
|
||||||
bool callShutdownSalmanoff = false;
|
bool callShutdownSalmanoff = false;
|
||||||
|
std::optional<MrnttNonViralPostingInvoker> initializeCReqInvoker;
|
||||||
|
std::optional<MrnttNonViralPostingInvoker> finalizeCReqInvoker;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::exception_ptr initializeLifetimeExceptionPtr;
|
||||||
|
std::exception_ptr finalizeLifetimeExceptionPtr;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::shared_ptr<sscl::PuppeteerThread> thread;
|
extern std::shared_ptr<sscl::PuppeteerThread> thread;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef SMO_MARIONETTE_THREAD_H
|
||||||
|
#define SMO_MARIONETTE_THREAD_H
|
||||||
|
|
||||||
|
#include <boost/asio/io_service.hpp>
|
||||||
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postingPromise.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace mrntt {
|
||||||
|
|
||||||
|
struct MrnttThreadTag
|
||||||
|
{
|
||||||
|
static boost::asio::io_service &io_service() noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using MrnttPostingPromise =
|
||||||
|
sscl::co::TaggedPostingPromise<T, MrnttThreadTag>;
|
||||||
|
|
||||||
|
using MrnttNonViralPostingInvoker =
|
||||||
|
sscl::co::NonViralPostingInvoker<MrnttPostingPromise>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using MrnttViralPostingInvoker =
|
||||||
|
sscl::co::ViralPostingInvoker<MrnttPostingPromise, T>;
|
||||||
|
|
||||||
|
using MrnttViralNonPostingInvoker =
|
||||||
|
sscl::co::ViralNonPostingInvoker<void>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using MrnttViralNonPostingInvokerT =
|
||||||
|
sscl::co::ViralNonPostingInvoker<T>;
|
||||||
|
|
||||||
|
} // namespace mrntt
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // SMO_MARIONETTE_THREAD_H
|
||||||
@@ -2,16 +2,15 @@
|
|||||||
#define _MIND_H
|
#define _MIND_H
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <spinscale/callback.h>
|
|
||||||
|
|
||||||
#include <spinscale/puppetApplication.h>
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <mindThread.h>
|
#include <mindThread.h>
|
||||||
#include <mindComponent.h>
|
#include <mindComponent.h>
|
||||||
|
#include <marionette/marionetteThread.h>
|
||||||
#include <director/director.h>
|
#include <director/director.h>
|
||||||
#include <simulator/simulator.h>
|
#include <simulator/simulator.h>
|
||||||
#include <body/body.h>
|
#include <body/body.h>
|
||||||
@@ -25,9 +24,8 @@ public:
|
|||||||
Mind(void);
|
Mind(void);
|
||||||
~Mind(void) = default;
|
~Mind(void) = default;
|
||||||
|
|
||||||
typedef std::function<void(bool)> mindLifetimeMgmtOpCbFn;
|
mrntt::MrnttViralNonPostingInvokerT<bool> initializeCReq();
|
||||||
void initializeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback);
|
mrntt::MrnttViralNonPostingInvokerT<bool> finalizeCReq();
|
||||||
void finalizeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback);
|
|
||||||
|
|
||||||
// ComponentThread access methods
|
// ComponentThread access methods
|
||||||
std::shared_ptr<MindThread> getComponentThread(sscl::ThreadId id) const;
|
std::shared_ptr<MindThread> getComponentThread(sscl::ThreadId id) const;
|
||||||
@@ -46,9 +44,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class body::Body;
|
friend class body::Body;
|
||||||
bool bodyComponentInitialized = false;
|
bool bodyComponentInitialized = false;
|
||||||
|
|
||||||
private:
|
|
||||||
class MindLifetimeMgmtOp;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mind {
|
namespace mind {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef SMO_SIMULATOR_THREAD_H
|
||||||
|
#define SMO_SIMULATOR_THREAD_H
|
||||||
|
|
||||||
|
#include <boost/asio/io_service.hpp>
|
||||||
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postingPromise.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace simulator {
|
||||||
|
|
||||||
|
struct SimulatorThreadTag
|
||||||
|
{
|
||||||
|
static boost::asio::io_service &io_service();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using SimulatorPostingPromise =
|
||||||
|
sscl::co::TaggedPostingPromise<T, SimulatorThreadTag>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using SimulatorViralPostingInvoker =
|
||||||
|
sscl::co::ViralPostingInvoker<SimulatorPostingPromise, T>;
|
||||||
|
|
||||||
|
} // namespace simulator
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // SMO_SIMULATOR_THREAD_H
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <user/senseApiDesc.h>
|
#include <user/senseApiDesc.h>
|
||||||
#include <spinscale/qutex.h>
|
#include <spinscale/co/coQutex.h>
|
||||||
|
#include <spinscale/sharedResourceGroup.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -31,10 +32,11 @@ public:
|
|||||||
StimBuffApiLib(
|
StimBuffApiLib(
|
||||||
const std::string& path, void *_dlopen_handle,
|
const std::string& path, void *_dlopen_handle,
|
||||||
SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *descFn)
|
SMO_GET_STIM_BUFF_API_DESC_FN_TYPEDEF *descFn)
|
||||||
: libraryPath(path), qutex("StimBuffApiLib-" + path),
|
: libraryPath(path),
|
||||||
isBeingDestroyed(false),
|
isBeingDestroyed(false),
|
||||||
dlopen_handle(_dlopen_handle, DlCloser()),
|
dlopen_handle(_dlopen_handle, DlCloser()),
|
||||||
SMO_GET_STIM_BUFF_API_DESC_FN_NAME(descFn)
|
SMO_GET_STIM_BUFF_API_DESC_FN_NAME(descFn),
|
||||||
|
s("StimBuffApiLib-" + path)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void setStimBuffApiDesc(const StimBuffApiDesc &desc)
|
void setStimBuffApiDesc(const StimBuffApiDesc &desc)
|
||||||
@@ -51,7 +53,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
std::string libraryPath;
|
std::string libraryPath;
|
||||||
sscl::Qutex qutex;
|
|
||||||
std::atomic<bool> isBeingDestroyed;
|
std::atomic<bool> isBeingDestroyed;
|
||||||
std::unique_ptr<void, DlCloser> dlopen_handle;
|
std::unique_ptr<void, DlCloser> dlopen_handle;
|
||||||
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
|
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
|
||||||
@@ -77,6 +78,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
StimBuffApiDesc stimBuffApiDesc;
|
StimBuffApiDesc stimBuffApiDesc;
|
||||||
|
|
||||||
|
struct StimBuffApiLibResources
|
||||||
|
{};
|
||||||
|
|
||||||
|
sscl::SharedResourceGroup<sscl::co::CoQutex, StimBuffApiLibResources> s;
|
||||||
|
|
||||||
std::string stringify() const {
|
std::string stringify() const {
|
||||||
std::string result = "Library Path: " + libraryPath + "\n";
|
std::string result = "Library Path: " + libraryPath + "\n";
|
||||||
result += "Stim Buff API Descriptor: " + stimBuffApiDesc.stringify() + "\n";
|
result += "Stim Buff API Descriptor: " + stimBuffApiDesc.stringify() + "\n";
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
|
||||||
#include <stimBuffApis/stimBuffApiLib.h>
|
#include <stimBuffApis/stimBuffApiLib.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/co/coQutex.h>
|
||||||
#include <spinscale/qutex.h>
|
#include <spinscale/sharedResourceGroup.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
@@ -19,6 +18,11 @@ namespace stim_buff {
|
|||||||
class StimBuffApiManager
|
class StimBuffApiManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct Resources
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<StimBuffApiLib>> stimBuffApiLibs;
|
||||||
|
};
|
||||||
|
|
||||||
static StimBuffApiManager& getInstance()
|
static StimBuffApiManager& getInstance()
|
||||||
{
|
{
|
||||||
static StimBuffApiManager instance;
|
static StimBuffApiManager instance;
|
||||||
@@ -54,17 +58,16 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
StimBuffApiManager()
|
StimBuffApiManager()
|
||||||
: qutex("StimBuffApiManager")
|
: s("StimBuffApiManager")
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~StimBuffApiManager() = default;
|
~StimBuffApiManager() = default;
|
||||||
|
|
||||||
StimBuffApiManager(const StimBuffApiManager&) = delete;
|
StimBuffApiManager(const StimBuffApiManager&) = delete;
|
||||||
StimBuffApiManager& operator=(const StimBuffApiManager&) = delete;
|
StimBuffApiManager& operator=(const StimBuffApiManager&) = delete;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<StimBuffApiLib>> stimBuffApiLibs;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
sscl::Qutex qutex;
|
sscl::SharedResourceGroup<sscl::co::CoQutex, Resources> s;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::optional<std::string> searchForLibInSmoSearchPaths(
|
static std::optional<std::string> searchForLibInSmoSearchPaths(
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef SMO_SUBCONSCIOUS_THREAD_H
|
||||||
|
#define SMO_SUBCONSCIOUS_THREAD_H
|
||||||
|
|
||||||
|
#include <boost/asio/io_service.hpp>
|
||||||
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postingPromise.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
|
||||||
|
struct SubconsciousThreadTag
|
||||||
|
{
|
||||||
|
static boost::asio::io_service &io_service();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using SubconsciousPostingPromise =
|
||||||
|
sscl::co::TaggedPostingPromise<T, SubconsciousThreadTag>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using SubconsciousViralPostingInvoker =
|
||||||
|
sscl::co::ViralPostingInvoker<SubconsciousPostingPromise, T>;
|
||||||
|
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // SMO_SUBCONSCIOUS_THREAD_H
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef SMO_WORLD_THREAD_H
|
||||||
|
#define SMO_WORLD_THREAD_H
|
||||||
|
|
||||||
|
#include <boost/asio/io_service.hpp>
|
||||||
|
#include <spinscale/co/invokers.h>
|
||||||
|
#include <spinscale/co/postingPromise.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
|
||||||
|
struct WorldThreadTag
|
||||||
|
{
|
||||||
|
static boost::asio::io_service &io_service();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using WorldPostingPromise =
|
||||||
|
sscl::co::TaggedPostingPromise<T, WorldThreadTag>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using WorldViralPostingInvoker =
|
||||||
|
sscl::co::ViralPostingInvoker<WorldPostingPromise, T>;
|
||||||
|
|
||||||
|
} // namespace smo
|
||||||
|
|
||||||
|
#endif // SMO_WORLD_THREAD_H
|
||||||
+59
-158
@@ -1,63 +1,61 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <stdexcept>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
|
||||||
#include <spinscale/callback.h>
|
#include <boost/asio/post.hpp>
|
||||||
#include <spinscale/callableTracer.h>
|
|
||||||
#include <spinscale/component.h>
|
|
||||||
#include <marionette/marionette.h>
|
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <deviceManager/deviceManager.h>
|
#include <deviceManager/deviceManager.h>
|
||||||
|
#include <marionette/marionette.h>
|
||||||
|
#include <marionette/marionetteThread.h>
|
||||||
#include <mindManager/mindManager.h>
|
#include <mindManager/mindManager.h>
|
||||||
|
#include <spinscale/componentThread.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace mrntt {
|
namespace mrntt {
|
||||||
|
|
||||||
class MarionetteComponent::MrnttLifetimeMgmtOp
|
namespace {
|
||||||
: public sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>
|
|
||||||
|
void assertMarionetteThread()
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
MrnttLifetimeMgmtOp(
|
|
||||||
MarionetteComponent &parent,
|
|
||||||
const std::shared_ptr<sscl::ComponentThread> &caller,
|
|
||||||
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
|
|
||||||
: sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
|
|
||||||
caller, callback),
|
|
||||||
parent(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
|
||||||
MarionetteComponent &parent;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void initializeReq1_posted(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MrnttLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
auto self = sscl::ComponentThread::getSelf();
|
||||||
if (self->id != smo::SmoThreadId::MRNTT)
|
if (self->id != SmoThreadId::MRNTT)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__func__)
|
throw std::runtime_error(
|
||||||
|
std::string(__func__)
|
||||||
+ ": Must be executed on Marionette thread");
|
+ ": Must be executed on Marionette thread");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void MarionetteComponent::holdInitializeCReq(
|
||||||
|
std::function<void()> completion)
|
||||||
|
{
|
||||||
|
initializeCReqInvoker.emplace(initializeCReq(
|
||||||
|
initializeLifetimeExceptionPtr, std::move(completion)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarionetteComponent::holdFinalizeCReq(
|
||||||
|
std::function<void()> completion)
|
||||||
|
{
|
||||||
|
finalizeCReqInvoker.emplace(finalizeCReq(
|
||||||
|
finalizeLifetimeExceptionPtr, std::move(completion)));
|
||||||
|
}
|
||||||
|
|
||||||
|
MrnttNonViralPostingInvoker MarionetteComponent::initializeCReq(
|
||||||
|
[[maybe_unused]] std::exception_ptr &exceptionPtr,
|
||||||
|
[[maybe_unused]] std::function<void()> callback)
|
||||||
|
{
|
||||||
|
assertMarionetteThread();
|
||||||
|
|
||||||
smo::mind::globalMind = std::make_shared<smo::Mind>();
|
smo::mind::globalMind = std::make_shared<smo::Mind>();
|
||||||
smo::mind::globalMind->initializeReq({context, std::bind(
|
|
||||||
&MrnttLifetimeMgmtOp::initializeReq2,
|
|
||||||
this, context, std::placeholders::_1)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeReq2(
|
bool mindInitialized = co_await smo::mind::globalMind->initializeCReq();
|
||||||
std::shared_ptr<MrnttLifetimeMgmtOp> context,
|
if (!mindInitialized)
|
||||||
bool success
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (!success)
|
|
||||||
{
|
{
|
||||||
std::cerr << __func__ << ": Failed to initialize globalMind"
|
std::cerr << __func__ << ": Failed to initialize globalMind"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
context->callOriginalCb(false);
|
co_return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
smo::device::DeviceManager::getInstance().initializeDeviceReattacher();
|
smo::device::DeviceManager::getInstance().initializeDeviceReattacher();
|
||||||
@@ -65,126 +63,30 @@ public:
|
|||||||
// Call negtrinEventInd on the Director in the final callback
|
// Call negtrinEventInd on the Director in the final callback
|
||||||
smo::mind::globalMind->director.negtrinEventInd();
|
smo::mind::globalMind->director.negtrinEventInd();
|
||||||
|
|
||||||
context->callOriginalCb(success);
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalizeReq1_posted(
|
MrnttNonViralPostingInvoker MarionetteComponent::finalizeCReq(
|
||||||
[[maybe_unused]] std::shared_ptr<MrnttLifetimeMgmtOp> context
|
[[maybe_unused]] std::exception_ptr &exceptionPtr,
|
||||||
)
|
[[maybe_unused]] std::function<void()> callback)
|
||||||
{
|
{
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
assertMarionetteThread();
|
||||||
if (self->id != smo::SmoThreadId::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": Must be executed on Marionette thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
smo::device::DeviceManager::getInstance().finalizeDeviceReattacher();
|
smo::device::DeviceManager::getInstance().finalizeDeviceReattacher();
|
||||||
|
|
||||||
/** FIXME:
|
if (!smo::mind::globalMind)
|
||||||
* It may be necessary to add a delay here to ensure that all in-flight
|
{
|
||||||
* timer timeouts have finished executing? Or some other mechanism.
|
co_return;
|
||||||
*
|
|
||||||
* We need some way to ensure that in-flight timeouts don't get fired
|
|
||||||
* during the finalize sequence. This is because they may depend on
|
|
||||||
* state that is being finalized or has been finalized at the point
|
|
||||||
* when they timeout.
|
|
||||||
*
|
|
||||||
* This seems to be actually happening with the delayed calls to
|
|
||||||
* AttachDeviceReq::attachDeviceReq2() inside of livoxGen1.cpp.
|
|
||||||
*
|
|
||||||
* One tactic might be to shut down device reattacher before finalizing
|
|
||||||
* and pause for a bit before continuing to shutdown other components.
|
|
||||||
*/
|
|
||||||
|
|
||||||
smo::mind::globalMind->finalizeReq({context, std::bind(
|
|
||||||
&MrnttLifetimeMgmtOp::finalizeReq2,
|
|
||||||
this, context, std::placeholders::_1)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalizeReq2(
|
bool mindFinalized = co_await smo::mind::globalMind->finalizeCReq();
|
||||||
std::shared_ptr<MrnttLifetimeMgmtOp> context,
|
if (!mindFinalized)
|
||||||
bool success
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (!success)
|
|
||||||
{
|
{
|
||||||
std::cerr << __func__ << ": globalMind finalization failed"
|
std::cerr << __func__ << ": globalMind finalization failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
context->callOriginalCb(false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context->callOriginalCb(success);
|
co_return;
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class MarionetteComponent::TerminationEvent
|
|
||||||
: public sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TerminationEvent(
|
|
||||||
const std::shared_ptr<sscl::ComponentThread> &caller)
|
|
||||||
: sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
|
|
||||||
caller, {nullptr, nullptr})
|
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void exceptionInd1_posted(
|
|
||||||
[[maybe_unused]] std::shared_ptr<TerminationEvent> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
|
||||||
if (self->id != smo::SmoThreadId::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": Must be executed on Marionette thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
smo::mrntt::mrntt.finalizeReq({nullptr, std::bind(
|
|
||||||
&smo::mrntt::marionetteFinalizeReqCb,
|
|
||||||
std::placeholders::_1)});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void MarionetteComponent::initializeReq(
|
|
||||||
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
|
|
||||||
{
|
|
||||||
auto mrntt = sscl::ComponentThread::getSelf();
|
|
||||||
|
|
||||||
if (mrntt->id != smo::SmoThreadId::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": Must be executed on Marionette thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto request = std::make_shared<MrnttLifetimeMgmtOp>(
|
|
||||||
*this, mrntt, callback);
|
|
||||||
|
|
||||||
mrntt->getIoService().post(
|
|
||||||
STC(std::bind(
|
|
||||||
&MrnttLifetimeMgmtOp::initializeReq1_posted,
|
|
||||||
request.get(), request)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarionetteComponent::finalizeReq(
|
|
||||||
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
|
|
||||||
{
|
|
||||||
auto mrntt = sscl::ComponentThread::getSelf();
|
|
||||||
|
|
||||||
if (mrntt->id != smo::SmoThreadId::MRNTT)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__func__)
|
|
||||||
+ ": Must be executed on Marionette thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto request = std::make_shared<MrnttLifetimeMgmtOp>(
|
|
||||||
*this, mrntt, callback);
|
|
||||||
|
|
||||||
mrntt->getIoService().post(
|
|
||||||
STC(std::bind(
|
|
||||||
&MrnttLifetimeMgmtOp::finalizeReq1_posted,
|
|
||||||
request.get(), request)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarionetteComponent::handleLoopExceptionHook()
|
void MarionetteComponent::handleLoopExceptionHook()
|
||||||
@@ -195,16 +97,15 @@ void MarionetteComponent::handleLoopExceptionHook()
|
|||||||
|
|
||||||
void MarionetteComponent::exceptionInd()
|
void MarionetteComponent::exceptionInd()
|
||||||
{
|
{
|
||||||
auto faultyThread = sscl::ComponentThread::getSelf();
|
auto puppeteer = sscl::ComponentThread::getPptr();
|
||||||
auto mrntt = sscl::ComponentThread::getPptr();
|
|
||||||
|
|
||||||
auto request = std::make_shared<TerminationEvent>(
|
boost::asio::post(
|
||||||
faultyThread);
|
puppeteer->getIoService(),
|
||||||
|
[]
|
||||||
mrntt->getIoService().post(
|
{
|
||||||
STC(std::bind(
|
mrntt.holdFinalizeCReq(
|
||||||
&TerminationEvent::exceptionInd1_posted,
|
[]() { marionetteFinalizeReqCb(true); });
|
||||||
request.get(), request)));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mrntt
|
} // namespace mrntt
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ void marionetteInitializeReqCb(bool success)
|
|||||||
std::cerr << __func__ << ": Failed to initialize Marionette. Shutting down."
|
std::cerr << __func__ << ": Failed to initialize Marionette. Shutting down."
|
||||||
<< '\n';
|
<< '\n';
|
||||||
|
|
||||||
mrntt.finalizeReq({nullptr, std::bind(
|
mrntt.holdFinalizeCReq(
|
||||||
&smo::mrntt::marionetteFinalizeReqCb,
|
[]() { marionetteFinalizeReqCb(true); });
|
||||||
std::placeholders::_1)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void marionetteFinalizeReqCb(bool success)
|
void marionetteFinalizeReqCb(bool success)
|
||||||
@@ -83,9 +82,8 @@ void MarionetteComponent::postJoltHook()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mrntt.finalizeReq({nullptr, std::bind(
|
mrntt.holdFinalizeCReq(
|
||||||
&marionetteFinalizeReqCb,
|
[]() { marionetteFinalizeReqCb(true); });
|
||||||
std::placeholders::_1)});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,9 +129,12 @@ void MarionetteComponent::preLoopHook()
|
|||||||
smo::initializeSalmanoff();
|
smo::initializeSalmanoff();
|
||||||
callShutdownSalmanoff = true;
|
callShutdownSalmanoff = true;
|
||||||
|
|
||||||
initializeReq(sscl::Callback<mrnttLifetimeMgmtOpCbFn>{
|
holdInitializeCReq(
|
||||||
nullptr,
|
[]
|
||||||
std::bind(&marionetteInitializeReqCb, std::placeholders::_1)});
|
{
|
||||||
|
marionetteInitializeReqCb(
|
||||||
|
!mrntt.initializeLifetimeExceptionPtr);
|
||||||
|
});
|
||||||
|
|
||||||
std::cout << "PuppeteerThread::main: Entering event loop" << "\n";
|
std::cout << "PuppeteerThread::main: Entering event loop" << "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-134
@@ -2,11 +2,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
|
||||||
#include <spinscale/asynchronousLoop.h>
|
|
||||||
#include <spinscale/callback.h>
|
|
||||||
#include <spinscale/callableTracer.h>
|
|
||||||
#include <spinscale/componentThread.h>
|
|
||||||
#include <mind.h>
|
#include <mind.h>
|
||||||
#include <mindThread.h>
|
#include <mindThread.h>
|
||||||
#include <director/director.h>
|
#include <director/director.h>
|
||||||
@@ -111,121 +106,8 @@ Mind::getMindThreads() const
|
|||||||
return mindThreads;
|
return mindThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mind::MindLifetimeMgmtOp
|
mrntt::MrnttViralNonPostingInvokerT<bool> Mind::initializeCReq()
|
||||||
: public sscl::PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
MindLifetimeMgmtOp(
|
|
||||||
Mind &parent, const std::shared_ptr<sscl::ComponentThread> &caller,
|
|
||||||
sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
|
|
||||||
: sscl::PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>(
|
|
||||||
caller, callback),
|
|
||||||
parent(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
|
||||||
Mind &parent;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void initializeReq1_posted(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
/* Jolt the threads, then start them */
|
|
||||||
parent.joltAllPuppetThreadsReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&MindLifetimeMgmtOp::initializeReq2,
|
|
||||||
context.get(), context)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeReq2(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
|
||||||
|
|
||||||
parent.startAllPuppetThreadsReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&MindLifetimeMgmtOp::initializeReq3,
|
|
||||||
context.get(), context)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeReq3(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: All mind threads started." << "\n";
|
|
||||||
|
|
||||||
parent.body.initializeReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&MindLifetimeMgmtOp::initializeReq4,
|
|
||||||
context.get(), context, std::placeholders::_1)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeReq4(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
|
||||||
bool success
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: Body component initialized." << "\n";
|
|
||||||
callOriginalCb(success);
|
|
||||||
}
|
|
||||||
|
|
||||||
void finalizeReq1_posted(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
parent.body.finalizeReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&MindLifetimeMgmtOp::finalizeReq2,
|
|
||||||
context.get(), context, std::placeholders::_1)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void finalizeReq2(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context,
|
|
||||||
bool success
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (!success) {
|
|
||||||
std::cerr << "Mrntt: Body component failed to finalize." << "\n";
|
|
||||||
} else {
|
|
||||||
std::cout << "Mrntt: Body component finalized." << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the threads haven't been jolted, we need to do that first, because
|
|
||||||
* otherwise they'll just enter their main loops and wait for control
|
|
||||||
* messages from mrntt after processing the exit request.
|
|
||||||
*/
|
|
||||||
parent.joltAllPuppetThreadsReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&MindLifetimeMgmtOp::finalizeReq3,
|
|
||||||
context.get(), context)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void finalizeReq3(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: All mind threads JOLTed for finalization." << "\n";
|
|
||||||
|
|
||||||
parent.exitAllPuppetThreadsReq(
|
|
||||||
{context, std::bind(
|
|
||||||
&MindLifetimeMgmtOp::finalizeReq4,
|
|
||||||
context.get(), context)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void finalizeReq4(
|
|
||||||
[[maybe_unused]] std::shared_ptr<MindLifetimeMgmtOp> context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cout << "Mrntt: All mind threads exited." << "\n";
|
|
||||||
callOriginalCb(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void Mind::initializeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
|
|
||||||
{
|
|
||||||
/* Distribute threads across available CPUs */
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
distributeAndPinThreadsAcrossCpus();
|
distributeAndPinThreadsAcrossCpus();
|
||||||
@@ -237,26 +119,34 @@ void Mind::initializeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
|
|||||||
"Error: " << e.what() << "\n";
|
"Error: " << e.what() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& caller = sscl::ComponentThread::getSelf();
|
co_await joltAllPuppetThreadsCReq();
|
||||||
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
||||||
*this, caller, callback);
|
|
||||||
|
|
||||||
mrntt::mrntt.thread->getIoService().post(
|
co_await startAllPuppetThreadsCReq();
|
||||||
STC(std::bind(
|
std::cout << "Mrntt: All mind threads started." << "\n";
|
||||||
&MindLifetimeMgmtOp::initializeReq1_posted,
|
|
||||||
request.get(), request)));
|
bool bodyInitialized = co_await body.initializeCReq();
|
||||||
|
std::cout << "Mrntt: Body component initialized." << "\n";
|
||||||
|
|
||||||
|
co_return bodyInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mind::finalizeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
|
mrntt::MrnttViralNonPostingInvokerT<bool> Mind::finalizeCReq()
|
||||||
{
|
{
|
||||||
const auto& caller = sscl::ComponentThread::getSelf();
|
bool bodyFinalized = co_await body.finalizeCReq();
|
||||||
auto request = std::make_shared<MindLifetimeMgmtOp>(
|
if (!bodyFinalized) {
|
||||||
*this, caller, callback);
|
std::cerr << "Mrntt: Body component failed to finalize." << "\n";
|
||||||
|
} else {
|
||||||
|
std::cout << "Mrntt: Body component finalized." << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
mrntt::mrntt.thread->getIoService().post(
|
co_await joltAllPuppetThreadsCReq();
|
||||||
STC(std::bind(
|
std::cout << "Mrntt: All mind threads JOLTed for finalization." << "\n";
|
||||||
&MindLifetimeMgmtOp::finalizeReq1_posted,
|
|
||||||
request.get(), request)));
|
co_await exitAllPuppetThreadsCReq();
|
||||||
|
std::cout << "Mrntt: All mind threads exited." << "\n";
|
||||||
|
|
||||||
|
co_return bodyFinalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <spinscale/callableTracer.h>
|
#include <spinscale/cps/callableTracer.h>
|
||||||
|
|
||||||
|
|
||||||
OptionParser::Exception::Exception(std::string message_)
|
OptionParser::Exception::Exception(std::string message_)
|
||||||
@@ -107,7 +107,7 @@ void OptionParser::parseArguments(int argc, char *argv[], char **envp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sscl::CallableTracer::optTraceCallables = traceCallables;
|
sscl::cps::CallableTracer::optTraceCallables = traceCallables;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string OptionParser::getUsage() const
|
std::string OptionParser::getUsage() const
|
||||||
|
|||||||
@@ -5,10 +5,6 @@
|
|||||||
#include <stimBuffApis/stimBuffApiManager.h>
|
#include <stimBuffApis/stimBuffApiManager.h>
|
||||||
#include <stimBuffApis/stimBuffApiLib.h>
|
#include <stimBuffApis/stimBuffApiLib.h>
|
||||||
#include <opts.h>
|
#include <opts.h>
|
||||||
#include <spinscale/asynchronousBridge.h>
|
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
|
||||||
#include <spinscale/asynchronousLoop.h>
|
|
||||||
#include <spinscale/callback.h>
|
|
||||||
#include <user/senseApiDesc.h>
|
#include <user/senseApiDesc.h>
|
||||||
#include <mind.h>
|
#include <mind.h>
|
||||||
#include <deviceManager/deviceManager.h>
|
#include <deviceManager/deviceManager.h>
|
||||||
@@ -198,47 +194,50 @@ StimBuffApiLib& StimBuffApiManager::loadStimBuffApiLib(
|
|||||||
auto lib = std::make_shared<StimBuffApiLib>(
|
auto lib = std::make_shared<StimBuffApiLib>(
|
||||||
libraryPath, dlopen_handle.release(), func);
|
libraryPath, dlopen_handle.release(), func);
|
||||||
lib->setStimBuffApiDesc(libApiDesc);
|
lib->setStimBuffApiDesc(libApiDesc);
|
||||||
stimBuffApiLibs.push_back(lib);
|
getInstance().s.rsrc.stimBuffApiLibs.push_back(lib);
|
||||||
return *stimBuffApiLibs.back();
|
return *getInstance().s.rsrc.stimBuffApiLibs.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::shared_ptr<StimBuffApiLib>>
|
std::optional<std::shared_ptr<StimBuffApiLib>>
|
||||||
StimBuffApiManager::getStimBuffApiLib(const std::string& libraryPath)
|
StimBuffApiManager::getStimBuffApiLib(const std::string& libraryPath)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
|
auto &libs = getInstance().s.rsrc.stimBuffApiLibs;
|
||||||
|
auto it = std::find_if(libs.begin(), libs.end(),
|
||||||
[&libPath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
|
[&libPath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
|
||||||
return lib->libraryPath == libPath;
|
return lib->libraryPath == libPath;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (it != stimBuffApiLibs.end()) { return *it; }
|
if (it != libs.end()) { return *it; }
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::shared_ptr<StimBuffApiLib>>
|
std::optional<std::shared_ptr<StimBuffApiLib>>
|
||||||
StimBuffApiManager::getStimBuffApiLibByApiName(const std::string& apiName)
|
StimBuffApiManager::getStimBuffApiLibByApiName(const std::string& apiName)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
|
auto &libs = getInstance().s.rsrc.stimBuffApiLibs;
|
||||||
|
auto it = std::find_if(libs.begin(), libs.end(),
|
||||||
[&apiName](const std::shared_ptr<StimBuffApiLib>& lib) {
|
[&apiName](const std::shared_ptr<StimBuffApiLib>& lib) {
|
||||||
return lib->stimBuffApiDesc.name == apiName;
|
return lib->stimBuffApiDesc.name == apiName;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (it != stimBuffApiLibs.end()) { return *it; }
|
if (it != libs.end()) { return *it; }
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StimBuffApiManager::unloadStimBuffApiLib(const std::string& libraryPath)
|
void StimBuffApiManager::unloadStimBuffApiLib(const std::string& libraryPath)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(stimBuffApiLibs.begin(), stimBuffApiLibs.end(),
|
auto &libs = getInstance().s.rsrc.stimBuffApiLibs;
|
||||||
|
auto it = std::find_if(libs.begin(), libs.end(),
|
||||||
[&lpath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
|
[&lpath = libraryPath](const std::shared_ptr<StimBuffApiLib>& lib) {
|
||||||
return lib->libraryPath == lpath;
|
return lib->libraryPath == lpath;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (it != stimBuffApiLibs.end())
|
if (it != libs.end())
|
||||||
{
|
{
|
||||||
stimBuffApiLibs.erase(it);
|
libs.erase(it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +247,7 @@ void StimBuffApiManager::unloadStimBuffApiLib(const std::string& libraryPath)
|
|||||||
|
|
||||||
void StimBuffApiManager::unloadAllStimBuffApiLibs(void)
|
void StimBuffApiManager::unloadAllStimBuffApiLibs(void)
|
||||||
{
|
{
|
||||||
stimBuffApiLibs.clear();
|
getInstance().s.rsrc.stimBuffApiLibs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
|
void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
|
||||||
@@ -264,7 +263,7 @@ void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
|
|||||||
std::string StimBuffApiManager::stringifyLibs() const
|
std::string StimBuffApiManager::stringifyLibs() const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
for (const auto& lib : stimBuffApiLibs) {
|
for (const auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||||
result += lib->stringify() + "\n";
|
result += lib->stringify() + "\n";
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -303,14 +302,14 @@ void StimBuffApiManager::finalizeStimBuffApiLib(StimBuffApiLib& lib)
|
|||||||
|
|
||||||
void StimBuffApiManager::initializeAllStimBuffApiLibs(void)
|
void StimBuffApiManager::initializeAllStimBuffApiLibs(void)
|
||||||
{
|
{
|
||||||
for (auto& lib : stimBuffApiLibs) {
|
for (auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||||
initializeStimBuffApiLib(*lib);
|
initializeStimBuffApiLib(*lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StimBuffApiManager::finalizeAllStimBuffApiLibs(void)
|
void StimBuffApiManager::finalizeAllStimBuffApiLibs(void)
|
||||||
{
|
{
|
||||||
for (auto& lib : stimBuffApiLibs) {
|
for (auto& lib : getInstance().s.rsrc.stimBuffApiLibs) {
|
||||||
finalizeStimBuffApiLib(*lib);
|
finalizeStimBuffApiLib(*lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
#include <boost/system/error_code.hpp>
|
#include <boost/system/error_code.hpp>
|
||||||
#include <livoxProto1/device.h>
|
#include <livoxProto1/device.h>
|
||||||
#include <livoxProto1/livoxProto1.h>
|
#include <livoxProto1/livoxProto1.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
#include <spinscale/asynchronousLoop.h>
|
||||||
#include <spinscale/asynchronousBridge.h>
|
#include <spinscale/cps/asynchronousBridge.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <spinscale/callableTracer.h>
|
#include <spinscale/cps/callableTracer.h>
|
||||||
#include <spinscale/spinLock.h>
|
#include <spinscale/spinLock.h>
|
||||||
#include "ioUringAssemblyEngine.h"
|
#include "ioUringAssemblyEngine.h"
|
||||||
#include "pcloudStimulusProducer.h"
|
#include "pcloudStimulusProducer.h"
|
||||||
@@ -175,7 +175,7 @@ void IoUringAssemblyEngine::finalize()
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService();
|
auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService();
|
||||||
sscl::AsynchronousBridge bridge(ioService);
|
sscl::cps::AsynchronousBridge bridge(ioService);
|
||||||
boost::asio::deadline_timer timeoutTimer(ioService);
|
boost::asio::deadline_timer timeoutTimer(ioService);
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
@@ -420,15 +420,15 @@ cleanup_eventfd:
|
|||||||
|
|
||||||
// Continuation class for assembleFrameReq
|
// Continuation class for assembleFrameReq
|
||||||
class IoUringAssemblyEngine::AssembleFrameReq
|
class IoUringAssemblyEngine::AssembleFrameReq
|
||||||
: public sscl::PostedAsynchronousContinuation<
|
: public sscl::cps::PostedAsynchronousContinuation<
|
||||||
IoUringAssemblyEngine::assembleFrameReqCbFn>
|
IoUringAssemblyEngine::assembleFrameReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AssembleFrameReq(
|
AssembleFrameReq(
|
||||||
IoUringAssemblyEngine& engine_,
|
IoUringAssemblyEngine& engine_,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& caller,
|
const std::shared_ptr<sscl::ComponentThread>& caller,
|
||||||
sscl::Callback<IoUringAssemblyEngine::assembleFrameReqCbFn> cb)
|
sscl::cps::Callback<IoUringAssemblyEngine::assembleFrameReqCbFn> cb)
|
||||||
: sscl::PostedAsynchronousContinuation<
|
: sscl::cps::PostedAsynchronousContinuation<
|
||||||
IoUringAssemblyEngine::assembleFrameReqCbFn>(caller, cb),
|
IoUringAssemblyEngine::assembleFrameReqCbFn>(caller, cb),
|
||||||
engine(engine_),
|
engine(engine_),
|
||||||
loop(engine_.frameAssemblyDesc->numSlots),
|
loop(engine_.frameAssemblyDesc->numSlots),
|
||||||
@@ -635,7 +635,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void IoUringAssemblyEngine::assembleFrameReq(
|
void IoUringAssemblyEngine::assembleFrameReq(
|
||||||
sscl::Callback<assembleFrameReqCbFn> cb)
|
sscl::cps::Callback<assembleFrameReqCbFn> cb)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
|
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
|
||||||
|
|||||||
@@ -16,9 +16,9 @@
|
|||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||||
#include <livoxProto1/device.h>
|
#include <livoxProto1/device.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
#include <spinscale/asynchronousLoop.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <spinscale/spinLock.h>
|
#include <spinscale/spinLock.h>
|
||||||
#include <user/frameAssemblyDesc.h>
|
#include <user/frameAssemblyDesc.h>
|
||||||
#include <user/stagingBuffer.h>
|
#include <user/stagingBuffer.h>
|
||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
void finalize();
|
void finalize();
|
||||||
|
|
||||||
typedef std::function<void(bool, sscl::AsynchronousLoop)> assembleFrameReqCbFn;
|
typedef std::function<void(bool, sscl::AsynchronousLoop)> assembleFrameReqCbFn;
|
||||||
void assembleFrameReq(sscl::Callback<assembleFrameReqCbFn> cb);
|
void assembleFrameReq(sscl::cps::Callback<assembleFrameReqCbFn> cb);
|
||||||
|
|
||||||
// Telemetry helpers
|
// Telemetry helpers
|
||||||
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
|
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
#include <user/senseApiDesc.h>
|
#include <user/senseApiDesc.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <user/intrinThresholdParams.h>
|
#include <user/intrinThresholdParams.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <livoxProto1/livoxProto1.h>
|
#include <livoxProto1/livoxProto1.h>
|
||||||
#include <livoxProto1/device.h>
|
#include <livoxProto1/device.h>
|
||||||
#include <livoxProto1/protocol.h>
|
#include <livoxProto1/protocol.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
#include "pcloudStimulusProducer.h"
|
#include "pcloudStimulusProducer.h"
|
||||||
#include "livoxGen1.h"
|
#include "livoxGen1.h"
|
||||||
@@ -91,13 +91,13 @@ LivoxProto1DllState livoxProto1;
|
|||||||
|
|
||||||
// Continuation classes for async operations
|
// Continuation classes for async operations
|
||||||
class AttachDeviceReq
|
class AttachDeviceReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>
|
: public sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AttachDeviceReq(
|
AttachDeviceReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
|
||||||
sscl::Callback<sal_mlo_attachDeviceReqCbFn> cb)
|
sscl::cps::Callback<sal_mlo_attachDeviceReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>(
|
: sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>(
|
||||||
std::move(cb)),
|
std::move(cb)),
|
||||||
spec(spec)
|
spec(spec)
|
||||||
{}
|
{}
|
||||||
@@ -360,14 +360,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class DetachDeviceReq
|
class DetachDeviceReq
|
||||||
: public sscl::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>
|
: public sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DetachDeviceReq(
|
DetachDeviceReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
|
||||||
const std::shared_ptr<StimulusBuffer>& stimBuffer,
|
const std::shared_ptr<StimulusBuffer>& stimBuffer,
|
||||||
sscl::Callback<sal_mlo_detachDeviceReqCbFn> cb)
|
sscl::cps::Callback<sal_mlo_detachDeviceReqCbFn> cb)
|
||||||
: sscl::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>(
|
: sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>(
|
||||||
std::move(cb)),
|
std::move(cb)),
|
||||||
spec(spec), stimBuffer(stimBuffer)
|
spec(spec), stimBuffer(stimBuffer)
|
||||||
{}
|
{}
|
||||||
@@ -625,7 +625,7 @@ extern "C" int livoxGen1_finalizeInd(void)
|
|||||||
extern "C" void livoxGen1_attachDeviceReq(
|
extern "C" void livoxGen1_attachDeviceReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
||||||
sscl::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
|
sscl::cps::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!livoxProto1.livoxProto1_getOrCreateDeviceReq)
|
if (!livoxProto1.livoxProto1_getOrCreateDeviceReq)
|
||||||
@@ -825,7 +825,7 @@ extern "C" void livoxGen1_attachDeviceReq(
|
|||||||
|
|
||||||
extern "C" void livoxGen1_detachDeviceReq(
|
extern "C" void livoxGen1_detachDeviceReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
||||||
sscl::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
|
sscl::cps::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Case 1: Check if StimBuffer doesn't exist (early return)
|
// Case 1: Check if StimBuffer doesn't exist (early return)
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/system/error_code.hpp>
|
#include <boost/system/error_code.hpp>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/deadline_timer.hpp>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <spinscale/asynchronousBridge.h>
|
#include <spinscale/cps/asynchronousBridge.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
#include <spinscale/asynchronousLoop.h>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <user/stimulusFrame.h>
|
#include <user/stimulusFrame.h>
|
||||||
@@ -229,7 +229,7 @@ void OpenClCollatingAndMeshingEngine::finalize()
|
|||||||
int delayMs = std::max(OCLCOLLMESH_ENGN_FINALIZE_DELAY_MS, 0);
|
int delayMs = std::max(OCLCOLLMESH_ENGN_FINALIZE_DELAY_MS, 0);
|
||||||
|
|
||||||
auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService();
|
auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService();
|
||||||
sscl::AsynchronousBridge bridge(ioService);
|
sscl::cps::AsynchronousBridge bridge(ioService);
|
||||||
boost::asio::deadline_timer timeoutTimer(ioService);
|
boost::asio::deadline_timer timeoutTimer(ioService);
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
@@ -1008,7 +1008,7 @@ void OpenClCollatingAndMeshingEngine::produceAmbienceStimulusFrame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OpenClCollatingAndMeshingEngine::CompactCollateAndMeshFrameReq
|
class OpenClCollatingAndMeshingEngine::CompactCollateAndMeshFrameReq
|
||||||
: public sscl::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>
|
: public sscl::cps::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
OpenClCollatingAndMeshingEngine& engine;
|
OpenClCollatingAndMeshingEngine& engine;
|
||||||
@@ -1027,8 +1027,8 @@ public:
|
|||||||
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc_,
|
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc_,
|
||||||
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc_,
|
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc_,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& caller,
|
const std::shared_ptr<sscl::ComponentThread>& caller,
|
||||||
sscl::Callback<compactCollateAndMeshFrameReqCbFn> cb)
|
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> cb)
|
||||||
: sscl::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>(
|
: sscl::cps::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>(
|
||||||
caller, cb),
|
caller, cb),
|
||||||
engine(engine_),
|
engine(engine_),
|
||||||
frameAssemblyResult(asyncLoop), stimulusFrame(stimulusFrame_),
|
frameAssemblyResult(asyncLoop), stimulusFrame(stimulusFrame_),
|
||||||
@@ -1253,7 +1253,7 @@ void OpenClCollatingAndMeshingEngine::compactCollateAndMeshFrameReq(
|
|||||||
std::optional<std::reference_wrapper<StimulusFrame>> intensityStimFrame,
|
std::optional<std::reference_wrapper<StimulusFrame>> intensityStimFrame,
|
||||||
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc,
|
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc,
|
||||||
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc,
|
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc,
|
||||||
sscl::Callback<compactCollateAndMeshFrameReqCbFn> callback)
|
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> callback)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
|
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#define CL_TARGET_OPENCL_VERSION 120
|
#define CL_TARGET_OPENCL_VERSION 120
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
#include <spinscale/asynchronousLoop.h>
|
#include <spinscale/asynchronousLoop.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <spinscale/spinLock.h>
|
#include <spinscale/spinLock.h>
|
||||||
#include <user/stimulusFrame.h>
|
#include <user/stimulusFrame.h>
|
||||||
#include <user/stagingBuffer.h>
|
#include <user/stagingBuffer.h>
|
||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
std::optional<std::reference_wrapper<StimulusFrame>> intensityStimFrame,
|
std::optional<std::reference_wrapper<StimulusFrame>> intensityStimFrame,
|
||||||
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc,
|
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc,
|
||||||
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc,
|
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc,
|
||||||
sscl::Callback<compactCollateAndMeshFrameReqCbFn> callback);
|
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Callback function types
|
// Callback function types
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ void PcloudStimulusProducer::stimFrameProductionTimesliceInd()
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PcloudStimulusProducer::ProduceFrameReq
|
class PcloudStimulusProducer::ProduceFrameReq
|
||||||
: public sscl::PostedAsynchronousContinuation<produceFrameReqCbFn>
|
: public sscl::cps::PostedAsynchronousContinuation<produceFrameReqCbFn>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
PcloudStimulusProducer& pcloudProducer;
|
PcloudStimulusProducer& pcloudProducer;
|
||||||
@@ -440,8 +440,8 @@ public:
|
|||||||
ProduceFrameReq(
|
ProduceFrameReq(
|
||||||
PcloudStimulusProducer& producer,
|
PcloudStimulusProducer& producer,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& caller,
|
const std::shared_ptr<sscl::ComponentThread>& caller,
|
||||||
sscl::Callback<produceFrameReqCbFn> cb)
|
sscl::cps::Callback<produceFrameReqCbFn> cb)
|
||||||
: sscl::PostedAsynchronousContinuation<produceFrameReqCbFn>(caller, cb),
|
: sscl::cps::PostedAsynchronousContinuation<produceFrameReqCbFn>(caller, cb),
|
||||||
pcloudProducer(producer),
|
pcloudProducer(producer),
|
||||||
frameAssemblyResult(0),
|
frameAssemblyResult(0),
|
||||||
stimulusFrame(producer.tempStimulusFrame)
|
stimulusFrame(producer.tempStimulusFrame)
|
||||||
@@ -724,7 +724,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void PcloudStimulusProducer::produceFrameReq(
|
void PcloudStimulusProducer::produceFrameReq(
|
||||||
sscl::Callback<produceFrameReqCbFn> callback)
|
sscl::cps::Callback<produceFrameReqCbFn> callback)
|
||||||
{
|
{
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
* We shouldn't acquire the StimulusProducer::shouldContinueLock here because
|
* We shouldn't acquire the StimulusProducer::shouldContinueLock here because
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
#include <user/stimulusProducer.h>
|
#include <user/stimulusProducer.h>
|
||||||
#include <user/stimulusFrame.h>
|
#include <user/stimulusFrame.h>
|
||||||
#include <livoxProto1/device.h>
|
#include <livoxProto1/device.h>
|
||||||
#include <spinscale/asynchronousContinuation.h>
|
#include <spinscale/cps/asynchronousContinuation.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <user/stagingBuffer.h>
|
#include <user/stagingBuffer.h>
|
||||||
#include "ioUringAssemblyEngine.h"
|
#include "ioUringAssemblyEngine.h"
|
||||||
#include "livoxPcloudFrameDumper.h"
|
#include "livoxPcloudFrameDumper.h"
|
||||||
@@ -87,7 +87,7 @@ protected:
|
|||||||
typedef std::function<void()> produceFrameReqCbFn;
|
typedef std::function<void()> produceFrameReqCbFn;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void produceFrameReq(sscl::Callback<produceFrameReqCbFn> callback);
|
void produceFrameReq(sscl::cps::Callback<produceFrameReqCbFn> callback);
|
||||||
|
|
||||||
size_t nDgramsPerStagingBufferFrame;
|
size_t nDgramsPerStagingBufferFrame;
|
||||||
std::shared_ptr<livoxProto1::Device> device;
|
std::shared_ptr<livoxProto1::Device> device;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <user/senseApiDesc.h>
|
#include <user/senseApiDesc.h>
|
||||||
#include <user/deviceAttachmentSpec.h>
|
#include <user/deviceAttachmentSpec.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/cps/callback.h>
|
||||||
#include <xcbXorg/xcbXorg.h>
|
#include <xcbXorg/xcbXorg.h>
|
||||||
#include "xcbWindow.h"
|
#include "xcbWindow.h"
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ static int xcbWindow_finalizeInd(void)
|
|||||||
static void xcbWindow_attachDeviceReq(
|
static void xcbWindow_attachDeviceReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
|
||||||
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
||||||
sscl::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
|
sscl::cps::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Not used yet, but may be used later.
|
// Not used yet, but may be used later.
|
||||||
@@ -302,7 +302,7 @@ static void xcbWindow_attachDeviceReq(
|
|||||||
|
|
||||||
static void xcbWindow_detachDeviceReq(
|
static void xcbWindow_detachDeviceReq(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
|
||||||
sscl::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
|
sscl::cps::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),
|
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <spinscale/qutex.h>
|
#include <spinscale/cps/qutex.h>
|
||||||
#include <spinscale/lockerAndInvokerBase.h>
|
#include <spinscale/cps/lockerAndInvokerBase.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -9,18 +9,18 @@
|
|||||||
namespace smo {
|
namespace smo {
|
||||||
|
|
||||||
// Mock implementation of LockerAndInvokerBase for testing
|
// Mock implementation of LockerAndInvokerBase for testing
|
||||||
class MockLockerAndInvoker : public LockerAndInvokerBase {
|
class MockLockerAndInvoker : public sscl::cps::LockerAndInvokerBase {
|
||||||
public:
|
public:
|
||||||
explicit MockLockerAndInvoker(const void* addr)
|
explicit MockLockerAndInvoker(const void* addr)
|
||||||
: LockerAndInvokerBase(addr), awakened(false) {}
|
: sscl::cps::LockerAndInvokerBase(addr), awakened(false) {}
|
||||||
|
|
||||||
bool awakened;
|
bool awakened;
|
||||||
sscl::Qutex* registeredQutex = nullptr;
|
sscl::cps::Qutex* registeredQutex = nullptr;
|
||||||
List::iterator queueIterator;
|
sscl::cps::LockerAndInvokerBase::List::iterator queueIterator;
|
||||||
|
|
||||||
List::iterator getLockvokerIteratorForQutex(sscl::Qutex& qutex) override {
|
sscl::cps::LockerAndInvokerBase::List::iterator getLockvokerIteratorForQutex(sscl::cps::Qutex& qutex) override {
|
||||||
registeredQutex = &qutex;
|
registeredQutex = &qutex;
|
||||||
queueIterator = qutex.registerInQueue(std::shared_ptr<LockerAndInvokerBase>(this));
|
queueIterator = qutex.registerInQueue(std::shared_ptr<sscl::cps::LockerAndInvokerBase>(this));
|
||||||
return queueIterator;
|
return queueIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ protected:
|
|||||||
// Clean up
|
// Clean up
|
||||||
}
|
}
|
||||||
|
|
||||||
sscl::Qutex qutex;
|
sscl::cps::Qutex qutex;
|
||||||
std::shared_ptr<MockLockerAndInvoker> mock1, mock2, mock3, mock4, mock5;
|
std::shared_ptr<MockLockerAndInvoker> mock1, mock2, mock3, mock4, mock5;
|
||||||
|
|
||||||
// Unique addresses for testing
|
// Unique addresses for testing
|
||||||
|
|||||||
Reference in New Issue
Block a user