2026-02-22 17:46:27 -04:00
|
|
|
#include <cstdlib>
|
2025-09-14 22:17:19 -04:00
|
|
|
#include <iostream>
|
2026-05-24 16:12:29 -04:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
#include <boost/asio/post.hpp>
|
2025-09-14 22:17:19 -04:00
|
|
|
#include <componentThread.h>
|
2025-09-29 01:07:32 -04:00
|
|
|
#include <deviceManager/deviceManager.h>
|
2026-05-24 16:12:29 -04:00
|
|
|
#include <marionette/marionette.h>
|
|
|
|
|
#include <marionette/marionetteThread.h>
|
2025-09-14 22:17:19 -04:00
|
|
|
#include <mindManager/mindManager.h>
|
2026-06-06 19:24:00 -04:00
|
|
|
#include <spinscale/co/nonViralCompletion.h>
|
2026-05-24 16:12:29 -04:00
|
|
|
#include <spinscale/componentThread.h>
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-02-22 17:46:27 -04:00
|
|
|
namespace smo {
|
|
|
|
|
namespace mrntt {
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
namespace {
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
void assertMarionetteThread()
|
|
|
|
|
{
|
|
|
|
|
auto self = sscl::ComponentThread::getSelf();
|
|
|
|
|
if (self->id != SmoThreadId::MRNTT)
|
2025-09-14 22:17:19 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
throw std::runtime_error(
|
|
|
|
|
std::string(__func__)
|
|
|
|
|
+ ": Must be executed on Marionette thread");
|
2025-09-14 22:17:19 -04:00
|
|
|
}
|
2026-05-24 16:12:29 -04:00
|
|
|
}
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
} // namespace
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
void MarionetteComponent::holdInitializeCReq(
|
2026-06-09 11:19:42 -04:00
|
|
|
std::function<void(std::exception_ptr &exceptionPtr)> completion)
|
2025-11-23 03:27:18 -04:00
|
|
|
{
|
2026-06-09 11:19:42 -04:00
|
|
|
taskNursery.launch(
|
|
|
|
|
[this](sscl::co::NonViralTaskNursery::Slot::Lease &lease)
|
2026-06-06 19:24:00 -04:00
|
|
|
{
|
2026-06-09 11:19:42 -04:00
|
|
|
return initializeCReq(
|
|
|
|
|
lease.getExceptionStorage(),
|
|
|
|
|
lease.getCallerLambda());
|
|
|
|
|
},
|
|
|
|
|
std::move(completion));
|
2026-05-24 16:12:29 -04:00
|
|
|
}
|
2025-11-23 03:27:18 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
void MarionetteComponent::holdFinalizeCReq(
|
2026-06-09 11:19:42 -04:00
|
|
|
std::function<void(std::exception_ptr &exceptionPtr)> completion)
|
2026-05-24 16:12:29 -04:00
|
|
|
{
|
2026-06-09 11:19:42 -04:00
|
|
|
taskNursery.launch(
|
|
|
|
|
[this](sscl::co::NonViralTaskNursery::Slot::Lease &lease)
|
2026-06-06 19:24:00 -04:00
|
|
|
{
|
2026-06-09 11:19:42 -04:00
|
|
|
return finalizeCReq(
|
|
|
|
|
lease.getExceptionStorage(),
|
|
|
|
|
lease.getCallerLambda());
|
|
|
|
|
},
|
|
|
|
|
std::move(completion));
|
2026-05-24 16:12:29 -04:00
|
|
|
}
|
2025-11-23 03:27:18 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
MrnttNonViralPostingInvoker MarionetteComponent::initializeCReq(
|
|
|
|
|
[[maybe_unused]] std::exception_ptr &exceptionPtr,
|
|
|
|
|
[[maybe_unused]] std::function<void()> callback)
|
2025-09-14 22:17:19 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
assertMarionetteThread();
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
smo::mind::globalMind = std::make_shared<smo::Mind>();
|
|
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
co_await smo::mind::globalMind->initializeCReq();
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
smo::device::DeviceManager::getInstance().initializeDeviceReattacher();
|
|
|
|
|
|
|
|
|
|
// Call negtrinEventInd on the Director in the final callback
|
|
|
|
|
smo::mind::globalMind->director.negtrinEventInd();
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
co_return;
|
2025-09-14 22:17:19 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
MrnttNonViralPostingInvoker MarionetteComponent::finalizeCReq(
|
|
|
|
|
[[maybe_unused]] std::exception_ptr &exceptionPtr,
|
|
|
|
|
[[maybe_unused]] std::function<void()> callback)
|
2025-09-14 22:17:19 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
assertMarionetteThread();
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
smo::device::DeviceManager::getInstance().finalizeDeviceReattacher();
|
|
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
if (!smo::mind::globalMind) { co_return; }
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
co_await smo::mind::globalMind->finalizeCReq();
|
2025-09-14 22:17:19 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
co_return;
|
2025-09-14 22:17:19 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 17:46:27 -04:00
|
|
|
void MarionetteComponent::handleLoopExceptionHook()
|
|
|
|
|
{
|
|
|
|
|
sscl::pptr::exitCode = EXIT_FAILURE;
|
|
|
|
|
exceptionInd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MarionetteComponent::exceptionInd()
|
2025-11-23 03:27:18 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
auto puppeteer = sscl::ComponentThread::getPptr();
|
2025-11-23 03:27:18 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
boost::asio::post(
|
2026-05-30 11:59:42 -04:00
|
|
|
puppeteer->getIoContext(),
|
2026-05-24 16:12:29 -04:00
|
|
|
[]
|
|
|
|
|
{
|
|
|
|
|
mrntt.holdFinalizeCReq(
|
2026-06-09 11:19:42 -04:00
|
|
|
[](std::exception_ptr &exceptionPtr)
|
|
|
|
|
{
|
|
|
|
|
sscl::co::NonViralCompletion nvc(exceptionPtr);
|
|
|
|
|
nvc.checkAndRethrowException();
|
|
|
|
|
marionetteFinalizeReqCb(true);
|
|
|
|
|
});
|
2026-05-24 16:12:29 -04:00
|
|
|
});
|
2025-11-23 03:27:18 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 17:46:27 -04:00
|
|
|
} // namespace mrntt
|
|
|
|
|
} // namespace smo
|