Spinscale: create new namespace sscl

This commit is contained in:
2025-12-27 16:21:22 -04:00
parent 0c4f427c0a
commit 34d76df7d9
67 changed files with 434 additions and 429 deletions
+16 -16
View File
@@ -14,32 +14,32 @@
namespace smo {
namespace body {
Body::Body(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
: PuppetComponent(parent, thread)
Body::Body(Mind &parent, const std::shared_ptr<sscl::ComponentThread> &thread)
: sscl::PuppetComponent(static_cast<sscl::PuppetApplication&>(parent), thread)
{
}
class Body::InitializeReq
: public PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>
: public sscl::PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>
{
public:
InitializeReq(
PuppetApplication &parent,
const std::shared_ptr<ComponentThread> &caller,
Callback<bodyLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(caller, callback),
sscl::PuppetApplication &parent,
const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<bodyLifetimeMgmtOpCbFn> callback)
: sscl::PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(caller, callback),
parent(parent)
{}
private:
PuppetApplication &parent;
sscl::PuppetApplication &parent;
public:
void initializeReq1_posted(
[[maybe_unused]] std::shared_ptr<InitializeReq> context
)
{
auto self = ComponentThread::getSelf();
auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::BODY)
{
throw std::runtime_error(std::string(__func__)
@@ -94,7 +94,7 @@ public:
void initializeReq2(
[[maybe_unused]] std::shared_ptr<InitializeReq> context,
smo::AsynchronousLoop &results
sscl::AsynchronousLoop &results
)
{
std::cout << "Mrntt: attached "
@@ -116,7 +116,7 @@ public:
[[maybe_unused]] std::shared_ptr<FinalizeReq> context
)
{
auto self = ComponentThread::getSelf();
auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::BODY)
{
throw std::runtime_error(std::string(__func__)
@@ -133,7 +133,7 @@ public:
void finalizeReq2(
[[maybe_unused]] std::shared_ptr<FinalizeReq> context,
smo::AsynchronousLoop &results
sscl::AsynchronousLoop &results
)
{
std::cout << "Mrntt: Successfully detached "
@@ -149,9 +149,9 @@ public:
}
};
void Body::initializeReq(Callback<bodyLifetimeMgmtOpCbFn> callback)
void Body::initializeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
auto mrntt = sscl::ComponentThread::getSelf();
if (mrntt->id != SmoThreadId::MRNTT)
{
@@ -168,9 +168,9 @@ void Body::initializeReq(Callback<bodyLifetimeMgmtOpCbFn> callback)
request.get(), request)));
}
void Body::finalizeReq(Callback<bodyLifetimeMgmtOpCbFn> callback)
void Body::finalizeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
auto mrntt = sscl::ComponentThread::getSelf();
if (mrntt->id != SmoThreadId::MRNTT)
{
+7 -7
View File
@@ -4,20 +4,20 @@
#include <pthread.h>
#include <componentThread.h>
namespace smo {
namespace sscl {
std::string ComponentThread::getThreadName(ThreadId id)
std::string ComponentThread::getThreadName(sscl::ThreadId id)
{
// Cast ThreadId to SmoThreadId for validation and lookup
SmoThreadId smoId = static_cast<SmoThreadId>(id);
if (static_cast<int>(smoId) >= static_cast<int>(SmoThreadId::N_ITEMS))
smo::SmoThreadId smoId = static_cast<smo::SmoThreadId>(id);
if (static_cast<int>(smoId) >= static_cast<int>(smo::SmoThreadId::N_ITEMS))
{
throw std::runtime_error(std::string(__func__)
+ ": Invalid thread ID");
}
// Use function-local static to ensure proper initialization order
static const std::string threadNames[static_cast<int>(SmoThreadId::N_ITEMS)]
static const std::string threadNames[static_cast<int>(smo::SmoThreadId::N_ITEMS)]
= {
"mrntt",
"director",
@@ -30,7 +30,7 @@ std::string ComponentThread::getThreadName(ThreadId id)
return threadNames[static_cast<int>(smoId)];
}
void PuppetThread::main(PuppetThread& self)
void sscl::PuppetThread::main(sscl::PuppetThread& self)
{
std::string threadName = "smo:" + self.name;
pthread_setname_np(pthread_self(), threadName.c_str());
@@ -87,4 +87,4 @@ void PuppetThread::main(PuppetThread& self)
std::cout << self.name << ":" << __func__ << ": Exited event loop" << "\n";
}
} // namespace smo
} // namespace sscl
+54 -54
View File
@@ -45,15 +45,15 @@ const std::string DeviceManager::stringifyDeviceSpecs(void)
}
class DeviceManager::NewDeviceAttachmentSpecInd
: public SerializedAsynchronousContinuation<newDeviceAttachmentSpecIndCbFn>
: public sscl::SerializedAsynchronousContinuation<newDeviceAttachmentSpecIndCbFn>
{
public:
NewDeviceAttachmentSpecInd(
const DeviceAttachmentSpec &spec,
const std::shared_ptr<ComponentThread> &caller,
Callback<newDeviceAttachmentSpecIndCbFn> cb,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<newDeviceAttachmentSpecIndCbFn>(
const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<newDeviceAttachmentSpecIndCbFn> cb,
std::vector<std::reference_wrapper<sscl::Qutex>> requiredLocks)
: sscl::SerializedAsynchronousContinuation<newDeviceAttachmentSpecIndCbFn>(
caller, cb, requiredLocks),
spec(spec)
{}
@@ -171,15 +171,15 @@ public:
};
class DeviceManager::RemoveDeviceAttachmentSpecReq
: public SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>
: public sscl::SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>
{
public:
RemoveDeviceAttachmentSpecReq(
const DeviceAttachmentSpec &spec,
const std::shared_ptr<ComponentThread> &caller,
Callback<removeDeviceAttachmentSpecReqCbFn> cb,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>(
const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<removeDeviceAttachmentSpecReqCbFn> cb,
std::vector<std::reference_wrapper<sscl::Qutex>> requiredLocks)
: sscl::SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>(
caller, cb, requiredLocks),
spec(spec)
{}
@@ -293,13 +293,13 @@ public:
void DeviceManager::newDeviceAttachmentSpecInd(
const DeviceAttachmentSpec &spec,
Callback<newDeviceAttachmentSpecIndCbFn> callback)
sscl::Callback<newDeviceAttachmentSpecIndCbFn> callback)
{
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<NewDeviceAttachmentSpecInd>(
spec, caller, callback,
LockSet<newDeviceAttachmentSpecIndCbFn>::Set{
sscl::LockSet<newDeviceAttachmentSpecIndCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex)
});
@@ -312,13 +312,13 @@ void DeviceManager::newDeviceAttachmentSpecInd(
void DeviceManager::removeDeviceAttachmentSpecReq(
const DeviceAttachmentSpec &spec,
Callback<removeDeviceAttachmentSpecReqCbFn> callback)
sscl::Callback<removeDeviceAttachmentSpecReqCbFn> callback)
{
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<RemoveDeviceAttachmentSpecReq>(
spec, caller, callback,
LockSet<removeDeviceAttachmentSpecReqCbFn>::Set{
sscl::LockSet<removeDeviceAttachmentSpecReqCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex)
});
@@ -331,17 +331,17 @@ void DeviceManager::removeDeviceAttachmentSpecReq(
}
class DeviceManager::AttachStimBuffDeviceReq
: public SerializedAsynchronousContinuation<
: public sscl::SerializedAsynchronousContinuation<
DeviceManager::attachStimBuffDeviceReqCbFn>
{
public:
AttachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
const std::shared_ptr<ComponentThread> &caller,
Callback<DeviceManager::attachStimBuffDeviceReqCbFn> cb,
const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<DeviceManager::attachStimBuffDeviceReqCbFn> cb,
std::shared_ptr<stim_buff::StimBuffApiLib> &stimBuffApiLib,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<attachStimBuffDeviceReqCbFn>(
std::vector<std::reference_wrapper<sscl::Qutex>> requiredLocks)
: sscl::SerializedAsynchronousContinuation<attachStimBuffDeviceReqCbFn>(
caller, cb, requiredLocks),
spec(spec), stimBuffApiLib(stimBuffApiLib)
{}
@@ -386,7 +386,7 @@ public:
* Introspectors are attached to the body thread; extrospectors are
* attached to the world thread.
*/
std::shared_ptr<ComponentThread> threadForAttachment;
std::shared_ptr<sscl::ComponentThread> threadForAttachment;
if (spec->sensorType == 'e')
{
threadForAttachment = mind::globalMind->world.thread;
@@ -473,10 +473,10 @@ public:
void DeviceManager::attachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<attachStimBuffDeviceReqCbFn> cb
sscl::Callback<attachStimBuffDeviceReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
// Get the stim buff API lib's qutex
auto libOpt = stim_buff::StimBuffApiManager::getInstance()
@@ -494,7 +494,7 @@ void DeviceManager::attachStimBuffDeviceReq(
auto request = std::make_shared<AttachStimBuffDeviceReq>(
spec, caller, cb, libOpt.value(),
LockSet<attachStimBuffDeviceReqCbFn>::Set{
sscl::LockSet<attachStimBuffDeviceReqCbFn>::Set{
std::ref(stim_buff::StimBuffApiManager::getInstance().qutex),
std::ref(lib.qutex)
});
@@ -508,10 +508,10 @@ void DeviceManager::attachStimBuffDeviceReq(
void DeviceManager::detachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<detachStimBuffDeviceReqCbFn> cb
sscl::Callback<detachStimBuffDeviceReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
// Get the stim buff API lib's qutex
auto libOpt = stim_buff::StimBuffApiManager::getInstance()
@@ -529,7 +529,7 @@ void DeviceManager::detachStimBuffDeviceReq(
auto request = std::make_shared<DetachStimBuffDeviceReq>(
spec, caller, cb, libOpt.value(),
LockSet<detachStimBuffDeviceReqCbFn>::Set{
sscl::LockSet<detachStimBuffDeviceReqCbFn>::Set{
std::ref(stim_buff::StimBuffApiManager::getInstance().qutex),
std::ref(lib.qutex)
});
@@ -542,16 +542,16 @@ void DeviceManager::detachStimBuffDeviceReq(
}
class DeviceManager::AttachAllUnattachedDevicesFromReq
: public PostedAsynchronousContinuation<
: public sscl::PostedAsynchronousContinuation<
attachAllUnattachedDevicesFromReqCbFn>
{
public:
AttachAllUnattachedDevicesFromReq(
const unsigned int totalNSpecs,
const std::shared_ptr<std::vector<DeviceAttachmentSpec>>& specs,
const std::shared_ptr<ComponentThread>& caller,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb)
: PostedAsynchronousContinuation<attachAllUnattachedDevicesFromReqCbFn>(
const std::shared_ptr<sscl::ComponentThread>& caller,
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb)
: sscl::PostedAsynchronousContinuation<attachAllUnattachedDevicesFromReqCbFn>(
caller, cb),
loop(totalNSpecs), specs(specs)
{}
@@ -606,23 +606,23 @@ public:
}
public:
AsynchronousLoop loop;
sscl::AsynchronousLoop loop;
std::shared_ptr<std::vector<DeviceAttachmentSpec>> specs;
};
void DeviceManager::attachAllUnattachedDevicesFromReq(
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb
)
{
if (specs->size() == 0)
{
AsynchronousLoop tmp(0);
sscl::AsynchronousLoop tmp(0);
cb.callbackFn(tmp);
return;
}
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<AttachAllUnattachedDevicesFromReq>(
specs->size(), specs, caller, std::move(cb));
@@ -634,7 +634,7 @@ void DeviceManager::attachAllUnattachedDevicesFromReq(
}
void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq(
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb
)
{
auto specs = std::make_shared<std::vector<DeviceAttachmentSpec>>(
@@ -643,15 +643,15 @@ void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq(
}
class DeviceManager::AttachAllUnattachedDevicesFromKnownListReq
: public SerializedAsynchronousContinuation<
: public sscl::SerializedAsynchronousContinuation<
attachAllUnattachedDevicesFromReqCbFn>
{
public:
AttachAllUnattachedDevicesFromKnownListReq(
const std::shared_ptr<ComponentThread> &caller,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb,
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
: SerializedAsynchronousContinuation<
const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb,
std::vector<std::reference_wrapper<sscl::Qutex>> requiredLocks)
: sscl::SerializedAsynchronousContinuation<
attachAllUnattachedDevicesFromReqCbFn>(
caller, cb, requiredLocks)
{}
@@ -703,7 +703,7 @@ public:
void attachAllUnattachedDevicesFromKnownListReq2(
[[maybe_unused]]
std::shared_ptr<AttachAllUnattachedDevicesFromKnownListReq> context,
AsynchronousLoop loop
sscl::AsynchronousLoop loop
)
{
callOriginalCb(loop);
@@ -711,14 +711,14 @@ public:
};
void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb
)
{
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<AttachAllUnattachedDevicesFromKnownListReq>(
caller, cb,
LockSet<attachAllUnattachedDevicesFromReqCbFn>::Set{
sscl::LockSet<attachAllUnattachedDevicesFromReqCbFn>::Set{
std::ref(DeviceManager::getInstance().qutex)
});
@@ -731,15 +731,15 @@ void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
}
class DeviceManager::DetachAllAttachedDeviceRoles
: public PostedAsynchronousContinuation<
: public sscl::PostedAsynchronousContinuation<
detachAllAttachedDeviceRolesCbFn>
{
public:
DetachAllAttachedDeviceRoles(
const unsigned int totalNSpecs,
const std::shared_ptr<ComponentThread>& caller,
Callback<detachAllAttachedDeviceRolesCbFn> cb)
: PostedAsynchronousContinuation<detachAllAttachedDeviceRolesCbFn>(
const std::shared_ptr<sscl::ComponentThread>& caller,
sscl::Callback<detachAllAttachedDeviceRolesCbFn> cb)
: sscl::PostedAsynchronousContinuation<detachAllAttachedDeviceRolesCbFn>(
caller, cb),
loop(totalNSpecs)
{}
@@ -788,21 +788,21 @@ public:
}
public:
AsynchronousLoop loop;
sscl::AsynchronousLoop loop;
};
void DeviceManager::detachAllAttachedDeviceRoles(
Callback<detachAllAttachedDeviceRolesCbFn> cb
sscl::Callback<detachAllAttachedDeviceRolesCbFn> cb
)
{
if (DeviceManager::getInstance().attachedDeviceRoles.size() == 0)
{
AsynchronousLoop tmp(0);
sscl::AsynchronousLoop tmp(0);
cb.callbackFn(tmp);
return;
}
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<DetachAllAttachedDeviceRoles>(
DeviceManager::getInstance().attachedDeviceRoles.size(),
caller, std::move(cb));
+4 -4
View File
@@ -9,7 +9,7 @@
namespace smo {
namespace device {
static void reattachmentCb(AsynchronousLoop& results)
static void reattachmentCb(sscl::AsynchronousLoop& results)
{
if (results.nTotal == 0) { return; }
@@ -19,7 +19,7 @@ static void reattachmentCb(AsynchronousLoop& results)
}
DeviceReattacher::DeviceReattacher(
DeviceManager& parent, std::shared_ptr<ComponentThread> ioThread)
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread)
: parent(parent), ioThread(ioThread), shouldContinue(false),
timer(ioThread->getIoService())
{
@@ -34,7 +34,7 @@ void DeviceReattacher::start()
void DeviceReattacher::stop()
{
{
SpinLock::Guard lock(shouldContinueLock);
sscl::SpinLock::Guard lock(shouldContinueLock);
shouldContinue = false;
}
@@ -70,7 +70,7 @@ void DeviceReattacher::onTimeout(const boost::system::error_code& error)
return;
}
SpinLock::Guard lock(shouldContinueLock);
sscl::SpinLock::Guard lock(shouldContinueLock);
if (!shouldContinue) {
return;
}
+2 -2
View File
@@ -6,8 +6,8 @@
namespace smo {
namespace director {
Director::Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
: PuppetComponent(static_cast<PuppetApplication&>(parent), thread)
Director::Director(Mind &parent, const std::shared_ptr<sscl::ComponentThread> &thread)
: sscl::PuppetComponent(static_cast<sscl::PuppetApplication&>(parent), thread)
{
}
+4 -5
View File
@@ -9,20 +9,19 @@
namespace smo {
class Mind;
class ComponentThread;
namespace body {
class Body
: public PuppetComponent
: public sscl::PuppetComponent
{
public:
Body(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
Body(Mind &parent, const std::shared_ptr<sscl::ComponentThread> &thread);
~Body() = default;
typedef std::function<void(bool)> bodyLifetimeMgmtOpCbFn;
void initializeReq(Callback<bodyLifetimeMgmtOpCbFn> callback);
void finalizeReq(Callback<bodyLifetimeMgmtOpCbFn> callback);
void initializeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback);
void finalizeReq(sscl::Callback<bodyLifetimeMgmtOpCbFn> callback);
private:
class InitializeReq;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace smo {
// Application-specific thread ID enum
// Using regular enum (not enum class) to allow implicit conversion to ThreadId
enum SmoThreadId : ThreadId
enum SmoThreadId : sscl::ThreadId
{
MRNTT = 0,
DIRECTOR,
+1 -1
View File
@@ -33,7 +33,7 @@ public:
public:
std::string deviceIdentifier;
std::vector<std::shared_ptr<DeviceRole>> deviceRoles;
Qutex qutex;
sscl::Qutex qutex;
};
} // namespace device
+11 -11
View File
@@ -55,10 +55,10 @@ public:
void newDeviceAttachmentSpecInd(
const DeviceAttachmentSpec &spec,
Callback<newDeviceAttachmentSpecIndCbFn> callback);
sscl::Callback<newDeviceAttachmentSpecIndCbFn> callback);
void removeDeviceAttachmentSpecReq(
const DeviceAttachmentSpec &spec,
Callback<removeDeviceAttachmentSpecReqCbFn> callback);
sscl::Callback<removeDeviceAttachmentSpecReqCbFn> callback);
// Device attachment/detachment methods moved from SenseApiManager
typedef stim_buff::sal_mlo_attachDeviceReqCbFn attachStimBuffDeviceReqCbFn;
@@ -66,25 +66,25 @@ public:
void attachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<attachStimBuffDeviceReqCbFn> cb);
sscl::Callback<attachStimBuffDeviceReqCbFn> cb);
void detachStimBuffDeviceReq(
const std::shared_ptr<DeviceAttachmentSpec>& spec,
Callback<detachStimBuffDeviceReqCbFn> cb);
sscl::Callback<detachStimBuffDeviceReqCbFn> cb);
typedef std::function<void(AsynchronousLoop &results)>
typedef std::function<void(sscl::AsynchronousLoop &results)>
attachAllUnattachedDevicesFromReqCbFn;
typedef std::function<void(AsynchronousLoop &results)>
typedef std::function<void(sscl::AsynchronousLoop &results)>
detachAllAttachedDeviceRolesCbFn;
void attachAllUnattachedDevicesFromReq(
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
void attachAllUnattachedDevicesFromKnownListReq(
Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
void attachAllUnattachedDevicesFromCmdlineReq(
Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
sscl::Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
void detachAllAttachedDeviceRoles(
Callback<detachAllAttachedDeviceRolesCbFn> cb);
sscl::Callback<detachAllAttachedDeviceRolesCbFn> cb);
private:
DeviceManager()
@@ -95,7 +95,7 @@ private:
DeviceManager& operator=(const DeviceManager&) = delete;
public:
Qutex qutex;
sscl::Qutex qutex;
std::string allDapSpecs;
static std::vector<std::shared_ptr<DeviceAttachmentSpec>>
deviceAttachmentSpecs;
@@ -9,8 +9,6 @@
namespace smo {
class ComponentThread;
namespace device {
class DeviceManager;
@@ -19,7 +17,7 @@ class DeviceReattacher
{
public:
DeviceReattacher(
DeviceManager& parent, std::shared_ptr<ComponentThread> ioThread);
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread);
~DeviceReattacher() = default;
// Non-copyable
@@ -35,8 +33,8 @@ private:
void onTimeout(const boost::system::error_code& error);
DeviceManager &parent;
std::shared_ptr<ComponentThread> ioThread;
SpinLock shouldContinueLock;
std::shared_ptr<sscl::ComponentThread> ioThread;
sscl::SpinLock shouldContinueLock;
bool shouldContinue;
boost::asio::deadline_timer timer;
};
+2 -3
View File
@@ -10,15 +10,14 @@
namespace smo {
class Mind;
class ComponentThread;
namespace director {
class Director
: public PuppetComponent
: public sscl::PuppetComponent
{
public:
Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
Director(Mind &parent, const std::shared_ptr<sscl::ComponentThread> &thread);
~Director() = default;
void negtrinEventInd(void);
+4 -4
View File
@@ -13,16 +13,16 @@ class MarionetteThread;
namespace mrntt {
class MarionetteComponent
: public Component
: public sscl::Component
{
public:
MarionetteComponent(const std::shared_ptr<ComponentThread> &thread);
MarionetteComponent(const std::shared_ptr<sscl::ComponentThread> &thread);
~MarionetteComponent() = default;
public:
typedef std::function<void(bool)> mrnttLifetimeMgmtOpCbFn;
void initializeReq(Callback<mrnttLifetimeMgmtOpCbFn> callback);
void finalizeReq(Callback<mrnttLifetimeMgmtOpCbFn> callback);
void initializeReq(sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback);
void finalizeReq(sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback);
// Intentionally doesn't take a callback.
void exceptionInd();
+6 -6
View File
@@ -18,18 +18,18 @@
namespace smo {
class Mind
: public PuppetApplication
: public sscl::PuppetApplication
{
public:
Mind(void);
~Mind(void) = default;
typedef std::function<void(bool)> mindLifetimeMgmtOpCbFn;
void initializeReq(Callback<mindLifetimeMgmtOpCbFn> callback);
void finalizeReq(Callback<mindLifetimeMgmtOpCbFn> callback);
void initializeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback);
void finalizeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback);
// ComponentThread access methods
std::shared_ptr<MindThread> getComponentThread(ThreadId id) const;
std::shared_ptr<MindThread> getComponentThread(sscl::ThreadId id) const;
std::shared_ptr<MindThread> getComponentThread(
const std::string& name) const;
// Get all this Mind's component threads.
@@ -38,9 +38,9 @@ public:
public:
director::Director director;
simulator::Simulator canvas;
PuppetComponent subconscious;
sscl::PuppetComponent subconscious;
body::Body body;
PuppetComponent world;
sscl::PuppetComponent world;
private:
friend class body::Body;
+3 -3
View File
@@ -9,11 +9,11 @@ namespace smo {
class Mind; // Forward declaration
class MindThread
: public PuppetThread
: public sscl::PuppetThread
{
public:
MindThread(ThreadId _id, Mind& parent)
: PuppetThread(_id),
MindThread(sscl::ThreadId _id, Mind& parent)
: sscl::PuppetThread(_id),
parent(parent)
{
}
+2 -3
View File
@@ -9,15 +9,14 @@
namespace smo {
class Mind;
class ComponentThread;
namespace simulator {
class Simulator
: public PuppetComponent
: public sscl::PuppetComponent
{
public:
Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
Simulator(Mind &parent, const std::shared_ptr<sscl::ComponentThread> &thread);
~Simulator() = default;
void initialize();
@@ -51,7 +51,7 @@ public:
public:
std::string libraryPath;
Qutex qutex;
sscl::Qutex qutex;
std::atomic<bool> isBeingDestroyed;
std::unique_ptr<void, DlCloser> dlopen_handle;
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
@@ -32,7 +32,7 @@ public:
StimBuffApiLib& loadStimBuffApiLib(
const std::string& libraryPath,
const std::shared_ptr<ComponentThread>& componentThread);
const std::shared_ptr<sscl::ComponentThread>& componentThread);
std::optional<std::shared_ptr<StimBuffApiLib>> getStimBuffApiLib(
const std::string& libraryPath);
@@ -44,7 +44,7 @@ public:
void finalizeStimBuffApiLib(StimBuffApiLib& lib);
void loadAllStimBuffApiLibsFromOptions(
const std::shared_ptr<ComponentThread>& componentThread);
const std::shared_ptr<sscl::ComponentThread>& componentThread);
void unloadAllStimBuffApiLibs(void);
void initializeAllStimBuffApiLibs(void);
@@ -64,7 +64,7 @@ private:
std::vector<std::shared_ptr<StimBuffApiLib>> stimBuffApiLibs;
public:
Qutex qutex;
sscl::Qutex qutex;
public:
static std::optional<std::string> searchForLibInSmoSearchPaths(
+16 -16
View File
@@ -13,13 +13,13 @@ namespace smo {
namespace mrntt {
class MarionetteComponent::MrnttLifetimeMgmtOp
: public PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>
: public sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>
{
public:
MrnttLifetimeMgmtOp(
MarionetteComponent &parent, const std::shared_ptr<ComponentThread> &caller,
Callback<mrnttLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
MarionetteComponent &parent, const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
: sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
caller, callback),
parent(parent)
{}
@@ -32,7 +32,7 @@ public:
[[maybe_unused]] std::shared_ptr<MrnttLifetimeMgmtOp> context
)
{
auto self = ComponentThread::getSelf();
auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::MRNTT)
{
throw std::runtime_error(std::string(__func__)
@@ -70,7 +70,7 @@ public:
[[maybe_unused]] std::shared_ptr<MrnttLifetimeMgmtOp> context
)
{
auto self = ComponentThread::getSelf();
auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::MRNTT)
{
throw std::runtime_error(std::string(__func__)
@@ -118,12 +118,12 @@ public:
};
class MarionetteComponent::TerminationEvent
: public PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>
: public sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>
{
public:
TerminationEvent(
const std::shared_ptr<ComponentThread> &caller)
: PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
const std::shared_ptr<sscl::ComponentThread> &caller)
: sscl::PostedAsynchronousContinuation<mrnttLifetimeMgmtOpCbFn>(
caller, {nullptr, nullptr})
{}
@@ -132,7 +132,7 @@ public:
[[maybe_unused]] std::shared_ptr<TerminationEvent> context
)
{
auto self = ComponentThread::getSelf();
auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::MRNTT)
{
throw std::runtime_error(std::string(__func__)
@@ -146,9 +146,9 @@ public:
};
void MarionetteComponent::initializeReq(
Callback<mrnttLifetimeMgmtOpCbFn> callback)
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
auto mrntt = sscl::ComponentThread::getSelf();
if (mrntt->id != SmoThreadId::MRNTT)
{
@@ -166,9 +166,9 @@ void MarionetteComponent::initializeReq(
}
void MarionetteComponent::finalizeReq(
Callback<mrnttLifetimeMgmtOpCbFn> callback)
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
{
auto mrntt = ComponentThread::getSelf();
auto mrntt = sscl::ComponentThread::getSelf();
if (mrntt->id != SmoThreadId::MRNTT)
{
@@ -187,8 +187,8 @@ void MarionetteComponent::finalizeReq(
void MarionetteComponent::exceptionInd()
{
auto faultyThread = ComponentThread::getSelf();
auto mrntt = ComponentThread::getMrntt();
auto faultyThread = sscl::ComponentThread::getSelf();
auto mrntt = sscl::ComponentThread::getMrntt();
auto request = std::make_shared<TerminationEvent>(
faultyThread);
+26 -21
View File
@@ -8,8 +8,9 @@
#include <typeinfo>
#include <boost/asio/signal_set.hpp>
#include <spinscale/asynchronousBridge.h>
#include <mindManager/mindManager.h>
#include <spinscale/componentThread.h>
#include <componentThread.h>
#include <mindManager/mindManager.h>
#include <marionette/marionette.h>
#include <salmanoff.h>
@@ -25,14 +26,14 @@ void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[])
namespace mrntt {
std::atomic<int> exitCode;
// Global marionette thread instance
std::shared_ptr<MarionetteThread> thread =
std::make_shared<MarionetteThread>();
MarionetteComponent mrntt(thread);
std::shared_ptr<sscl::MarionetteThread> thread =
std::make_shared<sscl::MarionetteThread>();
MarionetteComponent mrntt(std::static_pointer_cast<sscl::ComponentThread>(thread));
void exitMarionetteLoop()
{
mrntt::thread->keepLooping = false;
mrntt::thread->getIoService().stop();
thread->keepLooping = false;
thread->getIoService().stop();
std::cout << "Mrntt: Signaled main loop to exit." << "\n";
}
@@ -65,6 +66,10 @@ void marionetteInitializeReqCb(bool success)
} // namespace mrntt
} // namespace smo
namespace sscl {
void MarionetteThread::main(MarionetteThread& self)
{
std::string threadName = "smo:" + self.name;
@@ -73,7 +78,7 @@ void MarionetteThread::main(MarionetteThread& self)
std::cout << __func__ << ": Waiting for command line JOLT" << std::endl;
self.getIoService().run();
self.initializeTls();
mrntt::exitCode = EXIT_SUCCESS;
smo::mrntt::exitCode = EXIT_SUCCESS;
static boost::asio::signal_set signals(self.getIoService(), SIGINT);
bool callShutdownSalmanoff = false;
@@ -95,8 +100,8 @@ void MarionetteThread::main(MarionetteThread& self)
default:
break;
}
mrntt::mrntt.finalizeReq({nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb,
smo::mrntt::mrntt.finalizeReq({nullptr, std::bind(
&smo::mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)});
}
);
@@ -107,8 +112,8 @@ void MarionetteThread::main(MarionetteThread& self)
<< std::endl;
options.parseArguments(
crtCommandLineArgs.argc, crtCommandLineArgs.argv,
crtCommandLineArgs.envp);
smo::crtCommandLineArgs.argc, smo::crtCommandLineArgs.argv,
smo::crtCommandLineArgs.envp);
std::cout << __func__ << ": " << options.stringifyOptions()
<< std::endl;
@@ -135,12 +140,12 @@ void MarionetteThread::main(MarionetteThread& self)
* The latter is cleaner and more resource-respecting. The former is
* easier to implement.
*/
initializeSalmanoff();
smo::initializeSalmanoff();
callShutdownSalmanoff = true;
// Create new Mind instance just before initializeReq
mrntt::mrntt.initializeReq({nullptr, std::bind(
&mrntt::marionetteInitializeReqCb, std::placeholders::_1)});
smo::mrntt::mrntt.initializeReq({nullptr, std::bind(
&smo::mrntt::marionetteInitializeReqCb, std::placeholders::_1)});
std::cout << __func__ << ": Entering event loop" << "\n";
@@ -183,8 +188,8 @@ void MarionetteThread::main(MarionetteThread& self)
if (sendExceptionInd)
{
mrntt::exitCode = EXIT_FAILURE;
mrntt::mrntt.exceptionInd();
smo::mrntt::exitCode = EXIT_FAILURE;
smo::mrntt::mrntt.exceptionInd();
}
}
@@ -197,7 +202,7 @@ void MarionetteThread::main(MarionetteThread& self)
if (typeid(e) == typeid(OptionsParserError))
{
mrntt::exitCode = EXIT_FAILURE;
smo::mrntt::exitCode = EXIT_FAILURE;
out = &std::cerr;
outUsageMsg = std::string(__func__) + ": ";
}
@@ -208,17 +213,17 @@ void MarionetteThread::main(MarionetteThread& self)
{
std::cerr << __func__ << ": Exception occurred: " << e.what()
<< std::endl;
mrntt::exitCode = EXIT_FAILURE;
smo::mrntt::exitCode = EXIT_FAILURE;
}
catch (...)
{
std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
mrntt::exitCode = EXIT_FAILURE;
smo::mrntt::exitCode = EXIT_FAILURE;
}
if (callShutdownSalmanoff) {
shutdownSalmanoff();
smo::shutdownSalmanoff();
}
}
} // namespace smo
} // namespace sscl
+17 -17
View File
@@ -14,8 +14,8 @@
namespace smo {
Mind::Mind(void)
: PuppetApplication(
std::vector<std::shared_ptr<PuppetThread>>{
: sscl::PuppetApplication(
std::vector<std::shared_ptr<sscl::PuppetThread>>{
std::make_shared<MindThread>(SmoThreadId::DIRECTOR, *this),
std::make_shared<MindThread>(SmoThreadId::SIMULATOR, *this),
std::make_shared<MindThread>(SmoThreadId::SUBCONSCIOUS, *this),
@@ -24,22 +24,22 @@ Mind::Mind(void)
, std::make_shared<MindThread>(SmoThreadId::WORLD, *this)
#endif
}),
director(*this, std::static_pointer_cast<MindThread>(componentThreads[0])),
canvas(*this, std::static_pointer_cast<MindThread>(componentThreads[1])),
subconscious(*this, std::static_pointer_cast<MindThread>(componentThreads[2])),
body(*this, std::static_pointer_cast<MindThread>(componentThreads[3])),
director(*this, std::static_pointer_cast<sscl::ComponentThread>(componentThreads[0])),
canvas(*this, std::static_pointer_cast<sscl::ComponentThread>(componentThreads[1])),
subconscious(*this, std::static_pointer_cast<sscl::ComponentThread>(componentThreads[2])),
body(*this, std::static_pointer_cast<sscl::ComponentThread>(componentThreads[3])),
world(*this,
#ifndef CONFIG_WORLD_USE_BODY_THREAD
std::static_pointer_cast<MindThread>(componentThreads[4])
std::static_pointer_cast<sscl::ComponentThread>(componentThreads[4])
#else
std::static_pointer_cast<MindThread>(componentThreads[3])
std::static_pointer_cast<sscl::ComponentThread>(componentThreads[3])
#endif
)
{
}
std::shared_ptr<MindThread>
Mind::getComponentThread(ThreadId id) const
Mind::getComponentThread(sscl::ThreadId id) const
{
if (id == SmoThreadId::MRNTT)
{
@@ -98,13 +98,13 @@ Mind::getMindThreads() const
}
class Mind::MindLifetimeMgmtOp
: public PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>
: public sscl::PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>
{
public:
MindLifetimeMgmtOp(
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
Callback<mindLifetimeMgmtOpCbFn> callback)
: PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>(
Mind &parent, const std::shared_ptr<sscl::ComponentThread> &caller,
sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
: sscl::PostedAsynchronousContinuation<mindLifetimeMgmtOpCbFn>(
caller, callback),
parent(parent)
{}
@@ -209,7 +209,7 @@ public:
}
};
void Mind::initializeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
void Mind::initializeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
{
/* Distribute threads across available CPUs */
try
@@ -223,7 +223,7 @@ void Mind::initializeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
"Error: " << e.what() << "\n";
}
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<MindLifetimeMgmtOp>(
*this, caller, callback);
@@ -233,9 +233,9 @@ void Mind::initializeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
request.get(), request)));
}
void Mind::finalizeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
void Mind::finalizeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
{
const auto& caller = ComponentThread::getSelf();
const auto& caller = sscl::ComponentThread::getSelf();
auto request = std::make_shared<MindLifetimeMgmtOp>(
*this, caller, callback);
+2 -2
View File
@@ -4,8 +4,8 @@
namespace smo {
namespace simulator {
Simulator::Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
: PuppetComponent(static_cast<PuppetApplication&>(parent), thread)
Simulator::Simulator(Mind &parent, const std::shared_ptr<sscl::ComponentThread> &thread)
: sscl::PuppetComponent(static_cast<sscl::PuppetApplication&>(parent), thread)
{
}
+5 -5
View File
@@ -74,10 +74,10 @@ static std::optional<std::string> searchForLibInSmoSearchPaths(
return std::nullopt;
}
/* Local static function to wrap ComponentThread::getSelf for SmoCallbacks */
static std::shared_ptr<ComponentThread> ComponentThread_getSelf()
/* Local static function to wrap sscl::ComponentThread::getSelf for SmoCallbacks */
static std::shared_ptr<sscl::ComponentThread> ComponentThread_getSelf()
{
return ComponentThread::getSelf();
return sscl::ComponentThread::getSelf();
}
/* Local static function to wrap OptionParser::getOptions for SmoCallbacks */
@@ -145,7 +145,7 @@ std::optional<std::string> StimBuffApiManager::searchForLibInSmoSearchPaths(
StimBuffApiLib& StimBuffApiManager::loadStimBuffApiLib(
const std::string& libraryPath,
const std::shared_ptr<ComponentThread>& componentThread
const std::shared_ptr<sscl::ComponentThread>& componentThread
)
{
std::optional<std::string> fullPath = searchForLibInSmoSearchPaths(
@@ -252,7 +252,7 @@ void StimBuffApiManager::unloadAllStimBuffApiLibs(void)
}
void StimBuffApiManager::loadAllStimBuffApiLibsFromOptions(
const std::shared_ptr<ComponentThread>& componentThread
const std::shared_ptr<sscl::ComponentThread>& componentThread
)
{
const auto& options = OptionParser::getOptions();