|
86 | 86 | #include <cloe/core/abort.hpp> // for AsyncAbort
|
87 | 87 | #include <cloe/registrar.hpp> // for DirectCallback
|
88 | 88 | #include <cloe/trigger/example_actions.hpp> // for CommandFactory, BundleFactory, ...
|
89 |
| -#include <cloe/trigger/macros.hpp> // for DEFINE_SIMPLE_ACTION |
| 89 | +#include <cloe/trigger/set_action.hpp> // for DEFINE_SET_STATE_ACTION, SetDataActionFactory |
90 | 90 | #include <cloe/utility/resource_handler.hpp> // for INCLUDE_RESOURCE, RESOURCE_HANDLER
|
91 | 91 | #include <fable/utility.hpp> // for pretty_print
|
92 | 92 |
|
@@ -260,62 +260,26 @@ class SimulationMachine
|
260 | 260 | namespace actions {
|
261 | 261 |
|
262 | 262 | // clang-format off
|
263 |
| -DEFINE_SIMPLE_ACTION(Pause, "pause", "pause simulation", SimulationMachine, { ptr_->pause(); }) |
264 |
| -DEFINE_SIMPLE_ACTION(Resume, "resume", "resume paused simulation", SimulationMachine, { ptr_->resume(); }) |
265 |
| -DEFINE_SIMPLE_ACTION(Stop, "stop", "stop simulation with neither success nor failure", SimulationMachine, { ptr_->stop(); }) |
266 |
| -DEFINE_SIMPLE_ACTION(Succeed, "succeed", "stop simulation with success", SimulationMachine, { ptr_->succeed(); }) |
267 |
| -DEFINE_SIMPLE_ACTION(Fail, "fail", "stop simulation with failure", SimulationMachine, { ptr_->fail(); }) |
268 |
| -DEFINE_SIMPLE_ACTION(Reset, "reset", "attempt to reset simulation", SimulationMachine, { ptr_->reset(); }) |
269 |
| - |
270 |
| -DEFINE_SIMPLE_ACTION(KeepAlive, "keep_alive", "keep simulation alive after termination", |
271 |
| - SimulationContext, { ptr_->config.engine.keep_alive = true; }) |
272 |
| - |
273 |
| -DEFINE_SIMPLE_ACTION(ResetStatistics, "reset_statistics", "reset simulation statistics", |
274 |
| - SimulationStatistics, { ptr_->reset(); }) |
275 |
| -// clang-format on |
| 263 | +DEFINE_SET_STATE_ACTION(Pause, "pause", "pause simulation", SimulationMachine, { ptr_->pause(); }) |
| 264 | +DEFINE_SET_STATE_ACTION(Resume, "resume", "resume paused simulation", SimulationMachine, { ptr_->resume(); }) |
| 265 | +DEFINE_SET_STATE_ACTION(Stop, "stop", "stop simulation with neither success nor failure", SimulationMachine, { ptr_->stop(); }) |
| 266 | +DEFINE_SET_STATE_ACTION(Succeed, "succeed", "stop simulation with success", SimulationMachine, { ptr_->succeed(); }) |
| 267 | +DEFINE_SET_STATE_ACTION(Fail, "fail", "stop simulation with failure", SimulationMachine, { ptr_->fail(); }) |
| 268 | +DEFINE_SET_STATE_ACTION(Reset, "reset", "attempt to reset simulation", SimulationMachine, { ptr_->reset(); }) |
276 | 269 |
|
277 |
| -class RealtimeFactor : public cloe::Action { |
278 |
| - public: |
279 |
| - explicit RealtimeFactor(const std::string& name, SimulationSync* s, double realtime_factor) |
280 |
| - : Action(name), sync_(s), realtime_factor_(realtime_factor) {} |
281 |
| - cloe::ActionPtr clone() const override { |
282 |
| - return std::make_unique<RealtimeFactor>(name(), sync_, realtime_factor_); |
283 |
| - } |
284 |
| - void operator()(const cloe::Sync&, cloe::TriggerRegistrar&) override { |
285 |
| - logger()->info("Setting target simulation speed: {}", realtime_factor_); |
286 |
| - sync_->set_realtime_factor(realtime_factor_); |
287 |
| - } |
288 |
| - bool is_significant() const override { return false; } |
289 |
| - void to_json(cloe::Json& j) const override { |
290 |
| - j = cloe::Json{ |
291 |
| - {"factor", realtime_factor_}, |
292 |
| - }; |
293 |
| - } |
| 270 | +DEFINE_SET_STATE_ACTION(KeepAlive, "keep_alive", "keep simulation alive after termination", |
| 271 | + SimulationContext, { ptr_->config.engine.keep_alive = true; }) |
294 | 272 |
|
295 |
| - private: |
296 |
| - SimulationSync* sync_; |
297 |
| - double realtime_factor_; |
298 |
| -}; |
| 273 | +DEFINE_SET_STATE_ACTION(ResetStatistics, "reset_statistics", "reset simulation statistics", |
| 274 | + SimulationStatistics, { ptr_->reset(); }) |
299 | 275 |
|
300 |
| -class RealtimeFactorFactory : public cloe::ActionFactory { |
301 |
| - public: |
302 |
| - using ActionType = RealtimeFactor; |
303 |
| - explicit RealtimeFactorFactory(SimulationSync* s) |
304 |
| - : cloe::ActionFactory("realtime_factor", "modify the simulation speed"), sync_(s) {} |
305 |
| - cloe::ActionPtr make(const cloe::Conf& c) const override { |
306 |
| - auto factor = c.get<double>("factor"); |
307 |
| - return std::make_unique<RealtimeFactor>(name(), sync_, factor); |
308 |
| - } |
309 |
| - cloe::ActionPtr make(const std::string& s) const override { |
310 |
| - auto factor = std::stod(s); |
311 |
| - return make(cloe::Conf{cloe::Json{ |
312 |
| - {"factor", factor}, |
313 |
| - }}); |
314 |
| - } |
| 276 | +DEFINE_SET_DATA_ACTION(RealtimeFactor, "realtime_factor", "modify the simulation speed", SimulationSync, "factor", double, |
| 277 | + { |
| 278 | + logger()->info("Setting target simulation speed: {}", value_); |
| 279 | + ptr_->set_realtime_factor(value_); |
| 280 | + }) |
315 | 281 |
|
316 |
| - private: |
317 |
| - SimulationSync* sync_; |
318 |
| -}; |
| 282 | +// clang-format on |
319 | 283 |
|
320 | 284 | } // namespace actions
|
321 | 285 |
|
@@ -477,8 +441,8 @@ StateId SimulationMachine::Connect::impl(SimulationContext& ctx) {
|
477 | 441 | ctx.now_initializing = x.get();
|
478 | 442 |
|
479 | 443 | // Configure simulator:
|
480 |
| - auto r = ctx.registrar->with_trigger_prefix(name) |
481 |
| - ->with_api_prefix(std::string("/simulators/") + name); |
| 444 | + auto r = ctx.registrar->with_trigger_prefix(name)->with_api_prefix( |
| 445 | + std::string("/simulators/") + name); |
482 | 446 | x->connect();
|
483 | 447 | x->enroll(*r);
|
484 | 448 |
|
@@ -531,8 +495,8 @@ StateId SimulationMachine::Connect::impl(SimulationContext& ctx) {
|
531 | 495 | ctx.now_initializing = x.get();
|
532 | 496 |
|
533 | 497 | // Configure component:
|
534 |
| - auto r = ctx.registrar->with_trigger_prefix(name) |
535 |
| - ->with_api_prefix(std::string("/components/") + name); |
| 498 | + auto r = ctx.registrar->with_trigger_prefix(name)->with_api_prefix( |
| 499 | + std::string("/components/") + name); |
536 | 500 | x->connect();
|
537 | 501 | x->enroll(*r);
|
538 | 502 |
|
@@ -625,8 +589,8 @@ StateId SimulationMachine::Connect::impl(SimulationContext& ctx) {
|
625 | 589 | }
|
626 | 590 |
|
627 | 591 | // Configure vehicle:
|
628 |
| - auto r = ctx.registrar->with_trigger_prefix(c.name) |
629 |
| - ->with_api_prefix(std::string("/vehicles/") + c.name); |
| 592 | + auto r = ctx.registrar->with_trigger_prefix(c.name)->with_api_prefix( |
| 593 | + std::string("/vehicles/") + c.name); |
630 | 594 | x->connect();
|
631 | 595 | x->enroll(*r);
|
632 | 596 |
|
@@ -707,8 +671,8 @@ StateId SimulationMachine::Connect::impl(SimulationContext& ctx) {
|
707 | 671 | ctx.now_initializing = x.get();
|
708 | 672 |
|
709 | 673 | // Configure
|
710 |
| - auto r = ctx.registrar->with_trigger_prefix(name) |
711 |
| - ->with_api_prefix(std::string("/controllers/") + name); |
| 674 | + auto r = ctx.registrar->with_trigger_prefix(name)->with_api_prefix( |
| 675 | + std::string("/controllers/") + name); |
712 | 676 | x->set_vehicle(ctx.vehicles.at(c.vehicle));
|
713 | 677 | x->connect();
|
714 | 678 | x->enroll(*r);
|
|
0 commit comments