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