blob: d8ec721c2baccc4d6e335c0ca9b9d79c5c062161 [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>
Andrew Geisslerd02c3cb2020-05-16 10:28:02 -05007#include <string>
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05008
9namespace phosphor
10{
11namespace led
12{
13namespace fru
14{
15namespace fault
16{
17namespace monitor
18{
19
20/** @brief Assert or deassert an LED based on the input FRU
Patrick Venture91ac8d32018-11-01 17:03:22 -070021 * @param[in] bus - The Dbus bus object
22 * @param[in] path - Inventory path of the FRU
23 * @param[in] assert - Assert if true deassert if false
24 */
25void action(sdbusplus::bus::bus& bus, const std::string& path, bool assert);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050026
27class 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 */
34class Add
35{
Patrick Venture91ac8d32018-11-01 17:03:22 -070036 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;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050043
Patrick Venture91ac8d32018-11-01 17:03:22 -070044 /** @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 sdbusplus::bus::match::rules::interfacesAdded() +
Patrick Williams3eedbe42017-05-31 17:27:05 -050051 sdbusplus::bus::match::rules::path_namespace(
Patrick Venture91ac8d32018-11-01 17:03:22 -070052 "/xyz/openbmc_project/logging"),
53 std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
54 {
55 processExistingCallouts(bus);
56 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050057
Patrick Venture91ac8d32018-11-01 17:03:22 -070058 private:
59 /** @brief sdbusplus signal match for fault created */
60 sdbusplus::bus::match_t matchCreated;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050061
Patrick Venture91ac8d32018-11-01 17:03:22 -070062 std::vector<std::unique_ptr<Remove>> removeWatches;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050063
Patrick Venture91ac8d32018-11-01 17:03:22 -070064 /** @brief Callback function for fru fault created
65 * @param[in] msg - Data associated with subscribed signal
66 */
67 void created(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran891c4762017-07-31 14:26:37 -050068
Patrick Venture91ac8d32018-11-01 17:03:22 -070069 /** @brief This function process all callouts at application start
70 * @param[in] bus - The Dbus bus object
71 */
72 void processExistingCallouts(sdbusplus::bus::bus& bus);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050073};
74
75/** @class Remove
76 * @brief Implementation of LED handling after resolution of FRU fault
77 * @details Implement methods for watching the resolution of FRU faults
78 * and deasserting corresponding LED.
79 */
80class Remove
81{
Patrick Venture91ac8d32018-11-01 17:03:22 -070082 public:
83 Remove() = delete;
84 ~Remove() = default;
85 Remove(const Remove&) = delete;
86 Remove& operator=(const Remove&) = delete;
87 Remove(Remove&&) = default;
88 Remove& operator=(Remove&&) = default;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050089
Patrick Venture91ac8d32018-11-01 17:03:22 -070090 /** @brief constructs Remove
91 * @param[in] bus - The Dbus bus object
92 * @param[in] path - Inventory path to fru
93 */
94 Remove(sdbusplus::bus::bus& bus, const std::string& path) :
95 inventoryPath(path),
96 matchRemoved(bus, match(path),
97 std::bind(std::mem_fn(&Remove::removed), this,
98 std::placeholders::_1))
99 {
100 // Do nothing
101 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500102
Patrick Venture91ac8d32018-11-01 17:03:22 -0700103 private:
104 /** @brief inventory path of the FRU */
105 std::string inventoryPath;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500106
Patrick Venture91ac8d32018-11-01 17:03:22 -0700107 /** @brief sdbusplus signal matches for fault removed */
108 sdbusplus::bus::match_t matchRemoved;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500109
Patrick Venture91ac8d32018-11-01 17:03:22 -0700110 /** @brief Callback function for fru fault created
111 * @param[in] msg - Data associated with subscribed signal
112 */
113 void removed(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500114
Patrick Venture91ac8d32018-11-01 17:03:22 -0700115 /** @brief function to create fault remove match for a fru
116 * @param[in] path - Inventory path of the faulty unit.
117 */
118 std::string match(const std::string& path)
119 {
120 namespace MatchRules = sdbusplus::bus::match::rules;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500121
Patrick Venture91ac8d32018-11-01 17:03:22 -0700122 std::string matchStmt =
123 MatchRules::interfacesRemoved() +
124 MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION);
Patrick Williams3eedbe42017-05-31 17:27:05 -0500125
Patrick Venture91ac8d32018-11-01 17:03:22 -0700126 return matchStmt;
127 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500128};
Patrick Venture91ac8d32018-11-01 17:03:22 -0700129} // namespace monitor
130} // namespace fault
131} // namespace fru
132} // namespace led
133} // namespace phosphor