Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59647 - in sandbox/msm/boost/msm: back front front/euml
From: christophe.j.henry_at_[hidden]
Date: 2010-02-11 15:13:41


Author: chenry
Date: 2010-02-11 15:13:40 EST (Thu, 11 Feb 2010)
New Revision: 59647
URL: http://svn.boost.org/trac/boost/changeset/59647

Log:
added more deferring capabilities
Text files modified:
   sandbox/msm/boost/msm/back/metafunctions.hpp | 22 +++++++++++++++++-----
   sandbox/msm/boost/msm/back/state_machine.hpp | 22 ++++++++++++++++------
   sandbox/msm/boost/msm/front/euml/common.hpp | 30 ++++++++++++++++++++++++++++++
   sandbox/msm/boost/msm/front/functor_row.hpp | 10 ++++++++++
   4 files changed, 73 insertions(+), 11 deletions(-)

Modified: sandbox/msm/boost/msm/back/metafunctions.hpp
==============================================================================
--- sandbox/msm/boost/msm/back/metafunctions.hpp (original)
+++ sandbox/msm/boost/msm/back/metafunctions.hpp 2010-02-11 15:13:40 EST (Thu, 11 Feb 2010)
@@ -54,6 +54,7 @@
 BOOST_MPL_HAS_XXX_TRAIT_DEF(automatic_event)
 BOOST_MPL_HAS_XXX_TRAIT_DEF(no_exception_thrown)
 BOOST_MPL_HAS_XXX_TRAIT_DEF(no_message_queue)
