hsm icon indicating copy to clipboard operation
hsm copied to clipboard

[FEATURE] Call a state activity

Open Lecrapouille opened this issue 1 year ago • 0 comments

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);
  }
}

Lecrapouille avatar Dec 19 '23 14:12 Lecrapouille