xref: /openbmc/phosphor-state-manager/settings.hpp (revision 0e38d19e31b4f10d8c8fc963a0ae1837bcc7eec8)
1 #pragma once
2 
3 #include <sdbusplus/bus.hpp>
4 #include <xyz/openbmc_project/Control/Boot/RebootPolicy/client.hpp>
5 #include <xyz/openbmc_project/Control/Power/RestorePolicy/client.hpp>
6 
7 #include <string>
8 
9 namespace settings
10 {
11 
12 using Path = std::string;
13 using Service = std::string;
14 using Interface = std::string;
15 
16 constexpr auto defaultRoot = "/";
17 constexpr auto autoRebootIntf = sdbusplus::client::xyz::openbmc_project::
18     control::boot::RebootPolicy<>::interface;
19 using PowerRestorePolicy =
20     sdbusplus::common::xyz::openbmc_project::control::power::RestorePolicy;
21 constexpr auto powerRestoreIntf = PowerRestorePolicy::interface;
22 
23 /** @class Objects
24  *  @brief Fetch paths of settings d-bus objects of interest, upon construction
25  */
26 struct Objects
27 {
28   public:
29     /** @brief Constructor - fetch settings objects
30      *
31      * @param[in] bus  - The Dbus bus object
32      * @param[in] root - The root object path
33      */
34     explicit Objects(sdbusplus::bus_t& bus, const Path& root = defaultRoot);
35     Objects(const Objects&) = delete;
36     Objects& operator=(const Objects&) = delete;
37     Objects(Objects&&) = delete;
38     Objects& operator=(Objects&&) = delete;
39     ~Objects() = default;
40 
41     /** @brief Fetch d-bus service, given a path and an interface. The
42      *         service can't be cached because mapper returns unique
43      *         service names.
44      *
45      * @param[in] path - The Dbus object
46      * @param[in] interface - The Dbus interface
47      *
48      * @return std::string - the dbus service name
49      */
50     Service service(const Path& path, const Interface& interface) const;
51 
52     /** @brief host auto_reboot user settings object */
53     Path autoReboot;
54 
55     /** @brief host auto_reboot one-time settings object */
56     Path autoRebootOneTime;
57 
58     /** @brief host power_restore_policy settings object */
59     Path powerRestorePolicy;
60 
61     /** @brief host power_restore_policy one-time settings object */
62     Path powerRestorePolicyOneTime;
63 
64     /** @brief The Dbus bus object */
65     sdbusplus::bus_t& bus;
66 };
67 
68 /** @class HostObjects
69  *  @brief Fetch paths of settings d-bus objects of Host
70  *  @note  IMPORTANT: This class only supports settings under the
71  *         /xyz/openbmc_project/control/hostX object paths
72  */
73 struct HostObjects : public Objects
74 {
75   public:
76     /** @brief Constructor - fetch settings objects of Host
77      *
78      * @param[in] bus - The Dbus bus object
79      * @param[in] id  - The Host id
80      */
81     HostObjects(sdbusplus::bus_t& bus, size_t id);
82 };
83 
84 } // namespace settings
85