xref: /openbmc/phosphor-logging/elog_meta.hpp (revision 64007ac6)
1 #pragma once
2 
3 #include <vector>
4 #include <string>
5 #include <phosphor-logging/elog-errors.hpp>
6 #include "elog_entry.hpp"
7 
8 namespace phosphor
9 {
10 namespace logging
11 {
12 namespace metadata
13 {
14 
15 using Metadata = std::string;
16 
17 namespace associations
18 {
19 
20 using Type = void(const std::string&,
21                   const std::vector<std::string>&,
22                   AssociationList& list);
23 
24 /** @brief Pull out metadata name and value from the string
25  *         <metadata name>=<metadata value>
26  *  @param [in] data - metadata key=value entries
27  *  @param [out] metadata - map of metadata name:value
28  */
29 inline void parse(const std::vector<std::string>& data,
30                   std::map<std::string, std::string>& metadata)
31 {
32     constexpr auto separator = '=';
33     for(const auto& entry: data)
34     {
35         auto pos = entry.find(separator);
36         if(std::string::npos != pos)
37         {
38             auto key = entry.substr(0, entry.find(separator));
39             auto value = entry.substr(entry.find(separator) + 1);
40             metadata.emplace(std::move(key), std::move(value));
41         }
42     }
43 };
44 
45 /** @brief Build error associations specific to metadata. Specialize this
46  *         template for handling a specific type of metadata.
47  *  @tparam M - type of metadata
48  *  @param [in] match - metadata to be handled
49  *  @param [in] data - metadata key=value entries
50  *  @param [out] list - list of error association objects
51  */
52 template <typename M>
53 void build(const std::string& match,
54            const std::vector<std::string>& data,
55            AssociationList& list) = delete;
56 
57 // Example template specialization - we don't want to do anything
58 // for this metadata.
59 using namespace example::xyz::openbmc_project::Example::Elog;
60 template <>
61 inline void build<TestErrorTwo::DEV_ID>(const std::string& match,
62                                         const std::vector<std::string>& data,
63                                         AssociationList& list)
64 {
65 }
66 
67 } // namespace associations
68 } // namespace metadata
69 } // namespace logging
70 } // namespace phosphor
71