blob: 10dbf7bffaf5b35173af54d0f7bf38a291234549 [file] [log] [blame]
Lei YU96232822017-01-20 14:05:46 +08001#pragma once
2
3#include "epoch_base.hpp"
4
Lei YU7b218792017-02-09 12:10:13 +08005#include <chrono>
6
Lei YU96232822017-01-20 14:05:46 +08007namespace phosphor
8{
9namespace time
10{
11
Lei YU7b218792017-02-09 12:10:13 +080012using namespace std::chrono;
13
Lei YU96232822017-01-20 14:05:46 +080014/** @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 */
19class BmcEpoch : public EpochBase
20{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050021 public:
George Liucb421092022-08-16 17:02:31 +080022 BmcEpoch(sdbusplus::bus_t& bus, const char* objPath, Manager& manager);
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050023 ~BmcEpoch();
Lei YU96232822017-01-20 14:05:46 +080024
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050025 /**
26 * @brief Get value of Elapsed property
27 *
28 * @return The elapsed microseconds since UTC
29 **/
30 uint64_t elapsed() const override;
Lei YU96232822017-01-20 14:05:46 +080031
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050032 /**
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;
Lei YU7b218792017-02-09 12:10:13 +080039
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050040 private:
41 /** @brief The fd for time change event */
42 int timeFd = -1;
Lei YU7b218792017-02-09 12:10:13 +080043
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050044 /** @brief Initialize timerFd related resource */
45 void initialize();
Lei YU7b218792017-02-09 12:10:13 +080046
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050047 /** @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);
Lei YU7b218792017-02-09 12:10:13 +080056
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050057 /** @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)>;
Lei YU7b218792017-02-09 12:10:13 +080067
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050068 /** @brief The event source on system time change */
69 SdEventSource timeChangeEventSource{nullptr, sdEventSourceDeleter};
Lei YU96232822017-01-20 14:05:46 +080070};
71
Lei YUaf5abc52017-03-07 17:49:17 +080072} // namespace time
73} // namespace phosphor