blob: c645d3b4543f9e38cb01ba9d90002938e7c3d182 [file] [log] [blame]
George Liuff92ffe2021-02-09 15:01:53 +08001#include "config.h"
2
3#include "ramoops_manager.hpp"
4
George Liu858fbb22021-07-01 12:25:44 +08005#include <fmt/core.h>
6
George Liuff92ffe2021-02-09 15:01:53 +08007#include <sdbusplus/exception.hpp>
8
9namespace phosphor
10{
11namespace dump
12{
13namespace ramoops
14{
15
16Manager::Manager(const std::string& filePath)
17{
18 std::vector<std::string> files;
19 files.push_back(filePath);
20
21 createHelper(files);
22}
23
24void 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 Liuff92ffe2021-02-09 15:01:53 +080043 std::map<std::string, std::set<std::string>> mapperResponse;
44 try
45 {
George Liuf4694d72021-08-16 13:49:09 +080046 auto mapperResponseMsg = b.call(mapper);
George Liuff92ffe2021-02-09 15:01:53 +080047 mapperResponseMsg.read(mapperResponse);
48 }
Patrick Williams52ac69c2021-09-02 09:37:16 -050049 catch (const sdbusplus::exception::exception& e)
George Liuff92ffe2021-02-09 15:01:53 +080050 {
51 log<level::ERR>(
George Liuf4694d72021-08-16 13:49:09 +080052 fmt::format("Failed to parse dump create message, error({})",
53 e.what())
George Liu858fbb22021-07-01 12:25:44 +080054 .c_str());
George Liuff92ffe2021-02-09 15:01:53 +080055 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 Liuf4694d72021-08-16 13:49:09 +080067 try
68 {
69 b.call_noreply(m);
70 }
Patrick Williams52ac69c2021-09-02 09:37:16 -050071 catch (const sdbusplus::exception::exception& e)
George Liuf4694d72021-08-16 13:49:09 +080072 {
73 log<level::ERR>(
74 fmt::format("Failed to create ramoops dump, errormsg({})", e.what())
75 .c_str());
76 }
George Liuff92ffe2021-02-09 15:01:53 +080077}
78
79} // namespace ramoops
80} // namespace dump
81} // namespace phosphor