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