1 #pragma once
2 
3 #include "config.h"
4 
5 #include <sdbusplus/bus.hpp>
6 #include <sdbusplus/server.hpp>
7 
8 #include <string>
9 
10 namespace phosphor
11 {
12 namespace led
13 {
14 namespace fru
15 {
16 namespace fault
17 {
18 namespace monitor
19 {
20 
21 /** @brief Assert or deassert an LED based on the input FRU
22  *  @param[in] bus       -  The Dbus bus object
23  *  @param[in] path      -  Inventory path of the FRU
24  *  @param[in] assert    -  Assert if true deassert if false
25  */
26 void action(sdbusplus::bus_t& bus, const std::string& path, bool assert);
27 
28 class Remove;
29 
30 /** @class Add
31  *  @brief Implementation of LED handling during FRU fault
32  *  @details This implements methods for watching for a FRU fault
33  *  being logged to assert the corresponding LED
34  */
35 class Add
36 {
37   public:
38     Add() = delete;
39     ~Add() = default;
40     Add(const Add&) = delete;
41     Add& operator=(const Add&) = delete;
42     Add(Add&&) = default;
43     Add& operator=(Add&&) = default;
44 
45     /** @brief constructs Add a watch for FRU faults.
46      *  @param[in] bus -  The Dbus bus object
47      */
Add(sdbusplus::bus_t & bus)48     explicit Add(sdbusplus::bus_t& bus) :
49         matchCreated(
50             bus,
51             sdbusplus::bus::match::rules::interfacesAdded() +
52                 sdbusplus::bus::match::rules::path_namespace(
53                     "/xyz/openbmc_project/logging"),
54             std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
55     {
56         processExistingCallouts(bus);
57     }
58 
59   private:
60     /** @brief sdbusplus signal match for fault created */
61     sdbusplus::bus::match_t matchCreated;
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
67      */
68     void created(sdbusplus::message_t& msg);
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_t& bus);
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      */
Remove(sdbusplus::bus_t & bus,const std::string & path)95     Remove(sdbusplus::bus_t& bus, const std::string& path) :
96         inventoryPath(path),
97         matchRemoved(bus, match(path),
98                      std::bind(std::mem_fn(&Remove::removed), this,
99                                std::placeholders::_1))
100     {
101         // Do nothing
102     }
103 
104   private:
105     /** @brief inventory path of the FRU */
106     std::string inventoryPath;
107 
108     /** @brief sdbusplus signal matches for fault removed */
109     sdbusplus::bus::match_t matchRemoved;
110 
111     /** @brief Callback function for fru fault created
112      *  @param[in] msg       - Data associated with subscribed signal
113      */
114     void removed(sdbusplus::message_t& msg);
115 
116     /** @brief function to create fault remove match for a fru
117      *  @param[in] path  - Inventory path of the faulty unit.
118      */
match(const std::string & path)119     std::string match(const std::string& path)
120     {
121         namespace MatchRules = sdbusplus::bus::match::rules;
122 
123         std::string matchStmt =
124             MatchRules::interfacesRemoved() +
125             MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION);
126 
127         return matchStmt;
128     }
129 };
130 } // namespace monitor
131 } // namespace fault
132 } // namespace fru
133 } // namespace led
134 } // namespace phosphor
135