Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 3 | #include "property_change_listener.hpp" |
| 4 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <xyz/openbmc_project/Time/EpochTime/server.hpp> |
| 7 | |
| 8 | #include <chrono> |
| 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace time |
| 13 | { |
| 14 | |
| 15 | /** @class EpochBase |
| 16 | * @brief Base class for OpenBMC EpochTime implementation. |
| 17 | * @details A base class that implements xyz.openbmc_project.Time.EpochTime |
| 18 | * DBus API for epoch time. |
| 19 | */ |
| 20 | class EpochBase : public sdbusplus::server::object::object < |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Time::server::EpochTime >, |
| 22 | public PropertyChangeListner |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 23 | { |
| 24 | public: |
| 25 | friend class TestEpochBase; |
| 26 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 27 | EpochBase(sdbusplus::bus::bus& bus, |
| 28 | const char* objPath); |
| 29 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 30 | /** @brief Notified on time mode changed */ |
| 31 | void onModeChanged(Mode mode) override; |
| 32 | |
| 33 | /** @brief Notified on time owner changed */ |
| 34 | void onOwnerChanged(Owner owner) override; |
| 35 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 36 | protected: |
| 37 | /** @brief Persistent sdbusplus DBus connection */ |
| 38 | sdbusplus::bus::bus& bus; |
| 39 | |
| 40 | /** @brief The current time mode */ |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 41 | Mode timeMode = Mode::Manual; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 42 | |
| 43 | /** @brief The current time owner */ |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 44 | Owner timeOwner = Owner::Both; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 45 | |
| 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 |
Lei YU | fa02488 | 2017-11-09 10:49:26 +0800 | [diff] [blame] | 52 | * |
| 53 | * @return true or false to indicate if it sets time successfully |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 54 | */ |
Lei YU | fa02488 | 2017-11-09 10:49:26 +0800 | [diff] [blame] | 55 | bool setTime(const std::chrono::microseconds& timeOfDayUsec); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 56 | |
| 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 |