attn: Move create pel support to util
Move the create pel support from attention handler the util library.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I023add4b3e237d0253b218ff2912ea081961da6d
diff --git a/util/dbus.cpp b/util/dbus.cpp
index 4f28154..ea3fdf0 100644
--- a/util/dbus.cpp
+++ b/util/dbus.cpp
@@ -303,6 +303,58 @@
return dumpPolicyEnabled;
}
+/** @brief Create a PEL */
+uint32_t createPel(const std::string& i_message, const std::string& i_severity,
+ std::map<std::string, std::string>& io_additional,
+ const std::vector<util::FFDCTuple>& i_ffdc)
+{
+ // CreatePELWithFFDCFiles returns plid
+ int plid = 0;
+
+ // Sdbus call specifics
+ constexpr auto interface = "org.open_power.Logging.PEL";
+ constexpr auto path = "/xyz/openbmc_project/logging";
+
+ // we need to find the service implementing the interface
+ util::dbus::DBusService service;
+
+ if (0 == findService(interface, path, service))
+ {
+ try
+ {
+ constexpr auto function = "CreatePELWithFFDCFiles";
+
+ // The "Create" method requires manually adding the process ID.
+ io_additional["_PID"] = std::to_string(getpid());
+
+ // create dbus method
+ auto bus = sdbusplus::bus::new_system();
+ sdbusplus::message::message method =
+ bus.new_method_call(service.c_str(), path, interface, function);
+
+ // append additional dbus call paramaters
+ method.append(i_message, i_severity, io_additional, i_ffdc);
+
+ // using system dbus
+ auto response = bus.call(method);
+
+ // reply will be tuple containing bmc log id, platform log id
+ std::tuple<uint32_t, uint32_t> reply = {0, 0};
+
+ // parse dbus response into reply
+ response.read(reply);
+ plid = std::get<1>(reply); // platform log id is tuple "second"
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ trace::err("createPel exception");
+ trace::err(e.what());
+ }
+ }
+
+ return plid; // platform log id or 0
+}
+
} // namespace dbus
} // namespace util
diff --git a/util/dbus.hpp b/util/dbus.hpp
index ecc8d13..fc8f11a 100644
--- a/util/dbus.hpp
+++ b/util/dbus.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <sdbusplus/bus.hpp>
+#include <util/ffdc_file.hpp>
#include <string>
#include <variant>
@@ -113,6 +114,26 @@
*/
bool dumpPolicyEnabled();
+/**
+ * Create a PEL
+ *
+ * The additional data provided in the map will be placed in a user data
+ * section of the PEL and may additionally contain key words to trigger
+ * certain behaviors by the backend logging code. Each set of data described
+ * in the vector of ffdc data will be placed in additional user data
+ * sections. Note that the PID of the caller will be added to the additional
+ * data map with key "_PID".
+ *
+ * @param i_message - the event type
+ * @param i_severity - the severity level
+ * @param io_additional - map of additional data
+ * @param i_ffdc - vector of ffdc data
+ * @return Platform log id or 0 if error
+ */
+uint32_t createPel(const std::string& i_message, const std::string& i_severity,
+ std::map<std::string, std::string>& io_additional,
+ const std::vector<FFDCTuple>& i_ffdc);
+
} // namespace dbus
} // namespace util