#include #include #include #include #include // FSM behaviour plugin, v1. Defines a 3-state cycle (idle -> busy -> done // -> idle) and counts how many times its action ran. v2 keeps the same // state/event names so the host can swap_definition seamlessly. 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"); 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); } }; } // 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 = "1.0.0", .description = "FSM behaviour plugin (v1)", }; } // Stateless factory: returns a fresh pack the host uses only during // definition build. It does not need to be the IPlugin instance. Void::Fsm::IFsmBehaviorPack* void_plugin_fsm_behaviors() { static FsmPlugin pack; return &pack; } } // extern "C"