/** * @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 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 CountdownParameters(const T1 &t1, typename Boost::disable_if >::type *dummy = 0); template CountdownParameters(const T1 &t1, const T2 &t2); template CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3); template CountdownParameters(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4); template 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 LocalAlarm; /** * @brief Countdown timer, triggered when a specified number of system ticks have elapsed after the timer was created. */ typedef RequestHelper Countdown; /** * @brief Available tick-based chimes, triggered by system tick count. */ class TickChime { public: typedef RequestHelper Millisecond; typedef RequestHelper Second; typedef RequestHelper Minute; typedef RequestHelper Hour; }; /** * @brief Available clock-based chimes, triggered by local system clock. */ class LocalClockChime { public: typedef RequestHelper Second; typedef RequestHelper Minute; typedef RequestHelper Hour; typedef RequestHelper Day; }; /** * @brief Available clock-based chimes, triggered by UTC system clock. */ class UtcClockChime { public: typedef RequestHelper Second; typedef RequestHelper Minute; typedef RequestHelper Hour; typedef RequestHelper 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 TimerServiceApi::CountdownParameters::CountdownParameters(const T1 &t1, typename Boost::disable_if >::type *dummy) : m_countdownDuration(T1::MILLISECONDS_PER_UNIT * t1.m_value) { } // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- template 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 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 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 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)