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 | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame^] | 41 | Mode timeMode = Mode::NTP; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 42 | |
| 43 | /** @brief The current time owner */ |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame^] | 44 | Owner timeOwner = Owner::BMC; |
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 |
| 52 | */ |
| 53 | void setTime(const std::chrono::microseconds& timeOfDayUsec); |
| 54 | |
| 55 | /** @brief Get current time |
| 56 | * |
| 57 | * @return Microseconds since UTC |
| 58 | */ |
| 59 | std::chrono::microseconds getTime() const; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace time |
| 63 | } // namespace phosphor |