blob: 4f23d51fe433108bae26231e9497c4a34cf01d0a [file] [log] [blame]
Lei YU2f9c0cc2017-01-20 14:02:03 +08001#pragma once
2
Lei YU415b9642017-02-09 11:37:26 +08003#include "property_change_listener.hpp"
4
Lei YU2f9c0cc2017-01-20 14:02:03 +08005#include <sdbusplus/bus.hpp>
6#include <xyz/openbmc_project/Time/EpochTime/server.hpp>
7
8#include <chrono>
9
10namespace phosphor
11{
12namespace 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 */
20class EpochBase : public sdbusplus::server::object::object <
Lei YU415b9642017-02-09 11:37:26 +080021 sdbusplus::xyz::openbmc_project::Time::server::EpochTime >,
22 public PropertyChangeListner
Lei YU2f9c0cc2017-01-20 14:02:03 +080023{
24 public:
25 friend class TestEpochBase;
26
Lei YU2f9c0cc2017-01-20 14:02:03 +080027 EpochBase(sdbusplus::bus::bus& bus,
28 const char* objPath);
29
Lei YU415b9642017-02-09 11:37:26 +080030 /** @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 YU2f9c0cc2017-01-20 14:02:03 +080036 protected:
37 /** @brief Persistent sdbusplus DBus connection */
38 sdbusplus::bus::bus& bus;
39
40 /** @brief The current time mode */
Lei YUad143542017-07-25 14:27:07 +080041 Mode timeMode = Mode::Manual;
Lei YU2f9c0cc2017-01-20 14:02:03 +080042
43 /** @brief The current time owner */
Lei YUad143542017-07-25 14:27:07 +080044 Owner timeOwner = Owner::Both;
Lei YU2f9c0cc2017-01-20 14:02:03 +080045
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 YUfa024882017-11-09 10:49:26 +080052 *
53 * @return true or false to indicate if it sets time successfully
Lei YU2f9c0cc2017-01-20 14:02:03 +080054 */
Lei YUfa024882017-11-09 10:49:26 +080055 bool setTime(const std::chrono::microseconds& timeOfDayUsec);
Lei YU2f9c0cc2017-01-20 14:02:03 +080056
57 /** @brief Get current time
58 *
59 * @return Microseconds since UTC
60 */
61 std::chrono::microseconds getTime() const;
Lei YU2f9c0cc2017-01-20 14:02:03 +080062};
63
64} // namespace time
65} // namespace phosphor