blob: 77d3be217b3a747bd9a9f4245528079494359679 [file] [log] [blame]
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server.hpp>
5#include "config.h"
6
7namespace phosphor
8{
9namespace led
10{
11namespace fru
12{
13namespace fault
14{
15namespace monitor
16{
17
18/** @brief Assert or deassert an LED based on the input FRU
19 * @param[in] bus - The Dbus bus object
20 * @param[in] path - Inventory path of the FRU
21 * @param[in] assert - Assert if true deassert if false
22 */
23void action(sdbusplus::bus::bus& bus,
24 const std::string& path,
25 bool assert);
26
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{
36 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;
43
44 /** @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,
Patrick Williams3eedbe42017-05-31 17:27:05 -050050 sdbusplus::bus::match::rules::interfacesAdded() +
51 sdbusplus::bus::match::rules::path_namespace(
52 "/xyz/openbmc_project/logging"),
53 std::bind(std::mem_fn(&Add::created),
54 this, std::placeholders::_1))
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050055 {
Dhruvaraj Subhashchandran891c4762017-07-31 14:26:37 -050056 processExistingCallouts(bus);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050057 }
58 private:
59
60 /** @brief sdbusplus signal match for fault created */
Patrick Williams3eedbe42017-05-31 17:27:05 -050061 sdbusplus::bus::match_t matchCreated;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050062
63 std::vector<std::unique_ptr<Remove>> removeWatches;
64
65 /** @brief Callback function for fru fault created
66 * @param[in] msg - Data associated with subscribed signal
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050067 */
Patrick Williams3eedbe42017-05-31 17:27:05 -050068 void created(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran891c4762017-07-31 14:26:37 -050069
70 /** @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{
83 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;
90
91 /** @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(
98 bus,
Patrick Williams3eedbe42017-05-31 17:27:05 -050099 match(path),
100 std::bind(std::mem_fn(&Remove::removed),
101 this, std::placeholders::_1))
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500102 {
103 //Do nothing
104 }
105
106 private:
107
108 /** @brief inventory path of the FRU */
109 std::string inventoryPath;
110
111 /** @brief sdbusplus signal matches for fault removed */
Patrick Williams3eedbe42017-05-31 17:27:05 -0500112 sdbusplus::bus::match_t matchRemoved;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500113
114 /** @brief Callback function for fru fault created
115 * @param[in] msg - Data associated with subscribed signal
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500116 */
Patrick Williams3eedbe42017-05-31 17:27:05 -0500117 void removed(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500118
119 /** @brief function to create fault remove match for a fru
120 * @param[in] path - Inventory path of the faulty unit.
121 */
122 std::string match(const std::string& path)
123 {
Patrick Williams3eedbe42017-05-31 17:27:05 -0500124 namespace MatchRules = sdbusplus::bus::match::rules;
125
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500126 std::string matchStmt =
Matt Spinler9f782242017-11-06 12:32:35 -0600127 MatchRules::interfacesRemoved() +
128 MatchRules::argNpath(
129 0, path + "/" + CALLOUT_REV_ASSOCIATION);
Patrick Williams3eedbe42017-05-31 17:27:05 -0500130
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500131 return matchStmt;
132 }
133};
134}//namespace monitor
135}//namespace fault
136}//namespace fru
137}//namespace led
138}//namespace phosphor