Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 3 | #include "bmc_time_change_listener.hpp" |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 4 | #include "config.h" |
| 5 | #include "epoch_base.hpp" |
| 6 | |
| 7 | #include <chrono> |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace 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 YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 19 | class HostEpoch : public EpochBase, public BmcTimeChangeListener |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 20 | { |
| 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 YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 42 | /** @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 YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 52 | private: |
| 53 | /** @brief The diff between BMC and Host time */ |
| 54 | std::chrono::microseconds offset; |
| 55 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 56 | /** |
| 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 YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 67 | /** @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 YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace time |
| 74 | } // namespace phosphor |