Skip to content

Commit

Permalink
Rename SCXML model
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Jan 7, 2024
1 parent 5842c47 commit 51dd9ee
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 67 deletions.
6 changes: 3 additions & 3 deletions test/ScXmlFsm.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ScXmlFsm.hxx"

#define StatemachineTest_GET_INSTANCE_EVENT_ID(e) e
#define StatemachineTest_GET_STATIC_EVENT_ID(e) EScXmlEvent::e
#define ScXmlTest_GET_INSTANCE_EVENT_ID(e) e
#define ScXmlTest_GET_STATIC_EVENT_ID(e) EScXmlEvent::e

#include "generated/StatemachineTestInstance.hxx"
#include "generated/ScXmlTestInstance.hxx"
8 changes: 4 additions & 4 deletions test/ScXmlFsm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ inline std::ostream& operator<<(std::ostream& os, EScXmlEvent event)
return os;
}

class IStatemachineTestImpl;
using StatemachineTestBase = cpp_event_framework::Statemachine<IStatemachineTestImpl, EScXmlEvent>;
class IScXmlTestImpl;
using ScXmlTestBase = cpp_event_framework::Statemachine<IScXmlTestImpl, EScXmlEvent>;

#include "generated/IStatemachineTestImpl.hxx"
#include "generated/StatemachineTestDeclaration.hxx"
#include "generated/IScXmlTestImpl.hxx"
#include "generated/ScXmlTestDeclaration.hxx"
32 changes: 15 additions & 17 deletions test/ScXmlFsmImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,36 @@
#include <source_location>

#include "ScXmlFsmImpl.hxx"
#include "generated/StatemachineTestDeclaration.hxx"
#include "generated/ScXmlTestDeclaration.hxx"

ScXmlFsmImpl::ScXmlFsmImpl()
{
fsm_.on_handle_event_ =
[](StatemachineTest::Ref fsm, StatemachineTest::StateRef state, StatemachineTest::Event event)
fsm_.on_handle_event_ = [](ScXmlTest::Ref fsm, ScXmlTest::StateRef state, ScXmlTest::Event event)
{ std::cout << fsm.Name() << " State " << state.Name() << " handle event " << event << '\n'; };
fsm_.on_state_entry_ = [](StatemachineTest::Ref fsm, StatemachineTest::StateRef state)
fsm_.on_state_entry_ = [](ScXmlTest::Ref fsm, ScXmlTest::StateRef state)
{ std::cout << fsm.Name() << " Enter state" << state.Name() << '\n'; };
fsm_.on_state_exit_ = [](StatemachineTest::Ref fsm, StatemachineTest::StateRef state)
fsm_.on_state_exit_ = [](ScXmlTest::Ref fsm, ScXmlTest::StateRef state)
{ std::cout << fsm.Name() << " Exit state" << state.Name() << '\n'; };
fsm_.on_unhandled_event_ =
[](StatemachineTest::Ref fsm, StatemachineTest::StateRef state, StatemachineTest::Event event)
fsm_.on_unhandled_event_ = [](ScXmlTest::Ref fsm, ScXmlTest::StateRef state, ScXmlTest::Event event)
{ std::cout << fsm.Name() << " Unhandled event " << event << " in state " << state.Name() << '\n'; };

fsm_.Init(this, "ScXml", StatemachineTest::kInitialState);
fsm_.Init(this, "ScXml", ScXmlTest::kInitialState);
}

void ScXmlFsmImpl::Test()
{
assert(fsm_.CurrentState() == nullptr);
fsm_.Start();

assert(fsm_.CurrentState() == &StatemachineTest::kState_2);
assert(fsm_.CurrentState() == &ScXmlTest::kState_2);
fsm_.React(EScXmlEvent::Internal);
assert(fsm_.CurrentState() == &StatemachineTest::kState_2);
assert(fsm_.CurrentState() == &ScXmlTest::kState_2);
fsm_.React(EScXmlEvent::Transition_3);
assert(fsm_.CurrentState() == &StatemachineTest::kState_3);
assert(fsm_.CurrentState() == &ScXmlTest::kState_3);
fsm_.React(EScXmlEvent::Transition_7);
assert(fsm_.CurrentState() == &StatemachineTest::kState_4);
assert(fsm_.CurrentState() == &ScXmlTest::kState_4);
fsm_.React(EScXmlEvent::Transition_8);
assert(fsm_.CurrentState() == &StatemachineTest::kState_2);
assert(fsm_.CurrentState() == &ScXmlTest::kState_2);
}

