blob: f5c6f4c0f2d81b10266fa1fb1525adfe90482a19 [file] [log] [blame]
Deepak Kodihalli16e87542017-02-27 07:07:33 -06001#pragma once
2
3#include <vector>
4#include <string>
5#include <phosphor-logging/elog-errors.hpp>
6#include "elog_entry.hpp"
7
8namespace phosphor
9{
10namespace logging
11{
12namespace metadata
13{
14
15using Metadata = std::string;
16
17namespace associations
18{
19
20using Type = void(const std::string&,
21 const std::vector<std::string>&,
22 AssociationList& list);
23
Deepak Kodihalli66c46eb2017-03-02 03:07:10 -060024/** @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 */
29inline 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
Deepak Kodihalli16e87542017-02-27 07:07:33 -060045/** @brief Build error associations specific to metadata. Specialize this
46 * template for handling a specific type of metadata.
47 * @tparam M - type of metadata
Deepak Kodihalli327e5802017-02-28 02:39:56 -060048 * @param [in] match - metadata to be handled
Deepak Kodihalli16e87542017-02-27 07:07:33 -060049 * @param [in] data - metadata key=value entries
50 * @param [out] list - list of error association objects
51 */
52template <typename M>
53void build(const std::string& match,
54 const std::vector<std::string>& data,
55 AssociationList& list) = delete;
56
Deepak Kodihalli327e5802017-02-28 02:39:56 -060057// Example template specialization - we don't want to do anything
58// for this metadata.
59using namespace example::xyz::openbmc_project::Example::Elog;
60template <>
61inline void build<TestErrorTwo::DEV_ID>(const std::string& match,
62 const std::vector<std::string>& data,
63 AssociationList& list)
64{
65}
66
Deepak Kodihalli16e87542017-02-27 07:07:33 -060067} // namespace associations
68} // namespace metadata
69} // namespace logging
70} // namespace phosphor