Lei YU | 9623282 | 2017-01-20 14:05:46 +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 | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 4 | #include "epoch_base.hpp" |
| 5 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 6 | #include <chrono> |
| 7 | |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 8 | namespace phosphor |
| 9 | { |
| 10 | namespace time |
| 11 | { |
| 12 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 13 | using namespace std::chrono; |
| 14 | |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 15 | /** @class BmcEpoch |
| 16 | * @brief OpenBMC BMC EpochTime implementation. |
| 17 | * @details A concrete implementation for xyz.openbmc_project.Time.EpochTime |
| 18 | * DBus API for BMC's epoch time. |
| 19 | */ |
| 20 | class BmcEpoch : public EpochBase |
| 21 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 22 | public: |
| 23 | friend class TestBmcEpoch; |
| 24 | BmcEpoch(sdbusplus::bus::bus& bus, const char* objPath); |
| 25 | ~BmcEpoch(); |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 26 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 27 | /** |
| 28 | * @brief Get value of Elapsed property |
| 29 | * |
| 30 | * @return The elapsed microseconds since UTC |
| 31 | **/ |
| 32 | uint64_t elapsed() const override; |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 33 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 34 | /** |
| 35 | * @brief Set value of Elapsed property |
| 36 | * |
| 37 | * @param[in] value - The microseconds since UTC to set |
| 38 | * @return The updated elapsed microseconds since UTC |
| 39 | **/ |
| 40 | uint64_t elapsed(uint64_t value) override; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 41 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 42 | /** @brief Set the listner for bmc time change |
| 43 | * |
| 44 | * @param[in] listener - The pointer to the listener |
| 45 | */ |
| 46 | void setBmcTimeChangeListener(BmcTimeChangeListener* listener); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 47 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 48 | private: |
| 49 | /** @brief The fd for time change event */ |
| 50 | int timeFd = -1; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 51 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 52 | /** @brief Initialize timerFd related resource */ |
| 53 | void initialize(); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 54 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 55 | /** @brief Notify the listeners that bmc time is changed |
| 56 | * |
| 57 | * @param[in] time - The epoch time in microseconds to notify |
| 58 | */ |
| 59 | void notifyBmcTimeChange(const microseconds& time); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 60 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 61 | /** @brief The callback function on system time change |
| 62 | * |
| 63 | * @param[in] es - Source of the event |
| 64 | * @param[in] fd - File descriptor of the timer |
| 65 | * @param[in] revents - Not used |
| 66 | * @param[in] userdata - User data pointer |
| 67 | */ |
| 68 | static int onTimeChange(sd_event_source* es, int fd, uint32_t revents, |
| 69 | void* userdata); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 70 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 71 | /** @brief The reference of sdbusplus bus */ |
| 72 | sdbusplus::bus::bus& bus; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 73 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 74 | /** @brief The deleter of sd_event_source */ |
| 75 | std::function<void(sd_event_source*)> sdEventSourceDeleter = |
| 76 | [](sd_event_source* p) { |
| 77 | if (p) |
| 78 | { |
| 79 | sd_event_source_unref(p); |
| 80 | } |
| 81 | }; |
| 82 | using SdEventSource = |
| 83 | std::unique_ptr<sd_event_source, decltype(sdEventSourceDeleter)>; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 84 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 85 | /** @brief The event source on system time change */ |
| 86 | SdEventSource timeChangeEventSource{nullptr, sdEventSourceDeleter}; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 87 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 88 | /** @brief The listener for bmc time change */ |
| 89 | BmcTimeChangeListener* timeChangeListener = nullptr; |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 90 | }; |
| 91 | |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 92 | } // namespace time |
| 93 | } // namespace phosphor |