| #pragma once |
| |
| #include <sdbusplus/server.hpp> |
| |
| #include <filesystem> |
| #include <map> |
| #include <string> |
| #include <variant> |
| namespace openpower::dump::util |
| { |
| |
| using DumpCreateParams = |
| std::map<std::string, std::variant<std::string, uint64_t>>; |
| |
| /** @struct DumpPtr |
| * @brief a structure holding the data pointer |
| * @details This is a RAII container for the dump data |
| * returned by the SBE |
| */ |
| struct DumpDataPtr |
| { |
| public: |
| /** @brief Destructor for the object, free the allocated memory. |
| */ |
| ~DumpDataPtr() |
| { |
| // The memory is allocated using malloc |
| free(dataPtr); |
| } |
| /** @brief Returns the pointer to the data |
| */ |
| uint8_t** getPtr() |
| { |
| return &dataPtr; |
| } |
| /** @brief Returns the stored data |
| */ |
| uint8_t* getData() |
| { |
| return dataPtr; |
| } |
| |
| private: |
| /** The pointer to the data */ |
| uint8_t* dataPtr = nullptr; |
| }; |
| |
| /** |
| * @brief Get DBUS service for input interface via mapper call |
| * |
| * @param[in] bus - DBUS Bus Object |
| * @param[in] intf - DBUS Interface |
| * @param[in] path - DBUS Object Path |
| * |
| * @return distinct dbus name for input interface/path |
| **/ |
| std::string getService(sdbusplus::bus::bus& bus, const std::string& intf, |
| const std::string& path); |
| |
| /** |
| * @brief Set the property value based on the inputs |
| * |
| * @param[in] interface - the interface the property is on |
| * @param[in] propertName - the name of the property |
| * @param[in] path - the D-Bus path |
| * @param[in] service - the D-Bus service |
| * @param[in] bus - the D-Bus object |
| * @param[in] value - the value to set the property to |
| */ |
| template <typename T> |
| void setProperty(const std::string& interface, const std::string& propertyName, |
| const std::string& path, sdbusplus::bus::bus& bus, |
| const T& value) |
| { |
| constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties"; |
| |
| auto service = getService(bus, interface, path); |
| auto method = bus.new_method_call(service.c_str(), path.c_str(), |
| PROPERTY_INTF, "Set"); |
| method.append(interface, propertyName, value); |
| auto reply = bus.call(method); |
| } |
| |
| } // namespace openpower::dump::util |