1 #include "config.h" 2 3 #include "ramoops_manager.hpp" 4 5 #include <fmt/core.h> 6 7 #include <sdbusplus/exception.hpp> 8 9 namespace phosphor 10 { 11 namespace dump 12 { 13 namespace ramoops 14 { 15 16 Manager::Manager(const std::string& filePath) 17 { 18 std::vector<std::string> files; 19 files.push_back(filePath); 20 21 createHelper(files); 22 } 23 24 void Manager::createHelper(const std::vector<std::string>& files) 25 { 26 if (files.empty()) 27 { 28 return; 29 } 30 31 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; 32 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; 33 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; 34 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create"); 35 constexpr auto RAMOOPS = 36 "xyz.openbmc_project.Dump.Internal.Create.Type.Ramoops"; 37 38 auto b = sdbusplus::bus::new_default(); 39 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, 40 MAPPER_INTERFACE, "GetObject"); 41 mapper.append(OBJ_INTERNAL, std::set<std::string>({IFACE_INTERNAL})); 42 43 std::map<std::string, std::set<std::string>> mapperResponse; 44 try 45 { 46 auto mapperResponseMsg = b.call(mapper); 47 mapperResponseMsg.read(mapperResponse); 48 } 49 catch (const sdbusplus::exception::exception& e) 50 { 51 log<level::ERR>( 52 fmt::format("Failed to parse dump create message, error({})", 53 e.what()) 54 .c_str()); 55 return; 56 } 57 if (mapperResponse.empty()) 58 { 59 log<level::ERR>("Error reading mapper response"); 60 return; 61 } 62 63 const auto& host = mapperResponse.cbegin()->first; 64 auto m = 65 b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create"); 66 m.append(RAMOOPS, files); 67 try 68 { 69 b.call_noreply(m); 70 } 71 catch (const sdbusplus::exception::exception& e) 72 { 73 log<level::ERR>( 74 fmt::format("Failed to create ramoops dump, errormsg({})", e.what()) 75 .c_str()); 76 } 77 } 78 79 } // namespace ramoops 80 } // namespace dump 81 } // namespace phosphor 82