George Liu | ee1c19e | 2021-04-01 15:02:57 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "../utils.hpp" |
| 4 | |
| 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/server.hpp> |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace led |
| 11 | { |
| 12 | namespace Operational |
| 13 | { |
| 14 | namespace status |
| 15 | { |
| 16 | namespace monitor |
| 17 | { |
| 18 | using 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 | */ |
| 28 | class 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 Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 42 | explicit Monitor(sdbusplus::bus_t& bus) : |
George Liu | ee1c19e | 2021-04-01 15:02:57 +0800 | [diff] [blame] | 43 | 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 Liu | 226059b | 2024-08-22 16:01:44 +0800 | [diff] [blame] | 50 | [this](sdbusplus::message_t& m) { matchHandler(m); }) |
George Liu | ee1c19e | 2021-04-01 15:02:57 +0800 | [diff] [blame] | 51 | |
| 52 | {} |
| 53 | |
| 54 | private: |
| 55 | /** @brief sdbusplus D-Bus connection. */ |
Patrick Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 56 | sdbusplus::bus_t& bus; |
George Liu | ee1c19e | 2021-04-01 15:02:57 +0800 | [diff] [blame] | 57 | |
| 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 Williams | 3e073ba | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 72 | void matchHandler(sdbusplus::message_t& msg); |
George Liu | ee1c19e | 2021-04-01 15:02:57 +0800 | [diff] [blame] | 73 | |
| 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 | */ |
George Liu | 405ea28 | 2024-08-22 19:36:41 +0800 | [diff] [blame^] | 82 | std::vector<std::string> |
George Liu | ee1c19e | 2021-04-01 15:02:57 +0800 | [diff] [blame] | 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 |