Exceptions: Straight line convention refactor
This commit is contained in:
+27
-8
@@ -16,7 +16,7 @@ Body::Body(Mind &parent, const std::shared_ptr<sscl::PuppetThread> &thread)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BodyViralPostingInvoker<bool> Body::initializeCReq()
|
BodyViralPostingInvoker<void> Body::initializeCReq()
|
||||||
{
|
{
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
auto self = sscl::ComponentThread::getSelf();
|
||||||
if (self->id != SmoThreadId::BODY)
|
if (self->id != SmoThreadId::BODY)
|
||||||
@@ -71,10 +71,19 @@ BodyViralPostingInvoker<bool> Body::initializeCReq()
|
|||||||
<< attachResults.nSucceeded << " of " << attachResults.nTotal
|
<< attachResults.nSucceeded << " of " << attachResults.nTotal
|
||||||
<< " sense devices." << "\n";
|
<< " sense devices." << "\n";
|
||||||
|
|
||||||
co_return attachResults.nSucceeded > 0;
|
if (attachResults.nTotal > 0 && attachResults.nSucceeded == 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string(__func__)
|
||||||
|
+ ": Failed to attach any of "
|
||||||
|
+ std::to_string(attachResults.nTotal)
|
||||||
|
+ " requested sense devices");
|
||||||
|
}
|
||||||
|
|
||||||
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BodyViralPostingInvoker<bool> Body::finalizeCReq()
|
BodyViralPostingInvoker<void> Body::finalizeCReq()
|
||||||
{
|
{
|
||||||
auto self = sscl::ComponentThread::getSelf();
|
auto self = sscl::ComponentThread::getSelf();
|
||||||
if (self->id != SmoThreadId::BODY)
|
if (self->id != SmoThreadId::BODY)
|
||||||
@@ -89,15 +98,25 @@ BodyViralPostingInvoker<bool> Body::finalizeCReq()
|
|||||||
{
|
{
|
||||||
std::cout << "Mrntt: Body component not initialized. "
|
std::cout << "Mrntt: Body component not initialized. "
|
||||||
<< "Skipping finalization." << "\n";
|
<< "Skipping finalization." << "\n";
|
||||||
co_return true;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Mrntt: About to detach all sense devices." << "\n";
|
std::cout << "Mrntt: About to detach all sense devices." << "\n";
|
||||||
sscl::MultiOperationResultSet detachResults = co_await
|
sscl::MultiOperationResultSet detachResults = co_await
|
||||||
device::DeviceManager::getInstance().detachAllAttachedDeviceRolesCReq();
|
device::DeviceManager::getInstance().detachAllAttachedDeviceRolesCReq();
|
||||||
std::cout << "Mrntt: Successfully detached "
|
|
||||||
<< detachResults.nSucceeded << " of " << detachResults.nTotal
|
if (detachResults.nFailed > 0)
|
||||||
<< " sense devices." << "\n";
|
{
|
||||||
|
std::cerr << "Mrntt: Failed to detach "
|
||||||
|
<< detachResults.nFailed << " of " << detachResults.nTotal
|
||||||
|
<< " sense devices." << "\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Mrntt: Successfully detached "
|
||||||
|
<< detachResults.nSucceeded << " of " << detachResults.nTotal
|
||||||
|
<< " sense devices." << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n";
|
std::cout << "Mrntt: About to finalize all stim buff api libs." << "\n";
|
||||||
co_await stim_buff::StimBuffApiManager::getInstance()
|
co_await stim_buff::StimBuffApiManager::getInstance()
|
||||||
@@ -106,7 +125,7 @@ BodyViralPostingInvoker<bool> Body::finalizeCReq()
|
|||||||
std::cout << "Mrntt: About to unload all stim buff api libs." << "\n";
|
std::cout << "Mrntt: About to unload all stim buff api libs." << "\n";
|
||||||
stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs();
|
stim_buff::StimBuffApiManager::getInstance().unloadAllStimBuffApiLibs();
|
||||||
|
|
||||||
co_return detachResults.nSucceeded == detachResults.nTotal;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace body
|
} // namespace body
|
||||||
|
|||||||
@@ -19,8 +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;
|
||||||
|
|
||||||
BodyViralPostingInvoker<bool> initializeCReq();
|
BodyViralPostingInvoker<void> initializeCReq();
|
||||||
BodyViralPostingInvoker<bool> finalizeCReq();
|
BodyViralPostingInvoker<void> finalizeCReq();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace body
|
} // namespace body
|
||||||
|
|||||||
@@ -64,8 +64,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
std::exception_ptr initializeLifetimeExceptionPtr;
|
std::exception_ptr initializeLifetimeExceptionPtr;
|
||||||
std::exception_ptr finalizeLifetimeExceptionPtr;
|
std::exception_ptr finalizeLifetimeExceptionPtr;
|
||||||
/** Set true only when initializeCReq completes without failure. */
|
|
||||||
bool initializeLifetimeSucceeded = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::shared_ptr<sscl::PuppeteerThread> thread;
|
extern std::shared_ptr<sscl::PuppeteerThread> thread;
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public:
|
|||||||
Mind(void);
|
Mind(void);
|
||||||
~Mind(void) = default;
|
~Mind(void) = default;
|
||||||
|
|
||||||
mrntt::MrnttViralNonPostingInvokerT<bool> initializeCReq();
|
mrntt::MrnttViralNonPostingInvokerT<void> initializeCReq();
|
||||||
mrntt::MrnttViralNonPostingInvokerT<bool> finalizeCReq();
|
mrntt::MrnttViralNonPostingInvokerT<void> finalizeCReq();
|
||||||
|
|
||||||
// ComponentThread access methods
|
// ComponentThread access methods
|
||||||
std::shared_ptr<MindThread> getComponentThread(sscl::ThreadId id) const;
|
std::shared_ptr<MindThread> getComponentThread(sscl::ThreadId id) const;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <marionette/marionette.h>
|
#include <marionette/marionette.h>
|
||||||
#include <marionette/marionetteThread.h>
|
#include <marionette/marionetteThread.h>
|
||||||
#include <mindManager/mindManager.h>
|
#include <mindManager/mindManager.h>
|
||||||
|
#include <spinscale/co/nonViralCompletion.h>
|
||||||
#include <spinscale/componentThread.h>
|
#include <spinscale/componentThread.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
@@ -31,17 +32,31 @@ void assertMarionetteThread()
|
|||||||
void MarionetteComponent::holdInitializeCReq(
|
void MarionetteComponent::holdInitializeCReq(
|
||||||
std::function<void()> completion)
|
std::function<void()> completion)
|
||||||
{
|
{
|
||||||
initializeLifetimeSucceeded = false;
|
|
||||||
initializeLifetimeExceptionPtr = nullptr;
|
initializeLifetimeExceptionPtr = nullptr;
|
||||||
initializeCReqInvoker.emplace(initializeCReq(
|
initializeCReqInvoker.emplace(initializeCReq(
|
||||||
initializeLifetimeExceptionPtr, std::move(completion)));
|
initializeLifetimeExceptionPtr,
|
||||||
|
[completion = std::move(completion)]()
|
||||||
|
{
|
||||||
|
sscl::co::NonViralCompletion nvc(
|
||||||
|
mrntt.initializeLifetimeExceptionPtr);
|
||||||
|
nvc.checkAndRethrowException();
|
||||||
|
completion();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarionetteComponent::holdFinalizeCReq(
|
void MarionetteComponent::holdFinalizeCReq(
|
||||||
std::function<void()> completion)
|
std::function<void()> completion)
|
||||||
{
|
{
|
||||||
|
finalizeLifetimeExceptionPtr = nullptr;
|
||||||
finalizeCReqInvoker.emplace(finalizeCReq(
|
finalizeCReqInvoker.emplace(finalizeCReq(
|
||||||
finalizeLifetimeExceptionPtr, std::move(completion)));
|
finalizeLifetimeExceptionPtr,
|
||||||
|
[completion = std::move(completion)]()
|
||||||
|
{
|
||||||
|
sscl::co::NonViralCompletion nvc(
|
||||||
|
mrntt.finalizeLifetimeExceptionPtr);
|
||||||
|
nvc.checkAndRethrowException();
|
||||||
|
completion();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
MrnttNonViralPostingInvoker MarionetteComponent::initializeCReq(
|
MrnttNonViralPostingInvoker MarionetteComponent::initializeCReq(
|
||||||
@@ -52,15 +67,8 @@ MrnttNonViralPostingInvoker MarionetteComponent::initializeCReq(
|
|||||||
|
|
||||||
smo::mind::globalMind = std::make_shared<smo::Mind>();
|
smo::mind::globalMind = std::make_shared<smo::Mind>();
|
||||||
|
|
||||||
bool mindInitialized = co_await smo::mind::globalMind->initializeCReq();
|
co_await smo::mind::globalMind->initializeCReq();
|
||||||
if (!mindInitialized)
|
|
||||||
{
|
|
||||||
std::cerr << __func__ << ": Failed to initialize globalMind"
|
|
||||||
<< std::endl;
|
|
||||||
co_return;
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeLifetimeSucceeded = true;
|
|
||||||
smo::device::DeviceManager::getInstance().initializeDeviceReattacher();
|
smo::device::DeviceManager::getInstance().initializeDeviceReattacher();
|
||||||
|
|
||||||
// Call negtrinEventInd on the Director in the final callback
|
// Call negtrinEventInd on the Director in the final callback
|
||||||
@@ -77,17 +85,9 @@ MrnttNonViralPostingInvoker MarionetteComponent::finalizeCReq(
|
|||||||
|
|
||||||
smo::device::DeviceManager::getInstance().finalizeDeviceReattacher();
|
smo::device::DeviceManager::getInstance().finalizeDeviceReattacher();
|
||||||
|
|
||||||
if (!smo::mind::globalMind)
|
if (!smo::mind::globalMind) { co_return; }
|
||||||
{
|
|
||||||
co_return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool mindFinalized = co_await smo::mind::globalMind->finalizeCReq();
|
co_await smo::mind::globalMind->finalizeCReq();
|
||||||
if (!mindFinalized)
|
|
||||||
{
|
|
||||||
std::cerr << __func__ << ": globalMind finalization failed"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,12 +129,7 @@ void MarionetteComponent::preLoopHook()
|
|||||||
callShutdownSalmanoff = true;
|
callShutdownSalmanoff = true;
|
||||||
|
|
||||||
holdInitializeCReq(
|
holdInitializeCReq(
|
||||||
[]
|
[] { marionetteInitializeReqCb(true); });
|
||||||
{
|
|
||||||
marionetteInitializeReqCb(
|
|
||||||
mrntt.initializeLifetimeSucceeded
|
|
||||||
&& !mrntt.initializeLifetimeExceptionPtr);
|
|
||||||
});
|
|
||||||
|
|
||||||
std::cout << "PuppeteerThread::main: Entering event loop" << "\n";
|
std::cout << "PuppeteerThread::main: Entering event loop" << "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-11
@@ -106,7 +106,7 @@ Mind::getMindThreads() const
|
|||||||
return mindThreads;
|
return mindThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
mrntt::MrnttViralNonPostingInvokerT<bool> Mind::initializeCReq()
|
mrntt::MrnttViralNonPostingInvokerT<void> Mind::initializeCReq()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -125,20 +125,16 @@ mrntt::MrnttViralNonPostingInvokerT<bool> Mind::initializeCReq()
|
|||||||
co_await startAllPuppetThreadsCReq();
|
co_await startAllPuppetThreadsCReq();
|
||||||
std::cout << "Mrntt: All mind threads started." << "\n";
|
std::cout << "Mrntt: All mind threads started." << "\n";
|
||||||
|
|
||||||
bool bodyInitialized = co_await body.initializeCReq();
|
co_await body.initializeCReq();
|
||||||
std::cout << "Mrntt: Body component initialized." << "\n";
|
std::cout << "Mrntt: Body component initialized." << "\n";
|
||||||
|
|
||||||
co_return bodyInitialized;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mrntt::MrnttViralNonPostingInvokerT<bool> Mind::finalizeCReq()
|
mrntt::MrnttViralNonPostingInvokerT<void> Mind::finalizeCReq()
|
||||||
{
|
{
|
||||||
bool bodyFinalized = co_await body.finalizeCReq();
|
co_await body.finalizeCReq();
|
||||||
if (!bodyFinalized) {
|
std::cout << "Mrntt: Body component finalized." << "\n";
|
||||||
std::cerr << "Mrntt: Body component failed to finalize." << "\n";
|
|
||||||
} else {
|
|
||||||
std::cout << "Mrntt: Body component finalized." << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
co_await joltAllPuppetThreadsCReq();
|
co_await joltAllPuppetThreadsCReq();
|
||||||
std::cout << "Mrntt: All mind threads JOLTed for finalization." << "\n";
|
std::cout << "Mrntt: All mind threads JOLTed for finalization." << "\n";
|
||||||
@@ -146,7 +142,7 @@ mrntt::MrnttViralNonPostingInvokerT<bool> Mind::finalizeCReq()
|
|||||||
co_await exitAllPuppetThreadsCReq();
|
co_await exitAllPuppetThreadsCReq();
|
||||||
std::cout << "Mrntt: All mind threads exited." << "\n";
|
std::cout << "Mrntt: All mind threads exited." << "\n";
|
||||||
|
|
||||||
co_return bodyFinalized;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|||||||
Reference in New Issue
Block a user