clock_gettime(CLOCK_MONOTONIC, &now);
timespec_subtract(diff, now, start_local);
return diff.tv_sec + diff.tv_nsec/1000000000.0;
-}
\ No newline at end of file
+}
+
+void Robot::set_state_name(const char* name)
+{
+ sched.getActualHandle()->state_name = name;
+}
Processor *p = new Processor( processor_context(*this, (my_processor)) );
my_processor->processor_ = p;
processor_queue_list.push_back(my_processor);
+ actual_processor = processor_queue_list.back();
return handle;
}
else {
for(unsigned i = 0; i<processor_queue_list.size();i++) {
if(processor_queue_list[i]->event_queue_.size()>0) {
+ actual_processor = processor_queue_list[i];
processor_queue_list[i]->processor_->process_event(*(processor_queue_list[i]->event_queue_.front()));
+ printf("stav: %s\n",actual_processor->state_name);
Guard g(queue_lock);
processor_queue_list[i]->event_queue_.pop_front();
}
delete processor_queue_list[i];
}
}
+ processor_handle getActualHandle() {
+ return actual_processor;
+ }
private:
bool check_timer() {
#include <iostream>
#include <events.h>
#include <scheduler.hpp>
-
+#include <robot.h>
+#include <cxxabi.h>
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
std::list<Timer *> active_timers;
typedef typename boost::statechart::state<MostDerived, Context, Inner> base_type;
Scheduler::processor_handle handle_;
+ int status;
protected:
typedef TimedState base_state;
public:
TimedState(typename base_type::my_context ctx ) : base_type( ctx ) {
handle_ = base_type::outermost_context().my_handle();
+ handle_->state_name = abi::__cxa_demangle(typeid(MostDerived).name(),0,0,&status);
}
~TimedState() {
if(handle_->timer_list_.timeouts.size()>0 && active_timers.size()>0)
std::list<Timer *> active_timers;
typedef typename boost::statechart::simple_state<MostDerived, Context, Inner> base_type;
Scheduler::processor_handle handle_;
+ bool handle_owned;
+ int status;
protected:
typedef TimedSimpleState base_state;
public:
- TimedSimpleState() {
- handle_ = base_type::outermost_context().my_handle();
+ TimedSimpleState() : handle_owned(false) {
+ robot.set_state_name(abi::__cxa_demangle(typeid(MostDerived).name(),0,0,&status));
}
~TimedSimpleState() {
- if(handle_->timer_list_.timeouts.size()>0 && active_timers.size()>0)
- {
- std::list<Timer *>::iterator it;
- for(it = active_timers.begin(); it!= active_timers.end(); it++)
- handle_->timer_list_.timeouts.remove(*it);
- }
+ if(handle_owned)
+ if(handle_->timer_list_.timeouts.size()>0 && active_timers.size()>0)
+ {
+ std::list<Timer *>::iterator it;
+ for(it = active_timers.begin(); it!= active_timers.end(); it++)
+ handle_->timer_list_.timeouts.remove(*it);
+ }
}
void runTimer(Timer &t, long int milisec, const boost::intrusive_ptr< boost::statechart::event_base > &e) {
+ if(!handle_owned) {
+ handle_ = base_type::outermost_context().my_handle();
+ handle_owned = true;
+ }
handle_->timer_list_.addTimer(t, milisec, e);
active_timers.push_back(&t);
}