blob: 02dd253bf0eed284d5b134b30e2a69fd6ea52674 [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
Patrick Williams38679262022-07-22 19:26:55 -050030 explicit Manager(sdbusplus::bus_t& bus);
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050031 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
George Liucb421092022-08-16 17:02:31 +080037 void setTimeMode(Mode mode)
38 {
39 this->timeMode = mode;
40 }
41
42 Mode getTimeMode()
43 {
44 return this->timeMode;
45 }
46
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050047 private:
48 /** @brief Persistent sdbusplus DBus connection */
Patrick Williams38679262022-07-22 19:26:55 -050049 sdbusplus::bus_t& bus;
Lei YU415b9642017-02-09 11:37:26 +080050
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050051 /** @brief The match of settings property change */
Patrick Williams38679262022-07-22 19:26:55 -050052 std::vector<sdbusplus::bus::match_t> settingsMatches;
Lei YU710d49b2017-08-01 17:10:17 +080053
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050054 /** @brief Settings objects of intereset */
55 settings::Objects settings;
Lei YU710d49b2017-08-01 17:10:17 +080056
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050057 /** @brief The current time mode */
58 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU415b9642017-02-09 11:37:26 +080059
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050060 /** @brief Get setting from settingsd service
61 *
62 * @param[in] path - The dbus object path
63 * @param[in] interface - The dbus interface
64 * @param[in] setting - The string of the setting
65 *
66 * @return The setting value in string
67 */
68 std::string getSetting(const char* path, const char* interface,
69 const char* setting) const;
Lei YU710d49b2017-08-01 17:10:17 +080070
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050071 /** @brief Set current time mode from the time mode string
72 *
73 * @param[in] mode - The string of time mode
74 *
75 * @return - true if the mode is updated
76 * false if it's the same as before
77 */
78 bool setCurrentTimeMode(const std::string& mode);
Lei YUa5003ce2017-02-24 15:35:25 +080079
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050080 /** @brief Called on time mode is changed
81 *
82 * Notify listeners that time mode is changed and update ntp setting
83 *
84 * @param[in] mode - The string of time mode
85 */
86 void onTimeModeChanged(const std::string& mode);
Lei YU415b9642017-02-09 11:37:26 +080087
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050088 /** @brief Callback to handle change in a setting
89 *
90 * @param[in] msg - sdbusplus dbusmessage
91 *
92 * @return 0 on success, < 0 on failure.
93 */
Patrick Williams38679262022-07-22 19:26:55 -050094 int onSettingsChanged(sdbusplus::message_t& msg);
Lei YU710d49b2017-08-01 17:10:17 +080095
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050096 /** @brief Notified on settings property changed
97 *
98 * @param[in] key - The name of property that is changed
99 * @param[in] value - The value of the property
100 */
101 void onPropertyChanged(const std::string& key, const std::string& value);
Lei YU415b9642017-02-09 11:37:26 +0800102
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500103 /** @brief Update the NTP setting to systemd time service
104 *
105 * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL"
106 */
107 void updateNtpSetting(const std::string& value);
Lei YUa7417132017-02-23 15:24:05 +0800108
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500109 /** @brief The static function called on settings property changed
110 *
111 * @param[in] msg - Data associated with subscribed signal
112 * @param[in] userData - Pointer to this object instance
113 * @param[out] retError - Not used but required with signal API
114 */
115 static int onPropertyChanged(sd_bus_message* msg, void* userData,
116 sd_bus_error* retError);
Lei YU415b9642017-02-09 11:37:26 +0800117
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500118 /** @brief The string of time mode property */
119 static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
Lei YU415b9642017-02-09 11:37:26 +0800120};
121
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500122} // namespace time
123} // namespace phosphor