Boost::MSM do_actions while in state

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Boost::MSM do_actions while in state

Boost - Users mailing list
Is there any way to do this? Using boost::msm?
I know for fact that you can implement transition actions using the library,
I've searched a lot around the internet and I didn't find my answer.
So basically let's say I want to do this:
<http://boost.2283326.n4.nabble.com/file/t371323/boost_msm_1.png>
boost_msm_1.png
<http://boost.2283326.n4.nabble.com/file/t371323/boost_msm_1.png>  
diagram1.cpp <http://boost.2283326.n4.nabble.com/file/t371323/diagram1.cpp>  

#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/euml/euml.hpp>
#include <iostream>

using namespace boost::msm::front::euml;
namespace msm = boost::msm;

namespace fsm
{
    BOOST_MSM_EUML_EVENT(trigger);

    BOOST_MSM_EUML_ACTION(transition_action)
    {
        template <class FSM, class EVT, class SourceState, class
TargetState>
        void operator()(EVT const &, FSM &fsm, SourceState &, TargetState &)
        {
            std::cout << "-v- transition_action -v-" << std::endl;
            return;
        }
    };

    BOOST_MSM_EUML_ACTION(guard)
    {
        template <class FSM,class EVT,class SourceState,class TargetState>
        bool operator()(EVT const& evt,FSM&,SourceState& ,TargetState&)
        {
            std::cout << "[guard]" << std::endl;
            return true;
        }
    };

    BOOST_MSM_EUML_ACTION(entry_action)
    {
        template <class Event, class FSM, class STATE>
        void operator()(Event const &, FSM &, STATE &)
        {
            std::cout << "==>entry_action" << std::endl;
            return;
        }
    };

    BOOST_MSM_EUML_ACTION(exit_action)
    {
        template <class Event, class FSM, class STATE>
        void operator()(Event const &, FSM &, STATE &)
        {
            std::cout << "<==exit_action" << std::endl;
            return;
        }
    };
    BOOST_MSM_EUML_STATE((entry_action,exit_action), State1);
    // BOOST_MSM_EUML_STATE((entry_action,exit_action), State2);

    // define the transition table
    BOOST_MSM_EUML_TRANSITION_TABLE((
        State1 == State1 + trigger[guard] / transition_action
        // State1 == State2 + trigger[guard] / transition_action
        ),
        transition_table)

    // BOOST_MSM_EUML_DECLARE_STATE_MACHINE((transition_table, State1), fsm)
        // create a state machine "on the fly"
    BOOST_MSM_EUML_DECLARE_STATE_MACHINE((transition_table,
                                          init_ << State1,
                                          no_action,
                                          no_action,
                                          attributes_ << no_attributes_,
                                          configure_  << no_configure_,
                                          no_action
                                          ),
                                          my_fsm)

    typedef msm::back::state_machine<my_fsm> fsm_t;

} //namespace fsm

int main(int argc, char const *argv[])
{
    fsm::fsm_t example_fsm;
    example_fsm.start();
    example_fsm.process_event(fsm::trigger);
    example_fsm.process_event(fsm::trigger);
    return 0;
}
// OUTPUT
// ==>entry_action
// [guard]
// <==exit_action
// -v- transition_action -v-
// ==>entry_action
// [guard]
// <==exit_action
// -v- transition_action -v-
// ==>entry_action

But I want the machine to DO an action ONCE the Entry_action has completed
and BEFORE the states exits. This is sort of a token or mark, like it's used
in petri nets and GRAFCETS, basically. I want to add this
boost_msm_2.png
<http://boost.2283326.n4.nabble.com/file/t371323/boost_msm_2.png>  
<http://boost.2283326.n4.nabble.com/file/t371323/boost_msm_2.png>

And the output for should be something like
/ OUTPUT
// ==>entry_action
// -DO ACTION-
// [guard]
// <==exit_action
// -v- transition_action -v-
// ==>entry_action
// -DO ACTION-
// [guard]
// <==exit_action
// -v- transition_action -v-
// ==>entry_action


Thanks!



--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

[SPAM] Re: Boost::MSM do_actions while in state

Boost - Users mailing list
On 30/06/2018 07:25, IgnacioVizzo wrote:

> But I want the machine to DO an action ONCE the Entry_action has completed
> and BEFORE the states exits. This is sort of a token or mark, like it's used
> in petri nets and GRAFCETS, basically. I want to add this
> boost_msm_2.png
> <http://boost.2283326.n4.nabble.com/file/t371323/boost_msm_2.png>
>
> And the output for should be something like
> / OUTPUT
> // ==>entry_action
> // -DO ACTION-
> // [guard]
> // <==exit_action
> // -v- transition_action -v-
> // ==>entry_action
> // -DO ACTION-
> // [guard]
> // <==exit_action
> // -v- transition_action -v-
> // ==>entry_action

How is this different from adding your action to the end of the existing
entry_action?

If you instead want to trigger your action externally, then it probably
should be a state transition action; either back to the same state if
you want to be able to trigger it multiple times or to an alternate
state or substate if you want to only do it once.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users