Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 4 | |
| 5 | #include "bmc_time_change_listener.hpp" |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 6 | #include "epoch_base.hpp" |
| 7 | |
| 8 | #include <chrono> |
| 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace 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 YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 20 | class HostEpoch : public EpochBase, public BmcTimeChangeListener |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 21 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 22 | public: |
| 23 | friend class TestHostEpoch; |
| 24 | HostEpoch(sdbusplus::bus::bus& bus, const char* objPath); |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 25 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 26 | /** |
| 27 | * @brief Get value of Elapsed property |
| 28 | * |
| 29 | * @return The elapsed microseconds since UTC |
| 30 | **/ |
| 31 | uint64_t elapsed() const override; |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 32 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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; |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 41 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 42 | /** @brief Notified on time owner changed */ |
| 43 | void onOwnerChanged(Owner owner) override; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 44 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 45 | /** @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 YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 50 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 51 | private: |
| 52 | /** @brief The diff between BMC and Host time */ |
| 53 | std::chrono::microseconds offset; |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 54 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 55 | /** |
| 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 YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 62 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 63 | /** @brief Save the offset value into offsetFile */ |
| 64 | void saveOffset(); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 65 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 66 | /** @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 YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // namespace time |
| 73 | } // namespace phosphor |