blob: 79aca901ad7aabbbfaa9003a68f56b972c806003 [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"
Lei YU415b9642017-02-09 11:37:26 +08004#include "property_change_listener.hpp"
5
Lei YU2f9c0cc2017-01-20 14:02:03 +08006#include <sdbusplus/bus.hpp>
7#include <xyz/openbmc_project/Time/EpochTime/server.hpp>
8
9#include <chrono>
10
11namespace 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 */
21class EpochBase : public sdbusplus::server::object::object <
Lei YU415b9642017-02-09 11:37:26 +080022 sdbusplus::xyz::openbmc_project::Time::server::EpochTime >,
23 public PropertyChangeListner
Lei YU2f9c0cc2017-01-20 14:02:03 +080024{
25 public:
26 friend class TestEpochBase;
27
Lei YU2f9c0cc2017-01-20 14:02:03 +080028 EpochBase(sdbusplus::bus::bus& bus,
29 const char* objPath);
30
Lei YU415b9642017-02-09 11:37:26 +080031 /** @brief Notified on time mode changed */
32 void onModeChanged(Mode mode) override;
33
34 /** @brief Notified on time owner changed */
35 void onOwnerChanged(Owner owner) override;
36
Lei YU2f9c0cc2017-01-20 14:02:03 +080037 protected:
38 /** @brief Persistent sdbusplus DBus connection */
39 sdbusplus::bus::bus& bus;
40
41 /** @brief The current time mode */
Lei YU1cd42482018-07-24 10:40:59 +080042 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU2f9c0cc2017-01-20 14:02:03 +080043
44 /** @brief The current time owner */
Lei YU1cd42482018-07-24 10:40:59 +080045 Owner timeOwner = DEFAULT_TIME_OWNER;
Lei YU2f9c0cc2017-01-20 14:02:03 +080046
47 /** @brief Set current time to system
48 *
49 * This function set the time to system by invoking systemd
50 * org.freedesktop.timedate1's SetTime method.
51 *
52 * @param[in] timeOfDayUsec - Microseconds since UTC
Lei YUfa024882017-11-09 10:49:26 +080053 *
54 * @return true or false to indicate if it sets time successfully
Lei YU2f9c0cc2017-01-20 14:02:03 +080055 */
Lei YUfa024882017-11-09 10:49:26 +080056 bool setTime(const std::chrono::microseconds& timeOfDayUsec);
Lei YU2f9c0cc2017-01-20 14:02:03 +080057
58 /** @brief Get current time
59 *
60 * @return Microseconds since UTC
61 */
62 std::chrono::microseconds getTime() const;
Lei YU2f9c0cc2017-01-20 14:02:03 +080063};
64
65} // namespace time
66} // namespace phosphor