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, 50 "type='signal'," 51 "interface='org.freedesktop.DBus.ObjectManager'," 52 "member='InterfacesAdded'," 53 "path_namespace='/xyz/openbmc_project/logging'", 54 created, 55 this) 56 { 57 //Do nothing 58 } 59 private: 60 61 /** @brief sdbusplus signal match for fault created */ 62 sdbusplus::server::match::match matchCreated; 63 64 std::vector<std::unique_ptr<Remove>> removeWatches; 65 66 /** @brief Callback function for fru fault created 67 * @param[in] msg - Data associated with subscribed signal 68 * @param[in] data - Pointer to this object instance 69 * @param[out] retError - Error returned 70 * @return zero on success and error code upon failure 71 */ 72 static int created(sd_bus_message* msg, 73 void* data, 74 sd_bus_error* retError); 75 }; 76 77 /** @class Remove 78 * @brief Implementation of LED handling after resolution of FRU fault 79 * @details Implement methods for watching the resolution of FRU faults 80 * and deasserting corresponding LED. 81 */ 82 class Remove 83 { 84 public: 85 Remove() = delete; 86 ~Remove() = default; 87 Remove(const Remove&) = delete; 88 Remove& operator=(const Remove&) = delete; 89 Remove(Remove&&) = default; 90 Remove& operator=(Remove&&) = default; 91 92 /** @brief constructs Remove 93 * @param[in] bus - The Dbus bus object 94 * @param[in] path - Inventory path to fru 95 */ 96 Remove(sdbusplus::bus::bus& bus, const std::string& path): 97 inventoryPath(path), 98 matchRemoved( 99 bus, 100 match(path).c_str(), 101 removed, 102 this) 103 { 104 //Do nothing 105 } 106 107 private: 108 109 /** @brief inventory path of the FRU */ 110 std::string inventoryPath; 111 112 /** @brief sdbusplus signal matches for fault removed */ 113 sdbusplus::server::match::match matchRemoved; 114 115 /** @brief Callback function for fru fault created 116 * @param[in] msg - Data associated with subscribed signal 117 * @param[in] data - Pointer to this object instance 118 * @param[out] retError - Error returned 119 * @return zero on success and error code upon failure 120 */ 121 static int removed(sd_bus_message* msg, 122 void* data, 123 sd_bus_error* retError); 124 125 /** @brief function to create fault remove match for a fru 126 * @param[in] path - Inventory path of the faulty unit. 127 */ 128 std::string match(const std::string& path) 129 { 130 std::string matchStmt = 131 "type='signal'," 132 "interface='org.freedesktop.DBus.Properties'," 133 "member='PropertiesChanged'," 134 "path='" + path + 135 "/" + CALLOUT_REV_ASSOCIATION + "'"; 136 return matchStmt; 137 } 138 }; 139 }//namespace monitor 140 }//namespace fault 141 }//namespace fru 142 }//namespace led 143 }//namespace phosphor 144