George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "ramoops_manager.hpp" |
| 4 | |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 5 | #include <fmt/core.h> |
| 6 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 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 | auto mapperResponseMsg = b.call(mapper); |
| 44 | if (mapperResponseMsg.is_method_error()) |
| 45 | { |
| 46 | log<level::ERR>("Error in mapper call"); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | std::map<std::string, std::set<std::string>> mapperResponse; |
| 51 | try |
| 52 | { |
| 53 | mapperResponseMsg.read(mapperResponse); |
| 54 | } |
| 55 | catch (const sdbusplus::exception::SdBusError& e) |
| 56 | { |
| 57 | log<level::ERR>( |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 58 | fmt::format( |
| 59 | "Failed to parse dump create message, error({}), REPLY_SIG({})", |
| 60 | e.what(), mapperResponseMsg.get_signature()) |
| 61 | .c_str()); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 62 | return; |
| 63 | } |
| 64 | if (mapperResponse.empty()) |
| 65 | { |
| 66 | log<level::ERR>("Error reading mapper response"); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | const auto& host = mapperResponse.cbegin()->first; |
| 71 | auto m = |
| 72 | b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create"); |
| 73 | m.append(RAMOOPS, files); |
| 74 | b.call_noreply(m); |
| 75 | } |
| 76 | |
| 77 | } // namespace ramoops |
| 78 | } // namespace dump |
| 79 | } // namespace phosphor |