-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUptimeInfo.h
90 lines (74 loc) · 1.82 KB
/
UptimeInfo.h
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
/*
* UptimeInfo.h
*
* Created on: 01.10.2013
* Author: niklausd
*/
#ifndef UPTIMEINFO_H_
#define UPTIMEINFO_H_
/**
* Adapter Interface, will call-out the platform specific up-time info time in milliseconds.
*/
class UptimeInfoAdapter
{
public:
/**
* Up-time query call-out. To be implemented according to platform specific circumstances.
* @return Number of milliseconds since the program started.
*/
virtual unsigned long tMillis() = 0;
protected:
UptimeInfoAdapter() { }
public:
virtual ~UptimeInfoAdapter() { }
private: // forbidden functions
UptimeInfoAdapter(const UptimeInfoAdapter& src); // copy constructor
UptimeInfoAdapter& operator = (const UptimeInfoAdapter& src); // assignment operator
};
/**
* Helper class to use the appropriate time base depending on framework.
* Supported default frameworks:
* - Arduino (AVR and SAM)
* - POSIX
*/
class UptimeInfo
{
public:
static inline UptimeInfo* Instance()
{
if (0 == s_instance)
{
s_instance = new UptimeInfo();
}
return s_instance;
}
protected:
UptimeInfo();
public:
virtual ~UptimeInfo();
void setAdapter(UptimeInfoAdapter* adapter);
static inline UptimeInfoAdapter* adapter()
{
return s_adapter;
}
/**
* Returns the number of milliseconds since the program started.
* @return Number of milliseconds since the program started.
*/
static inline unsigned long tMillis()
{
unsigned long ms = 0;
if (0 != adapter())
{
ms = adapter()->tMillis();
}
return ms;
}
private:
static UptimeInfo* s_instance;
static UptimeInfoAdapter* s_adapter;
private: // forbidden functions
UptimeInfo& operator = (const UptimeInfo& src); // assignment operator
UptimeInfo(const UptimeInfo& src); // copy constructor
};
#endif /* UPTIMEINFO_H_ */