00001 #ifndef ORO_TIMER_COMPONENT_HPP 00002 #define ORO_TIMER_COMPONENT_HPP 00003 00004 00005 #include <rtt/os/TimeService.hpp> 00006 #include <rtt/TaskContext.hpp> 00007 #include <rtt/os/Timer.hpp> 00008 #include <rtt/OutputPort.hpp> 00009 00010 #include <rtt/RTT.hpp> 00011 #include <ocl/OCL.hpp> 00012 00013 namespace OCL 00014 { 00021 class TimerComponent 00022 : public RTT::TaskContext 00023 { 00024 protected: 00028 struct TimeoutCatcher : public os::Timer { 00029 RTT::OutputPort<RTT::os::Timer::TimerId>& me; 00030 TimeoutCatcher(RTT::os::Timer::TimerId max_timers, RTT::OutputPort<RTT::os::Timer::TimerId>& e) : 00031 os::Timer(max_timers, ORO_SCHED_RT, os::HighestPriority), me(e) 00032 {} 00033 virtual void timeout(os::Timer::TimerId id) { 00034 me.write(id); 00035 } 00036 }; 00037 00038 TimeoutCatcher mtimer; 00039 OutputPort<RTT::os::Timer::TimerId> mtimeoutEvent; 00040 00045 bool startHook(); 00046 void updateHook(); 00047 void stopHook(); 00048 00052 RTT::Operation<bool(RTT::os::Timer::TimerId)> waitForCommand; 00053 00057 RTT::Operation<bool(RTT::os::Timer::TimerId, double)> waitCommand; 00058 00062 bool waitFor(RTT::os::Timer::TimerId id); 00063 00067 bool wait(RTT::os::Timer::TimerId id, double seconds); 00068 00072 bool isTimerExpired(RTT::os::Timer::TimerId id) const; 00073 public: 00077 TimerComponent( std::string name = "os::Timer" ); 00078 00079 virtual ~TimerComponent(); 00080 }; 00081 00082 } 00083 00084 #endif