PEL: Add subscriptions for new and deleted PELs

Add functionality to the Repository class to be able to call functions
provided by others when PELs are added or removed from the repository.

This will be used in the future for things like knowing when a new PEL
is added so it can be sent to the host.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I2effc9d5fa9a38890311a88bcfb07eed1292a453
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index 21b0243..aaa6a87 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -128,6 +128,8 @@
     using pelID = LogID::Pel;
     using obmcID = LogID::Obmc;
     _idsToPELs.emplace(LogID(pelID(pel->id()), obmcID(pel->obmcLogID())), path);
+
+    processAddCallbacks(*pel);
 }
 
 void Repository::remove(const LogID& id)
@@ -137,6 +139,8 @@
     {
         fs::remove(pel->second);
         _idsToPELs.erase(pel);
+
+        processDeleteCallbacks(id.pelID.id);
     }
 }
 
@@ -198,5 +202,39 @@
     }
 }
 
+void Repository::processAddCallbacks(const PEL& pel) const
+{
+    for (auto& [name, func] : _addSubscriptions)
+    {
+        try
+        {
+            func(pel);
+        }
+        catch (std::exception& e)
+        {
+            log<level::ERR>("PEL Repository add callback exception",
+                            entry("NAME=%s", name.c_str()),
+                            entry("ERROR=%s", e.what()));
+        }
+    }
+}
+
+void Repository::processDeleteCallbacks(uint32_t id) const
+{
+    for (auto& [name, func] : _deleteSubscriptions)
+    {
+        try
+        {
+            func(id);
+        }
+        catch (std::exception& e)
+        {
+            log<level::ERR>("PEL Repository delete callback exception",
+                            entry("NAME=%s", name.c_str()),
+                            entry("ERROR=%s", e.what()));
+        }
+    }
+}
+
 } // namespace pels
 } // namespace openpower