summaryrefslogtreecommitdiff
path: root/source/LCM/Timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/LCM/Timer.h')
-rw-r--r--source/LCM/Timer.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/source/LCM/Timer.h b/source/LCM/Timer.h
new file mode 100644
index 0000000..2b395b6
--- /dev/null
+++ b/source/LCM/Timer.h
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (C) ST-Ericsson SA 2011
+ * License terms: 3-clause BSD license
+ ******************************************************************************/
+
+#ifndef _TIMER_H_
+#define _TIMER_H_
+
+#include "error_codes.h"
+#include "t_time_utilities.h"
+#include "Logger.h"
+#ifdef _WIN32
+#include "WinApiWrappers.h"
+#else
+#include "LinuxApiWrappers.h"
+#endif
+#include <ctime>
+
+class Timer
+{
+public:
+ Timer();
+ /*
+ * Initialization of the Timers handler.
+ *
+ * @param [in] Timers Numbers of defined timers.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If no timer s for initialization.
+ */
+ ErrorCode_e Init(uint32 Timers);
+
+ /*
+ * Reserve new timer.
+ *
+ * @param [in] Timer_p pointer to the timer data.
+ *
+ * @return Index of reserved timer.
+ * @return Index 0 if no free timers.
+ */
+ uint32 Get(Timer_t *Timer_p);
+
+ /*
+ * Release reserved timer.
+ *
+ * @param [in] TimerKey Index of reserved timer.
+ *
+ * @retval E_SUCCESS After successful execution.
+ * @retval E_INVALID_INPUT_PARAMETERS If one of the input.
+ * @retval E_NONEXIST_TIMER non exist timer.
+ */
+ ErrorCode_e Release(uint32 TimerKey);
+
+ /*
+ * Read the current time of timer.
+ *
+ * @param [in] TimerKey Index of reserved timer.
+ *
+ * @return Current time of the timer.
+ */
+ uint32 ReadTime(uint32 TimerKey);
+
+ /**
+ * Get current system time.
+ *
+ * @return System Time.
+ */
+ uint32 GetSystemTime(void);
+
+ /*
+ * The timer handler method which is polled in the main execution thread.
+ * Checks if there is a timer which time has elapsed and calls its callback,
+ * handle the timers time decrementation.
+ *
+ * @param [in] IsTimerOn Determinates if the timers are active to be handled.
+ *
+ * @return Function doesn't return value.
+ */
+ void DoTimerHandler(bool IsTimerOn);
+
+public:
+ ~Timer(void);
+ void SetLogger(Logger *logger) {
+ logger_ = logger;
+ }
+
+private:
+ TimerHeader_t timers_;
+ time_t systemTime_;
+
+ Logger *logger_;
+
+ uint32 GetIncrement();
+ uint32 FindFreeTimer();
+};
+
+#endif // _TIMER_H_