Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "epoch_base.hpp" |
| 4 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 5 | #include <chrono> |
| 6 | |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace time |
| 10 | { |
| 11 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 12 | using namespace std::chrono; |
| 13 | |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 14 | /** @class BmcEpoch |
| 15 | * @brief OpenBMC BMC EpochTime implementation. |
| 16 | * @details A concrete implementation for xyz.openbmc_project.Time.EpochTime |
| 17 | * DBus API for BMC's epoch time. |
| 18 | */ |
| 19 | class BmcEpoch : public EpochBase |
| 20 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 21 | public: |
| 22 | friend class TestBmcEpoch; |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 23 | BmcEpoch(sdbusplus::bus_t& bus, const char* objPath); |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 24 | ~BmcEpoch(); |
Lei YU | 9623282 | 2017-01-20 14:05:46 +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 | 9623282 | 2017-01-20 14:05:46 +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 | * @return The updated elapsed microseconds since UTC |
| 38 | **/ |
| 39 | uint64_t elapsed(uint64_t value) override; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 40 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 41 | private: |
| 42 | /** @brief The fd for time change event */ |
| 43 | int timeFd = -1; |
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 Initialize timerFd related resource */ |
| 46 | void initialize(); |
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 | /** @brief The callback function on system time change |
| 49 | * |
| 50 | * @param[in] es - Source of the event |
| 51 | * @param[in] fd - File descriptor of the timer |
| 52 | * @param[in] revents - Not used |
| 53 | * @param[in] userdata - User data pointer |
| 54 | */ |
| 55 | static int onTimeChange(sd_event_source* es, int fd, uint32_t revents, |
| 56 | void* userdata); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 57 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 58 | /** @brief The deleter of sd_event_source */ |
| 59 | std::function<void(sd_event_source*)> sdEventSourceDeleter = |
| 60 | [](sd_event_source* p) { |
| 61 | if (p) |
| 62 | { |
| 63 | sd_event_source_unref(p); |
| 64 | } |
| 65 | }; |
| 66 | using SdEventSource = |
| 67 | std::unique_ptr<sd_event_source, decltype(sdEventSourceDeleter)>; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 68 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 69 | /** @brief The event source on system time change */ |
| 70 | SdEventSource timeChangeEventSource{nullptr, sdEventSourceDeleter}; |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 71 | }; |
| 72 | |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 73 | } // namespace time |
| 74 | } // namespace phosphor |