xref: /openbmc/phosphor-led-manager/fault-monitor/fru-fault-monitor.hpp (revision f98004f63284ddf325e94af92bef1c7854692db2)
1 #pragma once
2 
3 #include "config.h"
4 
5 #include <sdbusplus/bus.hpp>
6 #include <sdbusplus/server.hpp>
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
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);
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 {
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;
42 
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() +
50                 sdbusplus::bus::match::rules::path_namespace(
51                     "/xyz/openbmc_project/logging"),
52             std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
53     {
54         processExistingCallouts(bus);
55     }
56 
57   private:
58     /** @brief sdbusplus signal match for fault created */
59     sdbusplus::bus::match_t matchCreated;
60 
61     std::vector<std::unique_ptr<Remove>> removeWatches;
62 
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);
67 
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);
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 {
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;
88 
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     }
101 
102   private:
103     /** @brief inventory path of the FRU */
104     std::string inventoryPath;
105 
106     /** @brief sdbusplus signal matches for fault removed */
107     sdbusplus::bus::match_t matchRemoved;
108 
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);
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     {
119         namespace MatchRules = sdbusplus::bus::match::rules;
120 
121         std::string matchStmt =
122             MatchRules::interfacesRemoved() +
123             MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION);
124 
125         return matchStmt;
126     }
127 };
128 } // namespace monitor
129 } // namespace fault
130 } // namespace fru
131 } // namespace led
132 } // namespace phosphor
133