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