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> |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 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 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 26 | public: |
| 27 | friend class TestManager; |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame] | 28 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 35 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 36 | private: |
| 37 | /** @brief Persistent sdbusplus DBus connection */ |
| 38 | sdbusplus::bus::bus& bus; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 39 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 40 | /** @brief The match of settings property change */ |
| 41 | std::vector<sdbusplus::bus::match::match> settingsMatches; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 42 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 43 | /** @brief Settings objects of intereset */ |
| 44 | settings::Objects settings; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 45 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 46 | /** @brief The current time mode */ |
| 47 | Mode timeMode = DEFAULT_TIME_MODE; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 48 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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; |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 59 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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); |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 68 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 76 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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); |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 84 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 91 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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); |
Lei YU | a741713 | 2017-02-23 15:24:05 +0800 | [diff] [blame] | 97 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 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); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 106 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 107 | /** @brief The string of time mode property */ |
| 108 | static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod"; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 109 | }; |
| 110 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 111 | } // namespace time |
| 112 | } // namespace phosphor |