OrocosComponentLibrary  2.8.3
TimerComponent.hpp
1 #ifndef ORO_TIMER_COMPONENT_HPP
2 #define ORO_TIMER_COMPONENT_HPP
3 
4 
5 #include <rtt/os/TimeService.hpp>
6 #include <rtt/TaskContext.hpp>
7 #include <rtt/os/Timer.hpp>
8 #include <rtt/OutputPort.hpp>
9 
10 #include <rtt/RTT.hpp>
11 #include <ocl/OCL.hpp>
12 
13 namespace OCL
14 {
22  : public RTT::TaskContext
23  {
24  protected:
28  struct TimeoutCatcher : public os::Timer {
29  RTT::OutputPort<RTT::os::Timer::TimerId>& me;
30  std::vector<RTT::OutputPort<RTT::os::Timer::TimerId>* >& m_port_timers;
31  TimeoutCatcher(std::vector<RTT::OutputPort<RTT::os::Timer::TimerId>* >& port_timers, RTT::OutputPort<RTT::os::Timer::TimerId>& op) :
32  os::Timer(port_timers.size(), ORO_SCHED_RT, os::HighestPriority),
33  me(op),
34  m_port_timers(port_timers)
35  {}
36  virtual void timeout(os::Timer::TimerId id) {
37  m_port_timers[id]->write(id);
38  me.write(id);
39  }
40  };
41 
42  std::vector<OutputPort<RTT::os::Timer::TimerId>* > port_timers;
43  OutputPort<RTT::os::Timer::TimerId> mtimeoutEvent;
44  TimeoutCatcher mtimer;
45 
50  bool startHook();
51  void updateHook();
52  void stopHook();
53 
57  RTT::Operation<bool(RTT::os::Timer::TimerId)> waitForCommand;
58 
62  RTT::Operation<bool(RTT::os::Timer::TimerId, double)> waitCommand;
63 
67  bool waitFor(RTT::os::Timer::TimerId id);
68 
72  bool wait(RTT::os::Timer::TimerId id, double seconds);
73 
77  bool isTimerExpired(RTT::os::Timer::TimerId id) const;
78  public:
82  TimerComponent( std::string name = "os::Timer" );
83 
84  virtual ~TimerComponent();
85  };
86 
87 }
88 
89 #endif
bool startHook()
This hook will check if a Activity has been properly setup.
RTT::Operation< bool(RTT::os::Timer::TimerId)> waitForCommand
Command: wait until a timer expires.
bool wait(RTT::os::Timer::TimerId id, double seconds)
Command Implementation: arm and wait until a timer expires.
A Component interface to the Real-Time types::Toolkit&#39;s timer.
The Orocos Component Library.
Definition: Component.hpp:43
Helper class for catching the virtual timeout function of Timer.
RTT::Operation< bool(RTT::os::Timer::TimerId, double)> waitCommand
Command: arm and wait until a timer expires.
bool isTimerExpired(RTT::os::Timer::TimerId id) const
Command Condition: return true if id expired.
TimerComponent(std::string name="os::Timer")
Set up a component for timing events.
bool waitFor(RTT::os::Timer::TimerId id)
Command Implementation: wait until a timer expires.