Timer.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef Timer_h
20 #define Timer_h
21 
22 #include <coil/TimeValue.h>
23 #include <coil/Listener.h>
24 #include <coil/Mutex.h>
25 #include <coil/Guard.h>
26 #include <coil/Task.h>
27 #include <vector>
28 
30 
31 namespace coil
32 {
53  class Timer
54  : public coil::Task
55  {
56  typedef coil::Mutex Mutex;
58  public:
76  Timer(TimeValue& interval);
77 
91  virtual ~Timer();
92 
93  //============================================================
94  // ACE_Task
95  //============================================================
119  virtual int open(void *args);
120 
140  virtual int svc(void);
141 
142  //============================================================
143  // public functions
144  //============================================================
158  void start();
159 
173  void stop();
174 
193  void invoke();
194 
226 
254  template <class ListenerClass>
255  ListenerId registerListenerObj(ListenerClass* obj,
256  void (ListenerClass::*cbf)(),
257  TimeValue tm)
258  {
259  return registerListener(new ListenerObject<ListenerClass>(obj, cbf), tm);
260  }
261 
287  {
288  return registerListener(new ListenerFunc(cbf), tm);
289  }
290 
315 
316  private:
318 
320  bool m_running;
321 
322  struct Task
323  {
325  : listener(l), period(p), remains(p)
326  {
327  }
331  };
332 
333  std::vector<Task> m_tasks;
334  Mutex m_taskMutex;
335  };
336 };
337 #endif // Timer_h
338 
Task(ListenerBase *l, TimeValue p)
Definition: Timer.h:324
ListenerBase * ListenerId
Definition: Timer.h:29
std::vector< Task > m_tasks
Definition: Timer.h:333
Mutex class.
ListenerId registerListener(ListenerBase *listener, TimeValue tm)
Register listener.
Definition: Timer.cpp:141
coil::Guard< Mutex > Guard
Definition: Timer.h:57
ListenerId registerListenerFunc(void(*cbf)(), TimeValue tm)
Register listener.
Definition: Timer.h:286
ListenerId registerListenerObj(ListenerClass *obj, void(ListenerClass::*cbf)(), TimeValue tm)
Register listener.
Definition: Timer.h:255
coil::Mutex Mutex
Definition: Timer.h:56
void stop()
Stop Timer task.
Definition: Timer.cpp:107
Mutex m_taskMutex
Definition: Timer.h:334
ListenerFunc class.
Definition: Listener.h:186
ListenerBase * listener
Definition: Timer.h:328
Mutex m_runningMutex
Definition: Timer.h:319
void invoke()
Invoke Timer task.
Definition: Timer.cpp:120
ListenerBase class.
Definition: Listener.h:43
TimeValue m_interval
Definition: Timer.h:317
virtual ~Timer()
Destructor.
Definition: Timer.cpp:43
TimeValue period
Definition: Timer.h:329
void start()
Start Timer task.
Definition: Timer.cpp:90
Timer(TimeValue &interval)
Constructor.
Definition: Timer.cpp:31
Task class.
TimeValue remains
Definition: Timer.h:330
ListenerObject class.
Definition: Listener.h:98
Guard template class.
Definition: Guard.h:41
bool unregisterListener(ListenerId id)
Unregister listener.
Definition: Timer.cpp:165
virtual int svc(void)
Thread execution function for Timer.
Definition: Timer.cpp:69
bool m_running
Definition: Timer.h:320
virtual int open(void *args)
Create thread for Timer.
Definition: Timer.cpp:56
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00