Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server.hpp> |
| 5 | #include "config.h" |
| 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace led |
| 10 | { |
| 11 | namespace fru |
| 12 | { |
| 13 | namespace fault |
| 14 | { |
| 15 | namespace monitor |
| 16 | { |
| 17 | |
| 18 | /** @brief Assert or deassert an LED based on the input FRU |
| 19 | * @param[in] bus - The Dbus bus object |
| 20 | * @param[in] path - Inventory path of the FRU |
| 21 | * @param[in] assert - Assert if true deassert if false |
| 22 | */ |
| 23 | void action(sdbusplus::bus::bus& bus, |
| 24 | const std::string& path, |
| 25 | bool assert); |
| 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 | { |
| 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; |
| 43 | |
| 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, |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 50 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 51 | sdbusplus::bus::match::rules::path_namespace( |
| 52 | "/xyz/openbmc_project/logging"), |
| 53 | std::bind(std::mem_fn(&Add::created), |
| 54 | this, std::placeholders::_1)) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 55 | { |
| 56 | //Do nothing |
| 57 | } |
| 58 | private: |
| 59 | |
| 60 | /** @brief sdbusplus signal match for fault created */ |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 61 | sdbusplus::bus::match_t matchCreated; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 62 | |
| 63 | std::vector<std::unique_ptr<Remove>> removeWatches; |
| 64 | |
| 65 | /** @brief Callback function for fru fault created |
| 66 | * @param[in] msg - Data associated with subscribed signal |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 67 | */ |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 68 | void created(sdbusplus::message::message& msg); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /** @class Remove |
| 72 | * @brief Implementation of LED handling after resolution of FRU fault |
| 73 | * @details Implement methods for watching the resolution of FRU faults |
| 74 | * and deasserting corresponding LED. |
| 75 | */ |
| 76 | class Remove |
| 77 | { |
| 78 | public: |
| 79 | Remove() = delete; |
| 80 | ~Remove() = default; |
| 81 | Remove(const Remove&) = delete; |
| 82 | Remove& operator=(const Remove&) = delete; |
| 83 | Remove(Remove&&) = default; |
| 84 | Remove& operator=(Remove&&) = default; |
| 85 | |
| 86 | /** @brief constructs Remove |
| 87 | * @param[in] bus - The Dbus bus object |
| 88 | * @param[in] path - Inventory path to fru |
| 89 | */ |
| 90 | Remove(sdbusplus::bus::bus& bus, const std::string& path): |
| 91 | inventoryPath(path), |
| 92 | matchRemoved( |
| 93 | bus, |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 94 | match(path), |
| 95 | std::bind(std::mem_fn(&Remove::removed), |
| 96 | this, std::placeholders::_1)) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 97 | { |
| 98 | //Do nothing |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | |
| 103 | /** @brief inventory path of the FRU */ |
| 104 | std::string inventoryPath; |
| 105 | |
| 106 | /** @brief sdbusplus signal matches for fault removed */ |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 107 | sdbusplus::bus::match_t matchRemoved; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 108 | |
| 109 | /** @brief Callback function for fru fault created |
| 110 | * @param[in] msg - Data associated with subscribed signal |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 111 | */ |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 112 | void removed(sdbusplus::message::message& msg); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 113 | |
| 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 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 119 | namespace MatchRules = sdbusplus::bus::match::rules; |
| 120 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 121 | std::string matchStmt = |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 122 | MatchRules::type::signal() + |
| 123 | MatchRules::interface("org.freedesktop.DBus.Properties") + |
| 124 | MatchRules::member("PropertiesChanged") + |
| 125 | MatchRules::path(path + "/" + CALLOUT_REV_ASSOCIATION); |
| 126 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 127 | return matchStmt; |
| 128 | } |
| 129 | }; |
| 130 | }//namespace monitor |
| 131 | }//namespace fault |
| 132 | }//namespace fru |
| 133 | }//namespace led |
| 134 | }//namespace phosphor |