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