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