Boost logo

Boost Users :

Subject: Re: [Boost-users] [MSM] Best place to execute an action with return value
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2013-11-28 03:08:23


Il 27/11/2013 21:23, Christophe Henry ha scritto:
>> Hi,
>>
>> I'm diving into this very useful piece of code which is MSM and I'm
>> modelling a state machine for a gsm modem.
>>
>> When I have to perform a call I need to move from the IDLE state to
>> WAITING_RESPONSE and, in the transaction action I have to call the
>> MakeCall() method on my GSM object.
>>
>> This method has a return value and a non 0 value means it is failed.
>> In this situation the SM don't have to move on to the next state but
>> remains in the IDLE one, so...
>>
>> Since the Actions has no return value, I have to use a Guard instead or
>> I have to add another state called MAKE_CALL?
>>
>> Thanks in advance,
>> Daniele.
>
> Hi,
>
> it depends how your code is structured.
> According to UML, guards should not execute any actions (just return a
> bool), but MSM will let you do.
> The question is, is MakeCall a long-lasting, blocking function?
> If yes then you're blocking the run-to-completion (the state machine
> stays long in an unstable state as it processes a transition), and it
> has bad side-effects (for example debugging and loggin). In such a case,
> yes you should have an extra state.
>
> If MakeCall is fast, then a possible solution would be to use a guard as
> you suggested. The guard would execute MakeCall, then return true or
> false, false would stop the transition at this point. If more
> transitions with the same event and source state are found in the
> transition table above this one, they would be tried then, which allows
> you to continue processing, add error handling, etc.
>
> HTH,
> Christophe

Hi Christophe,
thanks for your reply (and thanks a lot for this great library!).

I ask you another quick thing (also if I should open another topic):
using a functor front-end, how can I add more method to the states (Eg.
to add the visitor pattern)?

Thanks,
Daniele


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