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