Entry: Populate properties

Create an Entry dbus object when Commit is called and fill in
its properties with the journal data.

Change-Id: I155cacbdfdccfa8b1f594503d858710fa71f2026
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/elog_entry.hpp b/elog_entry.hpp
index bd3915c..92360cb 100644
--- a/elog_entry.hpp
+++ b/elog_entry.hpp
@@ -35,11 +35,30 @@
         virtual ~Entry() = default;
 
         /** @brief Constructor to put object onto bus at a dbus path.
+         *         Defer signal registration (pass true for deferSignal to the
+         *         base class) until after the properties are set.
          *  @param[in] bus - Bus to attach to.
          *  @param[in] path - Path to attach at.
+         *  @param[in] properties - Desired Entry properties.
          */
-        Entry(sdbusplus::bus::bus& bus, const char* path) :
-              details::ServerObject<details::EntryIface>(bus, path) {};
+        Entry(sdbusplus::bus::bus& bus,
+              const std::string& path,
+              uint32_t idErr,
+              Level severityErr,
+              std::string&& msgErr,
+              std::vector<std::string>&& additionalDataErr) :
+              details::ServerObject<details::EntryIface>
+                    (bus, path.c_str(), true)
+        {
+            id(idErr);
+            severity(severityErr);
+            message(std::move(msgErr));
+            additionalData(std::move(additionalDataErr));
+
+            // Emit deferred signal.
+            this->emit_object_added();
+        };
+
 };
 
 } // namespace logging
diff --git a/log_manager.cpp b/log_manager.cpp
index c9edd7e..e9f11ec 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -7,6 +7,8 @@
 #include <systemd/sd-bus.h>
 #include <systemd/sd-journal.h>
 #include "elog-lookup.cpp"
+#include "config.h"
+#include "elog_entry.hpp"
 #include "log.hpp"
 #include "log_manager.hpp"
 
@@ -21,7 +23,6 @@
     constexpr const auto path = "/tmp/elog";
     constexpr const auto transactionIdVar = "TRANSACTION_ID";
 
-    // Create log file
     std::string filename{};
     filename.append(path);
     // TODO Create error logs in their own separate dir once permanent location
@@ -41,6 +42,7 @@
 
     std::string transactionIdStr = std::to_string(transactionId);
     std::vector<std::string> metalist = g_errMetaMap[errMsg];
+    std::vector<std::string> additionalData;
 
     // Read the journal from the end to get the most recent entry first.
     // The result from the sd_journal_get_data() is of the form VARIABLE=value.
@@ -78,6 +80,7 @@
         {
             continue;
         }
+
         efile << "\t\"@" << data << "\"," << std::endl;
 
         // Search for the metadata variables in the current journal entry
@@ -94,6 +97,7 @@
             }
 
             // Metatdata variable found, write to file
+            additionalData.push_back(std::string(data));
             efile << "\t\"@" << data << "\"," << std::endl;
         }
         efile << "\t}" << std::endl;
@@ -104,6 +108,18 @@
     }
     sd_journal_close(j);
 
+    // Create error Entry dbus object
+    entryId++;
+    auto objPath =  std::string(OBJ_ENTRY) + '/' +
+        std::to_string(entryId);
+    entries.insert(std::make_pair(entryId, std::make_unique<Entry>(
+            busLog,
+            objPath,
+            entryId,
+            (Entry::Level)g_errLevelMap[errMsg],
+            std::move(errMsg),
+            std::move(additionalData))));
+
     efile << "}" << std::endl;
     efile.close();
     return;
diff --git a/log_manager.hpp b/log_manager.hpp
index 4ad0ced..43070ff 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -38,9 +38,10 @@
          *  @param[in] bus - Bus to attach to.
          *  @param[in] path - Path to attach at.
          */
-        Manager(sdbusplus::bus::bus& bus, const char* path) :
-                details::ServerObject<details::ManagerIface>(bus, path),
-                busLog(bus) {};
+        Manager(sdbusplus::bus::bus& bus, const char* objPath) :
+                details::ServerObject<details::ManagerIface>(bus, objPath),
+                busLog(bus),
+                entryId(0) {};
 
         /*
          * @fn commit()
@@ -61,6 +62,9 @@
 
         /** @brief Persistent map of Entry dbus objects and their ID */
         std::map<uint32_t, std::unique_ptr<Entry>> entries;
+
+        /** @brief Id of last error log entry */
+        uint32_t entryId;
 };
 
 } // namespace logging
diff --git a/log_manager_main.cpp b/log_manager_main.cpp
index 10b6e76..2d3ccf3 100644
--- a/log_manager_main.cpp
+++ b/log_manager_main.cpp
@@ -14,9 +14,6 @@
 
     bus.request_name(BUSNAME_LOGGING);
 
-    // TODO Create error log dbus object on demand, when the Commit interface
-    // creates an error log it'd call this entry interface to create an object.
-
     while(true)
     {
         bus.process_discard();