sel-cache: Add match for logging removed

Add the match for logging entry removed event.

Tested: Verify the cache is updated and the entry is removed when the
        logging entry is removed.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I98707d5e9119cfa58ca3c4b44f5386a6e8d33b18
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 8927490..ced34eb 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -78,12 +78,19 @@
 SELCacheMap selCacheMap __attribute__((init_priority(101)));
 std::unique_ptr<sdbusplus::bus::match::match> selAddedMatch
     __attribute__((init_priority(101)));
+std::unique_ptr<sdbusplus::bus::match::match> selRemovedMatch
+    __attribute__((init_priority(101)));
 
-std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p)
+static inline uint16_t getLoggingId(const std::string& p)
 {
     namespace fs = std::filesystem;
     fs::path entryPath(p);
-    auto id = static_cast<uint16_t>(std::stoul(entryPath.filename().string()));
+    return std::stoul(entryPath.filename().string());
+}
+
+std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p)
+{
+    auto id = getLoggingId(p);
     // TODO: parse the sel data
     return {id, {}};
 }
@@ -104,6 +111,22 @@
     selCacheMap.insert(parseLoggingEntry(p));
 }
 
+static void selRemovedCallback(sdbusplus::message::message& m)
+{
+    sdbusplus::message::object_path objPath;
+    try
+    {
+        m.read(objPath);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        log<level::ERR>("Failed to read object path");
+        return;
+    }
+    std::string p = objPath;
+    selCacheMap.erase(getLoggingId(p));
+}
+
 void registerSelCallbackHandler()
 {
     using namespace sdbusplus::bus::match::rules;
@@ -114,7 +137,12 @@
             bus, interfacesAdded(logWatchPath),
             std::bind(selAddedCallback, std::placeholders::_1));
     }
-    // TODO: Add other callbacks
+    if (!selRemovedMatch)
+    {
+        selRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
+            bus, interfacesRemoved(logWatchPath),
+            std::bind(selRemovedCallback, std::placeholders::_1));
+    }
 }
 
 void initSELCache()