blob: 97a212fd6c04e22b787840e6cfae18d8585cf2be [file] [log] [blame]
Deepak Kodihalli16e87542017-02-27 07:07:33 -06001#pragma once
2
Patrick Williams0bb89f82021-04-16 16:30:04 -05003#include "config.h"
4
Patrick Venturef18bf832018-10-26 18:14:00 -07005#include "callouts-gen.hpp"
6#include "elog_entry.hpp"
Patrick Williamsa06b4c62024-11-21 11:43:39 -05007#include "util.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07008
Patrick Williams2544b412022-10-04 08:41:06 -05009#include <phosphor-logging/elog-errors.hpp>
10
Deepak Kodihalli739e9252017-03-05 23:23:50 -060011#include <algorithm>
12#include <cstring>
Patrick Venturef18bf832018-10-26 18:14:00 -070013#include <string>
14#include <tuple>
15#include <vector>
Deepak Kodihalli16e87542017-02-27 07:07:33 -060016
17namespace phosphor
18{
19namespace logging
20{
21namespace metadata
22{
23
24using Metadata = std::string;
25
26namespace associations
27{
28
Patrick Venturef18bf832018-10-26 18:14:00 -070029using Type = void(const std::string&, const std::vector<std::string>&,
Deepak Kodihalli16e87542017-02-27 07:07:33 -060030 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
Deepak Kodihalli327e5802017-02-28 02:39:56 -060035 * @param [in] match - metadata to be handled
Deepak Kodihalli16e87542017-02-27 07:07:33 -060036 * @param [in] data - metadata key=value entries
37 * @param [out] list - list of error association objects
38 */
39template <typename M>
Patrick Venturef18bf832018-10-26 18:14:00 -070040void build(const std::string& match, const std::vector<std::string>& data,
Deepak Kodihalli16e87542017-02-27 07:07:33 -060041 AssociationList& list) = delete;
42
Deepak Kodihalli327e5802017-02-28 02:39:56 -060043// Example template specialization - we don't want to do anything
44// for this metadata.
Willy Tu6ddbf692023-09-05 10:54:16 -070045using namespace example::xyz::openbmc_project::example::elog;
Deepak Kodihalli327e5802017-02-28 02:39:56 -060046template <>
Patrick Williams075c7922024-08-16 15:19:49 -040047inline void build<TestErrorTwo::DEV_ID>(
48 const std::string& /*match*/, const std::vector<std::string>& /*data*/,
49 AssociationList& /*list*/)
Patrick Williams2544b412022-10-04 08:41:06 -050050{}
Deepak Kodihalli327e5802017-02-28 02:39:56 -060051
Deepak Kodihalli739e9252017-03-05 23:23:50 -060052template <>
Patrick Williams075c7922024-08-16 15:19:49 -040053inline 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)
Deepak Kodihalli739e9252017-03-05 23:23:50 -060057{
Patrick Williamsa06b4c62024-11-21 11:43:39 -050058 auto metadata = util::additional_data::parse(data);
Deepak Kodihalli739e9252017-03-05 23:23:50 -060059 auto iter = metadata.find(match);
Patrick Venturef18bf832018-10-26 18:14:00 -070060 if (metadata.end() != iter)
Deepak Kodihalli739e9252017-03-05 23:23:50 -060061 {
Patrick Venturef18bf832018-10-26 18:14:00 -070062 auto comp = [](const auto& first, const auto& second) {
Patrick Venture30047bf2018-11-01 18:52:15 -070063 return (std::strcmp(std::get<0>(first), second) < 0);
Deepak Kodihalli739e9252017-03-05 23:23:50 -060064 };
Patrick Venturef18bf832018-10-26 18:14:00 -070065 auto callout = std::lower_bound(callouts.begin(), callouts.end(),
66 (iter->second).c_str(), comp);
67 if ((callouts.end() != callout) &&
Patrick Venture30047bf2018-11-01 18:52:15 -070068 !std::strcmp((iter->second).c_str(), std::get<0>(*callout)))
Deepak Kodihalli739e9252017-03-05 23:23:50 -060069 {
Patrick Venturecaa73ad2018-10-30 13:13:06 -070070 constexpr auto ROOT = "/xyz/openbmc_project/inventory";
71
Patrick Venturef18bf832018-10-26 18:14:00 -070072 list.push_back(std::make_tuple(
73 "callout", "fault", std::string(ROOT) + std::get<1>(*callout)));
Deepak Kodihalli739e9252017-03-05 23:23:50 -060074 }
75 }
76}
77
Deepak Kodihalli5edacf32017-03-16 07:04:07 -050078// 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.
Deepak Kodihalli682326a2017-03-06 05:26:53 -060082#if defined PROCESS_META
83
84template <>
Willy Tu6ddbf692023-09-05 10:54:16 -070085void build<xyz::openbmc_project::common::callout::Device::CALLOUT_DEVICE_PATH>(
Patrick Venturef18bf832018-10-26 18:14:00 -070086 const std::string& match, const std::vector<std::string>& data,
Deepak Kodihalli682326a2017-03-06 05:26:53 -060087 AssociationList& list);
88
Tom Joseph213aaf62017-07-25 00:02:09 +053089template <>
Patrick Venturef18bf832018-10-26 18:14:00 -070090void build<
Willy Tu6ddbf692023-09-05 10:54:16 -070091 xyz::openbmc_project::common::callout::Inventory::CALLOUT_INVENTORY_PATH>(
Patrick Venturef18bf832018-10-26 18:14:00 -070092 const std::string& match, const std::vector<std::string>& data,
Tom Joseph213aaf62017-07-25 00:02:09 +053093 AssociationList& list);
94
Deepak Kodihalli682326a2017-03-06 05:26:53 -060095#endif // PROCESS_META
96
Deepak Kodihalli16e87542017-02-27 07:07:33 -060097} // namespace associations
98} // namespace metadata
99} // namespace logging
100} // namespace phosphor