338 lines
11 KiB
C++
338 lines
11 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/TimerServiceApi.h
|
|
*
|
|
* @brief Header file for the timer service api.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_TIMER_SERVICE_API_H)
|
|
#define ACTIV_FRAMEWORK_TIMER_SERVICE_API_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/DateTime.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
class Component;
|
|
class RequestId;
|
|
class ScopedAddress;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Api to the agent's timer service.
|
|
*/
|
|
class TimerServiceApi
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Request helper class.
|
|
*
|
|
* @param REQUEST_TYPE the request type.
|
|
* @param PARAMETERS the type of request parameters.
|
|
*/
|
|
template<MessageType REQUEST_TYPE, typename PARAMETERS>
|
|
class RequestHelper
|
|
{
|
|
public:
|
|
typedef PARAMETERS Parameters; ///< The parameters typedef.
|
|
|
|
/**
|
|
* @brief Create a new timer
|
|
*
|
|
* @param component the component wanting to set the timer.
|
|
* @param parameters the request parameters for the timer.
|
|
* @param address reference to a scoped address object to receive the address of the new timer.
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode Create(const Component &component, const Parameters ¶meters,
|
|
ScopedAddress &address);
|
|
|
|
static const MessageType REQUEST = REQUEST_TYPE; ///< The request type.
|
|
|
|
private:
|
|
ACTIV_FRAMEWORK_API static StatusCode PostRequest(const Component &component, const Parameters ¶meters,
|
|
const RequestId &requestId);
|
|
|
|
friend class Component;
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for setting an alarm timer (triggered by system clock).
|
|
*/
|
|
class AlarmParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param dateTime the alarm date time.
|
|
*/
|
|
ACTIV_FRAMEWORK_API AlarmParameters(const DateTime &dateTime);
|
|
|
|
DateTime m_dateTime; ///< DateTime of alarm.
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for setting a countdown timer (triggered by system tick count).
|
|
*/
|
|
class CountdownParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param countdownDuration the countdown duration in milliseconds.
|
|
*/
|
|
ACTIV_FRAMEWORK_API CountdownParameters(const uint64_t countdownDuration);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param t1 Date::Days or Time::Hours, Time::Minutes, Time::Seconds, Time::Milliseconds references,
|
|
* which will be used to calculate the total countdown duration in milliseconds.
|
|
* @param dummy unused.
|
|
*/
|
|
template<typename T1>
|
|
CountdownParameters(const T1 &t1, typename Boost::disable_if<Boost::is_integral<T1> >::type *dummy = 0);
|
|
|
|
template<typename T1, typename T2>
|
|
CountdownParameters(const T1 &t1, const T2 &t2);
|
|
|
|
template<typename T1, typename T2, typename T3>
|
|
CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3);
|
|
|
|
template<typename T1, typename T2, typename T3, typename T4>
|
|
CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4);
|
|
|
|
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
|
CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5);
|
|
|
|
uint64_t m_countdownDuration; ///< Countdown duration in milliseconds.
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for setting a chime, by default triggered by system tick count.
|
|
*/
|
|
class ChimeParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param intervalBetweenChimes the interval between chimes.
|
|
*/
|
|
ACTIV_FRAMEWORK_API ChimeParameters(const uint64_t intervalBetweenChimes);
|
|
|
|
uint64_t m_intervalBetweenChimes; ///< Interval between chimes.
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for setting a chime triggered by system clock.
|
|
*/
|
|
class ClockBasedChimeParameters : public ChimeParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param intervalBetweenChimes the interval between chimes.
|
|
* @param startDateTime the date time of the first chime.
|
|
*/
|
|
ACTIV_FRAMEWORK_API ClockBasedChimeParameters(const uint64_t intervalBetweenChimes, const DateTime &startDateTime);
|
|
|
|
DateTime m_startDateTime; ///< Date time of first chime.
|
|
};
|
|
|
|
/**
|
|
* @brief Local alarm, triggered when local system clock reaches the target date time.
|
|
*/
|
|
typedef RequestHelper<TIMER_REQUEST_SET_LOCAL_ALARM, AlarmParameters> LocalAlarm;
|
|
|
|
/**
|
|
* @brief Countdown timer, triggered when a specified number of system ticks have elapsed after the timer was created.
|
|
*/
|
|
typedef RequestHelper<TIMER_REQUEST_SET_COUNTDOWN, CountdownParameters> Countdown;
|
|
|
|
/**
|
|
* @brief Available tick-based chimes, triggered by system tick count.
|
|
*/
|
|
class TickChime
|
|
{
|
|
public:
|
|
typedef RequestHelper<TIMER_REQUEST_SET_TICK_BASED_MILLISECOND_CHIME, ChimeParameters> Millisecond;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_TICK_BASED_SECOND_CHIME, ChimeParameters> Second;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_TICK_BASED_MINUTE_CHIME, ChimeParameters> Minute;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_TICK_BASED_HOUR_CHIME, ChimeParameters> Hour;
|
|
};
|
|
|
|
/**
|
|
* @brief Available clock-based chimes, triggered by local system clock.
|
|
*/
|
|
class LocalClockChime
|
|
{
|
|
public:
|
|
typedef RequestHelper<TIMER_REQUEST_SET_LOCAL_CLOCK_BASED_SECOND_CHIME, ClockBasedChimeParameters> Second;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_LOCAL_CLOCK_BASED_MINUTE_CHIME, ClockBasedChimeParameters> Minute;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_LOCAL_CLOCK_BASED_HOUR_CHIME, ClockBasedChimeParameters> Hour;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_LOCAL_CLOCK_BASED_DAY_CHIME, ClockBasedChimeParameters> Day;
|
|
};
|
|
|
|
/**
|
|
* @brief Available clock-based chimes, triggered by UTC system clock.
|
|
*/
|
|
class UtcClockChime
|
|
{
|
|
public:
|
|
typedef RequestHelper<TIMER_REQUEST_SET_UTC_CLOCK_BASED_SECOND_CHIME, ClockBasedChimeParameters> Second;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_UTC_CLOCK_BASED_MINUTE_CHIME, ClockBasedChimeParameters> Minute;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_UTC_CLOCK_BASED_HOUR_CHIME, ClockBasedChimeParameters> Hour;
|
|
typedef RequestHelper<TIMER_REQUEST_SET_UTC_CLOCK_BASED_DAY_CHIME, ClockBasedChimeParameters> Day;
|
|
};
|
|
|
|
/**
|
|
* @brief Get current date (utc).
|
|
*
|
|
* @param component
|
|
* @param date reference to a Date object to set.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetCurrentUtcDate(const Component &component, Date &date);
|
|
|
|
/**
|
|
* @brief Get current time (utc).
|
|
*
|
|
* @param component
|
|
* @param time reference to a Time object to set.
|
|
* @param shouldSetMilliseconds whether to set the milliseconds component of @a time.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetCurrentUtcTime(const Component &component, Time &time,
|
|
const bool shouldSetMilliseconds = false);
|
|
|
|
/**
|
|
* @brief Get current date & time (utc).
|
|
*
|
|
* @param component
|
|
* @param dateTime reference to a DateTime object to set.
|
|
* @param shouldSetMilliseconds whether to set the milliseconds component of @a dateTime.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetCurrentUtcDateTime(const Component &component, DateTime &dateTime,
|
|
const bool shouldSetMilliseconds = false);
|
|
|
|
/**
|
|
* @brief Get current date (local).
|
|
*
|
|
* @param component
|
|
* @param date reference to a Date object to set.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetCurrentLocalDate(const Component &component, Date &date);
|
|
|
|
/**
|
|
* @brief Get current time (local).
|
|
*
|
|
* @param component
|
|
* @param time reference to a Time object to set.
|
|
* @param shouldSetMilliseconds whether to set the milliseconds component of @a time.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetCurrentLocalTime(const Component &component, Time &time,
|
|
const bool shouldSetMilliseconds = false);
|
|
|
|
/**
|
|
* @brief Get current date & time (local).
|
|
*
|
|
* @param component
|
|
* @param dateTime reference to a DateTime object to set.
|
|
* @param shouldSetMilliseconds whether to set the milliseconds component of @a dateTime.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetCurrentLocalDateTime(const Component &component, DateTime &dateTime,
|
|
const bool shouldSetMilliseconds = false);
|
|
|
|
/**
|
|
* @brief Adjust the system time.
|
|
*
|
|
* May adjust the system time immediately, or gradually, depending on the underlying platform.
|
|
* The TimerService may need to be running in a process with root privileges, depending on the platform.
|
|
*
|
|
* @param component
|
|
* @param milliseconds milliseconds to adjust by.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode AdjustSystemTime(const Component &component, const int32_t milliseconds);
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T1>
|
|
TimerServiceApi::CountdownParameters::CountdownParameters(const T1 &t1,
|
|
typename Boost::disable_if<Boost::is_integral<T1> >::type *dummy) :
|
|
m_countdownDuration(T1::MILLISECONDS_PER_UNIT * t1.m_value)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T1, typename T2>
|
|
TimerServiceApi::CountdownParameters::CountdownParameters(const T1 &t1, const T2 &t2) :
|
|
m_countdownDuration((T1::MILLISECONDS_PER_UNIT * t1.m_value) +
|
|
(T2::MILLISECONDS_PER_UNIT * t2.m_value))
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T1, typename T2, typename T3>
|
|
TimerServiceApi::CountdownParameters::CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3) :
|
|
m_countdownDuration((T1::MILLISECONDS_PER_UNIT * t1.m_value) +
|
|
(T2::MILLISECONDS_PER_UNIT * t2.m_value) +
|
|
(T3::MILLISECONDS_PER_UNIT * t3.m_value))
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T1, typename T2, typename T3, typename T4>
|
|
TimerServiceApi::CountdownParameters::CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) :
|
|
m_countdownDuration((T1::MILLISECONDS_PER_UNIT * t1.m_value) +
|
|
(T2::MILLISECONDS_PER_UNIT * t2.m_value) +
|
|
(T3::MILLISECONDS_PER_UNIT * t3.m_value) +
|
|
(T4::MILLISECONDS_PER_UNIT * t4.m_value))
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
|
TimerServiceApi::CountdownParameters::CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5) :
|
|
m_countdownDuration((T1::MILLISECONDS_PER_UNIT * t1.m_value) +
|
|
(T2::MILLISECONDS_PER_UNIT * t2.m_value) +
|
|
(T3::MILLISECONDS_PER_UNIT * t3.m_value) +
|
|
(T4::MILLISECONDS_PER_UNIT * t4.m_value) +
|
|
(T5::MILLISECONDS_PER_UNIT * t5.m_value))
|
|
{
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_TIMER_SERVICE_API_H)
|