blob: e31afa96db3e13a2a0ee445f35de355c3b1d0b75 [file] [log] [blame]
Deepak Kodihalli16e87542017-02-27 07:07:33 -06001#pragma once
2
3#include <vector>
4#include <string>
Deepak Kodihalli739e9252017-03-05 23:23:50 -06005#include <tuple>
6#include <algorithm>
7#include <cstring>
Deepak Kodihalli16e87542017-02-27 07:07:33 -06008#include <phosphor-logging/elog-errors.hpp>
9#include "elog_entry.hpp"
Deepak Kodihalli739e9252017-03-05 23:23:50 -060010#include "callouts-gen.hpp"
Deepak Kodihalli16e87542017-02-27 07:07:33 -060011
12namespace phosphor
13{
14namespace logging
15{
16namespace metadata
17{
18
19using Metadata = std::string;
20
21namespace associations
22{
23
24using Type = void(const std::string&,
25 const std::vector<std::string>&,
26 AssociationList& list);
27
Deepak Kodihalli66c46eb2017-03-02 03:07:10 -060028/** @brief Pull out metadata name and value from the string
29 * <metadata name>=<metadata value>
30 * @param [in] data - metadata key=value entries
31 * @param [out] metadata - map of metadata name:value
32 */
33inline void parse(const std::vector<std::string>& data,
34 std::map<std::string, std::string>& metadata)
35{
36 constexpr auto separator = '=';
37 for(const auto& entry: data)
38 {
39 auto pos = entry.find(separator);
40 if(std::string::npos != pos)
41 {
42 auto key = entry.substr(0, entry.find(separator));
43 auto value = entry.substr(entry.find(separator) + 1);
44 metadata.emplace(std::move(key), std::move(value));
45 }
46 }
47};
48
Deepak Kodihalli16e87542017-02-27 07:07:33 -060049/** @brief Build error associations specific to metadata. Specialize this
50 * template for handling a specific type of metadata.
51 * @tparam M - type of metadata
Deepak Kodihalli327e5802017-02-28 02:39:56 -060052 * @param [in] match - metadata to be handled
Deepak Kodihalli16e87542017-02-27 07:07:33 -060053 * @param [in] data - metadata key=value entries
54 * @param [out] list - list of error association objects
55 */
56template <typename M>
57void build(const std::string& match,
58 const std::vector<std::string>& data,
59 AssociationList& list) = delete;
60
Deepak Kodihalli327e5802017-02-28 02:39:56 -060061// Example template specialization - we don't want to do anything
62// for this metadata.
63using namespace example::xyz::openbmc_project::Example::Elog;
64template <>
65inline void build<TestErrorTwo::DEV_ID>(const std::string& match,
66 const std::vector<std::string>& data,
67 AssociationList& list)
68{
69}
70
Deepak Kodihalli739e9252017-03-05 23:23:50 -060071template <>
72inline void build<example::xyz::openbmc_project::
73 Example::Device::Callout::CALLOUT_DEVICE_PATH_TEST>(
74 const std::string& match,
75 const std::vector<std::string>& data,
76 AssociationList& list)
77{
78 constexpr auto ROOT = "/xyz/openbmc_project/inventory";
79 std::map<std::string, std::string> metadata;
80 parse(data, metadata);
81 auto iter = metadata.find(match);
82 if(metadata.end() != iter)
83 {
84 auto comp = [](const auto& first, const auto& second)
85 {
86 return (strcmp(std::get<0>(first), second) < 0);
87 };
88 auto callout = std::lower_bound(callouts.begin(),
89 callouts.end(),
90 (iter->second).c_str(),
91 comp);
92 if((callouts.end() != callout) &&
93 !strcmp((iter->second).c_str(), std::get<0>(*callout)))
94 {
95 list.push_back(std::make_tuple("callout",
96 "fault",
97 std::string(ROOT) +
98 std::get<1>(*callout)));
99 }
100 }
101}
102
Deepak Kodihalli5edacf32017-03-16 07:04:07 -0500103// The PROCESS_META flag is needed to get out of tree builds working. Such
104// builds will have access only to internal error interfaces, hence handlers
105// for out dbus error interfaces won't compile. This flag is not set by default,
106// the phosphor-logging recipe enabled it.
Deepak Kodihalli682326a2017-03-06 05:26:53 -0600107#if defined PROCESS_META
108
109template <>
110void build<xyz::openbmc_project::Common::
111 Callout::Device::CALLOUT_DEVICE_PATH>(
Deepak Kodihallia5d8d152017-03-16 05:10:05 -0500112 const std::string& match,
Deepak Kodihalli682326a2017-03-06 05:26:53 -0600113 const std::vector<std::string>& data,
114 AssociationList& list);
115
116#endif // PROCESS_META
117
118
Deepak Kodihalli16e87542017-02-27 07:07:33 -0600119} // namespace associations
120} // namespace metadata
121} // namespace logging
122} // namespace phosphor