Create a SEL error log

Log the SEL data to the journal and call the commit
interface to write the error log with the data.

Change-Id: Ifcb842e37f2fdb14f80ab24651d565da05da47bf
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/storageaddsel.cpp b/storageaddsel.cpp
index 84e3092..0b40d47 100644
--- a/storageaddsel.cpp
+++ b/storageaddsel.cpp
@@ -8,12 +8,15 @@
 #include <memory>
 #include <systemd/sd-bus.h>
 #include <mapper.h>
+#include <elog.hpp>
+#include <elog-errors-HostEvent.hpp>
 #include "host-ipmid/ipmid-api.h"
 #include "sensorhandler.h"
 #include "storagehandler.h"
 
 
 using namespace std;
+using namespace phosphor::logging;
 
 //////////////////////////
 struct esel_section_headers_t {
@@ -185,6 +188,26 @@
     const char *object_name  =  "/org/openbmc/records/events";
     char *bus_name = NULL;
 
+    // Allocate enough space to represent the data in hex separated by spaces,
+    // to mimic how IPMI would display the data.
+    unique_ptr<char[]> selData(new char[debuglen*3]());
+    uint32_t i = 0;
+    for(i = 0; i < debuglen; i++)
+    {
+        sprintf(&selData[i*3], "%02x ", 0xFF & ((char*)debug)[i]);
+    }
+    log<level::INFO>("Received Host Event", entry("ESEL=%s", selData.get()));
+
+    try
+    {
+        elog<org::open_power::Error::Host::Event>(
+            prev_entry<org::open_power::Error::Host::Event::ESEL>());
+    }
+    catch (elogException<org::open_power::Error::Host::Event>& e)
+    {
+        commit(e.name());
+    }
+
     mbus = ipmid_get_sd_bus_connection();
     r = mapper_get_service(mbus, object_name, &bus_name);
     if (r < 0) {