blob: f31a32b5943b886c7f2b3ffe418d9fb72bd35313 [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 YU415b9642017-02-09 11:37:26 +080041 Mode timeMode = Mode::NTP;
Lei YU2f9c0cc2017-01-20 14:02:03 +080042
43 /** @brief The current time owner */
Lei YU415b9642017-02-09 11:37:26 +080044 Owner timeOwner = Owner::BMC;
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
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 YU2f9c0cc2017-01-20 14:02:03 +080060};
61
62} // namespace time
63} // namespace phosphor