Add implementation for delete all error log entries in one shot

Resolves openbmc/openbmc#1561.

Change-Id: Iac5aaee1bdf9b87ccce9bf8801468ac5a8f9be6c
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
diff --git a/log_manager.hpp b/log_manager.hpp
index f366684..af176f9 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -4,6 +4,7 @@
 #include <phosphor-logging/log.hpp>
 #include "elog_entry.hpp"
 #include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
+#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
 
 namespace phosphor
 {
@@ -13,6 +14,9 @@
 extern const std::map<std::string,std::vector<std::string>> g_errMetaMap;
 extern const std::map<std::string,level> g_errLevelMap;
 
+using DeleteAllIface = sdbusplus::server::object::object <
+                       sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >;
+
 namespace details
 {
 
@@ -24,6 +28,9 @@
 
 } // namespace details
 
+namespace internal
+{
+
 /** @class Manager
  *  @brief OpenBMC logging manager implementation.
  *  @details A concrete implementation for the
@@ -73,6 +80,20 @@
          */
         void restore();
 
+        /** @brief  Erase all error log entries
+         *
+         */
+        void eraseAll()
+        {
+            auto iter = entries.begin();
+            while (iter != entries.end())
+            {
+                auto entry = iter->first;
+                ++iter;
+                erase(entry);
+            }
+        }
+
     private:
         /** @brief Call metadata handler(s), if any. Handlers may create
          *         associations.
@@ -104,5 +125,46 @@
         bool capped;
 };
 
+} //namespace internal
+
+/** @class Manager
+ *  @brief Implementation for delete all error log entries.
+ *  @details A concrete implementation for the
+ *  xyz.openbmc_project.Collection.DeleteAll
+ */
+class Manager : public DeleteAllIface
+{
+    public:
+        Manager() = delete;
+        Manager(const Manager&) = delete;
+        Manager& operator=(const Manager&) = delete;
+        Manager(Manager&&) = delete;
+        Manager& operator=(Manager&&) = delete;
+        virtual ~Manager() = default;
+
+        /** @brief Constructor to put object onto bus at a dbus path.
+         *         Defer signal registration (pass true for deferSignal to the
+         *         base class) until after the properties are set.
+         *  @param[in] bus - Bus to attach to.
+         *  @param[in] path - Path to attach at.
+         *  @param[in] manager - Reference to internal manager object.
+         */
+        Manager(sdbusplus::bus::bus& bus,
+                   const std::string& path,
+                   internal::Manager& manager) :
+            DeleteAllIface(bus, path.c_str(), true),
+            manager(manager) {};
+
+        /** @brief Delete all d-bus objects.
+         */
+        void deleteAll()
+        {
+            manager.eraseAll();
+        }
+    private:
+        /** @brief This is a reference to manager object */
+        internal::Manager& manager;
+};
+
 } // namespace logging
 } // namespace phosphor