xref: /openbmc/phosphor-state-manager/utils.hpp (revision 9f38152abf80aba2f0177cb55729ff107f54947d)
1 #pragma once
2 
3 #include "config.h"
4 
5 #include <sdbusplus/bus.hpp>
6 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
7 
8 namespace phosphor
9 {
10 namespace state
11 {
12 namespace manager
13 {
14 namespace utils
15 {
16 
17 /** @brief Tell systemd to generate d-bus events
18  *
19  * @param[in] bus          - The Dbus bus object
20  *
21  * @return void, will throw exception on failure
22  */
23 void subscribeToSystemdSignals(sdbusplus::bus_t& bus);
24 
25 /** @brief Get service name from object path and interface
26  *
27  * @param[in] bus          - The Dbus bus object
28  * @param[in] path         - The Dbus object path
29  * @param[in] interface    - The Dbus interface
30  *
31  * @return The name of the service
32  */
33 std::string getService(sdbusplus::bus_t& bus, std::string path,
34                        std::string interface);
35 
36 /** @brief Get the value of input property
37  *
38  * @param[in] bus          - The Dbus bus object
39  * @param[in] path         - The Dbus object path
40  * @param[in] interface    - The Dbus interface
41  * @param[in] property     - The property name to get
42  *
43  * @return The value of the property
44  */
45 std::string getProperty(sdbusplus::bus_t& bus, const std::string& path,
46                         const std::string& interface,
47                         const std::string& propertyName);
48 
49 /** @brief Set the value of property
50  *
51  * @param[in] bus          - The Dbus bus object
52  * @param[in] path         - The Dbus object path
53  * @param[in] interface    - The Dbus interface
54  * @param[in] property     - The property name to set
55  * @param[in] value        - The value of property
56  */
57 void setProperty(sdbusplus::bus_t& bus, const std::string& path,
58                  const std::string& interface, const std::string& property,
59                  const std::string& value);
60 
61 /** @brief Return the value of the input GPIO
62  *
63  * @param[in] gpioName          - The name of the GPIO to read
64  *
65  *  * @return The value of the gpio (0 or 1) or -1 on error
66  */
67 int getGpioValue(const std::string& gpioName);
68 
69 /** @brief Create an error log
70  *
71  * @param[in] bus           - The Dbus bus object
72  * @param[in] errorMsg      - The error message
73  * @param[in] errLevel      - The error level
74  * parampin] additionalData - Optional extra data to add to the log
75  */
76 void createError(
77     sdbusplus::bus_t& bus, const std::string& errorMsg,
78     sdbusplus::server::xyz::openbmc_project::logging::Entry::Level errLevel,
79     std::map<std::string, std::string> additionalData = {});
80 
81 /** @brief Call phosphor-dump-manager to create BMC user dump
82  *
83  * @param[in] bus          - The Dbus bus object
84  */
85 void createBmcDump(sdbusplus::bus_t& bus);
86 
87 /** @brief Attempt to locate the obmc-chassis-lost-power@ file
88  *    to indicate that an AC loss occurred.
89  *
90  * @param[in] chassisId  - the chassis instance
91  */
92 bool checkACLoss(size_t& chassisId);
93 
94 /** @brief Determine if the BMC is at its Ready state
95  *
96  * @param[in] bus          - The Dbus bus object
97  */
98 bool isBmcReady(sdbusplus::bus_t& bus);
99 
100 /** @brief Wait BMC to enter ready state or timeout reached.
101  *
102  * @param[in] bus          - The Dbus bus object
103  * @param[in] timeout      - Timeout in second
104  */
105 bool waitBmcReady(sdbusplus::bus_t& bus, std::chrono::seconds timeout);
106 
107 #ifdef CHECK_FWUPDATE_BEFORE_DO_TRANSITION
108 /** @brief Determine if any firmware being updated
109  *
110  * @param[in] bus          - The Dbus bus object
111  */
112 bool isFirmwareUpdating(sdbusplus::bus_t& bus);
113 #endif // CHECK_FWUPDATE_BEFORE_DO_TRANSITION
114 
115 } // namespace utils
116 } // namespace manager
117 } // namespace state
118 } // namespace phosphor
119