Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost::MSM: Transition Priority
From: christophe.j.henry_at_[hidden]
Date: 2015-03-14 04:39:47


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<class Event, class Fsm, class SourceState, class TargetState>
    bool operator()(Event const &, Fsm & aFsm, SourceState &, TargetState &)
    {
         return aFsm.get_deferred_queue().empty();
    }
};

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.

HTH,
Christophe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net