PEL: Check if PEL pruning necessary on a new PEL

When a new PEL is added check if the size of all PELs is now more than
95% of the maximum capacity.  If it is, call the repository's prune()
function from the event loop to make more space.  Also delete the
OpenBMC event logs corresponding to the PELs that were just deleted.

It's called from the event loop so that the current D-Bus method
response that the code is in now can return to the caller first.

It tops out at 95% to ensure that we never go over.  It's possible this
can be tuned in the future, but at the current 20MB limit that still
allows 19MB before pruning will take it down to at most 18MB.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I962866eceee89cd605fcd36ec08b20ff762fe6cd
diff --git a/extensions/openpower-pels/manager.hpp b/extensions/openpower-pels/manager.hpp
index d58b36b..2d443c6 100644
--- a/extensions/openpower-pels/manager.hpp
+++ b/extensions/openpower-pels/manager.hpp
@@ -254,6 +254,23 @@
     PelFFDC convertToPelFFDC(const phosphor::logging::FFDCEntries& ffdc);
 
     /**
+     * @brief Schedules a PEL repository prune to occur from
+     *        the event loop.
+     *
+     * Uses sd_event_add_defer
+     */
+    void scheduleRepoPrune();
+
+    /**
+     * @brief Prunes old PELs out of the repository to save space.
+     *
+     * This is called from the event loop.
+     *
+     * @param[in] source - The event source object used
+     */
+    void pruneRepo(sdeventplus::source::EventBase& source);
+
+    /**
      * @brief Reference to phosphor-logging's Manager class
      */
     phosphor::logging::internal::Manager& _logManager;
@@ -290,6 +307,12 @@
      *        it has been returned from the getPEL D-Bus method.
      */
     std::unique_ptr<sdeventplus::source::Defer> _fdCloserEventSource;
+
+    /**
+     * @brief The even source for removing old PELs when the repo is
+     *        running out of space to make room for new ones.
+     */
+    std::unique_ptr<sdeventplus::source::Defer> _repoPrunerEventSource;
 };
 
 } // namespace pels