blob: 2b395b6e9d4415886ae3ed49a7540f97c7ac9b7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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_
|