Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/server.hpp> |
| 4 | |
| 5 | #include <filesystem> |
| 6 | #include <map> |
| 7 | #include <string> |
| 8 | #include <variant> |
| 9 | namespace openpower::dump::util |
| 10 | { |
| 11 | |
| 12 | using DumpCreateParams = |
| 13 | std::map<std::string, std::variant<std::string, uint64_t>>; |
| 14 | |
| 15 | /** @struct DumpPtr |
| 16 | * @brief a structure holding the data pointer |
| 17 | * @details This is a RAII container for the dump data |
| 18 | * returned by the SBE |
| 19 | */ |
| 20 | struct DumpDataPtr |
| 21 | { |
| 22 | public: |
| 23 | /** @brief Destructor for the object, free the allocated memory. |
| 24 | */ |
| 25 | ~DumpDataPtr() |
| 26 | { |
| 27 | // The memory is allocated using malloc |
| 28 | free(dataPtr); |
| 29 | } |
| 30 | /** @brief Returns the pointer to the data |
| 31 | */ |
| 32 | uint8_t** getPtr() |
| 33 | { |
| 34 | return &dataPtr; |
| 35 | } |
| 36 | /** @brief Returns the stored data |
| 37 | */ |
| 38 | uint8_t* getData() |
| 39 | { |
| 40 | return dataPtr; |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | /** The pointer to the data */ |
| 45 | uint8_t* dataPtr = nullptr; |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * @brief Get DBUS service for input interface via mapper call |
| 50 | * |
| 51 | * @param[in] bus - DBUS Bus Object |
| 52 | * @param[in] intf - DBUS Interface |
| 53 | * @param[in] path - DBUS Object Path |
| 54 | * |
| 55 | * @return distinct dbus name for input interface/path |
| 56 | **/ |
| 57 | std::string getService(sdbusplus::bus::bus& bus, const std::string& intf, |
| 58 | const std::string& path); |
| 59 | |
| 60 | /** |
| 61 | * @brief Set the property value based on the inputs |
| 62 | * |
| 63 | * @param[in] interface - the interface the property is on |
| 64 | * @param[in] propertName - the name of the property |
| 65 | * @param[in] path - the D-Bus path |
| 66 | * @param[in] service - the D-Bus service |
| 67 | * @param[in] bus - the D-Bus object |
| 68 | * @param[in] value - the value to set the property to |
| 69 | */ |
| 70 | template <typename T> |
| 71 | void setProperty(const std::string& interface, const std::string& propertyName, |
| 72 | const std::string& path, sdbusplus::bus::bus& bus, |
| 73 | const T& value) |
| 74 | { |
| 75 | constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties"; |
| 76 | |
| 77 | auto service = getService(bus, interface, path); |
| 78 | auto method = bus.new_method_call(service.c_str(), path.c_str(), |
| 79 | PROPERTY_INTF, "Set"); |
| 80 | method.append(interface, propertyName, value); |
| 81 | auto reply = bus.call(method); |
| 82 | } |
| 83 | |
| 84 | } // namespace openpower::dump::util |