blob: 8ccea4af288a554bad6b57cd1bb68ec7dd2339f7 [file] [log] [blame]
Lei YU415b9642017-02-09 11:37:26 +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"
Lei YU710d49b2017-08-01 17:10:17 +08006#include "settings.hpp"
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05007#include "types.hpp"
Lei YU415b9642017-02-09 11:37:26 +08008
9#include <sdbusplus/bus.hpp>
10#include <sdbusplus/bus/match.hpp>
George Liuc6d33972020-06-22 10:35:29 +080011
Lei YU415b9642017-02-09 11:37:26 +080012#include <string>
13
14namespace phosphor
15{
16namespace time
17{
18
19/** @class Manager
20 * @brief The manager to handle OpenBMC time.
21 * @details It registers various time related settings and properties signals
22 * on DBus and handle the changes.
23 * For certain properties it also notifies the changed events to listeners.
24 */
25class Manager
26{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050027 public:
28 friend class TestManager;
Lei YU7f4fca52017-02-23 15:15:51 +080029
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050030 explicit Manager(sdbusplus::bus::bus& bus);
31 Manager(const Manager&) = delete;
32 Manager& operator=(const Manager&) = delete;
33 Manager(Manager&&) = delete;
34 Manager& operator=(Manager&&) = delete;
35 ~Manager() = default;
Lei YU415b9642017-02-09 11:37:26 +080036
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050037 private:
38 /** @brief Persistent sdbusplus DBus connection */
39 sdbusplus::bus::bus& bus;
Lei YU415b9642017-02-09 11:37:26 +080040
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050041 /** @brief The match of settings property change */
42 std::vector<sdbusplus::bus::match::match> settingsMatches;
Lei YU710d49b2017-08-01 17:10:17 +080043
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050044 /** @brief Settings objects of intereset */
45 settings::Objects settings;
Lei YU710d49b2017-08-01 17:10:17 +080046
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050047 /** @brief The current time mode */
48 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU415b9642017-02-09 11:37:26 +080049
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050050 /** @brief Get setting from settingsd service
51 *
52 * @param[in] path - The dbus object path
53 * @param[in] interface - The dbus interface
54 * @param[in] setting - The string of the setting
55 *
56 * @return The setting value in string
57 */
58 std::string getSetting(const char* path, const char* interface,
59 const char* setting) const;
Lei YU710d49b2017-08-01 17:10:17 +080060
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050061 /** @brief Set current time mode from the time mode string
62 *
63 * @param[in] mode - The string of time mode
64 *
65 * @return - true if the mode is updated
66 * false if it's the same as before
67 */
68 bool setCurrentTimeMode(const std::string& mode);
Lei YUa5003ce2017-02-24 15:35:25 +080069
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050070 /** @brief Called on time mode is changed
71 *
72 * Notify listeners that time mode is changed and update ntp setting
73 *
74 * @param[in] mode - The string of time mode
75 */
76 void onTimeModeChanged(const std::string& mode);
Lei YU415b9642017-02-09 11:37:26 +080077
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050078 /** @brief Callback to handle change in a setting
79 *
80 * @param[in] msg - sdbusplus dbusmessage
81 *
82 * @return 0 on success, < 0 on failure.
83 */
84 int onSettingsChanged(sdbusplus::message::message& msg);
Lei YU710d49b2017-08-01 17:10:17 +080085
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050086 /** @brief Notified on settings property changed
87 *
88 * @param[in] key - The name of property that is changed
89 * @param[in] value - The value of the property
90 */
91 void onPropertyChanged(const std::string& key, const std::string& value);
Lei YU415b9642017-02-09 11:37:26 +080092
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050093 /** @brief Update the NTP setting to systemd time service
94 *
95 * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL"
96 */
97 void updateNtpSetting(const std::string& value);
Lei YUa7417132017-02-23 15:24:05 +080098
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050099 /** @brief The static function called on settings property changed
100 *
101 * @param[in] msg - Data associated with subscribed signal
102 * @param[in] userData - Pointer to this object instance
103 * @param[out] retError - Not used but required with signal API
104 */
105 static int onPropertyChanged(sd_bus_message* msg, void* userData,
106 sd_bus_error* retError);
Lei YU415b9642017-02-09 11:37:26 +0800107
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500108 /** @brief The string of time mode property */
109 static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
Lei YU415b9642017-02-09 11:37:26 +0800110};
111
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500112} // namespace time
113} // namespace phosphor