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 | { |
Dhruvaraj Subhashchandran | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 56 | processExistingCallouts(bus); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 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 | 891c476 | 2017-07-31 14:26:37 -0500 | [diff] [blame] | 69 | |
| 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 | { |
| 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; |
| 90 | |
| 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( |
| 98 | bus, |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 99 | match(path), |
| 100 | std::bind(std::mem_fn(&Remove::removed), |
| 101 | this, std::placeholders::_1)) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 102 | { |
| 103 | //Do nothing |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | |
| 108 | /** @brief inventory path of the FRU */ |
| 109 | std::string inventoryPath; |
| 110 | |
| 111 | /** @brief sdbusplus signal matches for fault removed */ |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 112 | sdbusplus::bus::match_t matchRemoved; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 113 | |
| 114 | /** @brief Callback function for fru fault created |
| 115 | * @param[in] msg - Data associated with subscribed signal |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 116 | */ |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 117 | void removed(sdbusplus::message::message& msg); |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 118 | |
| 119 | /** @brief function to create fault remove match for a fru |
| 120 | * @param[in] path - Inventory path of the faulty unit. |
| 121 | */ |
| 122 | std::string match(const std::string& path) |
| 123 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 124 | namespace MatchRules = sdbusplus::bus::match::rules; |
| 125 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 126 | std::string matchStmt = |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 127 | MatchRules::type::signal() + |
| 128 | MatchRules::interface("org.freedesktop.DBus.Properties") + |
| 129 | MatchRules::member("PropertiesChanged") + |
| 130 | MatchRules::path(path + "/" + CALLOUT_REV_ASSOCIATION); |
| 131 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 132 | return matchStmt; |
| 133 | } |
| 134 | }; |
| 135 | }//namespace monitor |
| 136 | }//namespace fault |
| 137 | }//namespace fru |
| 138 | }//namespace led |
| 139 | }//namespace phosphor |