Implement the Delete interface

Implement the xyz.openbmc_project.Object.Delete interface
to delete an IBM logging object.

This is required because if someone calls Delete on an entry
in /xyz/openbmc_project/logging/, the REST server will also
call Delete on the corresponding object here.

Change-Id: I742320e49bcf1b371840dda4c7f5b1d0f572ad6a
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/delete.hpp b/delete.hpp
new file mode 100644
index 0000000..22d9447
--- /dev/null
+++ b/delete.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "interfaces.hpp"
+#include "manager.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+
+/**
+ *  @class Delete
+ *
+ *  Implements the xyz.openbmc_project.Object.Delete interface
+ *  to delete an IBM logging object.
+ */
+class Delete : public DeleteObject
+{
+  public:
+    Delete() = delete;
+    Delete(const Delete&) = delete;
+    Delete& operator=(const Delete&) = delete;
+    Delete(Delete&&) = default;
+    Delete& operator=(Delete&&) = default;
+    virtual ~Delete() = default;
+
+    /**
+     * Constructor
+     *
+     * @param[in] bus - the D-Bus bus object
+     * @param[in] path - the object path
+     * @param[in] manager - the Manager object
+     * @param[in] deferSignals - if the object creation signals
+     *                           should be deferred
+     */
+    Delete(sdbusplus::bus::bus& bus, const std::string& path, Manager& manager,
+           bool deferSignals) :
+        DeleteObject(bus, path.c_str(), deferSignals),
+        path(path), manager(manager)
+    {
+    }
+
+    /**
+     * The Delete D-Bus method
+     */
+    inline void delete_() override
+    {
+        manager.erase(path);
+    }
+
+  private:
+    /**
+     * The logging entry object path
+     */
+    const std::string path;
+
+    /**
+     * The Manager object
+     */
+    Manager& manager;
+};
+}
+}
diff --git a/interfaces.hpp b/interfaces.hpp
index 0dfa668..b889cbb 100644
--- a/interfaces.hpp
+++ b/interfaces.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <com/ibm/Logging/Policy/server.hpp>
+#include <xyz/openbmc_project/Object/Delete/server.hpp>
 
 namespace ibm
 {
@@ -10,12 +11,16 @@
 template <typename... T>
 using ServerObject = typename sdbusplus::server::object::object<T...>;
 
+using DeleteInterface = sdbusplus::xyz::openbmc_project::Object::server::Delete;
+using DeleteObject = ServerObject<DeleteInterface>;
+
 using PolicyInterface = sdbusplus::com::ibm::Logging::server::Policy;
 using PolicyObject = ServerObject<PolicyInterface>;
 
 enum class InterfaceType
 {
-    POLICY
+    POLICY,
+    DELETE
 };
 }
 }
diff --git a/manager.cpp b/manager.cpp
index 276a5a5..d47b3ad 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include "config.h"
+#include "delete.hpp"
 #include "manager.hpp"
 #include "policy_find.hpp"
 
@@ -68,6 +69,19 @@
 #ifdef USE_POLICY_INTERFACE
     createPolicyInterface(objectPath, properties);
 #endif
+
+    // Emits the interfaces added signal.
+    createDeleteInterface(objectPath);
+}
+
+void Manager::erase(const std::string& objectPath)
+{
+    auto entry = entries.find(getEntryID(objectPath));
+
+    if (entry != entries.end())
+    {
+        entries.erase(entry);
+    }
 }
 
 void Manager::addInterface(const std::string& objectPath, InterfaceType type,
@@ -88,6 +102,14 @@
     }
 }
 
+void Manager::createDeleteInterface(const std::string& objectPath)
+{
+    std::experimental::any object =
+        std::make_shared<Delete>(bus, objectPath, *this, false);
+
+    addInterface(objectPath, InterfaceType::DELETE, object);
+}
+
 #ifdef USE_POLICY_INTERFACE
 void Manager::createPolicyInterface(const std::string& objectPath,
                                     const DbusPropertyMap& properties)
@@ -99,8 +121,6 @@
     object->eventID(std::get<policy::EIDField>(values));
     object->description(std::get<policy::MsgField>(values));
 
-    object->emit_object_added();
-
     std::experimental::any anyObject = object;
 
     addInterface(objectPath, InterfaceType::POLICY, anyObject);
diff --git a/manager.hpp b/manager.hpp
index ca5e16b..69d9479 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -42,6 +42,13 @@
      */
     explicit Manager(sdbusplus::bus::bus& bus);
 
+    /**
+     * Deletes the entry with the specified path
+     *
+     * @param[in] objectPath - the entry object path
+     */
+    void erase(const std::string& objectPath);
+
   private:
     /**
      * The callback for an interfaces added signal
@@ -93,6 +100,14 @@
 #endif
 
     /**
+     * Creates the Delete interface for a single error log
+     * and saves it in the list of interfaces.
+     *
+     * @param[in] objectPath - object path of the error log
+     */
+    void createDeleteInterface(const std::string& objectPath);
+
+    /**
      * Returns the entry ID for a log
      *
      * @param[in] objectPath - the object path of the log