blob: 80fa3f462ef1129bec6bfd8636a8a39a4f4598bb [file] [log] [blame]
Lei YU2f9c0cc2017-01-20 14:02:03 +08001#pragma once
2
Lei YU1cd42482018-07-24 10:40:59 +08003#include "config.h"
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05004
Lei YU415b9642017-02-09 11:37:26 +08005#include "property_change_listener.hpp"
6
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05007#include <chrono>
Lei YU2f9c0cc2017-01-20 14:02:03 +08008#include <sdbusplus/bus.hpp>
9#include <xyz/openbmc_project/Time/EpochTime/server.hpp>
10
Lei YU2f9c0cc2017-01-20 14:02:03 +080011namespace phosphor
12{
13namespace 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 Millsab4cc6a2018-09-14 14:42:39 -050021class EpochBase : public sdbusplus::server::object::object<
22 sdbusplus::xyz::openbmc_project::Time::server::EpochTime>,
23 public PropertyChangeListner
Lei YU2f9c0cc2017-01-20 14:02:03 +080024{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050025 public:
26 friend class TestEpochBase;
Lei YU2f9c0cc2017-01-20 14:02:03 +080027
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050028 EpochBase(sdbusplus::bus::bus& bus, const char* objPath);
Lei YU2f9c0cc2017-01-20 14:02:03 +080029
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050030 /** @brief Notified on time mode changed */
31 void onModeChanged(Mode mode) override;
Lei YU415b9642017-02-09 11:37:26 +080032
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050033 /** @brief Notified on time owner changed */
34 void onOwnerChanged(Owner owner) override;
Lei YU415b9642017-02-09 11:37:26 +080035
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050036 protected:
37 /** @brief Persistent sdbusplus DBus connection */
38 sdbusplus::bus::bus& bus;
Lei YU2f9c0cc2017-01-20 14:02:03 +080039
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050040 /** @brief The current time mode */
41 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU2f9c0cc2017-01-20 14:02:03 +080042
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050043 /** @brief The current time owner */
44 Owner timeOwner = DEFAULT_TIME_OWNER;
Lei YU2f9c0cc2017-01-20 14:02:03 +080045
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050046 /** @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 YU2f9c0cc2017-01-20 14:02:03 +080056
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050057 /** @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