| Deepak Kodihalli | 16e8754 | 2017-02-27 07:07:33 -0600 | [diff] [blame] | 1 | #pragma once | 
 | 2 |  | 
| Patrick Williams | 0bb89f8 | 2021-04-16 16:30:04 -0500 | [diff] [blame] | 3 | #include "config.h" | 
 | 4 |  | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 5 | #include "callouts-gen.hpp" | 
 | 6 | #include "elog_entry.hpp" | 
| Patrick Williams | a06b4c6 | 2024-11-21 11:43:39 -0500 | [diff] [blame] | 7 | #include "util.hpp" | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 8 |  | 
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> | 
 | 10 |  | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 11 | #include <algorithm> | 
 | 12 | #include <cstring> | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 13 | #include <string> | 
 | 14 | #include <tuple> | 
 | 15 | #include <vector> | 
| Deepak Kodihalli | 16e8754 | 2017-02-27 07:07:33 -0600 | [diff] [blame] | 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 |  | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 29 | using Type = void(const std::string&, const std::vector<std::string>&, | 
| Deepak Kodihalli | 16e8754 | 2017-02-27 07:07:33 -0600 | [diff] [blame] | 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 | 
| Deepak Kodihalli | 327e580 | 2017-02-28 02:39:56 -0600 | [diff] [blame] | 35 |  *  @param [in] match - metadata to be handled | 
| Deepak Kodihalli | 16e8754 | 2017-02-27 07:07:33 -0600 | [diff] [blame] | 36 |  *  @param [in] data - metadata key=value entries | 
 | 37 |  *  @param [out] list - list of error association objects | 
 | 38 |  */ | 
 | 39 | template <typename M> | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 40 | void build(const std::string& match, const std::vector<std::string>& data, | 
| Deepak Kodihalli | 16e8754 | 2017-02-27 07:07:33 -0600 | [diff] [blame] | 41 |            AssociationList& list) = delete; | 
 | 42 |  | 
| Deepak Kodihalli | 327e580 | 2017-02-28 02:39:56 -0600 | [diff] [blame] | 43 | // Example template specialization - we don't want to do anything | 
 | 44 | // for this metadata. | 
| Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 45 | using namespace example::xyz::openbmc_project::example::elog; | 
| Deepak Kodihalli | 327e580 | 2017-02-28 02:39:56 -0600 | [diff] [blame] | 46 | template <> | 
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 47 | inline void build<TestErrorTwo::DEV_ID>( | 
 | 48 |     const std::string& /*match*/, const std::vector<std::string>& /*data*/, | 
 | 49 |     AssociationList& /*list*/) | 
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 50 | {} | 
| Deepak Kodihalli | 327e580 | 2017-02-28 02:39:56 -0600 | [diff] [blame] | 51 |  | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 52 | template <> | 
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 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) | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 57 | { | 
| Patrick Williams | a06b4c6 | 2024-11-21 11:43:39 -0500 | [diff] [blame] | 58 |     auto metadata = util::additional_data::parse(data); | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 59 |     auto iter = metadata.find(match); | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 60 |     if (metadata.end() != iter) | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 61 |     { | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 62 |         auto comp = [](const auto& first, const auto& second) { | 
| Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 63 |             return (std::strcmp(std::get<0>(first), second) < 0); | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 64 |         }; | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 65 |         auto callout = std::lower_bound(callouts.begin(), callouts.end(), | 
 | 66 |                                         (iter->second).c_str(), comp); | 
 | 67 |         if ((callouts.end() != callout) && | 
| Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 68 |             !std::strcmp((iter->second).c_str(), std::get<0>(*callout))) | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 69 |         { | 
| Patrick Venture | caa73ad | 2018-10-30 13:13:06 -0700 | [diff] [blame] | 70 |             constexpr auto ROOT = "/xyz/openbmc_project/inventory"; | 
 | 71 |  | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 72 |             list.push_back(std::make_tuple( | 
 | 73 |                 "callout", "fault", std::string(ROOT) + std::get<1>(*callout))); | 
| Deepak Kodihalli | 739e925 | 2017-03-05 23:23:50 -0600 | [diff] [blame] | 74 |         } | 
 | 75 |     } | 
 | 76 | } | 
 | 77 |  | 
| Deepak Kodihalli | 5edacf3 | 2017-03-16 07:04:07 -0500 | [diff] [blame] | 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. | 
| Deepak Kodihalli | 682326a | 2017-03-06 05:26:53 -0600 | [diff] [blame] | 82 | #if defined PROCESS_META | 
 | 83 |  | 
 | 84 | template <> | 
| Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 85 | void build<xyz::openbmc_project::common::callout::Device::CALLOUT_DEVICE_PATH>( | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 86 |     const std::string& match, const std::vector<std::string>& data, | 
| Deepak Kodihalli | 682326a | 2017-03-06 05:26:53 -0600 | [diff] [blame] | 87 |     AssociationList& list); | 
 | 88 |  | 
| Tom Joseph | 213aaf6 | 2017-07-25 00:02:09 +0530 | [diff] [blame] | 89 | template <> | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 90 | void build< | 
| Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 91 |     xyz::openbmc_project::common::callout::Inventory::CALLOUT_INVENTORY_PATH>( | 
| Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 92 |     const std::string& match, const std::vector<std::string>& data, | 
| Tom Joseph | 213aaf6 | 2017-07-25 00:02:09 +0530 | [diff] [blame] | 93 |     AssociationList& list); | 
 | 94 |  | 
| Deepak Kodihalli | 682326a | 2017-03-06 05:26:53 -0600 | [diff] [blame] | 95 | #endif // PROCESS_META | 
 | 96 |  | 
| Deepak Kodihalli | 16e8754 | 2017-02-27 07:07:33 -0600 | [diff] [blame] | 97 | } // namespace associations | 
 | 98 | } // namespace metadata | 
 | 99 | } // namespace logging | 
 | 100 | } // namespace phosphor |