blob: 923a0f9e6e2985f96ee26381f20f217de18efb54 [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 */
26void action(sdbusplus::bus::bus& bus, const std::string& path, bool assert);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050027
28class 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 */
35class Add
36{
Patrick Venture91ac8d32018-11-01 17:03:22 -070037 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;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050044
Patrick Venture91ac8d32018-11-01 17:03:22 -070045 /** @brief constructs Add a watch for FRU faults.
46 * @param[in] bus - The Dbus bus object
47 */
George Liuc5e0f312021-12-27 15:54:31 +080048 explicit Add(sdbusplus::bus::bus& bus) :
Patrick Venture91ac8d32018-11-01 17:03:22 -070049 matchCreated(
50 bus,
51 sdbusplus::bus::match::rules::interfacesAdded() +
Patrick Williams3eedbe42017-05-31 17:27:05 -050052 sdbusplus::bus::match::rules::path_namespace(
Patrick Venture91ac8d32018-11-01 17:03:22 -070053 "/xyz/openbmc_project/logging"),
54 std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
55 {
56 processExistingCallouts(bus);
57 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050058
Patrick Venture91ac8d32018-11-01 17:03:22 -070059 private:
60 /** @brief sdbusplus signal match for fault created */
61 sdbusplus::bus::match_t matchCreated;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050062
Patrick Venture91ac8d32018-11-01 17:03:22 -070063 std::vector<std::unique_ptr<Remove>> removeWatches;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050064
Patrick Venture91ac8d32018-11-01 17:03:22 -070065 /** @brief Callback function for fru fault created
66 * @param[in] msg - Data associated with subscribed signal
67 */
68 void created(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran891c4762017-07-31 14:26:37 -050069
Patrick Venture91ac8d32018-11-01 17:03:22 -070070 /** @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 Subhashchandran59b86cd2017-04-13 00:19:44 -050074};
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 */
81class Remove
82{
Patrick Venture91ac8d32018-11-01 17:03:22 -070083 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;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050090
Patrick Venture91ac8d32018-11-01 17:03:22 -070091 /** @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(bus, match(path),
98 std::bind(std::mem_fn(&Remove::removed), this,
99 std::placeholders::_1))
100 {
101 // Do nothing
102 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500103
Patrick Venture91ac8d32018-11-01 17:03:22 -0700104 private:
105 /** @brief inventory path of the FRU */
106 std::string inventoryPath;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500107
Patrick Venture91ac8d32018-11-01 17:03:22 -0700108 /** @brief sdbusplus signal matches for fault removed */
109 sdbusplus::bus::match_t matchRemoved;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500110
Patrick Venture91ac8d32018-11-01 17:03:22 -0700111 /** @brief Callback function for fru fault created
112 * @param[in] msg - Data associated with subscribed signal
113 */
114 void removed(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500115
Patrick Venture91ac8d32018-11-01 17:03:22 -0700116 /** @brief function to create fault remove match for a fru
117 * @param[in] path - Inventory path of the faulty unit.
118 */
119 std::string match(const std::string& path)
120 {
121 namespace MatchRules = sdbusplus::bus::match::rules;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500122
Patrick Venture91ac8d32018-11-01 17:03:22 -0700123 std::string matchStmt =
124 MatchRules::interfacesRemoved() +
125 MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION);
Patrick Williams3eedbe42017-05-31 17:27:05 -0500126
Patrick Venture91ac8d32018-11-01 17:03:22 -0700127 return matchStmt;
128 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500129};
Patrick Venture91ac8d32018-11-01 17:03:22 -0700130} // namespace monitor
131} // namespace fault
132} // namespace fru
133} // namespace led
134} // namespace phosphor