PEL: Close PEL FD after getPEL call

To close the file descriptor returned from the getPEL D-Bus method call,
use the 'Defer' sdeventplus object to schedule it to happen from the
event loop.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I2b850a1c92215e7f66166cc5440d7071663065c0
diff --git a/extensions/openpower-pels/manager.hpp b/extensions/openpower-pels/manager.hpp
index 7f1fcda..14904a9 100644
--- a/extensions/openpower-pels/manager.hpp
+++ b/extensions/openpower-pels/manager.hpp
@@ -11,6 +11,8 @@
 
 #include <org/open_power/Logging/PEL/server.hpp>
 #include <sdbusplus/server.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/source/event.hpp>
 
 namespace openpower
 {
@@ -176,6 +178,27 @@
                    const std::vector<std::string>& associations);
 
     /**
+     * @brief Schedules a close of the file descriptor to occur from
+     *        the event loop.
+     *
+     * Uses sd_event_add_defer
+     *
+     * @param[in] fd - The file descriptor to close
+     */
+    void scheduleFDClose(int fd);
+
+    /**
+     * @brief Closes the file descriptor passed in.
+     *
+     * This is called from the event loop to close FDs returned
+     * from getPEL().
+     *
+     * @param[in] fd - The file descriptor to close
+     * @param[in] source - The event source object used
+     */
+    void closeFD(int fd, sdeventplus::source::EventBase& source);
+
+    /**
      * @brief Reference to phosphor-logging's Manager class
      */
     phosphor::logging::internal::Manager& _logManager;
@@ -200,6 +223,12 @@
      *        host about new PELs
      */
     std::unique_ptr<HostNotifier> _hostNotifier;
+
+    /**
+     * @brief The event source for closing a PEL file descriptor after
+     *        it has been returned from the getPEL D-Bus method.
+     */
+    std::unique_ptr<sdeventplus::source::Defer> _fdCloserEventSource;
 };
 
 } // namespace pels