Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/server.hpp> |
George Liu | a6c18f8 | 2020-06-22 10:50:04 +0800 | [diff] [blame] | 7 | |
Andrew Geissler | d02c3cb | 2020-05-16 10:28:02 -0500 | [diff] [blame] | 8 | #include <string> |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace led |
| 13 | { |
| 14 | namespace fru |
| 15 | { |
| 16 | namespace fault |
| 17 | { |
| 18 | namespace monitor |
| 19 | { |
| 20 | |
| 21 | /** @brief Assert or deassert an LED based on the input FRU |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 22 | * @param[in] bus - The Dbus bus object |
| 23 | * @param[in] path - Inventory path of the FRU |
| 24 | * @param[in] assert - Assert if true deassert if false |
| 25 | */ |
| 26 | void action(sdbusplus::bus::bus& bus, const std::string& path, bool assert); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 27 | |
| 28 | class Remove; |
| 29 | |
| 30 | /** @class Add |
| 31 | * @brief Implementation of LED handling during FRU fault |
| 32 | * @details This implements methods for watching for a FRU fault |
| 33 | * being logged to assert the corresponding LED |
| 34 | */ |
| 35 | class Add |
| 36 | { |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 37 | public: |
| 38 | Add() = delete; |
| 39 | ~Add() = default; |
| 40 | Add(const Add&) = delete; |
| 41 | Add& operator=(const Add&) = delete; |
| 42 | Add(Add&&) = default; |
| 43 | Add& operator=(Add&&) = default; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 44 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 45 | /** @brief constructs Add a watch for FRU faults. |
| 46 | * @param[in] bus - The Dbus bus object |
| 47 | */ |
George Liu | c5e0f31 | 2021-12-27 15:54:31 +0800 | [diff] [blame] | 48 | explicit Add(sdbusplus::bus::bus& bus) : |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 49 | matchCreated( |
| 50 | bus, |
| 51 | sdbusplus::bus::match::rules::interfacesAdded() + |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 52 | sdbusplus::bus::match::rules::path_namespace( |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 53 | "/xyz/openbmc_project/logging"), |
| 54 | std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1)) |
| 55 | { |
| 56 | processExistingCallouts(bus); |
| 57 | } |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 58 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 59 | private: |
| 60 | /** @brief sdbusplus signal match for fault created */ |
| 61 | sdbusplus::bus::match_t matchCreated; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 62 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 63 | std::vector<std::unique_ptr<Remove>> removeWatches; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 64 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 65 | /** @brief Callback function for fru fault created |
| 66 | * @param[in] msg - Data associated with subscribed signal |
| 67 | */ |
| 68 | void created(sdbusplus::message::message& msg); |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 69 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 70 | /** @brief This function process all callouts at application start |
| 71 | * @param[in] bus - The Dbus bus object |
| 72 | */ |
| 73 | void processExistingCallouts(sdbusplus::bus::bus& bus); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /** @class Remove |
| 77 | * @brief Implementation of LED handling after resolution of FRU fault |
| 78 | * @details Implement methods for watching the resolution of FRU faults |
| 79 | * and deasserting corresponding LED. |
| 80 | */ |
| 81 | class Remove |
| 82 | { |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 83 | public: |
| 84 | Remove() = delete; |
| 85 | ~Remove() = default; |
| 86 | Remove(const Remove&) = delete; |
| 87 | Remove& operator=(const Remove&) = delete; |
| 88 | Remove(Remove&&) = default; |
| 89 | Remove& operator=(Remove&&) = default; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 90 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 91 | /** @brief constructs Remove |
| 92 | * @param[in] bus - The Dbus bus object |
| 93 | * @param[in] path - Inventory path to fru |
| 94 | */ |
| 95 | Remove(sdbusplus::bus::bus& bus, const std::string& path) : |
| 96 | inventoryPath(path), |
| 97 | matchRemoved(bus, match(path), |
| 98 | std::bind(std::mem_fn(&Remove::removed), this, |
| 99 | std::placeholders::_1)) |
| 100 | { |
| 101 | // Do nothing |
| 102 | } |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 103 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 104 | private: |
| 105 | /** @brief inventory path of the FRU */ |
| 106 | std::string inventoryPath; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 107 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 108 | /** @brief sdbusplus signal matches for fault removed */ |
| 109 | sdbusplus::bus::match_t matchRemoved; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 110 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 111 | /** @brief Callback function for fru fault created |
| 112 | * @param[in] msg - Data associated with subscribed signal |
| 113 | */ |
| 114 | void removed(sdbusplus::message::message& msg); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 115 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 116 | /** @brief function to create fault remove match for a fru |
| 117 | * @param[in] path - Inventory path of the faulty unit. |
| 118 | */ |
| 119 | std::string match(const std::string& path) |
| 120 | { |
| 121 | namespace MatchRules = sdbusplus::bus::match::rules; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 122 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 123 | std::string matchStmt = |
| 124 | MatchRules::interfacesRemoved() + |
| 125 | MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION); |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 126 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 127 | return matchStmt; |
| 128 | } |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 129 | }; |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 130 | } // namespace monitor |
| 131 | } // namespace fault |
| 132 | } // namespace fru |
| 133 | } // namespace led |
| 134 | } // namespace phosphor |