Exceptions: All of smocore likely now uses exceptions

This commit is contained in:
2026-06-07 19:37:50 -04:00
parent 241e8a6798
commit b2644f17c6
8 changed files with 304 additions and 242 deletions
+24 -17
View File
@@ -6,6 +6,7 @@
#include <deviceManager/deviceReattacher.h>
#include <deviceManager/deviceManager.h>
#include <marionette/marionetteThread.h>
#include <spinscale/co/nonViralCompletion.h>
namespace smo {
namespace device {
@@ -20,29 +21,25 @@ DeviceReattacher::DeviceReattacher(
DeviceManager& parent, std::shared_ptr<sscl::ComponentThread> ioThread)
: parent(parent), ioThread(ioThread), timer(ioThread->getIoContext())
{
/** EXPLANATION:
* The thread on which DeviceReattacher runs is whichever thread executes
* the io_context that owns deadline_timer. Timer async_wait handlers
* (onTimeout, holdReattachCReq, reattachKnownListCReq) are dispatched on
* that thread. ioThread selects that io_context here; start() only arms
* the timer on it.
*/
}
mrntt::MrnttNonViralPostingInvoker DeviceReattacher::reattachKnownListCReq(
[[maybe_unused]] sscl::co::ExplicitPostTarget postTarget,
mrntt::MrnttNonViralNonPostingInvoker DeviceReattacher::reattachKnownListCReq(
[[maybe_unused]] std::exception_ptr &exceptionPtr,
[[maybe_unused]] std::function<void()> callback)
{
/** EXPLANATION:
* DeviceManager attach APIs require the marionette thread; postTarget
* selects where this coroutine runs (mrntt io_context). Completion still
* posts back to the mrntt timer thread via callerIoContext.
* Non-posting: invoked from holdReattachCReq on the timer callback thread
* (see ctor). Nested DeviceManager attach APIs still post to MRNTT as
* needed via their own viral posting invokers.
*/
(void)postTarget;
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_await parent.attachAllUnattachedDevicesFromKnownListCReq();
co_return;
}
@@ -92,10 +89,20 @@ void DeviceReattacher::holdReattachCReq()
reattachCReqInvoker.reset();
reattachCReqInvoker.emplace(reattachKnownListCReq(
sscl::co::ExplicitPostTarget{ioThread->getIoContext()},
reattachLifetimeExceptionPtr,
[this]()
{
sscl::co::NonViralCompletion nvc(reattachLifetimeExceptionPtr);
if (nvc.hasException())
{
try {
nvc.checkAndRethrowException();
} catch (const std::exception &e) {
std::cerr << "DeviceReattacher: " << e.what()
<< std::endl;
}
}
sscl::SpinLock::Guard guard(deviceReattacherCanceler.s.lock);
reattachOpInFlight = false;
}));