I am really new to "boost msm", now I occured into a question, how to use boost signal within boost msm, I have tried many times but doesn't work.
What I want to achieve is when the machine changes its state, the action operator sends a signal out, my external entities catch the signal and proceed other function, but now I can't send signal out of the machine, I can't connect signal with external entities. Is there any examples?
You can combine Boost.Signals2 and Boost.MSM.
Here is the simple signals2 example.
https://wandbox.org/permlink/XZzGIIVWXjvOPzdd (Running demo)
The signal sending point is
s.send(). If we can calls.send()from msm's action, the goal would be achieved.Here is the simple msm example.
https://wandbox.org/permlink/tnRSQ07anNe49GpO (Running demo)
The action is defined as follows:
How to call
s.send()in the action?First, add sender's reference as a member variable of sm1_.
Then, initialize it at the constructor.
Then, pass
std::refwrapped sender when creating the state machine.Finally, call
s.send()in the action. You can accesssviaFsmreference as follows:Here is whole code:
https://wandbox.org/permlink/gh83EW8eado5iOi8 (Running demo)