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