blob: e5ddc5374738d1d82a5ecb8c11dbaa521631ae65 [file] [log] [blame]
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05001#pragma once
2
Patrick Venture91ac8d32018-11-01 17:03:22 -07003#include "config.h"
4
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05005#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server.hpp>
George Liua6c18f82020-06-22 10:50:04 +08007
Andrew Geisslerd02c3cb2020-05-16 10:28:02 -05008#include <string>
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05009
10namespace phosphor
11{
12namespace led
13{
14namespace fru
15{
16namespace fault
17{
18namespace monitor
19{
20
21/** @brief Assert or deassert an LED based on the input FRU
Patrick Venture91ac8d32018-11-01 17:03:22 -070022 * @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 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050026void action(sdbusplus::bus_t& bus, const std::string& path, bool assert);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050027
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050028/** @class Remove
29 * @brief Implementation of LED handling after resolution of FRU fault
30 * @details Implement methods for watching the resolution of FRU faults
31 * and deasserting corresponding LED.
32 */
33class Remove
34{
Patrick Venture91ac8d32018-11-01 17:03:22 -070035 public:
36 Remove() = delete;
37 ~Remove() = default;
38 Remove(const Remove&) = delete;
39 Remove& operator=(const Remove&) = delete;
40 Remove(Remove&&) = default;
41 Remove& operator=(Remove&&) = default;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050042
Patrick Venture91ac8d32018-11-01 17:03:22 -070043 /** @brief constructs Remove
44 * @param[in] bus - The Dbus bus object
45 * @param[in] path - Inventory path to fru
46 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050047 Remove(sdbusplus::bus_t& bus, const std::string& path) :
Patrick Venture91ac8d32018-11-01 17:03:22 -070048 inventoryPath(path),
49 matchRemoved(bus, match(path),
50 std::bind(std::mem_fn(&Remove::removed), this,
51 std::placeholders::_1))
52 {
53 // Do nothing
54 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050055
Patrick Venture91ac8d32018-11-01 17:03:22 -070056 private:
57 /** @brief inventory path of the FRU */
58 std::string inventoryPath;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050059
Patrick Venture91ac8d32018-11-01 17:03:22 -070060 /** @brief sdbusplus signal matches for fault removed */
61 sdbusplus::bus::match_t matchRemoved;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050062
Patrick Venture91ac8d32018-11-01 17:03:22 -070063 /** @brief Callback function for fru fault created
64 * @param[in] msg - Data associated with subscribed signal
65 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050066 void removed(sdbusplus::message_t& msg);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050067
Patrick Venture91ac8d32018-11-01 17:03:22 -070068 /** @brief function to create fault remove match for a fru
69 * @param[in] path - Inventory path of the faulty unit.
70 */
71 std::string match(const std::string& path)
72 {
73 namespace MatchRules = sdbusplus::bus::match::rules;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050074
Patrick Venture91ac8d32018-11-01 17:03:22 -070075 std::string matchStmt =
76 MatchRules::interfacesRemoved() +
77 MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION);
Patrick Williams3eedbe42017-05-31 17:27:05 -050078
Patrick Venture91ac8d32018-11-01 17:03:22 -070079 return matchStmt;
80 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050081};
George Liu191949c2024-07-22 15:17:49 +080082
83/** @class Add
84 * @brief Implementation of LED handling during FRU fault
85 * @details This implements methods for watching for a FRU fault
86 * being logged to assert the corresponding LED
87 */
88class Add
89{
90 public:
91 Add() = delete;
92 ~Add() = default;
93 Add(const Add&) = delete;
94 Add& operator=(const Add&) = delete;
95 Add(Add&&) = default;
96 Add& operator=(Add&&) = default;
97
98 /** @brief constructs Add a watch for FRU faults.
99 * @param[in] bus - The Dbus bus object
100 */
101 explicit Add(sdbusplus::bus_t& bus) :
102 matchCreated(
103 bus,
104 sdbusplus::bus::match::rules::interfacesAdded() +
105 sdbusplus::bus::match::rules::path_namespace(
106 "/xyz/openbmc_project/logging"),
107 std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
108 {
109 processExistingCallouts(bus);
110 }
111
112 private:
113 /** @brief sdbusplus signal match for fault created */
114 sdbusplus::bus::match_t matchCreated;
115
116 std::vector<std::unique_ptr<Remove>> removeWatches;
117
118 /** @brief Callback function for fru fault created
119 * @param[in] msg - Data associated with subscribed signal
120 */
121 void created(sdbusplus::message_t& msg);
122
123 /** @brief This function process all callouts at application start
124 * @param[in] bus - The Dbus bus object
125 */
126 void processExistingCallouts(sdbusplus::bus_t& bus);
127};
Patrick Venture91ac8d32018-11-01 17:03:22 -0700128} // namespace monitor
129} // namespace fault
130} // namespace fru
131} // namespace led
132} // namespace phosphor