Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 4 | #include <util/ffdc_file.hpp> |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 5 | |
| 6 | #include <string> |
| 7 | #include <variant> |
| 8 | #include <vector> |
| 9 | |
| 10 | namespace util |
| 11 | { |
| 12 | |
| 13 | namespace dbus |
| 14 | { |
| 15 | |
| 16 | using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>, |
| 17 | std::vector<std::string>>; |
| 18 | using DBusProperty = std::string; |
| 19 | using DBusInterface = std::string; |
| 20 | using DBusService = std::string; |
| 21 | using DBusPath = std::string; |
| 22 | using DBusInterfaceList = std::vector<DBusInterface>; |
| 23 | using DBusSubTree = |
| 24 | std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>; |
| 25 | |
| 26 | /** |
| 27 | * Find the dbus object path and service that implements the given interface |
| 28 | * |
| 29 | * @param[in] i_interface Interface to search for |
| 30 | * @param[out] o_path Path of dbus object implementing the interface |
| 31 | * @param[out] o_service Service implementing the dbus object path |
| 32 | * @return non-zero on error |
| 33 | */ |
| 34 | int find(const std::string& i_interface, std::string& o_path, |
| 35 | std::string& o_service); |
| 36 | |
| 37 | /** |
| 38 | * Find the dbus service that implements the given dbus object and interface |
| 39 | * |
| 40 | * @param[in] i_interface Interface that maps to the service |
| 41 | * @param[in] i_path Path that maps to the service |
| 42 | * @param[out] o_service Service implementing the dbus object and interface |
| 43 | * @return non-zer on error |
| 44 | */ |
| 45 | int findService(const std::string& i_interface, const std::string& i_path, |
| 46 | std::string& o_service); |
| 47 | |
| 48 | /** |
| 49 | * Read a property from a dbus object interface |
| 50 | * |
| 51 | * @param[in] i_interface Interface implementing the property |
| 52 | * @param[in] i_path Path of the dbus object |
| 53 | * @param[in] i_service Service implementing the dbus object and interface |
| 54 | * @param[in] i_property Property to read |
| 55 | * @return non-zero on error |
| 56 | */ |
| 57 | int getProperty(const std::string& i_interface, const std::string& i_path, |
| 58 | const std::string& i_service, const std::string& i_property, |
| 59 | DBusValue& o_response); |
| 60 | |
| 61 | /** |
| 62 | * Get the IBM compatible names defined for this system |
| 63 | * |
| 64 | * @return A vector of strings containing the system names |
| 65 | */ |
| 66 | std::vector<std::string> systemNames(); |
| 67 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 68 | /** @brief Host transition states for host transition operations */ |
Ben Tyner | 9306716 | 2021-07-23 10:39:30 -0500 | [diff] [blame] | 69 | enum class HostState |
| 70 | { |
| 71 | Quiesce, |
| 72 | Diagnostic, |
| 73 | Crash |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * @brief Transition the host state |
| 78 | * |
| 79 | * We will transition the host state by starting the appropriate dbus target. |
| 80 | * |
| 81 | * @param i_hostState the state to transition the host to |
| 82 | */ |
| 83 | void transitionHost(const HostState i_hostState); |
| 84 | |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 85 | /** |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 86 | * @brief Read autoRebootEnabled property |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 87 | * |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 88 | * @return false if autoRebootEnabled policy false, else true |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 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 | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 110 | /** |
| 111 | * @brief Read dumpPolicyEnabled property |
| 112 | * |
| 113 | * @return false if dumpPolicyEnabled property is false, else true |
| 114 | */ |
| 115 | bool dumpPolicyEnabled(); |
| 116 | |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 117 | /** |
| 118 | * Create a PEL |
| 119 | * |
| 120 | * The additional data provided in the map will be placed in a user data |
| 121 | * section of the PEL and may additionally contain key words to trigger |
| 122 | * certain behaviors by the backend logging code. Each set of data described |
| 123 | * in the vector of ffdc data will be placed in additional user data |
| 124 | * sections. Note that the PID of the caller will be added to the additional |
| 125 | * data map with key "_PID". |
| 126 | * |
| 127 | * @param i_message - the event type |
| 128 | * @param i_severity - the severity level |
| 129 | * @param io_additional - map of additional data |
| 130 | * @param i_ffdc - vector of ffdc data |
| 131 | * @return Platform log id or 0 if error |
| 132 | */ |
| 133 | uint32_t createPel(const std::string& i_message, const std::string& i_severity, |
| 134 | std::map<std::string, std::string>& io_additional, |
| 135 | const std::vector<FFDCTuple>& i_ffdc); |
| 136 | |
Caleb Palmer | 626270a | 2022-02-21 11:05:08 -0600 | [diff] [blame] | 137 | /** @brief Machine ID definitions */ |
| 138 | enum class MachineType |
| 139 | { |
| 140 | Rainier_2S4U, |
| 141 | Rainier_2S2U, |
| 142 | Rainier_1S4U, |
| 143 | Rainier_1S2U, |
| 144 | Everest, |
| 145 | }; |
| 146 | |
| 147 | /** |
| 148 | * @brief Read the System IM keyword to get the machine type |
| 149 | * |
| 150 | * @return An enum representing the machine type |
| 151 | */ |
| 152 | MachineType getMachineType(); |
| 153 | |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 154 | } // namespace dbus |
| 155 | |
| 156 | } // namespace util |