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 | { |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 12 | namespace dbus |
| 13 | { |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 14 | using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>, |
Ben Tyner | 2b26b2b | 2022-12-15 15:42:02 -0600 | [diff] [blame] | 15 | std::vector<std::string>, int32_t>; |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 16 | using DBusProperty = std::string; |
| 17 | using DBusInterface = std::string; |
| 18 | using DBusService = std::string; |
| 19 | using DBusPath = std::string; |
| 20 | using DBusInterfaceList = std::vector<DBusInterface>; |
| 21 | using DBusSubTree = |
| 22 | std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>; |
| 23 | |
| 24 | /** |
| 25 | * Find the dbus object path and service that implements the given interface |
| 26 | * |
| 27 | * @param[in] i_interface Interface to search for |
| 28 | * @param[out] o_path Path of dbus object implementing the interface |
| 29 | * @param[out] o_service Service implementing the dbus object path |
| 30 | * @return non-zero on error |
| 31 | */ |
| 32 | int find(const std::string& i_interface, std::string& o_path, |
| 33 | std::string& o_service); |
| 34 | |
| 35 | /** |
| 36 | * Find the dbus service that implements the given dbus object and interface |
| 37 | * |
| 38 | * @param[in] i_interface Interface that maps to the service |
| 39 | * @param[in] i_path Path that maps to the service |
| 40 | * @param[out] o_service Service implementing the dbus object and interface |
| 41 | * @return non-zer on error |
| 42 | */ |
| 43 | int findService(const std::string& i_interface, const std::string& i_path, |
| 44 | std::string& o_service); |
| 45 | |
| 46 | /** |
| 47 | * Read a property from a dbus object interface |
| 48 | * |
| 49 | * @param[in] i_interface Interface implementing the property |
| 50 | * @param[in] i_path Path of the dbus object |
| 51 | * @param[in] i_service Service implementing the dbus object and interface |
| 52 | * @param[in] i_property Property to read |
| 53 | * @return non-zero on error |
| 54 | */ |
| 55 | int getProperty(const std::string& i_interface, const std::string& i_path, |
| 56 | const std::string& i_service, const std::string& i_property, |
| 57 | DBusValue& o_response); |
| 58 | |
| 59 | /** |
| 60 | * Get the IBM compatible names defined for this system |
| 61 | * |
| 62 | * @return A vector of strings containing the system names |
| 63 | */ |
| 64 | std::vector<std::string> systemNames(); |
| 65 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 66 | /** @brief Host transition states for host transition operations */ |
Ben Tyner | 9306716 | 2021-07-23 10:39:30 -0500 | [diff] [blame] | 67 | enum class HostState |
| 68 | { |
| 69 | Quiesce, |
| 70 | Diagnostic, |
| 71 | Crash |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * @brief Transition the host state |
| 76 | * |
| 77 | * We will transition the host state by starting the appropriate dbus target. |
| 78 | * |
| 79 | * @param i_hostState the state to transition the host to |
| 80 | */ |
| 81 | void transitionHost(const HostState i_hostState); |
| 82 | |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 83 | /** |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 84 | * @brief Read autoRebootEnabled property |
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 | * @return false if autoRebootEnabled policy false, else true |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 87 | */ |
| 88 | bool autoRebootEnabled(); |
| 89 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 90 | /** @brief Host running states for host running operations */ |
| 91 | enum class HostRunningState |
| 92 | { |
| 93 | Unknown, |
| 94 | NotStarted, |
Andrew Geissler | 1ff926e | 2023-01-26 08:14:22 -0700 | [diff] [blame^] | 95 | Started, |
| 96 | Stopping |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * Get the host running state |
| 101 | * |
| 102 | * Use host boot progress to determine if a host has been started. If host |
| 103 | * boot progress can not be determined then host state will be unknown. |
| 104 | * |
| 105 | * @return HostType == "Unknown", "Started or "NotStarted" |
| 106 | */ |
| 107 | HostRunningState hostRunningState(); |
| 108 | |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 109 | /** |
| 110 | * @brief Read dumpPolicyEnabled property |
| 111 | * |
| 112 | * @return false if dumpPolicyEnabled property is false, else true |
| 113 | */ |
| 114 | bool dumpPolicyEnabled(); |
| 115 | |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 116 | /** |
| 117 | * Create a PEL |
| 118 | * |
| 119 | * The additional data provided in the map will be placed in a user data |
| 120 | * section of the PEL and may additionally contain key words to trigger |
| 121 | * certain behaviors by the backend logging code. Each set of data described |
| 122 | * in the vector of ffdc data will be placed in additional user data |
| 123 | * sections. Note that the PID of the caller will be added to the additional |
| 124 | * data map with key "_PID". |
| 125 | * |
| 126 | * @param i_message - the event type |
| 127 | * @param i_severity - the severity level |
| 128 | * @param io_additional - map of additional data |
| 129 | * @param i_ffdc - vector of ffdc data |
| 130 | * @return Platform log id or 0 if error |
| 131 | */ |
| 132 | uint32_t createPel(const std::string& i_message, const std::string& i_severity, |
| 133 | std::map<std::string, std::string>& io_additional, |
| 134 | const std::vector<FFDCTuple>& i_ffdc); |
| 135 | |
Caleb Palmer | 626270a | 2022-02-21 11:05:08 -0600 | [diff] [blame] | 136 | /** @brief Machine ID definitions */ |
| 137 | enum class MachineType |
| 138 | { |
| 139 | Rainier_2S4U, |
| 140 | Rainier_2S2U, |
| 141 | Rainier_1S4U, |
| 142 | Rainier_1S2U, |
| 143 | Everest, |
| 144 | }; |
| 145 | |
| 146 | /** |
| 147 | * @brief Read the System IM keyword to get the machine type |
| 148 | * |
| 149 | * @return An enum representing the machine type |
| 150 | */ |
| 151 | MachineType getMachineType(); |
| 152 | |
Ben Tyner | 88b1009 | 2022-12-14 20:43:50 -0600 | [diff] [blame] | 153 | /** @brief Get list of state sensor PDRs |
| 154 | * |
| 155 | * @param[out] pdrList - list of PDRs |
| 156 | * @param[in] stateSetId - ID of the state set of interest |
| 157 | * |
| 158 | * @return true if successful otherwise false |
| 159 | */ |
| 160 | bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList, |
| 161 | uint16_t stateSetId); |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 162 | |
Ben Tyner | 88b1009 | 2022-12-14 20:43:50 -0600 | [diff] [blame] | 163 | /** @brief Get list of state effecter PDRs |
| 164 | * |
| 165 | * @param[out] pdrList - list of PDRs |
| 166 | * @param[in] stateSetId - ID of the state set of interest |
| 167 | * |
| 168 | * @return true if successful otherwise false |
| 169 | */ |
| 170 | bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList, |
| 171 | uint16_t stateSetId); |
| 172 | |
| 173 | /** |
| 174 | * @brief Get MCTP instance ID associated with endpoint |
| 175 | * |
| 176 | * @param[out] mctpInstance - instance of MCTP |
| 177 | * @param[in] Eid - MCTP enpoint ID |
| 178 | * |
| 179 | * @return True on success otherwise False |
| 180 | */ |
| 181 | bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid); |
| 182 | |
Ben Tyner | 2b26b2b | 2022-12-15 15:42:02 -0600 | [diff] [blame] | 183 | /** |
| 184 | * @brief Determine if power fault was detected |
| 185 | * |
| 186 | * @return true if power fault or unknown, false otherwise |
| 187 | */ |
| 188 | bool powerFault(); |
| 189 | |
Ben Tyner | 88b1009 | 2022-12-14 20:43:50 -0600 | [diff] [blame] | 190 | } // namespace dbus |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 191 | } // namespace util |