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