Return the object path for user requested dumps.

Return the object path to a dump entry for the user requested
dump. A dump entry will be created when the user request for
the dump and that will be used for tracking the progress.
 The dump details like size etc  will be empty and the complete
details will be filled once the dump creation is completed.

Executed current BMC and system dump test cases on a test build
- Create BMC dump
- List All dumps
- Offload BMC dump
- Delete BMC dump
- Create manual system dump.
- Attempt to offload dump.

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I89b252e2731f4f1fb924d26c7ac05999341fc691
diff --git a/dump_manager_bmc.cpp b/dump_manager_bmc.cpp
index f6556f1..acd14a2 100644
--- a/dump_manager_bmc.cpp
+++ b/dump_manager_bmc.cpp
@@ -34,10 +34,30 @@
 
 } // namespace internal
 
-uint32_t Manager::createDump()
+sdbusplus::message::object_path Manager::createDump()
 {
     std::vector<std::string> paths;
-    return captureDump(Type::UserRequested, paths);
+    auto id = captureDump(Type::UserRequested, paths);
+
+    // Entry Object path.
+    auto objPath = fs::path(baseEntryPath) / std::to_string(id);
+
+    try
+    {
+        entries.insert(std::make_pair(
+            id, std::make_unique<bmc::Entry>(bus, objPath.c_str(), id, 0, 0,
+                                             std::string(), *this)));
+    }
+    catch (const std::invalid_argument& e)
+    {
+        log<level::ERR>(e.what());
+        log<level::ERR>("Error in creating dump entry",
+                        entry("OBJECTPATH=%s", objPath.c_str()),
+                        entry("ID=%d", id));
+        elog<InternalFailure>();
+    }
+
+    return objPath.string();
 }
 
 uint32_t Manager::captureDump(Type type,
@@ -110,12 +130,22 @@
     auto idString = match[ID_POS];
     auto msString = match[EPOCHTIME_POS];
 
+    auto id = stoul(idString);
+
+    // If there is an existing entry update it and return.
+    auto dumpEntry = entries.find(id);
+    if (dumpEntry != entries.end())
+    {
+        dynamic_cast<phosphor::dump::bmc::Entry*>(dumpEntry->second.get())
+            ->update(stoull(msString), fs::file_size(file), file);
+        return;
+    }
+
+    // Entry Object path.
+    auto objPath = fs::path(baseEntryPath) / std::to_string(id);
+
     try
     {
-        auto id = stoul(idString);
-        // Entry Object path.
-        auto objPath = fs::path(baseEntryPath) / std::to_string(id);
-
         entries.insert(
             std::make_pair(id, std::make_unique<bmc::Entry>(
                                    bus, objPath.c_str(), id, stoull(msString),
@@ -124,6 +154,12 @@
     catch (const std::invalid_argument& e)
     {
         log<level::ERR>(e.what());
+        log<level::ERR>("Error in creating dump entry",
+                        entry("OBJECTPATH=%s", objPath.c_str()),
+                        entry("ID=%d", id),
+                        entry("TIMESTAMP=%ull", stoull(msString)),
+                        entry("SIZE=%d", fs::file_size(file)),
+                        entry("FILENAME=%s", file.c_str()));
         return;
     }
 }