blob: 40025c49f423d8c13306bb1e5ce924800d0c18c8 [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 protected:
34 /** @brief Persistent sdbusplus DBus connection */
35 sdbusplus::bus::bus& bus;
Lei YU2f9c0cc2017-01-20 14:02:03 +080036
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050037 /** @brief The current time mode */
38 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU2f9c0cc2017-01-20 14:02:03 +080039
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050040 /** @brief Set current time to system
41 *
42 * This function set the time to system by invoking systemd
43 * org.freedesktop.timedate1's SetTime method.
44 *
45 * @param[in] timeOfDayUsec - Microseconds since UTC
46 *
47 * @return true or false to indicate if it sets time successfully
48 */
49 bool setTime(const std::chrono::microseconds& timeOfDayUsec);
Lei YU2f9c0cc2017-01-20 14:02:03 +080050
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050051 /** @brief Get current time
52 *
53 * @return Microseconds since UTC
54 */
55 std::chrono::microseconds getTime() const;
Lei YU2f9c0cc2017-01-20 14:02:03 +080056};
57
58} // namespace time
59} // namespace phosphor