blob: 89a7b8588f972a92d6dece3d7cda38eaaa7c3f7c [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 :
23 public sdbusplus::server::object::object<
24 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:
28 friend class TestEpochBase;
Lei YU2f9c0cc2017-01-20 14:02:03 +080029
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050030 EpochBase(sdbusplus::bus::bus& bus, const char* objPath);
Lei YU2f9c0cc2017-01-20 14:02:03 +080031
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050032 /** @brief Notified on time mode changed */
33 void onModeChanged(Mode mode) override;
Lei YU415b9642017-02-09 11:37:26 +080034
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050035 protected:
36 /** @brief Persistent sdbusplus DBus connection */
37 sdbusplus::bus::bus& bus;
Lei YU2f9c0cc2017-01-20 14:02:03 +080038
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050039 /** @brief The current time mode */
40 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU2f9c0cc2017-01-20 14:02:03 +080041
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050042 /** @brief Set current time to system
43 *
44 * This function set the time to system by invoking systemd
45 * org.freedesktop.timedate1's SetTime method.
46 *
47 * @param[in] timeOfDayUsec - Microseconds since UTC
48 *
49 * @return true or false to indicate if it sets time successfully
50 */
51 bool setTime(const std::chrono::microseconds& timeOfDayUsec);
Lei YU2f9c0cc2017-01-20 14:02:03 +080052
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050053 /** @brief Get current time
54 *
55 * @return Microseconds since UTC
56 */
57 std::chrono::microseconds getTime() const;
Lei YU2f9c0cc2017-01-20 14:02:03 +080058};
59
60} // namespace time
61} // namespace phosphor