callouts: implement metadata handler

Implement handler of the metadata CALLOUT_DEVICE_PATH. This handler will
convert a device path to an inventory path and call out the latter.

Change-Id: Icbf9c841884ec139f35ea2ac94648e355b421bb2
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/elog_meta.cpp b/elog_meta.cpp
new file mode 100644
index 0000000..b7b75a1
--- /dev/null
+++ b/elog_meta.cpp
@@ -0,0 +1,51 @@
+#include "config.h"
+#include "elog_meta.hpp"
+
+namespace phosphor
+{
+namespace logging
+{
+namespace metadata
+{
+namespace associations
+{
+
+#if defined PROCESS_META
+
+template <>
+void build<xyz::openbmc_project::Common::
+           Callout::Device::CALLOUT_DEVICE_PATH>(
+    std::string&& match,
+    const std::vector<std::string>& data,
+    AssociationList& list)
+{
+    std::map<std::string, std::string> metadata;
+    parse(data, metadata);
+    auto iter = metadata.find(match);
+    if(metadata.end() != iter)
+    {
+        auto comp = [](const auto& first, const auto& second)
+        {
+            return (strcmp(std::get<0>(first), second) < 0);
+        };
+        auto callout = std::lower_bound(callouts.begin(),
+                                        callouts.end(),
+                                        (iter->second).c_str(),
+                                        comp);
+        if((callouts.end() != callout) &&
+           !strcmp((iter->second).c_str(), std::get<0>(*callout)))
+        {
+            list.emplace_back(std::make_tuple(CALLOUT_FWD_ASSOCIATION,
+                                              CALLOUT_REV_ASSOCIATION,
+                                              std::string(INVENTORY_ROOT) +
+                                              std::get<1>(*callout)));
+        }
+    }
+}
+
+#endif
+
+} // namespace associations
+} // namespace metadata
+} // namespace logging
+} // namespace phosphor