blob: 9c2a9e02e611236a7c6b51ccd77b12a0f452284f [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
George Liucb421092022-08-16 17:02:31 +08005#include "manager.hpp"
Lei YU415b9642017-02-09 11:37:26 +08006#include "property_change_listener.hpp"
7
Lei YU2f9c0cc2017-01-20 14:02:03 +08008#include <sdbusplus/bus.hpp>
9#include <xyz/openbmc_project/Time/EpochTime/server.hpp>
10
George Liuc6d33972020-06-22 10:35:29 +080011#include <chrono>
12
Lei YU2f9c0cc2017-01-20 14:02:03 +080013namespace phosphor
14{
15namespace time
16{
17
18/** @class EpochBase
19 * @brief Base class for OpenBMC EpochTime implementation.
20 * @details A base class that implements xyz.openbmc_project.Time.EpochTime
21 * DBus API for epoch time.
22 */
George Liuc6d33972020-06-22 10:35:29 +080023class EpochBase :
Patrick Williams38679262022-07-22 19:26:55 -050024 public sdbusplus::server::object_t<
George Liuc6d33972020-06-22 10:35:29 +080025 sdbusplus::xyz::openbmc_project::Time::server::EpochTime>,
26 public PropertyChangeListner
Lei YU2f9c0cc2017-01-20 14:02:03 +080027{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050028 public:
George Liucb421092022-08-16 17:02:31 +080029 EpochBase(sdbusplus::bus_t& bus, const char* objPath, Manager& manager);
Lei YU2f9c0cc2017-01-20 14:02:03 +080030
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050031 /** @brief Notified on time mode changed */
32 void onModeChanged(Mode mode) override;
Lei YU415b9642017-02-09 11:37:26 +080033
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050034 protected:
35 /** @brief Persistent sdbusplus DBus connection */
Patrick Williams38679262022-07-22 19:26:55 -050036 sdbusplus::bus_t& bus;
Lei YU2f9c0cc2017-01-20 14:02:03 +080037
George Liucb421092022-08-16 17:02:31 +080038 /** @brief The manager to handle OpenBMC time */
39 Manager& manager;
Lei YU2f9c0cc2017-01-20 14:02:03 +080040
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050041 /** @brief Set current time to system
42 *
43 * This function set the time to system by invoking systemd
44 * org.freedesktop.timedate1's SetTime method.
45 *
46 * @param[in] timeOfDayUsec - Microseconds since UTC
47 *
48 * @return true or false to indicate if it sets time successfully
49 */
50 bool setTime(const std::chrono::microseconds& timeOfDayUsec);
Lei YU2f9c0cc2017-01-20 14:02:03 +080051
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050052 /** @brief Get current time
53 *
54 * @return Microseconds since UTC
55 */
56 std::chrono::microseconds getTime() const;
Lei YU2f9c0cc2017-01-20 14:02:03 +080057};
58
59} // namespace time
60} // namespace phosphor