From 57625858dffb0102b6febcd7f1d1a8e3946363a3 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 26 Aug 2022 09:37:42 +0200 Subject: [PATCH] Reproducer for control misbehavior --- examples/1-1/sampler.cxx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/1-1/sampler.cxx b/examples/1-1/sampler.cxx index 37c3d46d..f49a80d2 100644 --- a/examples/1-1/sampler.cxx +++ b/examples/1-1/sampler.cxx @@ -8,8 +8,9 @@ #include #include - +#include #include +#include namespace bpo = boost::program_options; @@ -17,6 +18,21 @@ struct Sampler : fair::mq::Device { void InitTask() override { + static std::vector transitions = {"END", "RESET DEVICE", "RESET TASK", "STOP"}; + static bool isRunning = false; + std::function stateWatcher = + [this](const fair::mq::State state) -> void { + if (state == fair::mq::State::Running) { + isRunning = true; + } + if (isRunning) { + LOG(info) << "Switching to " << transitions.back() << std::endl; + assert(transitions.empty() == false); + ChangeState(transitions.back()); + transitions.pop_back(); + } + }; + this->SubscribeToStateChange("dpl", stateWatcher); // Get the fText and fMaxIterations values from the command line options (via fConfig) fText = fConfig->GetProperty("text"); fMaxIterations = fConfig->GetProperty("max-iterations");