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