Boost::MSM: Transition Priority
I try to use boost::MSM to implement a simple state machine for testing
purpose. There are several events which have to be processed in the right
order, so i defer the other events, which are currently not allowed. I try
to defer the events in the transition table, to have one place to look for
it, despite having all states to look, what events they defer.
I tried to change the transition rows to change their priorities, but it
didnt help. If i unkomment the anonymous transition from live_got_image to
live_wait_for_image, it works as expected, but i want to transition
automaticly to repeatedly enter the states
live_wait_for_image/live_got_image until the ev_stop_live get sent.
I expect the following output:
------------------------------
entering: fsm_master
entering: not_ready
no transition from state 0 on event struct `anonymous
namespace'::ev_stop_live
leaving: not_ready
starting: live_wait_for_image
leaving: live_wait_for_image
starting: live_got_image
leaving: live_got_image
entering: not_ready
but actually i get the following output:
----------------------------------------
entering: fsm_master
entering: not_ready
no transition from state 0 on event struct `anonymous
namespace'::ev_stop_live
leaving: not_ready
starting: live_wait_for_image
leaving: live_wait_for_image
starting: live_got_image
leaving: live_got_image
starting: live_wait_for_image
I use boost 1.57.0 and MSVC-2013 (VS-12).
Could anybody get me a useful hint?
Georg
Here is the code:
#include <iostream>
// back-end
#include
Hi,
I try to use boost::MSM to implement a simple state machine for testing purpose. There are several events which have to be processed in the right order, so i defer the other events, which are currently not allowed. I try to defer the events in the transition table, to have one place to look for it, despite having all states to look, what events they defer.
I tried to change the transition rows to change their priorities, but it didnt help. If i unkomment the anonymous transition from live_got_image to live_wait_for_image, it works as expected, but i want to transition automaticly to repeatedly enter the states live_wait_for_image/live_got_image until the ev_stop_live get sent.
I'm afraid it won't work. According to the UML standard which MSM tries to
follow, anonymous transitions have higher priority than deferred events. You
could use a guard in the anonymous transition to disable it if you have a
deferred event in the queue, for example:
struct OnlyIfNoDeferred
{
template
Hi,
Hi,
As we're talking about anonymous transitions, I read "repeatedly", but please be careful not to add another anonymous transition back otherwise you might get into an endless loop of anonymous transitions.
I tried your suggestion, and only this did work.
struct OnlyIfNoDeferred
{
template
HTH, Christophe
Thanks, Georg
Hi,
I tried your suggestion, and only this did work.
struct OnlyIfNoDeferred { template
bool operator()(Event const &, Fsm & aFsm, SourceState &, TargetState &) { size_t s_mq = aFsm.get_message_queue().size(); size_t s_dq = aFsm.get_deferred_queue().size(); return aFsm.get_message_queue().empty(); } }; s_mq = 1 s_dq = 0
This functor does now work. I just answer and ask again, because i thought that the defered queue should be size=1 and not the message queue.... Is this a bug or is this intended behaviour?
Sorry, I tried with the develop branch version not 1.57. It is a bug, wich I coincidentally fixed last week in the develop branch, it really has to be the deferred queue, though for your case it probably matters little. HTH, Christophe
participants (2)
-
christophe.j.henry@gmail.com
-
georg@schorsch-tech.de