blob: c93c58f34602dbbe10e57a35cd3e4eca7cd8eeab [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>
Lei YU415b9642017-02-09 11:37:26 +080011#include <string>
12
13namespace phosphor
14{
15namespace time
16{
17
18/** @class Manager
19 * @brief The manager to handle OpenBMC time.
20 * @details It registers various time related settings and properties signals
21 * on DBus and handle the changes.
22 * For certain properties it also notifies the changed events to listeners.
23 */
24class Manager
25{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050026 public:
27 friend class TestManager;
Lei YU7f4fca52017-02-23 15:15:51 +080028
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050029 explicit Manager(sdbusplus::bus::bus& bus);
30 Manager(const Manager&) = delete;
31 Manager& operator=(const Manager&) = delete;
32 Manager(Manager&&) = delete;
33 Manager& operator=(Manager&&) = delete;
34 ~Manager() = default;
Lei YU415b9642017-02-09 11:37:26 +080035
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050036 private:
37 /** @brief Persistent sdbusplus DBus connection */
38 sdbusplus::bus::bus& bus;
Lei YU415b9642017-02-09 11:37:26 +080039
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050040 /** @brief The match of settings property change */
41 std::vector<sdbusplus::bus::match::match> settingsMatches;
Lei YU710d49b2017-08-01 17:10:17 +080042
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050043 /** @brief Settings objects of intereset */
44 settings::Objects settings;
Lei YU710d49b2017-08-01 17:10:17 +080045
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050046 /** @brief The current time mode */
47 Mode timeMode = DEFAULT_TIME_MODE;
Lei YU415b9642017-02-09 11:37:26 +080048
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050049 /** @brief Get setting from settingsd service
50 *
51 * @param[in] path - The dbus object path
52 * @param[in] interface - The dbus interface
53 * @param[in] setting - The string of the setting
54 *
55 * @return The setting value in string
56 */
57 std::string getSetting(const char* path, const char* interface,
58 const char* setting) const;
Lei YU710d49b2017-08-01 17:10:17 +080059
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050060 /** @brief Set current time mode from the time mode string
61 *
62 * @param[in] mode - The string of time mode
63 *
64 * @return - true if the mode is updated
65 * false if it's the same as before
66 */
67 bool setCurrentTimeMode(const std::string& mode);
Lei YUa5003ce2017-02-24 15:35:25 +080068
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050069 /** @brief Called on time mode is changed
70 *
71 * Notify listeners that time mode is changed and update ntp setting
72 *
73 * @param[in] mode - The string of time mode
74 */
75 void onTimeModeChanged(const std::string& mode);
Lei YU415b9642017-02-09 11:37:26 +080076
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050077 /** @brief Callback to handle change in a setting
78 *
79 * @param[in] msg - sdbusplus dbusmessage
80 *
81 * @return 0 on success, < 0 on failure.
82 */
83 int onSettingsChanged(sdbusplus::message::message& msg);
Lei YU710d49b2017-08-01 17:10:17 +080084
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050085 /** @brief Notified on settings property changed
86 *
87 * @param[in] key - The name of property that is changed
88 * @param[in] value - The value of the property
89 */
90 void onPropertyChanged(const std::string& key, const std::string& value);
Lei YU415b9642017-02-09 11:37:26 +080091
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050092 /** @brief Update the NTP setting to systemd time service
93 *
94 * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL"
95 */
96 void updateNtpSetting(const std::string& value);
Lei YUa7417132017-02-23 15:24:05 +080097
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050098 /** @brief The static function called on settings property changed
99 *
100 * @param[in] msg - Data associated with subscribed signal
101 * @param[in] userData - Pointer to this object instance
102 * @param[out] retError - Not used but required with signal API
103 */
104 static int onPropertyChanged(sd_bus_message* msg, void* userData,
105 sd_bus_error* retError);
Lei YU415b9642017-02-09 11:37:26 +0800106
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500107 /** @brief The string of time mode property */
108 static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
Lei YU415b9642017-02-09 11:37:26 +0800109};
110
Gunnar Millsab4cc6a2018-09-14 14:42:39 -0500111} // namespace time
112} // namespace phosphor