blob: 6bd2efc37ebbc135e2e1677147d8109ac2f2c911 [file] [log] [blame]
George Liuee1c19e2021-04-01 15:02:57 +08001#pragma once
2
3#include "../utils.hpp"
4
5#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server.hpp>
7
8namespace phosphor
9{
10namespace led
11{
12namespace Operational
13{
14namespace status
15{
16namespace monitor
17{
18using namespace phosphor::led::utils;
19
20/** @class Monitor
21 * @brief Implementation of LED handling during the change of the Functional
22 * property of the OperationalStatus interface
23 *
24 * @details This implements methods for watching OperationalStatus interface of
25 * Inventory D-Bus object and then assert corresponding LED Group
26 * D-Bus objects.
27 */
28class Monitor
29{
30 public:
31 Monitor() = delete;
32 ~Monitor() = default;
33 Monitor(const Monitor&) = delete;
34 Monitor& operator=(const Monitor&) = delete;
35 Monitor(Monitor&&) = default;
36 Monitor& operator=(Monitor&&) = default;
37
38 /** @brief Add a watch for OperationalStatus.
39 *
40 * @param[in] bus - D-Bus object
41 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050042 explicit Monitor(sdbusplus::bus_t& bus) :
George Liuee1c19e2021-04-01 15:02:57 +080043 bus(bus),
44 matchSignal(bus,
45 "type='signal',member='PropertiesChanged', "
46 "interface='org.freedesktop.DBus.Properties', "
47 "sender='xyz.openbmc_project.Inventory.Manager', "
48 "arg0namespace='xyz.openbmc_project.State.Decorator."
49 "OperationalStatus'",
George Liu226059b2024-08-22 16:01:44 +080050 [this](sdbusplus::message_t& m) { matchHandler(m); })
George Liuee1c19e2021-04-01 15:02:57 +080051
52 {}
53
54 private:
55 /** @brief sdbusplus D-Bus connection. */
Patrick Williams3e073ba2022-07-22 19:26:52 -050056 sdbusplus::bus_t& bus;
George Liuee1c19e2021-04-01 15:02:57 +080057
58 /** @brief sdbusplus signal matches for Monitor */
59 sdbusplus::bus::match_t matchSignal;
60
61 /** DBusHandler class handles the D-Bus operations */
62 DBusHandler dBusHandler;
63
64 /**
65 * @brief Callback handler that gets invoked when the PropertiesChanged
66 * signal is caught by this app. Message is scanned for Inventory
67 * D-Bus object path and if OperationalStatus::Functional is changed,
68 * then corresponding LED Group D-Bus object is called to assert.
69 *
70 * @param[in] msg - The D-Bus message contents
71 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050072 void matchHandler(sdbusplus::message_t& msg);
George Liuee1c19e2021-04-01 15:02:57 +080073
74 /**
75 * @brief From the Inventory D-Bus object, obtains the associated LED group
76 * D-Bus object, where the association name is "fault_led_group"
77 *
78 * @param[in] inventoryPath - Inventory D-Bus object path
79 *
80 * @return std::vector<std::string> - Vector of LED Group D-Bus object paths
81 */
82 const std::vector<std::string>
83 getLedGroupPaths(const std::string& inventoryPath) const;
84
85 /**
86 * @brief Update the Asserted property of the LED Group Manager.
87 *
88 * @param[in] ledGroupPaths - LED Group D-Bus object Paths
89 * @param[in] value - The Asserted property value, True / False
90 */
91 void updateAssertedProperty(const std::vector<std::string>& ledGroupPaths,
92 bool value);
93};
94} // namespace monitor
95} // namespace status
96} // namespace Operational
97} // namespace led
98} // namespace phosphor