blob: 1252ff931e386c143de2b94ca3e4c575636a0605 [file] [log] [blame]
Lei YUaf5abc52017-03-07 17:49:17 +08001#pragma once
2
3#include "config.h"
4#include "epoch_base.hpp"
5
6#include <chrono>
7
8namespace phosphor
9{
10namespace time
11{
12
13/** @class HostEpoch
14 * @brief OpenBMC HOST EpochTime implementation.
15 * @details A concrete implementation for xyz.openbmc_project.Time.EpochTime
16 * DBus API for HOST's epoch time.
17 */
18class HostEpoch : public EpochBase
19{
20 public:
21 friend class TestHostEpoch;
22 HostEpoch(sdbusplus::bus::bus& bus,
23 const char* objPath);
24
25 /**
26 * @brief Get value of Elapsed property
27 *
28 * @return The elapsed microseconds since UTC
29 **/
30 uint64_t elapsed() const override;
31
32 /**
33 * @brief Set value of Elapsed property
34 *
35 * @param[in] value - The microseconds since UTC to set
36 *
37 * @return The updated elapsed microseconds since UTC
38 **/
39 uint64_t elapsed(uint64_t value) override;
40
41 private:
42 /** @brief The diff between BMC and Host time */
43 std::chrono::microseconds offset;
44
45 /** @brief The file to store the offset in File System.
46 * Read back when starts
47 **/
48 static constexpr auto offsetFile = HOST_OFFSET_FILE;
49
50 /** @brief Read data with type T from file
51 *
52 * @param[in] fileName - The name of file to read from
53 *
54 * @return The data with type T
55 */
56 template <typename T>
57 static T readData(const char* fileName);
58
59 /** @brief Write data with type T to file
60 *
61 * @param[in] fileName - The name of file to write to
62 * @param[in] data - The data with type T to write to file
63 */
64 template <typename T>
65 static void writeData(const char* fileName, T&& data);
66};
67
68} // namespace time
69} // namespace phosphor