blob: f48e8dc28818b37f12921fb4946af518dc17736b [file] [log] [blame]
Jayanth Othayothd3273ea2017-07-12 22:55:32 -05001#include <phosphor-logging/log.hpp>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05002
3#include "core_manager.hpp"
Jayanth Othayothd3273ea2017-07-12 22:55:32 -05004#include "config.h"
Jayanth Othayothd02153c2017-07-02 22:29:42 -05005
6namespace phosphor
7{
8namespace dump
9{
10namespace core
11{
12namespace manager
13{
14
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050015using namespace phosphor::logging;
16using namespace std;
17
Jayanth Othayothd02153c2017-07-02 22:29:42 -050018void watchCallback(const UserMap& fileInfo)
19{
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050020 vector<string> files;
21
Jayanth Othayothd02153c2017-07-02 22:29:42 -050022 for (const auto& i : fileInfo)
23 {
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050024 // Get list of debug files.
Jayanth Othayothd02153c2017-07-02 22:29:42 -050025 if (IN_CLOSE_WRITE == i.second)
26 {
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050027 files.push_back(i.first.string());
Jayanth Othayothd02153c2017-07-02 22:29:42 -050028 }
29 }
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050030 if(!files.empty())
31 {
32 createHelper(files);
33 }
34}
35
36void createHelper(const vector<string>& files)
37{
38 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
39 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
40 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
41 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
42 constexpr auto APPLICATION_CORED =
43 "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
44
45 auto b = sdbusplus::bus::new_default();
46 auto mapper = b.new_method_call(
47 MAPPER_BUSNAME,
48 MAPPER_PATH,
49 MAPPER_INTERFACE,
50 "GetObject");
51 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
52
53 auto mapperResponseMsg = b.call(mapper);
54 if (mapperResponseMsg.is_method_error())
55 {
56 log<level::ERR>("Error in mapper call");
57 return;
58 }
59
60 map<string, vector<string>> mapperResponse;
61 mapperResponseMsg.read(mapperResponse);
62 if (mapperResponse.empty())
63 {
64 log<level::ERR>("Error reading mapper response");
65 return;
66 }
67
68 const auto& host = mapperResponse.cbegin()->first;
69 auto m = b.new_method_call(
70 host.c_str(),
71 OBJ_INTERNAL,
72 IFACE_INTERNAL,
73 "Create");
74 m.append(APPLICATION_CORED, files);
75 b.call_noreply(m);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050076}
77
78} // namespace manager
79} // namespace core
80} // namespace dump
81} // namespace phosphor