Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Lei YU | 1cd4248 | 2018-07-24 10:40:59 +0800 | [diff] [blame] | 3 | #include "config.h" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 4 | |
George Liu | cb42109 | 2022-08-16 17:02:31 +0800 | [diff] [blame^] | 5 | #include "manager.hpp" |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 6 | #include "property_change_listener.hpp" |
| 7 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <xyz/openbmc_project/Time/EpochTime/server.hpp> |
| 10 | |
George Liu | c6d3397 | 2020-06-22 10:35:29 +0800 | [diff] [blame] | 11 | #include <chrono> |
| 12 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 13 | namespace phosphor |
| 14 | { |
| 15 | namespace time |
| 16 | { |
| 17 | |
| 18 | /** @class EpochBase |
| 19 | * @brief Base class for OpenBMC EpochTime implementation. |
| 20 | * @details A base class that implements xyz.openbmc_project.Time.EpochTime |
| 21 | * DBus API for epoch time. |
| 22 | */ |
George Liu | c6d3397 | 2020-06-22 10:35:29 +0800 | [diff] [blame] | 23 | class EpochBase : |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 24 | public sdbusplus::server::object_t< |
George Liu | c6d3397 | 2020-06-22 10:35:29 +0800 | [diff] [blame] | 25 | sdbusplus::xyz::openbmc_project::Time::server::EpochTime>, |
| 26 | public PropertyChangeListner |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 27 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 28 | public: |
George Liu | cb42109 | 2022-08-16 17:02:31 +0800 | [diff] [blame^] | 29 | EpochBase(sdbusplus::bus_t& bus, const char* objPath, Manager& manager); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 30 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 31 | /** @brief Notified on time mode changed */ |
| 32 | void onModeChanged(Mode mode) override; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 33 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 34 | protected: |
| 35 | /** @brief Persistent sdbusplus DBus connection */ |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 36 | sdbusplus::bus_t& bus; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 37 | |
George Liu | cb42109 | 2022-08-16 17:02:31 +0800 | [diff] [blame^] | 38 | /** @brief The manager to handle OpenBMC time */ |
| 39 | Manager& manager; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 40 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 41 | /** @brief Set current time to system |
| 42 | * |
| 43 | * This function set the time to system by invoking systemd |
| 44 | * org.freedesktop.timedate1's SetTime method. |
| 45 | * |
| 46 | * @param[in] timeOfDayUsec - Microseconds since UTC |
| 47 | * |
| 48 | * @return true or false to indicate if it sets time successfully |
| 49 | */ |
| 50 | bool setTime(const std::chrono::microseconds& timeOfDayUsec); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 51 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 52 | /** @brief Get current time |
| 53 | * |
| 54 | * @return Microseconds since UTC |
| 55 | */ |
| 56 | std::chrono::microseconds getTime() const; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // namespace time |
| 60 | } // namespace phosphor |