#include <boost/statechart/state.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/event.hpp>
+#include <boost/statechart/custom_reaction.hpp>
#include <deque>
#include <stdio.h>
friend class Scheduler;
};
- Scheduler() {
+ Scheduler() : terminated_(false) {
pthread_mutex_init(& queue_lock, NULL);
sem_init(&waiting_sem, 0, 0);
- terminated_ = false;
}
template<class Processor>
};
struct Ev1 : sc::event< Ev1 > {
- Ev1() { printf("%s\n", __FUNCTION__); }
+ int *x;
+ Ev1(int *y = NULL) : x(y) { printf("%s\n", __FUNCTION__); }
~Ev1() { printf("%s\n", __FUNCTION__); }
};
Timer time;
Timer time1;
State2 (my_context ctx ) : my_base( ctx ) {
- outermost_context().addTimer<Ev1>(time1, 2000, new Ev1());
- outermost_context().addTimer<Ev2>(time, 8000, new Ev2());
+ outermost_context().addTimer<Ev1>(time1, 2000, new Ev1());
+ outermost_context().addTimer<Ev2>(time, 8000, new Ev2());
printf("%s\n", __FUNCTION__);
}
typedef sc::transition< Ev2, State1 > reactions;
struct State3 : sc::state<State3, MyStateMachine2>
{
+ int x;
Timer time;
State3(my_context ctx): my_base(ctx) {
- outermost_context().addTimer<Ev1>(time, 5000, new Ev1());
+ x = 6;
+ outermost_context().addTimer<Ev1>(time, 5000, new Ev1(&x));
printf("%s\n", __FUNCTION__);
}
- typedef sc::transition< Ev1, State4 > reactions;
+ typedef sc::custom_reaction< Ev1 > reactions;
+ sc::result react( const Ev1 & udalost)
+ {
+ if(udalost.x) std::cout<<*(udalost.x)<<"\n";
+ return transit<State4>();
+ }
};
struct State4 : sc::state<State4, MyStateMachine2>
{
Timer time1;
State4 (my_context ctx ) : my_base( ctx ) {
- outermost_context().addTimer<Ev2>(time1, 5000, new Ev2());
+ outermost_context().addTimer<Ev2>(time1, 5000, new Ev2());
printf("%s\n", __FUNCTION__);
}
typedef sc::transition< Ev2, State3 > reactions;
#ifdef USE_FIFO_SCHEDULER
scheduler.initiate_processor(machine);
#endif
- scheduler.queue_event(machine, new Ev1);
-// scheduler.queue_event(machine, new Ev2);
-Scheduler::processor_handle machine2 = scheduler.create_processor<MyStateMachine2>();
+ scheduler.queue_event(machine, new Ev1());
+ Scheduler::processor_handle machine2 = scheduler.create_processor<MyStateMachine2>();
#ifdef USE_FIFO_SCHEDULER
scheduler.initiate_processor(machine2);
#endif