blob: 2a1081284a33f209f3b7b5e869edf11f9cf03b30 [file] [log] [blame]
George Liuee1c19e2021-04-01 15:02:57 +08001#include "operational-status-monitor.hpp"
2
3#include <phosphor-logging/elog.hpp>
George Liue9fb5c62021-07-01 14:05:32 +08004#include <phosphor-logging/lg2.hpp>
George Liuee1c19e2021-04-01 15:02:57 +08005
6namespace phosphor
7{
8namespace led
9{
10namespace Operational
11{
12namespace status
13{
14namespace monitor
15{
George Liuee1c19e2021-04-01 15:02:57 +080016
Patrick Williams3e073ba2022-07-22 19:26:52 -050017void Monitor::matchHandler(sdbusplus::message_t& msg)
George Liuee1c19e2021-04-01 15:02:57 +080018{
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 Williamsf2044032022-03-17 05:12:30 -050026 std::unordered_map<std::string, std::variant<bool>> properties;
George Liuee1c19e2021-04-01 15:02:57 +080027 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);
Konstantin Aladyshevfecdd4d2025-02-07 12:28:19 +030033 if (value == nullptr)
George Liuee1c19e2021-04-01 15:02:57 +080034 {
George Liue9fb5c62021-07-01 14:05:32 +080035 lg2::error(
Manojkiran Eda94e894c2024-06-17 11:44:39 +053036 "Failed to get the Functional property, INVENTORY_PATH = {PATH}",
George Liue9fb5c62021-07-01 14:05:32 +080037 "PATH", invObjectPath);
George Liuee1c19e2021-04-01 15:02:57 +080038 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 Liue9fb5c62021-07-01 14:05:32 +080046 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 Liuee1c19e2021-04-01 15:02:57 +080050 return;
51 }
52
53 // Update the Asserted property by the Functional property value.
54 updateAssertedProperty(ledGroupPath, *value);
55 }
56}
57
Patrick Williams275ad182025-03-03 11:19:17 -050058std::vector<std::string> Monitor::getLedGroupPaths(
59 const std::string& inventoryPath)
George Liuee1c19e2021-04-01 15:02:57 +080060{
Priyanga Ramasamyfcf3a9d2023-05-24 02:37:43 -050061 // Get endpoints from fType
62 std::string faultLedAssociation = inventoryPath + "/fault_identifying";
George Liuee1c19e2021-04-01 15:02:57 +080063
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 {
Konstantin Aladyshevfecdd4d2025-02-07 12:28:19 +030071 endpoint = phosphor::led::utils::DBusHandler::getProperty(
72 faultLedAssociation, "xyz.openbmc_project.Association",
73 "endpoints");
George Liuee1c19e2021-04-01 15:02:57 +080074 }
Patrick Williams3e073ba2022-07-22 19:26:52 -050075 catch (const sdbusplus::exception_t& e)
George Liuee1c19e2021-04-01 15:02:57 +080076 {
George Liue9fb5c62021-07-01 14:05:32 +080077 lg2::error(
78 "Failed to get endpoints property, ERROR = {ERROR}, PATH = {PATH}",
79 "ERROR", e, "PATH", faultLedAssociation);
George Liuee1c19e2021-04-01 15:02:57 +080080
81 return {};
82 }
83
George Liuc5e0f312021-12-27 15:54:31 +080084 return std::get<std::vector<std::string>>(endpoint);
George Liuee1c19e2021-04-01 15:02:57 +080085}
86
87void 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};
Konstantin Aladyshevfecdd4d2025-02-07 12:28:19 +030098 phosphor::led::utils::DBusHandler::setProperty(
99 path, "xyz.openbmc_project.Led.Group", "Asserted",
100 assertedValue);
George Liuee1c19e2021-04-01 15:02:57 +0800101 }
Patrick Williams3e073ba2022-07-22 19:26:52 -0500102 catch (const sdbusplus::exception_t& e)
George Liuee1c19e2021-04-01 15:02:57 +0800103 {
George Liue9fb5c62021-07-01 14:05:32 +0800104 lg2::error(
105 "Failed to set Asserted property, ERROR = {ERROR}, PATH = {PATH}",
106 "ERROR", e, "PATH", path);
George Liuee1c19e2021-04-01 15:02:57 +0800107 }
108 }
109}
110} // namespace monitor
111} // namespace status
112} // namespace Operational
113} // namespace led
114} // namespace phosphor