Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | |
| 5 | #include <string> |
| 6 | #include <variant> |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace util |
| 10 | { |
| 11 | |
| 12 | namespace dbus |
| 13 | { |
| 14 | |
| 15 | using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>, |
| 16 | std::vector<std::string>>; |
| 17 | using DBusProperty = std::string; |
| 18 | using DBusInterface = std::string; |
| 19 | using DBusService = std::string; |
| 20 | using DBusPath = std::string; |
| 21 | using DBusInterfaceList = std::vector<DBusInterface>; |
| 22 | using DBusSubTree = |
| 23 | std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>; |
| 24 | |
| 25 | /** |
| 26 | * Find the dbus object path and service that implements the given interface |
| 27 | * |
| 28 | * @param[in] i_interface Interface to search for |
| 29 | * @param[out] o_path Path of dbus object implementing the interface |
| 30 | * @param[out] o_service Service implementing the dbus object path |
| 31 | * @return non-zero on error |
| 32 | */ |
| 33 | int find(const std::string& i_interface, std::string& o_path, |
| 34 | std::string& o_service); |
| 35 | |
| 36 | /** |
| 37 | * Find the dbus service that implements the given dbus object and interface |
| 38 | * |
| 39 | * @param[in] i_interface Interface that maps to the service |
| 40 | * @param[in] i_path Path that maps to the service |
| 41 | * @param[out] o_service Service implementing the dbus object and interface |
| 42 | * @return non-zer on error |
| 43 | */ |
| 44 | int findService(const std::string& i_interface, const std::string& i_path, |
| 45 | std::string& o_service); |
| 46 | |
| 47 | /** |
| 48 | * Read a property from a dbus object interface |
| 49 | * |
| 50 | * @param[in] i_interface Interface implementing the property |
| 51 | * @param[in] i_path Path of the dbus object |
| 52 | * @param[in] i_service Service implementing the dbus object and interface |
| 53 | * @param[in] i_property Property to read |
| 54 | * @return non-zero on error |
| 55 | */ |
| 56 | int getProperty(const std::string& i_interface, const std::string& i_path, |
| 57 | const std::string& i_service, const std::string& i_property, |
| 58 | DBusValue& o_response); |
| 59 | |
| 60 | /** |
| 61 | * Get the IBM compatible names defined for this system |
| 62 | * |
| 63 | * @return A vector of strings containing the system names |
| 64 | */ |
| 65 | std::vector<std::string> systemNames(); |
| 66 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 67 | /** @brief Host transition states for host transition operations */ |
Ben Tyner | 9306716 | 2021-07-23 10:39:30 -0500 | [diff] [blame] | 68 | enum class HostState |
| 69 | { |
| 70 | Quiesce, |
| 71 | Diagnostic, |
| 72 | Crash |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * @brief Transition the host state |
| 77 | * |
| 78 | * We will transition the host state by starting the appropriate dbus target. |
| 79 | * |
| 80 | * @param i_hostState the state to transition the host to |
| 81 | */ |
| 82 | void transitionHost(const HostState i_hostState); |
| 83 | |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 84 | /** |
| 85 | * @brief Read autoreboot property |
| 86 | * |
| 87 | * Read the autoreboot property via dbus. This status will be used to |
| 88 | * determine whether to either mpipl or quiesce the host on TI condition. |
| 89 | */ |
| 90 | bool autoRebootEnabled(); |
| 91 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 92 | /** @brief Host running states for host running operations */ |
| 93 | enum class HostRunningState |
| 94 | { |
| 95 | Unknown, |
| 96 | NotStarted, |
| 97 | Started |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * Get the host running state |
| 102 | * |
| 103 | * Use host boot progress to determine if a host has been started. If host |
| 104 | * boot progress can not be determined then host state will be unknown. |
| 105 | * |
| 106 | * @return HostType == "Unknown", "Started or "NotStarted" |
| 107 | */ |
| 108 | HostRunningState hostRunningState(); |
| 109 | |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 110 | } // namespace dbus |
| 111 | |
| 112 | } // namespace util |