blob: 3b67edbeb5e845c22b0a7f37d6596a0bdb1b09c8 [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'",
50 std::bind(std::mem_fn(&Monitor::matchHandler), this,
51 std::placeholders::_1))
52
53 {}
54
55 private:
56 /** @brief sdbusplus D-Bus connection. */
Patrick Williams3e073ba2022-07-22 19:26:52 -050057 sdbusplus::bus_t& bus;
George Liuee1c19e2021-04-01 15:02:57 +080058
59 /** @brief sdbusplus signal matches for Monitor */
60 sdbusplus::bus::match_t matchSignal;
61
62 /** DBusHandler class handles the D-Bus operations */
63 DBusHandler dBusHandler;
64
65 /**
66 * @brief Callback handler that gets invoked when the PropertiesChanged
67 * signal is caught by this app. Message is scanned for Inventory
68 * D-Bus object path and if OperationalStatus::Functional is changed,
69 * then corresponding LED Group D-Bus object is called to assert.
70 *
71 * @param[in] msg - The D-Bus message contents
72 */
Patrick Williams3e073ba2022-07-22 19:26:52 -050073 void matchHandler(sdbusplus::message_t& msg);
George Liuee1c19e2021-04-01 15:02:57 +080074
75 /**
76 * @brief From the Inventory D-Bus object, obtains the associated LED group
77 * D-Bus object, where the association name is "fault_led_group"
78 *
79 * @param[in] inventoryPath - Inventory D-Bus object path
80 *
81 * @return std::vector<std::string> - Vector of LED Group D-Bus object paths
82 */
83 const std::vector<std::string>
84 getLedGroupPaths(const std::string& inventoryPath) const;
85
86 /**
87 * @brief Update the Asserted property of the LED Group Manager.
88 *
89 * @param[in] ledGroupPaths - LED Group D-Bus object Paths
90 * @param[in] value - The Asserted property value, True / False
91 */
92 void updateAssertedProperty(const std::vector<std::string>& ledGroupPaths,
93 bool value);
94};
95} // namespace monitor
96} // namespace status
97} // namespace Operational
98} // namespace led
99} // namespace phosphor