Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 1 | #include <phosphor-logging/log.hpp> |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 2 | |
| 3 | #include "core_manager.hpp" |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 4 | #include "config.h" |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace dump |
| 9 | { |
| 10 | namespace core |
| 11 | { |
| 12 | namespace manager |
| 13 | { |
| 14 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 15 | using namespace phosphor::logging; |
| 16 | using namespace std; |
| 17 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 18 | void watchCallback(const UserMap& fileInfo) |
| 19 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 20 | vector<string> files; |
| 21 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 22 | for (const auto& i : fileInfo) |
| 23 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 24 | // Get list of debug files. |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 25 | if (IN_CLOSE_WRITE == i.second) |
| 26 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 27 | files.push_back(i.first.string()); |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 28 | } |
| 29 | } |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 30 | if(!files.empty()) |
| 31 | { |
| 32 | createHelper(files); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | void 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 Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } // namespace manager |
| 79 | } // namespace core |
| 80 | } // namespace dump |
| 81 | } // namespace phosphor |