Boost logo

Boost Users :

Subject: Re: [Boost-users] [msm] interrupt_state with more then one event that ends interrupt?
From: Sam Fisher (infest21h_at_[hidden])
Date: 2013-07-09 03:00:37


On 05.06.2013 1:06, Christophe Henry wrote:

> Hi,
> this should now work (rev 84642 in trunk). Could you give it a try?
> It's too late for 1.54 so it will make it into 1.55.
>
I tested it against trunk rev 84986 with vs2012u2.
It works perfectly!
Looking forward to see it in 1.55

test code:

#include <iostream>
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/functor_row.hpp>
#include <assert.h>

namespace msm = boost::msm;
namespace mpl = boost::mpl;

using msm::front::none;
using msm::front::Row;

#define ENTRY_EXIT_INFO() \
        template <typename Event, typename FSM> \
        void on_entry(const Event&, FSM&) { \
                std::cout << "entering: " << typeid(*this).name() << std::endl; \
        } \
        template <typename Event, typename FSM> \
        void on_exit(const Event&, FSM&) { \
                std::cout << "leaving: " << typeid(*this).name() << std::endl; \
        }

struct init {};
struct interrupt {};
struct proceed {};
struct finish {};

struct fsm_ : public msm::front::state_machine_def<fsm_>
{
        struct Empty : public msm::front::state<>
        {
                ENTRY_EXIT_INFO();
        };

        struct Proceed : public msm::front::state<>
        {
                ENTRY_EXIT_INFO();
        };

        struct Interrupted : public
msm::front::interrupt_state<mpl::vector<proceed, finish> >
        {
                ENTRY_EXIT_INFO();
        };

        struct Finished : public msm::front::terminate_state<>
        {
                ENTRY_EXIT_INFO();
        };

        typedef mpl::vector<Empty> initial_state;

        struct transition_table : mpl::vector<
                // Start Event Next Action Guard
                //
+-------------+-------------+------------+---------------------+----------------------+
                Row < Empty , init , Proceed , none , none
>,
                Row < Proceed , interrupt , Interrupted , none , none
>,
                Row < Interrupted , proceed , Proceed , none , none
>,
                Row < Interrupted , finish , Finished , none , none
>
> {};

        enum States
        {
                STATE_Empty,
                STATE_Proceed,
                STATE_Interupted,
                STATE_Finished
        };
};

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

int tmain()
{
        fsm_t fsm;
        fsm.start();
        fsm.process_event(init());
        assert(fsm.current_state()[0] == fsm_t::STATE_Proceed);
        fsm.process_event(interrupt());
        assert(fsm.current_state()[0] == fsm_t::STATE_Interupted);
        fsm.process_event(proceed());
        assert(fsm.current_state()[0] == fsm_t::STATE_Proceed);
        fsm.process_event(interrupt());
        assert(fsm.current_state()[0] == fsm_t::STATE_Interupted);
        fsm.process_event(finish());
        assert(fsm.current_state()[0] == fsm_t::STATE_Finished);

        return 0;
}


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