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");