libtasks Documentation  1.6
timer_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _TASKS_TIMER_TASK_H_
9 #define _TASKS_TIMER_TASK_H_
10 
11 #include <tasks/event_task.h>
12 #include <tasks/ev_wrapper.h>
13 #include <memory>
14 #include <sstream>
15 
16 namespace tasks {
17 
18 class worker;
19 
20 class timer_task : public event_task {
21  public:
22  timer_task(double after, double repeat);
23  virtual ~timer_task();
24 
25  inline std::string get_string() const {
26  std::ostringstream os;
27  os << "timer_task(" << this << ")";
28  return os.str();
29  }
30 
31  inline ev_timer* watcher() const { return m_timer.get(); }
32 
33  inline double after() const { return m_after; }
34 
35  inline double repeat() const { return m_repeat; }
36 
37  void init_watcher() {}
39  void stop_watcher(worker* worker);
40 
41  private:
42  std::unique_ptr<ev_timer> m_timer;
43  double m_after = 0;
44  double m_repeat = 0.;
45 };
46 
47 } // tasks
48 
49 #endif // _TASKS_TIMER_TASK_H_
virtual ~timer_task()
Definition: timer_task.cpp:23
void stop_watcher(worker *worker)
Deactivate the underlying watcher.
Definition: timer_task.cpp:34
void init_watcher()
Initialize the underlying watcher object.
Definition: timer_task.h:37
std::unique_ptr< ev_timer > m_timer
Definition: timer_task.h:42
void start_watcher(worker *worker)
Activate the underlying watcher to listen for I/O or timer events.
Definition: timer_task.cpp:25
double after() const
Definition: timer_task.h:33
double repeat() const
Definition: timer_task.h:35
ev_timer * watcher() const
Definition: timer_task.h:31
std::string get_string() const
Definition: timer_task.h:25
timer_task(double after, double repeat)
Definition: timer_task.cpp:15