blob: 1eb3167f962dee6b406d2214c1387dc72c94d78c [file] [log] [blame]
Lei YUaf5abc52017-03-07 17:49:17 +08001#pragma once
2
Lei YU7b218792017-02-09 12:10:13 +08003#include "bmc_time_change_listener.hpp"
Lei YUaf5abc52017-03-07 17:49:17 +08004#include "config.h"
5#include "epoch_base.hpp"
6
7#include <chrono>
8
9namespace phosphor
10{
11namespace time
12{
13
14/** @class HostEpoch
15 * @brief OpenBMC HOST EpochTime implementation.
16 * @details A concrete implementation for xyz.openbmc_project.Time.EpochTime
17 * DBus API for HOST's epoch time.
18 */
Lei YU7b218792017-02-09 12:10:13 +080019class HostEpoch : public EpochBase, public BmcTimeChangeListener
Lei YUaf5abc52017-03-07 17:49:17 +080020{
21 public:
22 friend class TestHostEpoch;
23 HostEpoch(sdbusplus::bus::bus& bus,
24 const char* objPath);
25
26 /**
27 * @brief Get value of Elapsed property
28 *
29 * @return The elapsed microseconds since UTC
30 **/
31 uint64_t elapsed() const override;
32
33 /**
34 * @brief Set value of Elapsed property
35 *
36 * @param[in] value - The microseconds since UTC to set
37 *
38 * @return The updated elapsed microseconds since UTC
39 **/
40 uint64_t elapsed(uint64_t value) override;
41
Lei YU7b218792017-02-09 12:10:13 +080042 /** @brief Notified on time owner changed */
43 void onOwnerChanged(Owner owner) override;
44
45 /** @brief Notified on bmc time is changed
46 *
47 * @param[in] bmcTime - The epoch time in microseconds
48 */
49 void onBmcTimeChanged(
50 const std::chrono::microseconds& bmcTime) override;
51
Lei YUaf5abc52017-03-07 17:49:17 +080052 private:
53 /** @brief The diff between BMC and Host time */
54 std::chrono::microseconds offset;
55
Lei YU7b218792017-02-09 12:10:13 +080056 /**
57 * @brief The diff between host time and steady clock
58 * @details This diff is used to calculate the host time if BMC time
59 * is changed and the owner is SPLIT.
60 * Without this the host time is lost if BMC time is changed.
61 */
62 std::chrono::microseconds diffToSteadyClock;
63
64 /** @brief Save the offset value into offsetFile */
65 void saveOffset();
66
Lei YUaf5abc52017-03-07 17:49:17 +080067 /** @brief The file to store the offset in File System.
68 * Read back when starts
69 **/
70 static constexpr auto offsetFile = HOST_OFFSET_FILE;
Lei YUaf5abc52017-03-07 17:49:17 +080071};
72
73} // namespace time
74} // namespace phosphor