eSEL : Handle logging of eSEL in OpenPower OEM library

The eSEL sent from host is logged as D-Bus error object only when
Add SEL command is from the host. Since the eSEL is an OpenPower
error representation, this should not be handled in the phosphor
implementation of the Add SEL command. The eSEL is logged as D-Bus
error object when the progress indicator in the Partial Add eSEL data
indicates last portion of the eSEL data.

Change-Id: I85c91e3c4819fb610ccf5ef27c2878e836c0f70e
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/oemhandler.cpp b/oemhandler.cpp
index a66f3e6..e215e39 100644
--- a/oemhandler.cpp
+++ b/oemhandler.cpp
@@ -16,6 +16,7 @@
 #include <host-interface.hpp>
 #include <host-ipmid/ipmid-host-cmd.hpp>
 #include <memory>
+#include <org/open_power/Host/error.hpp>
 #include <org/open_power/OCC/Metrics/error.hpp>
 #include <sdbusplus/bus.hpp>
 
@@ -68,6 +69,30 @@
     report<error>(metadata::ESEL(data.get()));
 }
 
+void createHostEntry(const std::string& eSELData)
+{
+    // Each byte in eSEL is formatted as %02x with a space between bytes and
+    // insert '/0' at the end of the character array.
+    std::string inventoryPath{};
+    constexpr auto byteSeperator = 3;
+
+    std::unique_ptr<char[]> data(
+        new char[(eSELData.size() * byteSeperator) + 1]());
+
+    for (size_t i = 0; i < eSELData.size(); i++)
+    {
+        sprintf(&data[i * byteSeperator], "%02x ", eSELData[i]);
+    }
+    data[eSELData.size() * byteSeperator] = '\0';
+
+    using hosterror = sdbusplus::org::open_power::Host::Error::Event;
+    using hostmetadata = org::open_power::Host::Event;
+
+    report<hosterror>(
+        Entry::Level::Warning, hostmetadata::ESEL(data.get()),
+        hostmetadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str()));
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // For the First partial add eSEL the SEL Record ID and offset
 // value should be 0x0000. The extended data needs to be in
@@ -161,6 +186,10 @@
         {
             createOCCLogEntry(eSELData);
         }
+        else
+        {
+            createHostEntry(eSELData);
+        }
     }
 
     return rc;