blob: e80aa097756649dfdcfd0dc1599578987f5a2711 [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
Lei YU2f9c0cc2017-01-20 14:02:03 +08007#include <sdbusplus/bus.hpp>
8#include <xyz/openbmc_project/Time/EpochTime/server.hpp>
9
George Liuc6d33972020-06-22 10:35:29 +080010#include <chrono>
11
Lei YU2f9c0cc2017-01-20 14:02:03 +080012namespace phosphor
13{
14namespace time
15{
16
17/** @class EpochBase
18 * @brief Base class for OpenBMC EpochTime implementation.
19 * @details A base class that implements xyz.openbmc_project.Time.EpochTime
20 * DBus API for epoch time.
21 */
George Liuc6d33972020-06-22 10:35:29 +080022class EpochBase :
Patrick Williams38679262022-07-22 19:26:55 -050023 public sdbusplus::server::object_t<
George Liuc6d33972020-06-22 10:35:29 +080024 sdbusplus::xyz::openbmc_project::Time::server::EpochTime>,
25 public PropertyChangeListner
Lei YU2f9c0cc2017-01-20 14:02:03 +080026{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050027 public:
Patrick Williams38679262022-07-22 19:26:55 -050028 EpochBase(sdbusplus::bus_t& 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 */
Patrick Williams38679262022-07-22 19:26:55 -050035 sdbusplus::bus_t& 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