Add support to enable dump collection for core dump

Implemented d-bus internal create function.

Change-Id: I34088d4c084a5a086189f4bc9e84e53a39193501
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/core_manager.cpp b/core_manager.cpp
index 8a91a27..f48e8dc 100644
--- a/core_manager.cpp
+++ b/core_manager.cpp
@@ -1,7 +1,7 @@
-#include <unistd.h>
-#include <sys/inotify.h>
+#include <phosphor-logging/log.hpp>
 
 #include "core_manager.hpp"
+#include "config.h"
 
 namespace phosphor
 {
@@ -12,16 +12,67 @@
 namespace manager
 {
 
+using namespace phosphor::logging;
+using namespace std;
+
 void watchCallback(const UserMap& fileInfo)
 {
+    vector<string> files;
+
     for (const auto& i : fileInfo)
     {
-        // For any new dump file create dump entry object.
+        // Get list of debug files.
         if (IN_CLOSE_WRITE == i.second)
         {
-            //TODO openbmc/openbmc#1795 Enable Dump collection function here
+            files.push_back(i.first.string());
         }
     }
+    if(!files.empty())
+    {
+        createHelper(files);
+    }
+}
+
+void createHelper(const vector<string>& files)
+{
+    constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
+    constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
+    constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
+    constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
+    constexpr auto APPLICATION_CORED =
+              "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
+
+    auto b = sdbusplus::bus::new_default();
+    auto mapper = b.new_method_call(
+                      MAPPER_BUSNAME,
+                      MAPPER_PATH,
+                      MAPPER_INTERFACE,
+                      "GetObject");
+    mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
+
+    auto mapperResponseMsg = b.call(mapper);
+    if (mapperResponseMsg.is_method_error())
+    {
+        log<level::ERR>("Error in mapper call");
+        return;
+    }
+
+    map<string, vector<string>> mapperResponse;
+    mapperResponseMsg.read(mapperResponse);
+    if (mapperResponse.empty())
+    {
+        log<level::ERR>("Error reading mapper response");
+        return;
+    }
+
+    const auto& host = mapperResponse.cbegin()->first;
+    auto m = b.new_method_call(
+                 host.c_str(),
+                 OBJ_INTERNAL,
+                 IFACE_INTERNAL,
+                 "Create");
+    m.append(APPLICATION_CORED, files);
+    b.call_noreply(m);
 }
 
 } // namespace manager