#include <AsyncTimer.h>
#include <iostream> #include <AsyncCppApplication.h> #include <AsyncTimer.h> using namespace std; using namespace Async; class MyClass : public SigC::Object { public: MyClass(void) : count(0) { timer = new Timer(1000, Timer::TYPE_PERIODIC); timer->expired.connect(slot(*this, &MyClass::onTimerExpired)); } ~MyClass(void) { delete timer; } private: Timer * timer; int count; void onTimerExpired(Timer *t) { if (++count == 3) { Application::app().quit(); } cout << "Timer expired " << count << "...\n"; } }; int main(int argc, char **argv) { CppApplication app; MyClass my_class; app.exec(); }
Definition at line 116 of file AsyncTimer.h.
enum Async::Timer::Type |
The type of the timer.
TYPE_ONESHOT | A timer that expires once. |
TYPE_PERIODIC | A timer that restarts itself every time it expires. |
Definition at line 122 of file AsyncTimer.h.
Async::Timer::Timer | ( | int | timeout_ms = 0 , |
|
Type | type = TYPE_ONESHOT | |||
) |
Constructor.
timeout_ms | The timeout value in milliseconds | |
type | The type of timer to use (see Type) |
Async::Timer::~Timer | ( | void | ) |
Destructor.
Type Async::Timer::type | ( | void | ) | const [inline] |
Return the type of this timer.
Definition at line 149 of file AsyncTimer.h.
void Async::Timer::setTimeout | ( | int | timeout_ms | ) |
Set (change) the timeout value.
timeout_ms | The new timeout value in milliseconds |
int Async::Timer::timeout | ( | void | ) | const [inline] |
Return the setting of the timeout value.
Definition at line 166 of file AsyncTimer.h.
void Async::Timer::setEnable | ( | bool | do_enable | ) |
Enable or disable the timer.
do_enable | Set to true to enable the timer or false to disable it |
bool Async::Timer::isEnabled | ( | void | ) | const [inline] |
Check if the timer is enabled.
Definition at line 180 of file AsyncTimer.h.
void Async::Timer::reset | ( | void | ) |
Reset (restart) the timer.
This function is used to reset the timer. After reset it will take timeout milliseconds before the timer expires, where timeout is the previously set timeout value. If the timer is disabled, this function will do nothing.
SigC::Signal1<void, Timer *> Async::Timer::expired |
A signal that is emitted when the timer expires.
timer | A pointer to the timer that has expired |
Definition at line 200 of file AsyncTimer.h.