summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-11-06 15:40:45 -0600
committerMatt Spinler <spinler@us.ibm.com>2019-12-03 15:08:08 -0600
commit421f6531c5563d1e4e66b17062ebb9e632ca967b (patch)
tree4e83a7d0cf1ea426634ea392316f2beff46af79d /extensions/openpower-pels
parenta7d9d9615308d6a43d69b0fedea67218f00322ae (diff)
downloadphosphor-logging-421f6531c5563d1e4e66b17062ebb9e632ca967b.tar.gz
phosphor-logging-421f6531c5563d1e4e66b17062ebb9e632ca967b.zip
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
Diffstat (limited to 'extensions/openpower-pels')
-rw-r--r--extensions/openpower-pels/repository.cpp38
-rw-r--r--extensions/openpower-pels/repository.hpp86
2 files changed, 124 insertions, 0 deletions
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 @@ void Repository::add(std::unique_ptr<PEL>& pel)
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 @@ void Repository::remove(const LogID& id)
{
fs::remove(pel->second);
_idsToPELs.erase(pel);
+
+ processDeleteCallbacks(id.pelID.id);
}
}
@@ -198,5 +202,39 @@ void Repository::for_each(ForEachFunc func) const
}
}
+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
diff --git a/extensions/openpower-pels/repository.hpp b/extensions/openpower-pels/repository.hpp
index a1d4a24..78ab174 100644
--- a/extensions/openpower-pels/repository.hpp
+++ b/extensions/openpower-pels/repository.hpp
@@ -168,6 +168,68 @@ class Repository
*/
void for_each(ForEachFunc func) const;
+ using AddCallback = std::function<void(const PEL&)>;
+
+ /**
+ * @brief Subscribe to PELs being added to the repository.
+ *
+ * Every time a PEL is added to the repository, the provided
+ * function will be called with the new PEL as the argument.
+ *
+ * The function must be of type void(const PEL&).
+ *
+ * @param[in] name - The subscription name
+ * @param[in] func - The callback function
+ */
+ void subscribeToAdds(const std::string& name, AddCallback func)
+ {
+ if (_addSubscriptions.find(name) == _addSubscriptions.end())
+ {
+ _addSubscriptions.emplace(name, func);
+ }
+ }
+
+ /**
+ * @brief Unsubscribe from new PELs.
+ *
+ * @param[in] name - The subscription name
+ */
+ void unsubscribeFromAdds(const std::string& name)
+ {
+ _addSubscriptions.erase(name);
+ }
+
+ using DeleteCallback = std::function<void(uint32_t)>;
+
+ /**
+ * @brief Subscribe to PELs being deleted from the repository.
+ *
+ * Every time a PEL is deleted from the repository, the provided
+ * function will be called with the PEL ID as the argument.
+ *
+ * The function must be of type void(const uint32_t).
+ *
+ * @param[in] name - The subscription name
+ * @param[in] func - The callback function
+ */
+ void subscribeToDeletes(const std::string& name, DeleteCallback func)
+ {
+ if (_deleteSubscriptions.find(name) == _deleteSubscriptions.end())
+ {
+ _deleteSubscriptions.emplace(name, func);
+ }
+ }
+
+ /**
+ * @brief Unsubscribe from deleted PELs.
+ *
+ * @param[in] name - The subscription name
+ */
+ void unsubscribeFromDeletes(const std::string& name)
+ {
+ _deleteSubscriptions.erase(name);
+ }
+
private:
/**
* @brief Finds an entry in the _idsToPELs map.
@@ -183,6 +245,20 @@ class Repository
}
/**
+ * @brief Call any subscribed functions for new PELs
+ *
+ * @param[in] pel - The new PEL
+ */
+ void processAddCallbacks(const PEL& pel) const;
+
+ /**
+ * @brief Call any subscribed functions for deleted PELs
+ *
+ * @param[in] id - The ID of the deleted PEL
+ */
+ void processDeleteCallbacks(uint32_t id) const;
+
+ /**
* @brief Restores the _idsToPELs map on startup based on the existing
* PEL data files.
*/
@@ -197,6 +273,16 @@ class Repository
* @brief A map of the PEL/OBMC IDs to the PEL data files.
*/
std::map<LogID, std::filesystem::path> _idsToPELs;
+
+ /**
+ * @brief Subcriptions for new PELs.
+ */
+ std::map<std::string, AddCallback> _addSubscriptions;
+
+ /**
+ * @brief Subscriptions for deleted PELs.
+ */
+ std::map<std::string, DeleteCallback> _deleteSubscriptions;
};
} // namespace pels
OpenPOWER on IntegriCloud