From 0425ab55ef3483031224e1f13cc36fc4aedd660c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 27 Jan 2024 17:49:49 +0100 Subject: [PATCH] Also use event pools in XMI implementation --- test/XmiFsm.hxx | 10 +++++++++- test/XmiFsmImpl.cxx | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/XmiFsm.hxx b/test/XmiFsm.hxx index 43f5f57..1944aff 100644 --- a/test/XmiFsm.hxx +++ b/test/XmiFsm.hxx @@ -6,10 +6,14 @@ #include #include -class Transition_1 : public cpp_event_framework::SignalBase +class EventPoolAllocator : public cpp_event_framework::PoolAllocator { }; +class Transition_1 + : public cpp_event_framework::SignalBase +{ +}; class Transition_2 : public cpp_event_framework::NextSignal { }; @@ -32,6 +36,10 @@ class Internal : public cpp_event_framework::NextSignal { }; +using PoolSizeCalculator = + cpp_event_framework::SignalPoolElementSizeCalculator; + inline std::ostream& operator<<(std::ostream& os, const cpp_event_framework::Signal::SPtr& event) { switch (event->Id()) diff --git a/test/XmiFsmImpl.cxx b/test/XmiFsmImpl.cxx index b24764e..159732d 100644 --- a/test/XmiFsmImpl.cxx +++ b/test/XmiFsmImpl.cxx @@ -1,10 +1,17 @@ +#include #include #include +#include "XmiFsm.hxx" #include "XmiFsmImpl.hxx" +constexpr size_t kPoolSize = 10; + XmiFsmImpl::XmiFsmImpl() { + auto pool = cpp_event_framework::Pool<>::MakeShared(PoolSizeCalculator::kSptrSize, kPoolSize, "MyPool"); + EventPoolAllocator::SetPool(pool); + fsm_.on_handle_event_ = [](XmiTest::Ref fsm, XmiTest::StateRef state, XmiTest::Event event) { std::cout << fsm.Name() << " State " << state.Name() << " handle event " << event << '\n'; }; fsm_.on_state_entry_ = [](XmiTest::Ref fsm, XmiTest::StateRef state) @@ -22,6 +29,8 @@ XmiFsmImpl::XmiFsmImpl() void XmiFsmImpl::Test() { + assert(EventPoolAllocator::pool->FillLevel() == kPoolSize); + // FSM not started CheckAllFalse(); assert(fsm_.CurrentState() == nullptr); @@ -135,6 +144,8 @@ void XmiFsmImpl::Test() assert(choice_action2_called_); choice_action2_called_ = false; CheckAllFalse(); + + assert(EventPoolAllocator::pool->FillLevel() == kPoolSize); } void XmiFsmImpl::CheckAllFalse() const