1 #pragma once
2
3 #include "config.h"
4
5 #include "callouts-gen.hpp"
6 #include "elog_entry.hpp"
7 #include "util.hpp"
8
9 #include <phosphor-logging/elog-errors.hpp>
10
11 #include <algorithm>
12 #include <cstring>
13 #include <string>
14 #include <tuple>
15 #include <vector>
16
17 namespace phosphor
18 {
19 namespace logging
20 {
21 namespace metadata
22 {
23
24 using Metadata = std::string;
25
26 namespace associations
27 {
28
29 using Type = void(const std::string&, const std::vector<std::string>&,
30 AssociationList& list);
31
32 /** @brief Build error associations specific to metadata. Specialize this
33 * template for handling a specific type of metadata.
34 * @tparam M - type of metadata
35 * @param [in] match - metadata to be handled
36 * @param [in] data - metadata key=value entries
37 * @param [out] list - list of error association objects
38 */
39 template <typename M>
40 void build(const std::string& match, const std::vector<std::string>& data,
41 AssociationList& list) = delete;
42
43 // Example template specialization - we don't want to do anything
44 // for this metadata.
45 using namespace example::xyz::openbmc_project::example::elog;
46 template <>
build(const std::string &,const std::vector<std::string> &,AssociationList &)47 inline void build<TestErrorTwo::DEV_ID>(
48 const std::string& /*match*/, const std::vector<std::string>& /*data*/,
49 AssociationList& /*list*/)
50 {}
51
52 template <>
build(const std::string & match,const std::vector<std::string> & data,AssociationList & list)53 inline void build<example::xyz::openbmc_project::example::device::Callout::
54 CALLOUT_DEVICE_PATH_TEST>(
55 const std::string& match, const std::vector<std::string>& data,
56 AssociationList& list)
57 {
58 auto metadata = util::additional_data::parse(data);
59 auto iter = metadata.find(match);
60 if (metadata.end() != iter)
61 {
62 auto comp = [](const auto& first, const auto& second) {
63 return (std::strcmp(std::get<0>(first), second) < 0);
64 };
65 auto callout = std::lower_bound(callouts.begin(), callouts.end(),
66 (iter->second).c_str(), comp);
67 if ((callouts.end() != callout) &&
68 !std::strcmp((iter->second).c_str(), std::get<0>(*callout)))
69 {
70 constexpr auto ROOT = "/xyz/openbmc_project/inventory";
71
72 list.push_back(std::make_tuple(
73 "callout", "fault", std::string(ROOT) + std::get<1>(*callout)));
74 }
75 }
76 }
77
78 // The PROCESS_META flag is needed to get out of tree builds working. Such
79 // builds will have access only to internal error interfaces, hence handlers
80 // for out dbus error interfaces won't compile. This flag is not set by default,
81 // the phosphor-logging recipe enabled it.
82 #if defined PROCESS_META
83
84 template <>
85 void build<xyz::openbmc_project::common::callout::Device::CALLOUT_DEVICE_PATH>(
86 const std::string& match, const std::vector<std::string>& data,
87 AssociationList& list);
88
89 template <>
90 void build<
91 xyz::openbmc_project::common::callout::Inventory::CALLOUT_INVENTORY_PATH>(
92 const std::string& match, const std::vector<std::string>& data,
93 AssociationList& list);
94
95 #endif // PROCESS_META
96
97 } // namespace associations
98 } // namespace metadata
99 } // namespace logging
100 } // namespace phosphor
101