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 | */ |
Patrick Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 26 | void action(sdbusplus::bus_t& bus, const std::string& path, bool assert); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 27 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 28 | /** @class Remove |
| 29 | * @brief Implementation of LED handling after resolution of FRU fault |
| 30 | * @details Implement methods for watching the resolution of FRU faults |
| 31 | * and deasserting corresponding LED. |
| 32 | */ |
| 33 | class Remove |
| 34 | { |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 35 | public: |
| 36 | Remove() = delete; |
| 37 | ~Remove() = default; |
| 38 | Remove(const Remove&) = delete; |
| 39 | Remove& operator=(const Remove&) = delete; |
| 40 | Remove(Remove&&) = default; |
| 41 | Remove& operator=(Remove&&) = default; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 42 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 43 | /** @brief constructs Remove |
| 44 | * @param[in] bus - The Dbus bus object |
| 45 | * @param[in] path - Inventory path to fru |
| 46 | */ |
Patrick Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 47 | Remove(sdbusplus::bus_t& bus, const std::string& path) : |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 48 | inventoryPath(path), |
| 49 | matchRemoved(bus, match(path), |
George Liu | 226059b | 2024-08-22 16:01:44 +0800 | [diff] [blame] | 50 | [this](sdbusplus::message_t& m) { removed(m); }) |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 51 | { |
| 52 | // Do nothing |
| 53 | } |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 54 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 55 | private: |
| 56 | /** @brief inventory path of the FRU */ |
| 57 | std::string inventoryPath; |
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 | /** @brief sdbusplus signal matches for fault removed */ |
| 60 | sdbusplus::bus::match_t matchRemoved; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 61 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 62 | /** @brief Callback function for fru fault created |
| 63 | * @param[in] msg - Data associated with subscribed signal |
| 64 | */ |
Patrick Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 65 | void removed(sdbusplus::message_t& msg); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 66 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 67 | /** @brief function to create fault remove match for a fru |
| 68 | * @param[in] path - Inventory path of the faulty unit. |
| 69 | */ |
George Liu | f059255 | 2024-08-23 09:46:17 +0800 | [diff] [blame] | 70 | static std::string match(const std::string& path) |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 71 | { |
| 72 | namespace MatchRules = sdbusplus::bus::match::rules; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 73 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 74 | std::string matchStmt = |
| 75 | MatchRules::interfacesRemoved() + |
| 76 | MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION); |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 77 | |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 78 | return matchStmt; |
| 79 | } |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 80 | }; |
George Liu | 191949c | 2024-07-22 15:17:49 +0800 | [diff] [blame] | 81 | |
| 82 | /** @class Add |
| 83 | * @brief Implementation of LED handling during FRU fault |
| 84 | * @details This implements methods for watching for a FRU fault |
| 85 | * being logged to assert the corresponding LED |
| 86 | */ |
| 87 | class Add |
| 88 | { |
| 89 | public: |
| 90 | Add() = delete; |
| 91 | ~Add() = default; |
| 92 | Add(const Add&) = delete; |
| 93 | Add& operator=(const Add&) = delete; |
| 94 | Add(Add&&) = default; |
| 95 | Add& operator=(Add&&) = default; |
| 96 | |
| 97 | /** @brief constructs Add a watch for FRU faults. |
| 98 | * @param[in] bus - The Dbus bus object |
| 99 | */ |
| 100 | explicit Add(sdbusplus::bus_t& bus) : |
George Liu | 226059b | 2024-08-22 16:01:44 +0800 | [diff] [blame] | 101 | matchCreated(bus, |
| 102 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 103 | sdbusplus::bus::match::rules::path_namespace( |
| 104 | "/xyz/openbmc_project/logging"), |
| 105 | [this](sdbusplus::message_t& m) { created(m); }) |
George Liu | 191949c | 2024-07-22 15:17:49 +0800 | [diff] [blame] | 106 | { |
| 107 | processExistingCallouts(bus); |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | /** @brief sdbusplus signal match for fault created */ |
| 112 | sdbusplus::bus::match_t matchCreated; |
| 113 | |
| 114 | std::vector<std::unique_ptr<Remove>> removeWatches; |
| 115 | |
| 116 | /** @brief Callback function for fru fault created |
| 117 | * @param[in] msg - Data associated with subscribed signal |
| 118 | */ |
| 119 | void created(sdbusplus::message_t& msg); |
| 120 | |
| 121 | /** @brief This function process all callouts at application start |
| 122 | * @param[in] bus - The Dbus bus object |
| 123 | */ |
| 124 | void processExistingCallouts(sdbusplus::bus_t& bus); |
| 125 | }; |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 126 | } // namespace monitor |
| 127 | } // namespace fault |
| 128 | } // namespace fru |
| 129 | } // namespace led |
| 130 | } // namespace phosphor |