#include #include #include #include #include #include namespace watchdog { namespace dump { using namespace phosphor::logging; int dbusMethod(const std::string& path, const std::string& interface, const std::string& function, sdbusplus::message_t& method, const std::string& extended) { int rc = RC_DBUS_ERROR; // assume error try { constexpr auto serviceFind = "xyz.openbmc_project.ObjectMapper"; constexpr auto pathFind = "/xyz/openbmc_project/object_mapper"; constexpr auto interfaceFind = "xyz.openbmc_project.ObjectMapper"; constexpr auto functionFind = "GetObject"; auto bus = sdbusplus::bus::new_system(); // using system dbus // method to find service from object path and object interface auto newMethod = bus.new_method_call(serviceFind, pathFind, interfaceFind, functionFind); // find the service for specified object path and interface newMethod.append(path.c_str()); newMethod.append(std::vector({interface})); auto reply = bus.call(newMethod); // dbus call results std::map> responseFindService; reply.read(responseFindService); // If we successfully found the service associated with the dbus object // path and interface then create a method for the specified interface // and function. if (!responseFindService.empty()) { auto service = responseFindService.begin()->first; // Some methods (e.g. get attribute) take an extended parameter if (extended == "") { // return the method method = bus.new_method_call(service.c_str(), path.c_str(), interface.c_str(), function.c_str()); } else { // return extended method method = bus.new_method_call(service.c_str(), path.c_str(), extended.c_str(), function.c_str()); } rc = RC_SUCCESS; } else { // This trace will be picked up in event log log("dbusMethod service not found"); std::string traceMsgPath = std::string(path, maxTraceLen); log(traceMsgPath.c_str()); std::string traceMsgIface = std::string(interface, maxTraceLen); log(traceMsgIface.c_str()); } } catch (const sdbusplus::exception_t& e) { log("Error in dbusMethod", entry("ERROR=%s", e.what())); } return rc; } uint32_t createPel(const std::string& eventType, std::map& additional, const std::vector& ffdc) { // Create returns plid int plid = 0; // Need to provide pid when using create or create-with-ffdc methods additional.emplace("_PID", std::to_string(getpid())); // Sdbus call specifics constexpr auto interface = "org.open_power.Logging.PEL"; constexpr auto function = "CreatePELWithFFDCFiles"; sdbusplus::message_t method; if (0 == dbusMethod(pathLogging, interface, function, method)) { try { // append additional dbus call paramaters method.append(eventType, levelPelError, additional, ffdc); // using system dbus auto bus = sdbusplus::bus::new_system(); auto response = bus.call(method); // reply will be tuple containing bmc log id, platform log id std::tuple reply = {0, 0}; // parse dbus response into reply response.read(reply); plid = std::get<1>(reply); // platform log id is tuple "second" } catch (const sdbusplus::exception_t& e) { log("Error in createPel CreatePELWithFFDCFiles", entry("ERROR=%s", e.what())); } } return plid; // platform log id or 0 } } // namespace dump } // namespace watchdog