Skip to content

Commit

Permalink
Also use event pools in XMI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Jan 27, 2024
1 parent 530b5f9 commit 0425ab5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/XmiFsm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
#include <cpp_event_framework/Signal.hxx>
#include <cpp_event_framework/Statemachine.hxx>

class Transition_1 : public cpp_event_framework::SignalBase<Transition_1, 0>
class EventPoolAllocator : public cpp_event_framework::PoolAllocator<EventPoolAllocator>
{
};

class Transition_1
: public cpp_event_framework::SignalBase<Transition_1, 0, cpp_event_framework::Signal, EventPoolAllocator>
{
};
class Transition_2 : public cpp_event_framework::NextSignal<Transition_2, Transition_1>
{
};
Expand All @@ -32,6 +36,10 @@ class Internal : public cpp_event_framework::NextSignal<Internal, Transition_8>
{
};

using PoolSizeCalculator =
cpp_event_framework::SignalPoolElementSizeCalculator<Transition_1, Transition_2, Transition_3, Transition_4,
Transition_6, Transition_7, Transition_8, Internal>;

inline std::ostream& operator<<(std::ostream& os, const cpp_event_framework::Signal::SPtr& event)
{
switch (event->Id())
Expand Down
11 changes: 11 additions & 0 deletions test/XmiFsmImpl.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include <cstddef>
#include <iostream>
#include <source_location>

#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)
Expand All @@ -22,6 +29,8 @@ XmiFsmImpl::XmiFsmImpl()

void XmiFsmImpl::Test()
{
assert(EventPoolAllocator::pool->FillLevel() == kPoolSize);

// FSM not started
CheckAllFalse();
assert(fsm_.CurrentState() == nullptr);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0425ab5

Please sign in to comment.