pinhole: utility interface to create errors

This will be utilized in later commit to create an informational error
when the pinhole reset is detected

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I3ba0e9bbce306db29dcc70954ffafe90287e1a14
diff --git a/utils.cpp b/utils.cpp
index 8e0e7ed..a93fa39 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -96,6 +96,40 @@
     return gpioval;
 }
 
+void createError(
+    sdbusplus::bus::bus& bus, const std::string& errorMsg,
+    sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level errLevel)
+{
+
+    try
+    {
+        // Create interface requires something for additionalData
+        std::map<std::string, std::string> additionalData;
+        additionalData.emplace("_PID", std::to_string(getpid()));
+
+        auto method = bus.new_method_call(
+            "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
+            "xyz.openbmc_project.Logging.Create", "Create");
+
+        method.append(errorMsg, errLevel, additionalData);
+        auto resp = bus.call(method);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        error("sdbusplus D-Bus call exception, error {ERROR} trying to create "
+              "an error with {ERROR_MSG}",
+              "ERROR", e, "ERROR_MSG", errorMsg);
+
+        throw std::runtime_error(
+            "Error in invoking D-Bus logging create interface");
+    }
+    catch (const std::exception& e)
+    {
+        error("D-bus call exception: {ERROR}", "ERROR", e);
+        throw e;
+    }
+}
+
 } // namespace utils
 } // namespace manager
 } // namespace state
diff --git a/utils.hpp b/utils.hpp
index 0127206..004d97a 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <sdbusplus/bus.hpp>
+#include <xyz/openbmc_project/Logging/Entry/server.hpp>
 
 namespace phosphor
 {
@@ -42,6 +43,16 @@
  */
 int getGpioValue(const std::string& gpioName);
 
+/** @brief Create an error log
+ *
+ * @param[in] bus          - The Dbus bus object
+ * @param[in] errorMsg     - The error message
+ * @param[in] errLevel     - The error level
+ */
+void createError(
+    sdbusplus::bus::bus& bus, const std::string& errorMsg,
+    sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level errLevel);
+
 } // namespace utils
 } // namespace manager
 } // namespace state