1 #pragma once
2 
3 #include "sbe_type.hpp"
4 
5 #include <sdbusplus/server.hpp>
6 
7 #include <filesystem>
8 #include <map>
9 #include <string>
10 #include <variant>
11 namespace openpower::dump::util
12 {
13 
14 constexpr auto SBE_DUMP_TIMEOUT = 4 * 60; // Timeout in seconds
15 
16 using DumpCreateParams =
17     std::map<std::string, std::variant<std::string, uint64_t>>;
18 
19 /** @struct DumpPtr
20  * @brief a structure holding the data pointer
21  * @details This is a RAII container for the dump data
22  * returned by the SBE
23  */
24 struct DumpDataPtr
25 {
26   public:
27     /** @brief Destructor for the object, free the allocated memory.
28      */
~DumpDataPtropenpower::dump::util::DumpDataPtr29     ~DumpDataPtr()
30     {
31         // The memory is allocated using malloc
32         free(dataPtr);
33     }
34     /** @brief Returns the pointer to the data
35      */
getPtropenpower::dump::util::DumpDataPtr36     uint8_t** getPtr()
37     {
38         return &dataPtr;
39     }
40     /** @brief Returns the stored data
41      */
getDataopenpower::dump::util::DumpDataPtr42     uint8_t* getData()
43     {
44         return dataPtr;
45     }
46 
47   private:
48     /** The pointer to the data */
49     uint8_t* dataPtr = nullptr;
50 };
51 
52 /**
53  * @brief Get DBUS service for input interface via mapper call
54  *
55  * @param[in] bus -  DBUS Bus Object
56  * @param[in] intf - DBUS Interface
57  * @param[in] path - DBUS Object Path
58  *
59  * @return distinct dbus name for input interface/path
60  **/
61 std::string getService(sdbusplus::bus_t& bus, const std::string& intf,
62                        const std::string& path);
63 
64 /**
65  * @brief Set the property value based on the inputs
66  *
67  * @param[in] interface - the interface the property is on
68  * @param[in] propertName - the name of the property
69  * @param[in] path - the D-Bus path
70  * @param[in] service - the D-Bus service
71  * @param[in] bus - the D-Bus object
72  * @param[in] value - the value to set the property to
73  */
74 template <typename T>
setProperty(const std::string & interface,const std::string & propertyName,const std::string & path,sdbusplus::bus_t & bus,const T & value)75 void setProperty(const std::string& interface, const std::string& propertyName,
76                  const std::string& path, sdbusplus::bus_t& bus, const T& value)
77 {
78     constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties";
79 
80     auto service = getService(bus, interface, path);
81     auto method = bus.new_method_call(service.c_str(), path.c_str(),
82                                       PROPERTY_INTF, "Set");
83     method.append(interface, propertyName, value);
84     auto reply = bus.call(method);
85 }
86 
87 /**
88  * Request SBE dump from the dump manager
89  *
90  * Request SBE dump from the dump manager and register a monitor for observing
91  * the dump progress.
92  *
93  * @param failingUnit The id of the proc containing failed SBE
94  * @param eid Error log id associated with dump
95  * @param sbeType Type of the SBE
96  */
97 void requestSBEDump(const uint32_t failingUnit, const uint32_t eid,
98                     SBETypes sbeType);
99 
100 } // namespace openpower::dump::util
101