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      */
Monitor(sdbusplus::bus_t & bus)42     explicit Monitor(sdbusplus::bus_t& bus) :
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'",
50                     std::bind(std::mem_fn(&Monitor::matchHandler), this,
51                               std::placeholders::_1))
52 
53     {}
54 
55   private:
56     /** @brief sdbusplus D-Bus connection. */
57     sdbusplus::bus_t& bus;
58 
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      */
73     void matchHandler(sdbusplus::message_t& msg);
74 
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
100