#include <Pt/System/Timer.h>
Notifies clients in constant intervals. More...
Public Member Functions | |
| Timer () | |
| Default constructor. More... | |
| ~Timer () | |
| Destructor. More... | |
| EventLoop * | loop () |
| Returns the used event loop. | |
| void | setActive (EventLoop &loop) |
| Sets the used event loop. | |
| void | detach () |
| Detach from used event loop. | |
| bool | isStarted () const |
| Returs true if timer was started. | |
| std::size_t | interval () const |
| Returns the current timer interval in milliseconds. | |
| void | start (std::size_t interval) |
| Starts the timer. More... | |
| void | start (const Pt::Timespan &interval) |
| Starts the timer. More... | |
| void | stop () |
| Stops the timer. More... | |
| Signal & | timeout () |
| Notifies about interval timeouts. More... | |
Timers can be used to be notified if a time interval expires. It usually works with an event loop, where the Timer needs to be registered. Timers send the timeout signal in given intervals, to which the interested clients connect. The interval can be changed at any time and timers can switch between an active and inactive state.
The following code calls the function onTimer every second:
| Timer | ( | ) |
Constructs an inactive timer.
| ~Timer | ( | ) |
The destructor sends the destroyed signal.
| void start | ( | std::size_t | interval | ) |
Start a timer from the moment this method is called. The Timer needs to be registered with an event loop, otherwise the timeout signal will not be sent.
| interval | Timeout interval in milliseconds |
| void start | ( | const Pt::Timespan & | interval | ) |
Start a timer from the moment this method is called. The Timer needs to be registered with an event loop, otherwise the timeout signal will not be sent.
| void stop | ( | ) |
If the Timer is registered with an event loop, the timout signal will not be sent anymore.
| Signal& timeout | ( | ) |
This signal is sent if the interval time has expired.