erikzenker / hsm

Finite state machine library based on the boost hana meta programming library. It follows the principles of the boost msm and boost sml libraries, but tries to reduce own complex meta programming code to a minimum.
MIT License
187 stars 18 forks source link

[FEATURE] Call a state activity #189

Open Lecrapouille opened 8 months ago

Lecrapouille commented 8 months ago

Problem

How to run a state activity when I'm on a given state ?

An action is instantaneous: it does not consume time (contrary to the activity). The activity can be seen as a thread that is preempted by any external events the state reacts to. https://cs.emis.de/LNI/Proceedings/Proceedings07/TowardEfficCode_3.pdf

struct MyState {
  MyState(hsm::sm<MyFSM>& fsm)
    : m_sfm(fsm)
   {}

  void tickActivity()
  {
      // do_something not blocking too much
      // Allow m_fsm.process_event(EventXXX {});
  }

  sm::sm<MyFSM>& m_fsm;
};

main()
{
  hsm::sm<MyFSM> fsm;
  while (true)
  {
      fsm.tickActivity(); // Call the current state tickActivity()
      pause(x_ms);
  }
}