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 | |
George Liu | cb42109 | 2022-08-16 17:02:31 +0800 | [diff] [blame] | 37 | void setTimeMode(Mode mode) |
| 38 | { |
| 39 | this->timeMode = mode; |
| 40 | } |
| 41 | |
| 42 | Mode getTimeMode() |
| 43 | { |
| 44 | return this->timeMode; |
| 45 | } |
| 46 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 47 | private: |
| 48 | /** @brief Persistent sdbusplus DBus connection */ |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 49 | sdbusplus::bus_t& bus; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 50 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 51 | /** @brief The match of settings property change */ |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 52 | std::vector<sdbusplus::bus::match_t> settingsMatches; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 53 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 54 | /** @brief Settings objects of intereset */ |
| 55 | settings::Objects settings; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 56 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 57 | /** @brief The current time mode */ |
| 58 | Mode timeMode = DEFAULT_TIME_MODE; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 59 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 60 | /** @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 YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 70 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 71 | /** @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 YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 79 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 80 | /** @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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 87 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 88 | /** @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 Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 94 | int onSettingsChanged(sdbusplus::message_t& msg); |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 95 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 96 | /** @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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 102 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 103 | /** @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 YU | a741713 | 2017-02-23 15:24:05 +0800 | [diff] [blame] | 108 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 109 | /** @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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 117 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 118 | /** @brief The string of time mode property */ |
| 119 | static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod"; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 120 | }; |
| 121 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 122 | } // namespace time |
| 123 | } // namespace phosphor |