#include #include #include #include #include // FSM behaviour plugin, v2. Same state/event names as v1 (so the host // adopts the active configuration seamlessly on swap_definition) plus a // new "skip" transition idle -> done that proves the reloaded behaviour // is live. namespace { std::atomic g_action_runs{0}; class FsmPlugin final : public Void::Plugin::IPlugin, public Void::Fsm::IFsmBehaviorPack { public: [[nodiscard]] std::string_view name() const noexcept override { return "FsmPlugin"; } void register_into(Void::Fsm::Builder& b) override { using namespace Void::Fsm; auto idle = b.state("idle"); auto busy = b.state("busy"); auto done = b.state("done"); b.initial(idle); const auto start = b.event("start"); const auto finish = b.event("finish"); const auto reset = b.event("reset"); const auto skip = b.event("skip"); // new in v2 b.transition(idle, start, busy) .action(SyncAction{[](Machine&, const Event&) { g_action_runs.fetch_add(1, std::memory_order_relaxed); }}); b.transition(busy, finish, done); b.transition(done, reset, idle); b.transition(idle, skip, done); // new behaviour } }; } // namespace extern "C" { void* void_plugin_create() { return new FsmPlugin; } void void_plugin_destroy(void* p) { delete static_cast(p); } Void::Plugin::PluginInfo void_plugin_info() { return { .abi_version = Void::Plugin::ABI_VERSION, .name = "FsmPlugin", .plugin_version = "2.0.0", .description = "FSM behaviour plugin (v2)", }; } Void::Fsm::IFsmBehaviorPack* void_plugin_fsm_behaviors() { static FsmPlugin pack; return &pack; } } // extern "C"