Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Lei YU | 1cd4248 | 2018-07-24 10:40:59 +0800 | [diff] [blame] | 3 | #include "config.h" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 4 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 5 | #include "property_change_listener.hpp" |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 6 | #include "settings.hpp" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 7 | #include "types.hpp" |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 8 | |
| 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/bus/match.hpp> |
George Liu | c6d3397 | 2020-06-22 10:35:29 +0800 | [diff] [blame] | 11 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 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 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 27 | public: |
| 28 | friend class TestManager; |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame] | 29 | |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 30 | explicit Manager(sdbusplus::bus_t& bus); |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 31 | Manager(const Manager&) = delete; |
| 32 | Manager& operator=(const Manager&) = delete; |
| 33 | Manager(Manager&&) = delete; |
| 34 | Manager& operator=(Manager&&) = delete; |
| 35 | ~Manager() = default; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 36 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 37 | private: |
| 38 | /** @brief Persistent sdbusplus DBus connection */ |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 39 | sdbusplus::bus_t& bus; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 40 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 41 | /** @brief The match of settings property change */ |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 42 | std::vector<sdbusplus::bus::match_t> settingsMatches; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 43 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 44 | /** @brief Settings objects of intereset */ |
| 45 | settings::Objects settings; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 46 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 47 | /** @brief The current time mode */ |
| 48 | Mode timeMode = DEFAULT_TIME_MODE; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 49 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 50 | /** @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 YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 60 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 61 | /** @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 YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 69 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 70 | /** @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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 77 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 78 | /** @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 | */ |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 84 | int onSettingsChanged(sdbusplus::message_t& msg); |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 85 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 86 | /** @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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 92 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 93 | /** @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 YU | a741713 | 2017-02-23 15:24:05 +0800 | [diff] [blame] | 98 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 99 | /** @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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 107 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 108 | /** @brief The string of time mode property */ |
| 109 | static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod"; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 110 | }; |
| 111 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 112 | } // namespace time |
| 113 | } // namespace phosphor |