106 lines
2.7 KiB
C++
106 lines
2.7 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/ThreadTimer.h
|
|
*
|
|
* @brief ThreadTimer header file.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_THREAD_TIMER_H)
|
|
#define ACTIV_FRAMEWORK_THREAD_TIMER_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/Time.h"
|
|
#include "ActivMiddleware/ActivFramework/Timer.h"
|
|
#include "ActivMiddleware/CxxYZ/functional.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
// Forward declaration.
|
|
class ManagedEndPoint;
|
|
|
|
//! ThreadTimer namespace.
|
|
namespace ThreadTimer
|
|
{
|
|
|
|
typedef Timer::TickChimeCallbackFunction CallbackFunction;
|
|
typedef Timer::Microseconds Microseconds;
|
|
typedef Timer::Milliseconds Milliseconds;
|
|
typedef Timer::Seconds Seconds;
|
|
typedef Timer::Minutes Minutes;
|
|
typedef Timer::Hours Hours;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Countdown timer.
|
|
class CountdownTimer
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param managedEndPoint the ManagedEndPoint to add a timer to.
|
|
* @param name the name of the timer (for logging).
|
|
* @param interval the interval of the timer in milliseconds.
|
|
* @param callbackFunction the function to call when timer expires.
|
|
*
|
|
* @throw std::exception
|
|
* @throw StatusCodeException
|
|
*/
|
|
CountdownTimer(ManagedEndPoint &managedEndPoint, const String &name, const Timer::Interval interval,
|
|
const CallbackFunction &callbackFunction) :
|
|
m_timer(Timer::CreateCountdown(managedEndPoint, name, interval, callbackFunction))
|
|
{
|
|
}
|
|
|
|
//! Cancel.
|
|
void Cancel()
|
|
{
|
|
m_timer.Cancel();
|
|
}
|
|
|
|
private:
|
|
Timer m_timer;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Repeating timer.
|
|
class ChimeTimer
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param managedEndPoint the ManagedEndPoint to add a timer to.
|
|
* @param name the name of the timer (for logging).
|
|
* @param interval the interval of the timer in milliseconds.
|
|
* @param callbackFunction the function to call when timer expires.
|
|
*
|
|
* @throw std::exception
|
|
* @throw StatusCodeException
|
|
*/
|
|
ChimeTimer(ManagedEndPoint &managedEndPoint, const String &name, const Timer::Interval interval,
|
|
const CallbackFunction &callbackFunction) :
|
|
m_timer(Timer::CreateTickChime(managedEndPoint, name, interval, callbackFunction))
|
|
{
|
|
}
|
|
|
|
//! Cancel.
|
|
void Cancel()
|
|
{
|
|
m_timer.Cancel();
|
|
}
|
|
|
|
private:
|
|
Timer m_timer;
|
|
};
|
|
|
|
} // namespace ThreadTimer
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_THREAD_TIMER_H)
|