[AMBClient] - added time sync message
[profile/ivi/automotive-message-broker.git] / lib / timestamp.h
1 #ifndef _TIMESTAMP_H___
2 #define _TIMESTAMP_H___
3
4
5 namespace amb {
6
7 double currentTime();
8
9 /*!
10  * \brief The Timestamp class provides system time and monotonic time helper functions
11  * Timestamp is meant to be a singleton class.  Access through instance().
12  * \code
13  * double currentMonotonicTime = amb::Timestamp::instance()->currentTime();
14  * double epocTimeForMonotonicTime = amb::Timestamp::instance()->epochTime(currentMonotonicTime);
15  * \endcode
16  */
17 class Timestamp {
18 protected:
19         Timestamp();
20
21 public:
22
23         /*!
24          * \brief currentTime
25          * \return current monotonic (steady) time in seconds.
26          */
27         double currentTime();
28
29         /*!
30          * \brief epochTime
31          * \param time monotonic time usually from currentTime()
32          * \return number of seconds.milliseconds since unix epoch
33          */
34         double epochTime(double time);
35
36         /*!
37          * \brief epochTime
38          * \return current system time in seconds since unix epoch
39          */
40         double epochTime();
41
42 public:
43         /*!
44          * \brief instance
45          * \return instance of Timestamp;
46          */
47         static Timestamp *instance();
48
49 private:
50         double startTimeEpoch;
51         static Timestamp* mInstance;
52 };
53
54 }
55
56 #endif