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 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 43 | std::map<std::string, std::set<std::string>> mapperResponse; |
| 44 | try |
| 45 | { |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 46 | auto mapperResponseMsg = b.call(mapper); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 47 | mapperResponseMsg.read(mapperResponse); |
| 48 | } |
Patrick Williams | 52ac69c | 2021-09-02 09:37:16 -0500 | [diff] [blame] | 49 | catch (const sdbusplus::exception::exception& e) |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 50 | { |
| 51 | log<level::ERR>( |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 52 | fmt::format("Failed to parse dump create message, error({})", |
| 53 | e.what()) |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 54 | .c_str()); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 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); |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 67 | try |
| 68 | { |
| 69 | b.call_noreply(m); |
| 70 | } |
Patrick Williams | 52ac69c | 2021-09-02 09:37:16 -0500 | [diff] [blame] | 71 | catch (const sdbusplus::exception::exception& e) |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 72 | { |
| 73 | log<level::ERR>( |
| 74 | fmt::format("Failed to create ramoops dump, errormsg({})", e.what()) |
| 75 | .c_str()); |
| 76 | } |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } // namespace ramoops |
| 80 | } // namespace dump |
| 81 | } // namespace phosphor |