1 #pragma once 2 3 #include "epoch_base.hpp" 4 5 #include <chrono> 6 7 namespace phosphor 8 { 9 namespace time 10 { 11 12 using namespace std::chrono; 13 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 { 21 public: 22 BmcEpoch(sdbusplus::bus_t& bus, const char* objPath, Manager& manager); 23 ~BmcEpoch(); 24 25 /** 26 * @brief Get value of Elapsed property 27 * 28 * @return The elapsed microseconds since UTC 29 **/ 30 uint64_t elapsed() const override; 31 32 /** 33 * @brief Set value of Elapsed property 34 * 35 * @param[in] value - The microseconds since UTC to set 36 * @return The updated elapsed microseconds since UTC 37 **/ 38 uint64_t elapsed(uint64_t value) override; 39 40 private: 41 /** @brief The fd for time change event */ 42 int timeFd = -1; 43 44 /** @brief Initialize timerFd related resource */ 45 void initialize(); 46 47 /** @brief The callback function on system time change 48 * 49 * @param[in] es - Source of the event 50 * @param[in] fd - File descriptor of the timer 51 * @param[in] revents - Not used 52 * @param[in] userdata - User data pointer 53 */ 54 static int onTimeChange(sd_event_source* es, int fd, uint32_t revents, 55 void* userdata); 56 57 /** @brief The deleter of sd_event_source */ 58 std::function<void(sd_event_source*)> sdEventSourceDeleter = 59 [](sd_event_source* p) { 60 if (p) 61 { 62 sd_event_source_unref(p); 63 } 64 }; 65 using SdEventSource = 66 std::unique_ptr<sd_event_source, decltype(sdEventSourceDeleter)>; 67 68 /** @brief The event source on system time change */ 69 SdEventSource timeChangeEventSource{nullptr, sdEventSourceDeleter}; 70 }; 71 72 } // namespace time 73 } // namespace phosphor 74