+BOOST_MPL_HAS_XXX_TRAIT_DEF(activate_deferred_events)
 
 namespace boost { namespace msm { namespace back
 {
@@ -264,7 +265,7 @@
>::type type;
 };
 
-// returns a mpl::bool_<true> if State has Event as delayed event
+// returns a mpl::bool_<true> if State has Event as deferred event
 template <class State, class Event>
 struct has_state_delayed_event
 {
@@ -274,7 +275,7 @@
             ::boost::mpl::bool_<false>,
             ::boost::mpl::bool_<true> >::type type;
 };
-// returns a mpl::bool_<true> if State has any delayed event
+// returns a mpl::bool_<true> if State has any deferred event
 template <class State>
 struct has_state_delayed_events
 {
@@ -413,13 +414,24 @@
 
 // metafunction used to say if a SM has pseudo exit states
 template <class Derived>
-struct has_fsm_delayed_events
+struct has_fsm_deferred_events
 {
     typedef typename create_stt<Derived>::type Stt;
     typedef typename generate_state_set<Stt>::type state_list;
 
- typedef ::boost::mpl::bool_< ::boost::mpl::count_if<
- state_list,has_state_delayed_events< ::boost::mpl::placeholders::_1 > >::value != 0> type;
+ typedef typename ::boost::mpl::or_<
+ typename has_activate_deferred_events<Derived>::type,
+ ::boost::mpl::bool_< ::boost::mpl::count_if<
+ typename Derived::configuration,
+ has_activate_deferred_events< ::boost::mpl::placeholders::_1 > >::value != 0>
+ >::type found_in_fsm;
+
+ typedef typename ::boost::mpl::or_<
+ found_in_fsm,
+ ::boost::mpl::bool_< ::boost::mpl::count_if<
+ state_list,has_state_delayed_events<
+ ::boost::mpl::placeholders::_1 > >::value != 0>
+ >::type type;
 };
 
 // returns a mpl::bool_<true> if State has any delayed event

Modified: sandbox/msm/boost/msm/back/state_machine.hpp
==============================================================================
--- sandbox/msm/boost/msm/back/state_machine.hpp (original)
+++ sandbox/msm/boost/msm/back/state_machine.hpp 2010-02-11 15:13:40 EST (Thu, 11 Feb 2010)
@@ -164,7 +164,7 @@
     template <class StateType>
     struct deferred_msg_queue_helper<StateType,
         typename ::boost::enable_if<
- typename ::boost::msm::back::has_fsm_delayed_events<StateType>::type >::type>
+ typename ::boost::msm::back::has_fsm_deferred_events<StateType>::type >::type>
     {
     public:
         deferred_msg_queue_helper():m_deferred_events_queue(){}
@@ -1086,6 +1086,19 @@
 #undef MSM_VISIT_STATE_EXECUTE
 #undef MSM_VISIT_STATE_SUB
 
+ // puts the given event into the deferred queue
+ template <class Event>
+ void defer_event(Event const& e)
+ {
+ // to call this function, you need either a state with a deferred_events typedef
+ // or that the fsm provides the activate_deferred_events typedef
+ BOOST_MPL_ASSERT(( has_fsm_deferred_events<library_sm> ));
+ execute_return (library_sm::*pf) (Event const& evt)= &library_sm::process_event;
+ Event temp (e);
+ ::boost::function<execute_return () > f= ::boost::bind(pf, this,temp);
+ post_deferred_event(f);
+ }
+
  protected: // interface for the derived class
 
      // helper used to fill the initial states
@@ -1264,7 +1277,7 @@
     // otherwise the standard version handling the deferred events
     template <class StateType>
     struct handle_defer_helper
- <StateType, typename enable_if< typename ::boost::msm::back::has_fsm_delayed_events<StateType>::type >::type>
+ <StateType, typename enable_if< typename ::boost::msm::back::has_fsm_deferred_events<StateType>::type >::type>
     {
         handle_defer_helper(deferred_msg_queue_helper<library_sm>& a_queue):
             events_queue(a_queue),next_deferred_event(){}
@@ -1985,10 +1998,7 @@
     template <class Event>
     static HandledEnum defer_transition(library_sm& fsm, int , int , Event const& e)
     {
- execute_return (library_sm::*pf) (Event const& evt)= &library_sm::process_event;
- Event temp (e);
- ::boost::function<execute_return () > f= ::boost::bind(pf, ::boost::ref(fsm),temp);
- fsm.post_deferred_event(f);
+ fsm.defer_event(e);
         return HANDLED_DEFERRED;
     }
 

Modified: sandbox/msm/boost/msm/front/euml/common.hpp
==============================================================================
--- sandbox/msm/boost/msm/front/euml/common.hpp (original)
+++ sandbox/msm/boost/msm/front/euml/common.hpp 2010-02-11 15:13:40 EST (Thu, 11 Feb 2010)
@@ -267,6 +267,10 @@
 {
     typedef int no_message_queue;
 };
+struct deferred_events : euml_config<deferred_events>
+{
+ typedef int activate_deferred_events;
+};
 
 struct invalid_type{};
 struct make_invalid_type
@@ -1502,6 +1506,32 @@
 };
 Get_Flag_Helper const is_flag_;
 
+// deferring an event
+struct DeferEvent_ : euml_action< DeferEvent_ >
+{
+ typedef ::boost::mpl::set<action_tag> tag_type;
+ template <class EVT,class FSM,class SourceState,class TargetState>
+ void operator()(EVT const& evt,FSM& fsm,SourceState& ,TargetState& ) const
+ {
+ fsm.defer_event(evt);
+ }
+};
+struct defer_event_tag {};
+struct Defer_Helper : proto::extends< proto::terminal<defer_event_tag>::type, Defer_Helper, sm_domain>
+{
+ using proto::extends< proto::terminal<defer_event_tag>::type, Defer_Helper, sm_domain>::operator=;
+ template <class Arg1,class Arg2,class Arg3,class Arg4,class Arg5
+#ifdef BOOST_MSVC
+ ,class Arg6
+#endif
+>
+ struct In
+ {
+ typedef DeferEvent_ type;
+ };
+};
+Defer_Helper const defer_;
+
 #ifdef BOOST_MSVC
 #define MSM_EUML_FUNCTION(functor,function,function_name,result_trans,result_state) \
     template <class Param1=void , class Param2=void , class Param3=void , class Param4=void, \

Modified: sandbox/msm/boost/msm/front/functor_row.hpp
==============================================================================
--- sandbox/msm/boost/msm/front/functor_row.hpp (original)
+++ sandbox/msm/boost/msm/front/functor_row.hpp 2010-02-11 15:13:40 EST (Thu, 11 Feb 2010)
@@ -298,5 +298,15 @@
                 (Call2<EVT,FSM,SourceState,TargetState>(evt,fsm,src,tgt));
         }
     };
+
+ // functor pre-defined for basic functionality
+ struct Defer
+ {
+ template <class EVT,class FSM,class SourceState,class TargetState>
+ void operator()(EVT const& evt,FSM& fsm,SourceState& ,TargetState& ) const
+ {
+ fsm.defer_event(evt);
+ }
+ };
 }}}
 #endif //BOOST_MSM_FRONT_FUNCTOR_ROW_H


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk