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 12 #include <string> 13 14 namespace phosphor 15 { 16 namespace 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 */ 25 class Manager 26 { 27 public: 28 friend class TestManager; 29 30 explicit Manager(sdbusplus::bus_t& bus); 31 Manager(const Manager&) = delete; 32 Manager& operator=(const Manager&) = delete; 33 Manager(Manager&&) = delete; 34 Manager& operator=(Manager&&) = delete; 35 ~Manager() = default; 36 setTimeMode(Mode mode)37 void setTimeMode(Mode mode) 38 { 39 this->timeMode = mode; 40 } 41 getTimeMode()42 Mode getTimeMode() 43 { 44 return this->timeMode; 45 } 46 47 private: 48 /** @brief Persistent sdbusplus DBus connection */ 49 sdbusplus::bus_t& bus; 50 51 /** @brief The match of systemd timedate property change */ 52 std::vector<sdbusplus::bus::match_t> timedateMatches; 53 54 /** @brief The match of settings property change */ 55 std::vector<sdbusplus::bus::match_t> settingsMatches; 56 57 /** @brief Settings objects of intereset */ 58 settings::Objects settings; 59 60 /** @brief The current time mode */ 61 Mode timeMode = DEFAULT_TIME_MODE; 62 63 /** @brief Get setting from settingsd service 64 * 65 * @param[in] path - The dbus object path 66 * @param[in] interface - The dbus interface 67 * @param[in] setting - The string of the setting 68 * 69 * @return The setting value in string 70 */ 71 std::string getSetting(const char* path, const char* interface, 72 const char* setting) const; 73 74 /** @brief Set current time mode from the time mode string 75 * 76 * @param[in] mode - The string of time mode 77 * 78 * @return - true if the mode is updated 79 * false if it's the same as before 80 */ 81 bool setCurrentTimeMode(const std::string& mode); 82 83 /** @brief Called on time mode is changed 84 * 85 * Notify listeners that time mode is changed and update ntp setting 86 * 87 * @param[in] mode - The string of time mode 88 */ 89 void onTimeModeChanged(const std::string& mode); 90 91 /** @brief Callback to handle change in NTP 92 * 93 * @param[in] msg - sdbusplus dbusmessage 94 * 95 * @return 0 on success, < 0 on failure. 96 */ 97 int onTimedateChanged(sdbusplus::message_t& msg); 98 99 /** @brief Callback to handle change in a setting 100 * 101 * @param[in] msg - sdbusplus dbusmessage 102 * 103 * @return 0 on success, < 0 on failure. 104 */ 105 int onSettingsChanged(sdbusplus::message_t& msg); 106 107 /** @brief Notified on settings property changed 108 * 109 * @param[in] key - The name of property that is changed 110 * @param[in] value - The value of the property 111 * @param[in] forceSet - true: Force sync NTP Settings to systemd time 112 * service, only be used during initialization 113 * false: This is default value 114 */ 115 void onPropertyChanged(const std::string& key, const std::string& value, 116 bool forceSet = false); 117 118 /** @brief Update the NTP setting to systemd time service 119 * 120 * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL" 121 */ 122 void updateNtpSetting(const std::string& value); 123 124 /** @brief The static function called on settings property changed 125 * 126 * @param[in] msg - Data associated with subscribed signal 127 * @param[in] userData - Pointer to this object instance 128 * @param[out] retError - Not used but required with signal API 129 */ 130 static int onPropertyChanged(sd_bus_message* msg, void* userData, 131 sd_bus_error* retError); 132 133 /** @brief The string of time mode property */ 134 static constexpr auto propertyTimeMode = "TimeSyncMethod"; 135 }; 136 137 } // namespace time 138 } // namespace phosphor 139