Integrate FSM with Plugin: states/actions from plugins, hot reload

Fsm/PluginBehavior.hpp: IFsmBehaviorPack::register_into(Builder&) lets a
plugin contribute states/events/guards/actions; plugins export it via
extern "C" void_plugin_fsm_behaviors(). build_machine_def(pack) runs the
pack through a Builder and validates.

PluginManager::raw_symbol(name, symbol) resolves an optional extra entry
point from a plugin's current .so (returns nullptr if absent), so the
host can fetch the behaviour factory without widening the frozen IPlugin
vtable.

Integration flow (tests/internal/FsmPluginHotReload.cpp): build a machine
def from the plugin pack, run it; on reload, rebuild from the reloaded
pack and swap_definition between RTC steps. Same state names across
versions ⇒ the live configuration is adopted seamlessly (machine keeps
running, queue intact); v2's new "skip" transition goes live. Safety:
plugin actions are std::functions whose code lives in the .so, so a
PluginHandle is pinned for the machine's lifetime and dlclose_on_swap=
false keeps the code pages mapped under in-flight frames.

Tests: FsmPluginV1/V2 (same idle/busy/done states; v2 adds skip).
Definition-swap test proves configuration survival + new behaviour; the
stress test runs 4 producer threads posting while 5 v1<->v2 rebuild+swaps
happen concurrently, then asserts exactly one active leaf. 967 tests
green, stable across runs, ASan+UBSan clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Fable 5 committed 2026-06-13 18:13:03 +03:00
1 parent b343bce396
commit c988f635e9
8 files changed
+403

No files matched your search

+18
View File
@@ -116,4 +116,22 @@ if(TARGET Void::Plugin)
target_include_directories(VoidTests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/plugins")
add_dependencies(VoidTests VoidStatefulPluginV1 VoidStatefulPluginV2)
# FSM behaviour plugins (states/actions provided by a plugin) for the
# FSM x Plugin hot-reload integration test. Same state names across
# versions so swap_definition adopts the live configuration.
if(TARGET Void::Fsm)
add_library(VoidFsmPluginV1 SHARED
"${CMAKE_CURRENT_SOURCE_DIR}/plugins/FsmPluginV1.cpp")
add_library(VoidFsmPluginV2 SHARED
"${CMAKE_CURRENT_SOURCE_DIR}/plugins/FsmPluginV2.cpp")
foreach(_fp VoidFsmPluginV1 VoidFsmPluginV2)
target_link_libraries(${_fp} PRIVATE Void::Plugin Void::Fsm)
endforeach()
target_compile_definitions(VoidTests PRIVATE
"VOID_FSM_PLUGIN_V1_PATH=\"$<TARGET_FILE:VoidFsmPluginV1>\""
"VOID_FSM_PLUGIN_V2_PATH=\"$<TARGET_FILE:VoidFsmPluginV2>\""
)
add_dependencies(VoidTests VoidFsmPluginV1 VoidFsmPluginV2)
endif()
endif()