1 #pragma once 2 3 #include "config.h" 4 5 #include "property_change_listener.hpp" 6 #include "settings.hpp" 7 #include "types.hpp" 8 9 #include <sdbusplus/bus.hpp> 10 #include <sdbusplus/bus/match.hpp> 11 #include <string> 12 13 namespace phosphor 14 { 15 namespace 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 */ 24 class Manager 25 { 26 public: 27 friend class TestManager; 28 29 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; 35 36 private: 37 /** @brief Persistent sdbusplus DBus connection */ 38 sdbusplus::bus::bus& bus; 39 40 /** @brief The match of settings property change */ 41 std::vector<sdbusplus::bus::match::match> settingsMatches; 42 43 /** @brief Settings objects of intereset */ 44 settings::Objects settings; 45 46 /** @brief The current time mode */ 47 Mode timeMode = DEFAULT_TIME_MODE; 48 49 /** @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; 59 60 /** @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); 68 69 /** @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); 76 77 /** @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); 84 85 /** @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); 91 92 /** @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); 97 98 /** @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); 106 107 /** @brief The string of time mode property */ 108 static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod"; 109 }; 110 111 } // namespace time 112 } // namespace phosphor 113