Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame^] | 3 | #include <experimental/filesystem> |
| 4 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/server/object.hpp> |
| 7 | #include <xyz/openbmc_project/Dump/Create/server.hpp> |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 8 | |
| 9 | #include "xyz/openbmc_project/Dump/Internal/Create/server.hpp" |
| 10 | #include "dump_entry.hpp" |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame^] | 11 | #include "dump_utils.hpp" |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 12 | |
| 13 | namespace phosphor |
| 14 | { |
| 15 | namespace dump |
| 16 | { |
| 17 | namespace internal |
| 18 | { |
| 19 | |
| 20 | class Manager; |
| 21 | |
| 22 | } // namespace internal |
| 23 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 24 | using Type = |
| 25 | sdbusplus::xyz::openbmc_project::Dump::Internal::server::Create::Type; |
| 26 | |
| 27 | using CreateIface = sdbusplus::server::object::object< |
| 28 | sdbusplus::xyz::openbmc_project::Dump::server::Create>; |
| 29 | |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame^] | 30 | namespace fs = std::experimental::filesystem; |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 31 | |
| 32 | /** @class Manager |
| 33 | * @brief OpenBMC Dump manager implementation. |
| 34 | * @details A concrete implementation for the |
| 35 | * xyz.openbmc_project.Dump.Create DBus API. |
| 36 | */ |
| 37 | class Manager : public CreateIface |
| 38 | { |
| 39 | friend class internal::Manager; |
| 40 | friend class Entry; |
| 41 | |
| 42 | public: |
| 43 | Manager() = delete; |
| 44 | Manager(const Manager&) = default; |
| 45 | Manager& operator=(const Manager&) = delete; |
| 46 | Manager(Manager&&) = delete; |
| 47 | Manager& operator=(Manager&&) = delete; |
| 48 | virtual ~Manager() = default; |
| 49 | |
| 50 | /** @brief Constructor to put object onto bus at a dbus path. |
| 51 | * @param[in] bus - Bus to attach to. |
| 52 | * @param[in] event - Dump manager sd_event loop. |
| 53 | * @param[in] path - Path to attach at. |
| 54 | */ |
| 55 | Manager(sdbusplus::bus::bus& bus, |
| 56 | const EventPtr& event, const char* path) : |
| 57 | CreateIface(bus, path), |
| 58 | bus(bus), |
| 59 | eventLoop(event.get()), |
| 60 | lastEntryId(0) |
| 61 | {} |
| 62 | |
| 63 | /** @brief Implementation for CreateDump |
| 64 | * Method to create Dump. |
| 65 | * |
| 66 | * @return id - The Dump entry id number. |
| 67 | */ |
| 68 | uint32_t createDump() override; |
| 69 | |
| 70 | private: |
| 71 | /** @brief Create Dump entry d-bus object |
| 72 | * @param[in] fullPath - Full path of the Dump file name |
| 73 | */ |
| 74 | void createEntry(const fs::path& fullPath); |
| 75 | |
| 76 | /** @brief Capture BMC Dump based on the Dump type. |
| 77 | * @param[in] type - Type of the Dump. |
| 78 | * @param[in] fullPaths - List of absolute paths to the files |
| 79 | * to be included as part of Dump package. |
| 80 | * @return id - The Dump entry id number. |
| 81 | */ |
| 82 | uint32_t captureDump( |
| 83 | Type type, |
| 84 | const std::vector<std::string>& fullPaths); |
| 85 | |
| 86 | /** @brief Erase specified entry d-bus object |
| 87 | * |
| 88 | * @param[in] entryId - unique identifier of the entry |
| 89 | */ |
| 90 | void erase(uint32_t entryId); |
| 91 | |
| 92 | /** @brief sd_event_add_child callback |
| 93 | * |
| 94 | * @param[in] s - event source |
| 95 | * @param[in] si - signal info |
| 96 | * @param[in] userdata - pointer to Watch object |
| 97 | * |
| 98 | * @returns 0 on success, -1 on fail |
| 99 | */ |
| 100 | static int callback(sd_event_source* s, |
| 101 | const siginfo_t* si, |
| 102 | void* userdata) |
| 103 | { |
| 104 | //No specific action required in |
| 105 | //the sd_event_add_child callback. |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /** @brief sdbusplus DBus bus connection. */ |
| 110 | sdbusplus::bus::bus& bus; |
| 111 | |
| 112 | /** @brief sdbusplus Dump event loop */ |
| 113 | EventPtr eventLoop; |
| 114 | |
| 115 | /** @brief Dump Entry dbus objects map based on entry id */ |
| 116 | std::map<uint32_t, std::unique_ptr<Entry>> entries; |
| 117 | |
| 118 | /** @brief Id of the last Dump entry */ |
| 119 | uint32_t lastEntryId; |
| 120 | }; |
| 121 | |
| 122 | } // namespace dump |
| 123 | } // namespace phosphor |