xref: /openbmc/phosphor-time-manager/manager.hpp (revision 3867926613f478afe5fa7e700ebe0cb293e88efd)
1415b964fSLei YU #pragma once
2415b964fSLei YU 
31cd4248dSLei YU #include "config.h"
4ab4cc6a5SGunnar Mills 
5415b964fSLei YU #include "property_change_listener.hpp"
6710d49beSLei YU #include "settings.hpp"
7ab4cc6a5SGunnar Mills #include "types.hpp"
8415b964fSLei YU 
9415b964fSLei YU #include <sdbusplus/bus.hpp>
10415b964fSLei YU #include <sdbusplus/bus/match.hpp>
11c6d33972SGeorge Liu 
12415b964fSLei YU #include <string>
13415b964fSLei YU 
14415b964fSLei YU namespace phosphor
15415b964fSLei YU {
16415b964fSLei YU namespace time
17415b964fSLei YU {
18415b964fSLei YU 
19415b964fSLei YU /** @class Manager
20415b964fSLei YU  *  @brief The manager to handle OpenBMC time.
21415b964fSLei YU  *  @details It registers various time related settings and properties signals
22415b964fSLei YU  *  on DBus and handle the changes.
23415b964fSLei YU  *  For certain properties it also notifies the changed events to listeners.
24415b964fSLei YU  */
25415b964fSLei YU class Manager
26415b964fSLei YU {
27415b964fSLei YU   public:
28415b964fSLei YU     friend class TestManager;
297f4fca55SLei YU 
30*38679266SPatrick Williams     explicit Manager(sdbusplus::bus_t& bus);
31c6fe8693SLei YU     Manager(const Manager&) = delete;
32c6fe8693SLei YU     Manager& operator=(const Manager&) = delete;
33c6fe8693SLei YU     Manager(Manager&&) = delete;
34c6fe8693SLei YU     Manager& operator=(Manager&&) = delete;
35710d49beSLei YU     ~Manager() = default;
36415b964fSLei YU 
37415b964fSLei YU   private:
38415b964fSLei YU     /** @brief Persistent sdbusplus DBus connection */
39*38679266SPatrick Williams     sdbusplus::bus_t& bus;
40415b964fSLei YU 
41415b964fSLei YU     /** @brief The match of settings property change */
42*38679266SPatrick Williams     std::vector<sdbusplus::bus::match_t> settingsMatches;
43710d49beSLei YU 
44710d49beSLei YU     /** @brief Settings objects of intereset */
45710d49beSLei YU     settings::Objects settings;
46710d49beSLei YU 
47415b964fSLei YU     /** @brief The current time mode */
481cd4248dSLei YU     Mode timeMode = DEFAULT_TIME_MODE;
49415b964fSLei YU 
50710d49beSLei YU     /** @brief Get setting from settingsd service
51710d49beSLei YU      *
52710d49beSLei YU      * @param[in] path - The dbus object path
53710d49beSLei YU      * @param[in] interface - The dbus interface
54710d49beSLei YU      * @param[in] setting - The string of the setting
55710d49beSLei YU      *
56710d49beSLei YU      * @return The setting value in string
57710d49beSLei YU      */
58ab4cc6a5SGunnar Mills     std::string getSetting(const char* path, const char* interface,
59710d49beSLei YU                            const char* setting) const;
60710d49beSLei YU 
61a5003cebSLei YU     /** @brief Set current time mode from the time mode string
62a5003cebSLei YU      *
63a5003cebSLei YU      * @param[in] mode - The string of time mode
64a5003cebSLei YU      *
65a5003cebSLei YU      * @return - true if the mode is updated
66a5003cebSLei YU      *           false if it's the same as before
67a5003cebSLei YU      */
68a5003cebSLei YU     bool setCurrentTimeMode(const std::string& mode);
69a5003cebSLei YU 
70a5003cebSLei YU     /** @brief Called on time mode is changed
71a5003cebSLei YU      *
72a5003cebSLei YU      * Notify listeners that time mode is changed and update ntp setting
73415b964fSLei YU      *
74415b964fSLei YU      * @param[in] mode - The string of time mode
75415b964fSLei YU      */
76a5003cebSLei YU     void onTimeModeChanged(const std::string& mode);
77415b964fSLei YU 
78710d49beSLei YU     /** @brief Callback to handle change in a setting
79710d49beSLei YU      *
80710d49beSLei YU      *  @param[in] msg - sdbusplus dbusmessage
81710d49beSLei YU      *
82710d49beSLei YU      *  @return 0 on success, < 0 on failure.
83710d49beSLei YU      */
84*38679266SPatrick Williams     int onSettingsChanged(sdbusplus::message_t& msg);
85710d49beSLei YU 
86415b964fSLei YU     /** @brief Notified on settings property changed
87415b964fSLei YU      *
88415b964fSLei YU      * @param[in] key - The name of property that is changed
89415b964fSLei YU      * @param[in] value - The value of the property
90415b964fSLei YU      */
91ab4cc6a5SGunnar Mills     void onPropertyChanged(const std::string& key, const std::string& value);
92415b964fSLei YU 
93a741713cSLei YU     /** @brief Update the NTP setting to systemd time service
94a741713cSLei YU      *
95a741713cSLei YU      * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL"
96a741713cSLei YU      */
97a741713cSLei YU     void updateNtpSetting(const std::string& value);
98a741713cSLei YU 
99415b964fSLei YU     /** @brief The static function called on settings property changed
100415b964fSLei YU      *
101415b964fSLei YU      * @param[in] msg - Data associated with subscribed signal
102415b964fSLei YU      * @param[in] userData - Pointer to this object instance
103415b964fSLei YU      * @param[out] retError  - Not used but required with signal API
104415b964fSLei YU      */
105ab4cc6a5SGunnar Mills     static int onPropertyChanged(sd_bus_message* msg, void* userData,
106415b964fSLei YU                                  sd_bus_error* retError);
107415b964fSLei YU 
1087f4fca55SLei YU     /** @brief The string of time mode property */
109710d49beSLei YU     static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
110415b964fSLei YU };
111415b964fSLei YU 
112ab4cc6a5SGunnar Mills } // namespace time
113ab4cc6a5SGunnar Mills } // namespace phosphor
114