void ScXmlFsmImpl::entry()
Expand All @@ -44,19 +42,19 @@ void ScXmlFsmImpl::exit()
{
std::cout << std::source_location::current().function_name() << "\n";
}
void ScXmlFsmImpl::action(StatemachineTestBase::Event /*event*/)
void ScXmlFsmImpl::action(ScXmlTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
}
void ScXmlFsmImpl::action2(StatemachineTestBase::Event /*event*/)
void ScXmlFsmImpl::action2(ScXmlTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
}
void ScXmlFsmImpl::internalaction(StatemachineTestBase::Event /*event*/)
void ScXmlFsmImpl::internalaction(ScXmlTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
}
bool ScXmlFsmImpl::guard(StatemachineTestBase::Event /*event*/)
bool ScXmlFsmImpl::guard(ScXmlTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
return true;
Expand Down
12 changes: 6 additions & 6 deletions test/ScXmlFsmImpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

#include "ScXmlFsm.hxx"

class ScXmlFsmImpl : private IStatemachineTestImpl
class ScXmlFsmImpl : private IScXmlTestImpl
{
public:
ScXmlFsmImpl();

void Test();

private:
StatemachineTest fsm_;
ScXmlTest fsm_;

void entry() override;
void exit() override;
void action(StatemachineTestBase::Event event) override;
void action2(StatemachineTestBase::Event event) override;
bool guard(StatemachineTestBase::Event event) override;
void internalaction(StatemachineTestBase::Event event) override;
void action(ScXmlTestBase::Event event) override;
void action2(ScXmlTestBase::Event event) override;
bool guard(ScXmlTestBase::Event event) override;
void internalaction(ScXmlTestBase::Event event) override;
};
15 changes: 15 additions & 0 deletions test/generated/IScXmlTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class IScXmlTestImpl
{
public:
// Actions
virtual void action(ScXmlTestBase::Event event) = 0;
virtual void action2(ScXmlTestBase::Event event) = 0;
virtual void internalaction(ScXmlTestBase::Event event) = 0;

// Guards
virtual bool guard(ScXmlTestBase::Event event) = 0;

// Entry/Exit
virtual void entry() = 0;
virtual void exit() = 0;
};
15 changes: 0 additions & 15 deletions test/generated/IStatemachineTestImpl.hxx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Statemachine StatemachineTest declaration
// Statemachine ScXmlTest declaration

#pragma once

class StatemachineTest : public StatemachineTestBase
class ScXmlTest : public ScXmlTestBase
{
public:
static const StatePtr kInitialState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Statemachine StatemachineTest instance
// Statemachine ScXmlTest instance

// Override the following defines according to your needs if you are not using cpp_event_framework:

Expand All @@ -11,38 +11,38 @@
#endif

// Initial state
const StatemachineTest::StatePtr StatemachineTest::kInitialState = &StatemachineTest::kState_1;
const ScXmlTest::StatePtr ScXmlTest::kInitialState = &ScXmlTest::kState_1;

// State State_1
const StatemachineTest::State StatemachineTest::kState_1("State_1", &State_1Handler, nullptr, &kState_2, nullptr, nullptr);
StatemachineTest::Transition StatemachineTest::State_1Handler(ImplPtr impl, Event event)
const ScXmlTest::State ScXmlTest::kState_1("State_1", &State_1Handler, nullptr, &kState_2, nullptr, nullptr);
ScXmlTest::Transition ScXmlTest::State_1Handler(ImplPtr impl, Event event)
{
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(StatemachineTest_GET_INSTANCE_EVENT_ID(event))
switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
default:
return UnhandledEvent();
}
}

// State State_2
const StatemachineTest::HistoryState StatemachineTest::kState_2("State_2", &State_2Handler, &kState_1, nullptr, nullptr, nullptr);
StatemachineTest::Transition StatemachineTest::State_2Handler(ImplPtr impl, Event event)
const ScXmlTest::HistoryState ScXmlTest::kState_2("State_2", &State_2Handler, &kState_1, nullptr, nullptr, nullptr);
ScXmlTest::Transition ScXmlTest::State_2Handler(ImplPtr impl, Event event)
{
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(StatemachineTest_GET_INSTANCE_EVENT_ID(event))
switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
case StatemachineTest_GET_STATIC_EVENT_ID(Internal):
case ScXmlTest_GET_STATIC_EVENT_ID(Internal):
if (true)
{
static const Transition::ActionContainer<1> kActions = {&Impl::internalaction};
return TransitionTo(kNone, kActions);
}
return UnhandledEvent();

case StatemachineTest_GET_STATIC_EVENT_ID(Transition_3):
case ScXmlTest_GET_STATIC_EVENT_ID(Transition_3):
if (impl->guard(event))
{
static const Transition::ActionContainer<2> kActions = {&Impl::action, &Impl::action2};
Expand All @@ -56,14 +56,14 @@ StatemachineTest::Transition StatemachineTest::State_2Handler(ImplPtr impl, Even
}

// State State_3
const StatemachineTest::State StatemachineTest::kState_3("State_3", &State_3Handler, &kState_1, nullptr, &Impl::entry, &Impl::exit);
StatemachineTest::Transition StatemachineTest::State_3Handler(ImplPtr impl, Event event)
const ScXmlTest::State ScXmlTest::kState_3("State_3", &State_3Handler, &kState_1, nullptr, &Impl::entry, &Impl::exit);
ScXmlTest::Transition ScXmlTest::State_3Handler(ImplPtr impl, Event event)
{
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(StatemachineTest_GET_INSTANCE_EVENT_ID(event))
switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
case StatemachineTest_GET_STATIC_EVENT_ID(Transition_7):
case ScXmlTest_GET_STATIC_EVENT_ID(Transition_7):
if (true)
{
return TransitionTo(kState_4);
Expand All @@ -76,14 +76,14 @@ StatemachineTest::Transition StatemachineTest::State_3Handler(ImplPtr impl, Even
}

// State State_4
const StatemachineTest::State StatemachineTest::kState_4("State_4", &State_4Handler, &kState_1, nullptr, nullptr, nullptr);
StatemachineTest::Transition StatemachineTest::State_4Handler(ImplPtr impl, Event event)
const ScXmlTest::State ScXmlTest::kState_4("State_4", &State_4Handler, &kState_1, nullptr, nullptr, nullptr);
ScXmlTest::Transition ScXmlTest::State_4Handler(ImplPtr impl, Event event)
{
(void)impl; // impl parameter is unused when there is no guard function being called in here

switch(StatemachineTest_GET_INSTANCE_EVENT_ID(event))
switch(ScXmlTest_GET_INSTANCE_EVENT_ID(event))
{
case StatemachineTest_GET_STATIC_EVENT_ID(Transition_8):
case ScXmlTest_GET_STATIC_EVENT_ID(Transition_8):
if (true)
{
return TransitionTo(kState_2);
Expand Down
4 changes: 2 additions & 2 deletions test/scxml/StatemachineTest.scxml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" xmlns:qt="http://www.qt.io/2015/02/scxml-ext" name="StatemachineTest" qt:editorversion="10.0.2" initial="State_1">
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" xmlns:qt="http://www.qt.io/2015/02/scxml-ext" name="ScXmlTest" qt:editorversion="10.0.2" initial="State_1">
<qt:editorinfo initialGeometry="173.60;133.78;-20;-20;40;40"/>
<state id="State_1">
<qt:editorinfo geometry="292.06;222.62;-60;-78.36;626.74;589.96" scenegeometry="292.06;222.62;232.06;144.26;626.74;589.96"/>
<state id="State_2">
<qt:editorinfo geometry="119.48;168.49;-106;-50;166;100" scenegeometry="411.54;391.11;305.54;341.11;166;100"/>
<qt:editorinfo geometry="119.48;168.49;-122.47;-50;182.47;100" scenegeometry="411.54;391.11;289.07;341.11;182.47;100"/>
<transition type="external" event="Transition_3" target="State_3" cond="guard">
<qt:editorinfo endTargetFactors="25.22;50.88"/>
<script src="action"/>
Expand Down

0 comments on commit 51dd9ee

Please sign in to comment.