blob: d8510ac88f462afe4f845da3e636bf5bf88b4234 [file] [log] [blame]
Ben Tyner324234b2021-06-28 17:01:17 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
Ben Tyner13159682022-02-16 14:55:38 -06004#include <util/ffdc_file.hpp>
Ben Tyner324234b2021-06-28 17:01:17 -05005
6#include <string>
7#include <variant>
8#include <vector>
9
10namespace util
11{
12
13namespace dbus
14{
15
16using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>,
17 std::vector<std::string>>;
18using DBusProperty = std::string;
19using DBusInterface = std::string;
20using DBusService = std::string;
21using DBusPath = std::string;
22using DBusInterfaceList = std::vector<DBusInterface>;
23using 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 */
34int 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 */
45int 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 */
57int 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 */
66std::vector<std::string> systemNames();
67
Ben Tynerfe2c50d2021-07-23 13:38:53 -050068/** @brief Host transition states for host transition operations */
Ben Tyner93067162021-07-23 10:39:30 -050069enum 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 */
83void transitionHost(const HostState i_hostState);
84
Ben Tynerffb48672021-07-23 12:29:03 -050085/**
Ben Tyner39fcf652021-10-19 20:38:29 -050086 * @brief Read autoRebootEnabled property
Ben Tynerffb48672021-07-23 12:29:03 -050087 *
Ben Tyner39fcf652021-10-19 20:38:29 -050088 * @return false if autoRebootEnabled policy false, else true
Ben Tynerffb48672021-07-23 12:29:03 -050089 */
90bool autoRebootEnabled();
91
Ben Tynerfe2c50d2021-07-23 13:38:53 -050092/** @brief Host running states for host running operations */
93enum 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 */
108HostRunningState hostRunningState();
109
Ben Tyner39fcf652021-10-19 20:38:29 -0500110/**
111 * @brief Read dumpPolicyEnabled property
112 *
113 * @return false if dumpPolicyEnabled property is false, else true
114 */
115bool dumpPolicyEnabled();
116
Ben Tyner13159682022-02-16 14:55:38 -0600117/**
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 */
133uint32_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 Palmer626270a2022-02-21 11:05:08 -0600137/** @brief Machine ID definitions */
138enum 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 */
152MachineType getMachineType();
153
Ben Tyner324234b2021-06-28 17:01:17 -0500154} // namespace dbus
155
156} // namespace util