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