Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 1 | #include <phosphor-logging/elog.hpp> |
| 2 | #include "xyz/openbmc_project/Led/Fru/Monitor/error.hpp" |
| 3 | #include "xyz/openbmc_project/Led/Mapper/error.hpp" |
| 4 | #include "elog-errors.hpp" |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 5 | #include "fru-fault-monitor.hpp" |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 6 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace led |
| 10 | { |
| 11 | namespace fru |
| 12 | { |
| 13 | namespace fault |
| 14 | { |
| 15 | namespace monitor |
| 16 | { |
| 17 | |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 18 | using namespace phosphor::logging; |
| 19 | |
| 20 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 21 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 22 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 23 | constexpr auto OBJMGR_IFACE = "org.freedesktop.DBus.ObjectManager"; |
| 24 | constexpr auto LED_GROUPS = "/xyz/openbmc_project/led/groups/"; |
| 25 | constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; |
| 26 | |
| 27 | using AssociationList = std::vector<std::tuple< |
| 28 | std::string, std::string, std::string>>; |
| 29 | using MethodErr = |
| 30 | sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError; |
| 31 | using ObjectNotFoundErr = |
| 32 | sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError; |
| 33 | using AssociationRetrieveErr = |
| 34 | sdbusplus::xyz::openbmc_project:: |
| 35 | Led::Fru::Monitor::Error::AssociationRetrieveError; |
| 36 | using InventoryPathErr = |
| 37 | sdbusplus::xyz::openbmc_project:: |
| 38 | Led::Fru::Monitor::Error::InventoryPathError; |
| 39 | |
| 40 | std::string getService(sdbusplus::bus::bus& bus, |
| 41 | const std::string& path) |
| 42 | { |
| 43 | auto mapper = bus.new_method_call(MAPPER_BUSNAME, |
| 44 | MAPPER_OBJ_PATH, |
| 45 | MAPPER_IFACE, "GetObject"); |
| 46 | mapper.append(path.c_str(), std::vector<std::string>({OBJMGR_IFACE})); |
| 47 | auto mapperResponseMsg = bus.call(mapper); |
| 48 | if (mapperResponseMsg.is_method_error()) |
| 49 | { |
| 50 | using namespace xyz::openbmc_project::Led::Mapper; |
| 51 | elog<MethodErr>( |
| 52 | MethodError::METHOD_NAME("GetObject"), |
| 53 | MethodError::PATH(path.c_str()), |
| 54 | MethodError::INTERFACE( |
| 55 | OBJMGR_IFACE)); |
| 56 | } |
| 57 | |
| 58 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 59 | mapperResponseMsg.read(mapperResponse); |
| 60 | if (mapperResponse.empty()) |
| 61 | { |
| 62 | using namespace xyz::openbmc_project::Led::Mapper; |
| 63 | elog<ObjectNotFoundErr>( |
| 64 | ObjectNotFoundError::METHOD_NAME("GetObject"), |
| 65 | ObjectNotFoundError::PATH(path.c_str()), |
| 66 | ObjectNotFoundError::INTERFACE( |
| 67 | OBJMGR_IFACE)); |
| 68 | } |
| 69 | |
| 70 | return mapperResponse.cbegin()->first; |
| 71 | } |
| 72 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 73 | void action(sdbusplus::bus::bus& bus, |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 74 | const std::string& path, |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 75 | bool assert) |
| 76 | { |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 77 | std::string service; |
| 78 | try |
| 79 | { |
| 80 | service = getService(bus, LED_GROUPS); |
| 81 | } |
| 82 | catch (MethodErr& e) |
| 83 | { |
| 84 | commit<MethodErr>(); |
| 85 | return; |
| 86 | } |
| 87 | catch (ObjectNotFoundErr& e) |
| 88 | { |
| 89 | commit<ObjectNotFoundErr>(); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | auto pos = path.rfind("/"); |
| 94 | if (pos == std::string::npos) |
| 95 | { |
| 96 | using namespace xyz::openbmc_project::Led::Fru::Monitor; |
| 97 | report<InventoryPathErr>( |
| 98 | InventoryPathError::PATH( |
| 99 | path.c_str())); |
| 100 | return; |
| 101 | } |
| 102 | auto unit = path.substr(pos + 1); |
| 103 | |
| 104 | std::string ledPath = LED_GROUPS + |
| 105 | unit + '_' + LED_FAULT; |
| 106 | |
| 107 | auto method = bus.new_method_call(service.c_str(), |
| 108 | ledPath.c_str(), |
| 109 | "org.freedesktop.DBus.Properties", |
| 110 | "Set"); |
| 111 | method.append("xyz.openbmc_project.Led.Group"); |
| 112 | method.append("Asserted"); |
| 113 | |
| 114 | method.append(sdbusplus::message::variant<bool>(assert)); |
| 115 | bus.call_noreply(method); |
| 116 | |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 120 | void Add::created(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 121 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 122 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 123 | |
| 124 | sdbusplus::message::object_path obPath; |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 125 | msg.read(obPath); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 126 | std::string objectPath(std::move(obPath)); |
| 127 | |
| 128 | std::size_t found = objectPath.find(ELOG_ENTRY); |
| 129 | if (found == std::string::npos) |
| 130 | { |
| 131 | //Not a new error entry skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 132 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | std::string service; |
| 136 | try |
| 137 | { |
| 138 | service = getService(bus, LOG_PATH); |
| 139 | } |
| 140 | catch (MethodErr& e) |
| 141 | { |
| 142 | commit<MethodErr>(); |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 143 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 144 | } |
| 145 | catch (ObjectNotFoundErr& e) |
| 146 | { |
| 147 | commit<ObjectNotFoundErr>(); |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 148 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | auto method = bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 152 | "org.freedesktop.DBus.Properties", |
| 153 | "Get"); |
| 154 | |
| 155 | method.append("org.openbmc.Associations"); |
| 156 | method.append("associations"); |
| 157 | auto reply = bus.call(method); |
| 158 | if (reply.is_method_error()) |
| 159 | { |
| 160 | using namespace xyz::openbmc_project::Led::Fru::Monitor; |
| 161 | report<AssociationRetrieveErr>( |
| 162 | AssociationRetrieveError::ELOG_ENTRY_PATH( |
| 163 | objectPath.c_str())); |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 164 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | sdbusplus::message::variant<AssociationList> assoc; |
| 168 | reply.read(assoc); |
| 169 | |
| 170 | auto assocs = |
| 171 | sdbusplus::message::variant_ns::get<AssociationList>(assoc); |
| 172 | if (assocs.empty()) |
| 173 | { |
| 174 | //No associations skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 175 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | for (const auto& item : assocs) |
| 179 | { |
| 180 | if (std::get<1>(item).compare(CALLOUT_REV_ASSOCIATION) == 0) |
| 181 | { |
| 182 | action(bus, std::get<2>(item), true); |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 183 | removeWatches.emplace_back( |
| 184 | std::make_unique<Remove>(bus, std::get<2>(item))); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 185 | } |
| 186 | } |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 187 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 190 | void Remove::removed(sdbusplus::message::message& msg) |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 191 | { |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 192 | auto bus = msg.get_bus(); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 193 | std::string assoc; |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 194 | msg.read(assoc); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 195 | |
| 196 | if (assoc.compare("org.openbmc.Association")) |
| 197 | { |
| 198 | //Skip if not about association |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 199 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | std::map<std::string, std::vector<std::string>> endPoints; |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 203 | msg.read(endPoints); |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 204 | auto it = endPoints.find("endpoints"); |
| 205 | |
| 206 | if (it == endPoints.end()) |
| 207 | { |
| 208 | //No end points,skip |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 209 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | if (!((*it).second.empty())) |
| 213 | { |
| 214 | //Skip, end points are not empty |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 215 | return; |
Dhruvaraj Subhashchandran | 3c6f29a | 2017-04-20 09:47:28 -0500 | [diff] [blame] | 216 | } |
| 217 | |
Patrick Williams | 3eedbe4 | 2017-05-31 17:27:05 -0500 | [diff] [blame] | 218 | action(bus, inventoryPath, false); |
| 219 | return; |
Dhruvaraj Subhashchandran | 59b86cd | 2017-04-13 00:19:44 -0500 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | }//namespace monitor |
| 223 | }//namespace fault |
| 224 | }//namespace fru |
| 225 | }//namespace led |
| 226 | }//namespace phosphor |