Async 1.8.0
Async::Timer Class Reference

A class that produces timer events. More...

#include <AsyncTimer.h>

Inheritance diagram for Async::Timer:

Public Types

enum  Type { TYPE_ONESHOT , TYPE_PERIODIC }
 The type of the timer. More...
 

Public Member Functions

 Timer (int timeout_ms=0, Type type=TYPE_ONESHOT, bool enabled=true)
 Constructor.
 
 ~Timer (void)
 Destructor.
 
Type type (void) const
 Return the type of this timer.
 
void setTimeout (int timeout_ms)
 Set (change) the timeout value.
 
int timeout (void) const
 Return the setting of the timeout value.
 
void setEnable (bool do_enable)
 Enable or disable the timer.
 
bool isEnabled (void) const
 Check if the timer is enabled.
 
void reset (void)
 Reset (restart) the timer.
 

Public Attributes

sigc::signal< void, Timer * > expired
 A signal that is emitted when the timer expires.
 

Detailed Description

A class that produces timer events.

Author
Tobias Blomberg
Date
2003-03-26

This class is used to create timer objects. These objects will emit a signal when the specified time has elapsed. An example of how to use it is shown below.

#include <iostream>
#include <AsyncTimer.h>
using namespace std;
using namespace Async;
class MyClass : public sigc::trackable
{
public:
MyClass(void) : count(0)
{
timer = new Timer(1000, Timer::TYPE_PERIODIC);
timer->expired.connect(mem_fun(*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)
{
MyClass my_class;
app.exec();
}
The core class for writing asyncronous cpp applications.
Contains a single shot or periodic timer that emits a signal on timeout.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
A class that produces timer events.
Definition AsyncTimer.h:117
Namespace for the asynchronous programming classes.
Examples
AsyncAudioContainer_demo.cpp, AsyncPtyStreamBuf_demo.cpp, and AsyncTimer_demo.cpp.

Definition at line 116 of file AsyncTimer.h.

Member Enumeration Documentation

◆ Type

The type of the timer.

Enumerator
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.

Constructor & Destructor Documentation

◆ Timer()

Async::Timer::Timer ( int timeout_ms = 0,
Type type = TYPE_ONESHOT,
bool enabled = true )

Constructor.

Parameters
timeout_msThe timeout value in milliseconds
typeThe type of timer to use (see Type)
enabledSet to false if the timer should be disabled

If no arguments are given (default constructor) a timer that expires immediately will be created. Such a timer can for example be used to delay the execution of some function until all active callbacks have returned. If a negative timeout value is given, the timer will be disabled. The timer must not be enabled until a timeout value equal or greater than zero has been set.

◆ ~Timer()

Async::Timer::~Timer ( void )

Destructor.

Member Function Documentation

◆ isEnabled()

bool Async::Timer::isEnabled ( void ) const
inline

Check if the timer is enabled.

Returns
Returns true if the timer is enabled or false if it is disabled

Definition at line 190 of file AsyncTimer.h.

◆ reset()

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.

◆ setEnable()

void Async::Timer::setEnable ( bool do_enable)

Enable or disable the timer.

Parameters
do_enableSet to true to enable the timer or false to disable it

This function will enable or disable an existing timer. A timer that has a negative timeout value set must not be enabled.

Referenced by Async::StateMachine< ContextT, StateTopT >::clearTimeout(), and Async::StateMachine< ContextT, StateTopT >::setTimeout().

◆ setTimeout()

void Async::Timer::setTimeout ( int timeout_ms)

Set (change) the timeout value.

Parameters
timeout_msThe new timeout value in milliseconds

Use this function to set a new timeout value on an existing timer. The timer will be reset so the timer will expire when the new timeout time has elapsed. If the timer is disabled, this function will set the new timeout value but it will not enable the timer. If a negative timeout value is given, the timer will be disabled. The timer must not be enabled until a timeout value equal or greater than zero has been set.

Referenced by Async::StateMachine< ContextT, StateTopT >::setTimeout().

◆ timeout()

int Async::Timer::timeout ( void ) const
inline

Return the setting of the timeout value.

Returns
Returns the timeout value in milliseconds

Definition at line 173 of file AsyncTimer.h.

◆ type()

Type Async::Timer::type ( void ) const
inline

Return the type of this timer.

Returns
Returns the type of this timer

Definition at line 153 of file AsyncTimer.h.

Member Data Documentation

◆ expired

sigc::signal<void, Timer *> Async::Timer::expired

A signal that is emitted when the timer expires.

Parameters
timerA pointer to the timer that has expired

This signal is emitted when the timer expires. It is perfectly legal to delete the timer in the connected slot if it is known to be the only connected slot.

Definition at line 210 of file AsyncTimer.h.

Referenced by Async::StateMachine< ContextT, StateTopT >::StateMachine().


The documentation for this class was generated from the following file: