Revert "Remove the interfaces removed handler"

Listening for the interfaces removed signal is required so
that ibm-logging can remove its objects when phosphor-logging
prunes its entries after hitting capacity.

Previously, ibm-logging depended on someone calling Delete or
DeleteAll to remove objects.

This reverts commit 19ff79fafee4bdf695ae71522715e16bedb1349a.

Tested: Delete xyz.openbmc_project.Logging entries and verify
        these logs get deleted too.

Change-Id: Ib172100cc455563fc026330182d46b96f97679b5
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/manager.cpp b/manager.cpp
index 60d26ef..45982fc 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -29,7 +29,12 @@
              sdbusplus::bus::match::rules::interfacesAdded() +
                  sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
              std::bind(std::mem_fn(&Manager::interfaceAdded), this,
-                       std::placeholders::_1))
+                       std::placeholders::_1)),
+    removeMatch(bus,
+                sdbusplus::bus::match::rules::interfacesRemoved() +
+                    sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
+                std::bind(std::mem_fn(&Manager::interfaceRemoved), this,
+                          std::placeholders::_1))
 #ifdef USE_POLICY_INTERFACE
     ,
     policies(POLICY_JSON_PATH)
@@ -145,5 +150,29 @@
         create(path, propertyMap->second);
     }
 }
+
+void Manager::interfaceRemoved(sdbusplus::message::message& msg)
+{
+    sdbusplus::message::object_path path;
+    DbusInterfaceList interfaces;
+
+    msg.read(path, interfaces);
+
+    // If the Logging.Entry interface was removed, then remove
+    // our object
+
+    auto i = std::find(interfaces.begin(), interfaces.end(), LOGGING_IFACE);
+
+    if (i != interfaces.end())
+    {
+        auto id = getEntryID(path);
+
+        auto entry = entries.find(id);
+        if (entry != entries.end())
+        {
+            entries.erase(entry);
+        }
+    }
+}
 }
 }
diff --git a/manager.hpp b/manager.hpp
index d09d103..0320b0c 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -66,6 +66,16 @@
     void interfaceAdded(sdbusplus::message::message& msg);
 
     /**
+     * The callback for an interfaces removed signal
+     *
+     * Removes the IBM interfaces for the log entry
+     * that was just removed.
+     *
+     * @param[in] msg - the sdbusplus message
+     */
+    void interfaceRemoved(sdbusplus::message::message& msg);
+
+    /**
      * Creates the IBM interfaces for all existing error log
      * entries.
      */
@@ -135,6 +145,11 @@
      */
     sdbusplus::bus::match_t addMatch;
 
+    /**
+     * The match object for interfacesRemoved
+     */
+    sdbusplus::bus::match_t removeMatch;
+
     using EntryID = uint32_t;
     using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
     using EntryMap = std::map<EntryID, InterfaceMap>;