Invoke metadata handler
Check if error metadata fields have associated handlers, if yes, invoke
them before construction the error d-bus object.
Change-Id: I197385c5c43242f633274b82289cd70c85c1d6e7
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/log_manager.cpp b/log_manager.cpp
index b094c0e..21111a0 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -14,6 +14,11 @@
#include "elog_entry.hpp"
#include <phosphor-logging/log.hpp>
#include "log_manager.hpp"
+#include "elog_meta.hpp"
+
+using namespace phosphor::logging;
+extern const std::map<metadata::Metadata,
+ std::function<metadata::associations::Type>> meta;
namespace phosphor
{
@@ -127,7 +132,10 @@
std::chrono::system_clock::now().time_since_epoch()).count();
auto objPath = std::string(OBJ_ENTRY) + '/' +
std::to_string(entryId);
+
AssociationList objects {};
+ processMetadata(errMsg, additionalData, objects);
+
entries.insert(std::make_pair(entryId, std::make_unique<Entry>(
busLog,
objPath,
@@ -140,5 +148,26 @@
return;
}
+void Manager::processMetadata(const std::string& errorName,
+ const std::vector<std::string>& additionalData,
+ AssociationList& objects) const
+{
+ // additionalData is a list of "metadata=value"
+ constexpr auto separator = '=';
+ for(const auto& entry: additionalData)
+ {
+ auto found = entry.find(separator);
+ if(std::string::npos != found)
+ {
+ auto metadata = entry.substr(0, found);
+ auto iter = meta.find(metadata);
+ if(meta.end() != iter)
+ {
+ (iter->second)(metadata, additionalData, objects);
+ }
+ }
+ }
+}
+
} // namespace logging
} // namepsace phosphor
diff --git a/log_manager.hpp b/log_manager.hpp
index 43070ff..285b337 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -57,6 +57,16 @@
private:
+ /** @brief Call metadata handler(s), if any. Handlers may create
+ * associations.
+ * @param[in] errorName - name of the error
+ * @param[in] additionalData - list of metadata (in key=value format)
+ * @param[out] objects - list of error's association objects
+ */
+ void processMetadata(const std::string& errorName,
+ const std::vector<std::string>& additionalData,
+ AssociationList& objects) const;
+
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus::bus& busLog;