xref: /openbmc/phosphor-led-manager/fault-monitor/operational-status-monitor.cpp (revision 405ea28684703dfc609ad8a42c853a5a609fa61c)
1ee1c19e5SGeorge Liu #include "operational-status-monitor.hpp"
2ee1c19e5SGeorge Liu 
3ee1c19e5SGeorge Liu #include <phosphor-logging/elog.hpp>
4e9fb5c6aSGeorge Liu #include <phosphor-logging/lg2.hpp>
5ee1c19e5SGeorge Liu 
6ee1c19e5SGeorge Liu namespace phosphor
7ee1c19e5SGeorge Liu {
8ee1c19e5SGeorge Liu namespace led
9ee1c19e5SGeorge Liu {
10ee1c19e5SGeorge Liu namespace Operational
11ee1c19e5SGeorge Liu {
12ee1c19e5SGeorge Liu namespace status
13ee1c19e5SGeorge Liu {
14ee1c19e5SGeorge Liu namespace monitor
15ee1c19e5SGeorge Liu {
16ee1c19e5SGeorge Liu 
matchHandler(sdbusplus::message_t & msg)173e073ba6SPatrick Williams void Monitor::matchHandler(sdbusplus::message_t& msg)
18ee1c19e5SGeorge Liu {
19ee1c19e5SGeorge Liu     // Get the ObjectPath of the `xyz.openbmc_project.Inventory.Manager`
20ee1c19e5SGeorge Liu     // service
21ee1c19e5SGeorge Liu     std::string invObjectPath = msg.get_path();
22ee1c19e5SGeorge Liu 
23ee1c19e5SGeorge Liu     // Get all the properties of
24ee1c19e5SGeorge Liu     // "xyz.openbmc_project.State.Decorator.OperationalStatus" interface
25ee1c19e5SGeorge Liu     std::string interfaceName{};
26f2044037SPatrick Williams     std::unordered_map<std::string, std::variant<bool>> properties;
27ee1c19e5SGeorge Liu     msg.read(interfaceName, properties);
28ee1c19e5SGeorge Liu 
29ee1c19e5SGeorge Liu     const auto it = properties.find("Functional");
30ee1c19e5SGeorge Liu     if (it != properties.end())
31ee1c19e5SGeorge Liu     {
32ee1c19e5SGeorge Liu         const bool* value = std::get_if<bool>(&it->second);
33ee1c19e5SGeorge Liu         if (!value)
34ee1c19e5SGeorge Liu         {
35e9fb5c6aSGeorge Liu             lg2::error(
3694e894cbSManojkiran Eda                 "Failed to get the Functional property, INVENTORY_PATH = {PATH}",
37e9fb5c6aSGeorge Liu                 "PATH", invObjectPath);
38ee1c19e5SGeorge Liu             return;
39ee1c19e5SGeorge Liu         }
40ee1c19e5SGeorge Liu 
41ee1c19e5SGeorge Liu         // See if the Inventory D-Bus object has an association with LED groups
42ee1c19e5SGeorge Liu         // D-Bus object.
43ee1c19e5SGeorge Liu         auto ledGroupPath = getLedGroupPaths(invObjectPath);
44ee1c19e5SGeorge Liu         if (ledGroupPath.empty())
45ee1c19e5SGeorge Liu         {
46e9fb5c6aSGeorge Liu             lg2::info(
47e9fb5c6aSGeorge Liu                 "The inventory D-Bus object is not associated with the LED "
48e9fb5c6aSGeorge Liu                 "group D-Bus object. INVENTORY_PATH = {PATH}",
49e9fb5c6aSGeorge Liu                 "PATH", invObjectPath);
50ee1c19e5SGeorge Liu             return;
51ee1c19e5SGeorge Liu         }
52ee1c19e5SGeorge Liu 
53ee1c19e5SGeorge Liu         // Update the Asserted property by the Functional property value.
54ee1c19e5SGeorge Liu         updateAssertedProperty(ledGroupPath, *value);
55ee1c19e5SGeorge Liu     }
56ee1c19e5SGeorge Liu }
57ee1c19e5SGeorge Liu 
58*405ea286SGeorge Liu std::vector<std::string>
getLedGroupPaths(const std::string & inventoryPath) const59ee1c19e5SGeorge Liu     Monitor::getLedGroupPaths(const std::string& inventoryPath) const
60ee1c19e5SGeorge Liu {
61fcf3a9d0SPriyanga Ramasamy     // Get endpoints from fType
62fcf3a9d0SPriyanga Ramasamy     std::string faultLedAssociation = inventoryPath + "/fault_identifying";
63ee1c19e5SGeorge Liu 
64ee1c19e5SGeorge Liu     // endpoint contains the vector of strings, where each string is a Inventory
65ee1c19e5SGeorge Liu     // D-Bus object that this, associated with this LED Group D-Bus object
66ee1c19e5SGeorge Liu     // pointed to by fru_fault
67ee1c19e5SGeorge Liu     PropertyValue endpoint{};
68ee1c19e5SGeorge Liu 
69ee1c19e5SGeorge Liu     try
70ee1c19e5SGeorge Liu     {
71ee1c19e5SGeorge Liu         endpoint = dBusHandler.getProperty(faultLedAssociation,
72ee1c19e5SGeorge Liu                                            "xyz.openbmc_project.Association",
73ee1c19e5SGeorge Liu                                            "endpoints");
74ee1c19e5SGeorge Liu     }
753e073ba6SPatrick Williams     catch (const sdbusplus::exception_t& e)
76ee1c19e5SGeorge Liu     {
77e9fb5c6aSGeorge Liu         lg2::error(
78e9fb5c6aSGeorge Liu             "Failed to get endpoints property, ERROR = {ERROR}, PATH = {PATH}",
79e9fb5c6aSGeorge Liu             "ERROR", e, "PATH", faultLedAssociation);
80ee1c19e5SGeorge Liu 
81ee1c19e5SGeorge Liu         return {};
82ee1c19e5SGeorge Liu     }
83ee1c19e5SGeorge Liu 
84c5e0f31cSGeorge Liu     return std::get<std::vector<std::string>>(endpoint);
85ee1c19e5SGeorge Liu }
86ee1c19e5SGeorge Liu 
updateAssertedProperty(const std::vector<std::string> & ledGroupPaths,bool value)87ee1c19e5SGeorge Liu void Monitor::updateAssertedProperty(
88ee1c19e5SGeorge Liu     const std::vector<std::string>& ledGroupPaths, bool value)
89ee1c19e5SGeorge Liu {
90ee1c19e5SGeorge Liu     for (const auto& path : ledGroupPaths)
91ee1c19e5SGeorge Liu     {
92ee1c19e5SGeorge Liu         try
93ee1c19e5SGeorge Liu         {
94ee1c19e5SGeorge Liu             // Call "Group Asserted --> true" if the value of Functional is
95ee1c19e5SGeorge Liu             // false Call "Group Asserted --> false" if the value of Functional
96ee1c19e5SGeorge Liu             // is true
97ee1c19e5SGeorge Liu             PropertyValue assertedValue{!value};
98ee1c19e5SGeorge Liu             dBusHandler.setProperty(path, "xyz.openbmc_project.Led.Group",
99ee1c19e5SGeorge Liu                                     "Asserted", assertedValue);
100ee1c19e5SGeorge Liu         }
1013e073ba6SPatrick Williams         catch (const sdbusplus::exception_t& e)
102ee1c19e5SGeorge Liu         {
103e9fb5c6aSGeorge Liu             lg2::error(
104e9fb5c6aSGeorge Liu                 "Failed to set Asserted property, ERROR = {ERROR}, PATH = {PATH}",
105e9fb5c6aSGeorge Liu                 "ERROR", e, "PATH", path);
106ee1c19e5SGeorge Liu         }
107ee1c19e5SGeorge Liu     }
108ee1c19e5SGeorge Liu }
109ee1c19e5SGeorge Liu } // namespace monitor
110ee1c19e5SGeorge Liu } // namespace status
111ee1c19e5SGeorge Liu } // namespace Operational
112ee1c19e5SGeorge Liu } // namespace led
113ee1c19e5SGeorge Liu } // namespace phosphor
114