#include <cxxtools/timer.h>
Public Member Functions | |
| Timer () | |
| Default constructor. | |
| ~Timer () | |
| Destructor. | |
| SelectorBase * | selector () |
| void | setSelector (SelectorBase *s) |
| bool | active () const |
| Returs true if timer is active. | |
| std::size_t | interval () const |
| Returns the current timer interval. | |
| void | start (std::size_t interval) |
| Starts the timer. | |
| void | stop () |
| Stops the timer. | |
| bool | update () |
| Update the timer. | |
| bool | update (const Timespan &now) |
| const Timespan & | finished () const |
Public Attributes | |
| Signal | timeout |
| Notifies about interval timeouts. | |
void onTimer() { std::cerr << "Time out!\n"; } int main() { cxxtools::Timer timer; connect(timer.timeout, onTimer); cxxtools::EventLoop loop; loop.addTimer(timer); timer.start(1000); loop.run(); return 0; }
| Timer | ( | ) |
Contructs an inactive timer.
| ~Timer | ( | ) |
The destructor sends the destroyed signal.
| std::size_t interval | ( | ) | const |
Returns the current interval of the timer in milliseconds.
| void start | ( | std::size_t | interval | ) |
Start a timer from the moment this method is called. The Timer needs to be registered with a Selector or event loop, otherwise the timeout signal will not be sent.
| interval | Timeout interval in milliseconds |
| void stop | ( | ) |
If the Timer is registered with a Selector or an event loop, the timout signal will not be sent anymore.
| bool update | ( | ) |
This method is supposed to be called by the Selector or an event loop. If the interval timeout is passed the Timer will send the timeout signal and return true, otherwise internal times are updated and false is returned.
| Signal timeout |
This signal is sent if the interval time has expired.