blob: b6865602f6b69452798d72f88c2a8a3c955c5618 [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 {
56 //Do nothing
57 }
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 Subhashchandran59b86cd2017-04-13 00:19:44 -050069};
70
71/** @class Remove
72 * @brief Implementation of LED handling after resolution of FRU fault
73 * @details Implement methods for watching the resolution of FRU faults
74 * and deasserting corresponding LED.
75 */
76class Remove
77{
78 public:
79 Remove() = delete;
80 ~Remove() = default;
81 Remove(const Remove&) = delete;
82 Remove& operator=(const Remove&) = delete;
83 Remove(Remove&&) = default;
84 Remove& operator=(Remove&&) = default;
85
86 /** @brief constructs Remove
87 * @param[in] bus - The Dbus bus object
88 * @param[in] path - Inventory path to fru
89 */
90 Remove(sdbusplus::bus::bus& bus, const std::string& path):
91 inventoryPath(path),
92 matchRemoved(
93 bus,
Patrick Williams3eedbe42017-05-31 17:27:05 -050094 match(path),
95 std::bind(std::mem_fn(&Remove::removed),
96 this, std::placeholders::_1))
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -050097 {
98 //Do nothing
99 }
100
101 private:
102
103 /** @brief inventory path of the FRU */
104 std::string inventoryPath;
105
106 /** @brief sdbusplus signal matches for fault removed */
Patrick Williams3eedbe42017-05-31 17:27:05 -0500107 sdbusplus::bus::match_t matchRemoved;
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500108
109 /** @brief Callback function for fru fault created
110 * @param[in] msg - Data associated with subscribed signal
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500111 */
Patrick Williams3eedbe42017-05-31 17:27:05 -0500112 void removed(sdbusplus::message::message& msg);
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500113
114 /** @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 {
Patrick Williams3eedbe42017-05-31 17:27:05 -0500119 namespace MatchRules = sdbusplus::bus::match::rules;
120
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500121 std::string matchStmt =
Patrick Williams3eedbe42017-05-31 17:27:05 -0500122 MatchRules::type::signal() +
123 MatchRules::interface("org.freedesktop.DBus.Properties") +
124 MatchRules::member("PropertiesChanged") +
125 MatchRules::path(path + "/" + CALLOUT_REV_ASSOCIATION);
126
Dhruvaraj Subhashchandran59b86cd2017-04-13 00:19:44 -0500127 return matchStmt;
128 }
129};
130}//namespace monitor
131}//namespace fault
132}//namespace fru
133}//namespace led
134}//namespace phosphor