Refactor core dump handling functions into core manager class

Change-Id: I700ecf517f26332c0a5e0de87c77cffd94f6bb9a
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/core_manager.cpp b/core_manager.cpp
index eb6cef5..beddd89 100644
--- a/core_manager.cpp
+++ b/core_manager.cpp
@@ -12,13 +12,11 @@
 {
 namespace core
 {
-namespace manager
-{
 
 using namespace phosphor::logging;
 using namespace std;
 
-void watchCallback(const UserMap& fileInfo)
+void Manager::watchCallback(const UserMap& fileInfo)
 {
     vector<string> files;
 
@@ -55,7 +53,7 @@
     }
 }
 
-void createHelper(const vector<string>& files)
+void Manager::createHelper(const vector<string>& files)
 {
     constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
     constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
@@ -97,7 +95,6 @@
     b.call_noreply(m);
 }
 
-} // namespace manager
 } // namespace core
 } // namespace dump
 } // namespace phosphor
diff --git a/core_manager.hpp b/core_manager.hpp
index 84818e5..6187486 100644
--- a/core_manager.hpp
+++ b/core_manager.hpp
@@ -4,6 +4,7 @@
 
 #include "dump_utils.hpp"
 #include "watch.hpp"
+#include "config.h"
 
 namespace phosphor
 {
@@ -11,23 +12,58 @@
 {
 namespace core
 {
-namespace manager
-{
-
+using Watch = phosphor::dump::inotify::Watch;
 using UserMap = phosphor::dump::inotify::UserMap;
 
-/** @brief Implementation of core watch call back
-  * @param [in] fileInfo - map of file info  path:event
-  */
-void watchCallback(const UserMap& fileInfo);
-
-/** @brief Helper function for initiating dump request using
- *         D-bus internal create interface.
- *  @param [in] files - Core files list
+/** @class Manager
+ *  @brief OpenBMC Core manager implementation.
  */
-void createHelper(const std::vector<std::string>& files);
+class Manager
+{
+    public:
+        Manager() = delete;
+        Manager(const Manager&) = default;
+        Manager& operator=(const Manager&) = delete;
+        Manager(Manager&&) = delete;
+        Manager& operator=(Manager&&) = delete;
+        virtual ~Manager() = default;
 
-} // namespace manager
+        /** @brief Constructor to create core watch object.
+         *  @param[in] event - Dump manager sd_event loop.
+         */
+        Manager(const EventPtr& event) :
+            eventLoop(event.get()),
+            coreWatch(eventLoop,
+                      IN_NONBLOCK,
+                      IN_CLOSE_WRITE,
+                      EPOLLIN,
+                      CORE_FILE_DIR,
+                      std::bind(
+                          std::mem_fn(
+                              &phosphor::dump::core::Manager::watchCallback),
+                          this, std::placeholders::_1))
+        {}
+
+    private:
+        /** @brief Helper function for initiating dump request using
+         *         D-bus internal create interface.
+         *  @param [in] files - Core files list
+         */
+        void createHelper(const std::vector<std::string>& files);
+
+
+        /** @brief Implementation of core watch call back
+         * @param [in] fileInfo - map of file info  path:event
+         */
+        void watchCallback(const UserMap& fileInfo);
+
+        /** @brief sdbusplus Dump event loop */
+        EventPtr eventLoop;
+
+        /** @brief Core watch object */
+        Watch coreWatch;
+};
+
 } // namepsace core
 } // namespace dump
 } // namespace phosphor
diff --git a/core_manager_main.cpp b/core_manager_main.cpp
index 6f7383f..1f9d195 100644
--- a/core_manager_main.cpp
+++ b/core_manager_main.cpp
@@ -27,15 +27,7 @@
 
     try
     {
-        phosphor::dump::inotify::Watch watch(
-            eventP,
-            IN_NONBLOCK,
-            IN_CLOSE_WRITE,
-            EPOLLIN,
-            CORE_FILE_DIR,
-            std::bind(
-                &phosphor::dump::core::manager::watchCallback,
-                std::placeholders::_1));
+        phosphor::dump::core::Manager manager(eventP);
 
         auto rc = sd_event_loop(eventP.get());
         if (rc < 0)