Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost MSM: Can not get out of the submachine
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2011-06-05 16:47:32


> Thank you for the response. I have moved generation of the event
> "last_state"
> to main function instead of the payment_done struct (I have attached the
> code too. As I mentioned the code and some logic is not sophisticated.)
> and
> the code seems to be working.

ok

>However if I want to make an auto-transition
> from the Payment sub-machine (once it reaches the final "payment_done"
> state) to the next state in the vending machine how do I do that? I tried
> to
> declare en exit_pseudo_state without an event (struct payment_done: public
> exit_pseudo_state<last_state>) and then declare an auto-transition from
> "Payment" submachine to "waiting" state in the vending machine (Row <
> Payment::exit_pt<payment_done>, none, waiting, dispense_item, none>) but I
> am receiving compilation errors.

I tried and it worked. I did:
- declare pseudo exit: struct payment_done: public exit_pseudo_state<none>
- change inside transition: Row < check_payment, none, payment_done, none,
is_paid>
- changed outside transition: Row < Payment::exit_pt<payment_done>, none,
waiting, dispense_item, none>

And it compiles and does the work (from what I understood of your program).
I tried with the newest version. If you still have a problem, it might be an
old bug. What version are you using?

> I have another question to ask. If one wants to access info stored in one
> state from another state, what will be an elegant way to do that? For eg.
> In
> case of the vending machine example, lets assume the selection state
> stores
> the product selected by the customer. This info then needs to be accessed
> while dispensing the product at later stages. One way could be storing
> pointers to all the instances of structs that represent state in the state
> machine. However in this case submachines may not be able to access the
> info
> stored in the parent machine.

An elegant way to do this is to add this info in the event. Like this you
can save it in Payment (you get the event in on_entry and the target state
is also passed to the transition).
I like to see this as the UML equivalent of a function call.

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