blob: 54eb6552f9cd442875abbc575d6d4a0b16f5cbf5 [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>
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05007
8namespace phosphor
9{
10namespace led
11{
12namespace fru
13{
14namespace fault
15{
16namespace monitor
17{
18
19/** @brief Assert or deassert an LED based on the input FRU
Patrick Venture91ac8d32018-11-01 17:03:22 -070020 * @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 */
24void action(sdbusplus::bus::bus& bus, const std::string& path, bool assert);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050025
26class 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 */
33class Add
34{
Patrick Venture91ac8d32018-11-01 17:03:22 -070035 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;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050042
Patrick Venture91ac8d32018-11-01 17:03:22 -070043 /** @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() +
Patrick Williams3eedbe42017-05-31 17:27:05 -050050 sdbusplus::bus::match::rules::path_namespace(
Patrick Venture91ac8d32018-11-01 17:03:22 -070051 "/xyz/openbmc_project/logging"),
52 std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
53 {
54 processExistingCallouts(bus);
55 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050056
Patrick Venture91ac8d32018-11-01 17:03:22 -070057 private:
58 /** @brief sdbusplus signal match for fault created */
59 sdbusplus::bus::match_t matchCreated;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050060
Patrick Venture91ac8d32018-11-01 17:03:22 -070061 std::vector<std::unique_ptr<Remove>> removeWatches;
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 */
66 void created(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran891c4762017-07-31 14:26:37 -050067
Patrick Venture91ac8d32018-11-01 17:03:22 -070068 /** @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);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050072};
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 */
79class Remove
80{
Patrick Venture91ac8d32018-11-01 17:03:22 -070081 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;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050088
Patrick Venture91ac8d32018-11-01 17:03:22 -070089 /** @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 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500101
Patrick Venture91ac8d32018-11-01 17:03:22 -0700102 private:
103 /** @brief inventory path of the FRU */
104 std::string inventoryPath;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500105
Patrick Venture91ac8d32018-11-01 17:03:22 -0700106 /** @brief sdbusplus signal matches for fault removed */
107 sdbusplus::bus::match_t matchRemoved;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500108
Patrick Venture91ac8d32018-11-01 17:03:22 -0700109 /** @brief Callback function for fru fault created
110 * @param[in] msg - Data associated with subscribed signal
111 */
112 void removed(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500113
Patrick Venture91ac8d32018-11-01 17:03:22 -0700114 /** @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;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500120
Patrick Venture91ac8d32018-11-01 17:03:22 -0700121 std::string matchStmt =
122 MatchRules::interfacesRemoved() +
123 MatchRules::argNpath(0, path + "/" + CALLOUT_REV_ASSOCIATION);
Patrick Williams3eedbe42017-05-31 17:27:05 -0500124
Patrick Venture91ac8d32018-11-01 17:03:22 -0700125 return matchStmt;
126 }
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500127};
Patrick Venture91ac8d32018-11-01 17:03:22 -0700128} // namespace monitor
129} // namespace fault
130} // namespace fru
131} // namespace led
132} // namespace phosphor