blob: bbf9d22a583c37b1f8ad48b9944785e412988c33 [file] [log] [blame]
Lei YUaf5abc52017-03-07 17:49:17 +08001#pragma once
2
3#include "config.h"
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05004
5#include "bmc_time_change_listener.hpp"
Lei YUaf5abc52017-03-07 17:49:17 +08006#include "epoch_base.hpp"
7
8#include <chrono>
9
10namespace phosphor
11{
12namespace time
13{
14
15/** @class HostEpoch
16 * @brief OpenBMC HOST EpochTime implementation.
17 * @details A concrete implementation for xyz.openbmc_project.Time.EpochTime
18 * DBus API for HOST's epoch time.
19 */
Lei YU7b218792017-02-09 12:10:13 +080020class HostEpoch : public EpochBase, public BmcTimeChangeListener
Lei YUaf5abc52017-03-07 17:49:17 +080021{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050022 public:
23 friend class TestHostEpoch;
24 HostEpoch(sdbusplus::bus::bus& bus, const char* objPath);
Lei YUaf5abc52017-03-07 17:49:17 +080025
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050026 /**
27 * @brief Get value of Elapsed property
28 *
29 * @return The elapsed microseconds since UTC
30 **/
31 uint64_t elapsed() const override;
Lei YUaf5abc52017-03-07 17:49:17 +080032
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050033 /**
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;
Lei YUaf5abc52017-03-07 17:49:17 +080041
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050042 /** @brief Notified on time owner changed */
43 void onOwnerChanged(Owner owner) override;
Lei YU7b218792017-02-09 12:10:13 +080044
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050045 /** @brief Notified on bmc time is changed
46 *
47 * @param[in] bmcTime - The epoch time in microseconds
48 */
49 void onBmcTimeChanged(const std::chrono::microseconds& bmcTime) override;
Lei YU7b218792017-02-09 12:10:13 +080050
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050051 private:
52 /** @brief The diff between BMC and Host time */
53 std::chrono::microseconds offset;
Lei YUaf5abc52017-03-07 17:49:17 +080054
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050055 /**
56 * @brief The diff between host time and steady clock
57 * @details This diff is used to calculate the host time if BMC time
58 * is changed and the owner is SPLIT.
59 * Without this the host time is lost if BMC time is changed.
60 */
61 std::chrono::microseconds diffToSteadyClock;
Lei YU7b218792017-02-09 12:10:13 +080062
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050063 /** @brief Save the offset value into offsetFile */
64 void saveOffset();
Lei YU7b218792017-02-09 12:10:13 +080065
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050066 /** @brief The file to store the offset in File System.
67 * Read back when starts
68 **/
69 static constexpr auto offsetFile = HOST_OFFSET_FILE;
Lei YUaf5abc52017-03-07 17:49:17 +080070};
71
72} // namespace time
73} // namespace phosphor