Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "dump_entry.hpp" |
| 4 | #include "xyz/openbmc_project/Dump/Entry/BMC/server.hpp" |
| 5 | #include "xyz/openbmc_project/Dump/Entry/server.hpp" |
| 6 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
| 7 | #include "xyz/openbmc_project/Time/EpochTime/server.hpp" |
| 8 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/server/object.hpp> |
| 11 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 12 | #include <filesystem> |
| 13 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 14 | namespace phosphor |
| 15 | { |
| 16 | namespace dump |
| 17 | { |
| 18 | namespace bmc |
| 19 | { |
| 20 | template <typename T> |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 21 | using ServerObject = typename sdbusplus::server::object_t<T>; |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 22 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 23 | using EntryIfaces = sdbusplus::server::object_t< |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Dump::Entry::server::BMC>; |
| 25 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 26 | using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server:: |
| 27 | OriginatedBy::OriginatorTypes; |
| 28 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 29 | /** @class Entry |
| 30 | * @brief OpenBMC Dump Entry implementation. |
| 31 | * @details A concrete implementation for the |
| 32 | * xyz.openbmc_project.Dump.Entry DBus API |
| 33 | */ |
Lei YU | 05ef816 | 2022-11-23 13:49:53 +0800 | [diff] [blame] | 34 | class Entry : virtual public phosphor::dump::Entry, virtual public EntryIfaces |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | Entry() = delete; |
| 38 | Entry(const Entry&) = delete; |
| 39 | Entry& operator=(const Entry&) = delete; |
| 40 | Entry(Entry&&) = delete; |
| 41 | Entry& operator=(Entry&&) = delete; |
| 42 | ~Entry() = default; |
| 43 | |
| 44 | /** @brief Constructor for the Dump Entry Object |
| 45 | * @param[in] bus - Bus to attach to. |
| 46 | * @param[in] objPath - Object path to attach to |
| 47 | * @param[in] dumpId - Dump id. |
| 48 | * @param[in] timeStamp - Dump creation timestamp |
| 49 | * since the epoch. |
| 50 | * @param[in] fileSize - Dump file size in bytes. |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 51 | * @param[in] file - Absolute path to the dump file. |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 52 | * @param[in] status - status of the dump. |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 53 | * @param[in] originatorId - Id of the originator of the dump |
| 54 | * @param[in] originatorType - Originator type |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 55 | * @param[in] parent - The dump entry's parent. |
| 56 | */ |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 57 | Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId, |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 58 | uint64_t timeStamp, uint64_t fileSize, |
| 59 | const std::filesystem::path& file, |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 60 | phosphor::dump::OperationStatus status, std::string originatorId, |
| 61 | originatorTypes originatorType, phosphor::dump::Manager& parent) : |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 62 | phosphor::dump::Entry(bus, objPath.c_str(), dumpId, timeStamp, fileSize, |
Dhruvaraj Subhashchandran | 64f8da9 | 2021-12-08 03:48:23 -0600 | [diff] [blame] | 63 | file, status, originatorId, originatorType, |
Lei YU | 05ef816 | 2022-11-23 13:49:53 +0800 | [diff] [blame] | 64 | parent), |
| 65 | EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit) |
Dhruvaraj Subhashchandran | 2f8e276 | 2021-02-11 07:22:35 -0600 | [diff] [blame] | 66 | { |
| 67 | // Emit deferred signal. |
| 68 | this->phosphor::dump::bmc::EntryIfaces::emit_object_added(); |
| 69 | } |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 70 | |
| 71 | /** @brief Delete this d-bus object. |
| 72 | */ |
| 73 | void delete_() override; |
| 74 | |
Dhruvaraj Subhashchandran | 580d91d | 2020-04-22 12:29:18 -0500 | [diff] [blame] | 75 | /** @brief Method to initiate the offload of dump |
| 76 | * @param[in] uri - URI to offload dump |
| 77 | */ |
| 78 | void initiateOffload(std::string uri) override; |
| 79 | |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 80 | /** @brief Method to update an existing dump entry, once the dump creation |
| 81 | * is completed this function will be used to update the entry which got |
| 82 | * created during the dump request. |
| 83 | * @param[in] timeStamp - Dump creation timestamp |
| 84 | * @param[in] fileSize - Dump file size in bytes. |
| 85 | * @param[in] file - Name of dump file. |
| 86 | */ |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 87 | void update(uint64_t timeStamp, uint64_t fileSize, |
| 88 | const std::filesystem::path& filePath) |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 89 | { |
| 90 | elapsed(timeStamp); |
| 91 | size(fileSize); |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 92 | // TODO: Handled dump failed case with #ibm-openbmc/2808 |
| 93 | status(OperationStatus::Completed); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 94 | file = filePath; |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 95 | // TODO: serialization of this property will be handled with |
| 96 | // #ibm-openbmc/2597 |
| 97 | completedTime(timeStamp); |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 98 | serialize(); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @brief Update dump entry attributes from the file name. |
| 103 | * |
| 104 | * @param[in] dumpPath - The path to the dump directory. |
| 105 | */ |
| 106 | void updateFromFile(const std::filesystem::path& dumpPath); |
| 107 | |
| 108 | /** |
| 109 | * @brief Deserialize and create an entry |
| 110 | * @param[in] bus - Bus to attach to. |
| 111 | * @param[in] id - Dump id. |
| 112 | * @param[in] objPath - Object path to attach to. |
| 113 | * @param[in] filePath - Path to the dump file. |
| 114 | * @param[in] parent - The dump entry's parent. |
| 115 | * @return A unique pointer to the created entry. |
| 116 | */ |
| 117 | static std::unique_ptr<Entry> deserializeEntry( |
| 118 | sdbusplus::bus_t& bus, uint32_t id, const std::string& objPath, |
| 119 | const std::filesystem::path& filePath, phosphor::dump::Manager& parent) |
| 120 | { |
| 121 | try |
| 122 | { |
| 123 | auto entry = std::unique_ptr<Entry>( |
| 124 | new Entry(bus, objPath, id, filePath, parent)); |
| 125 | entry->updateFromFile(filePath); |
| 126 | entry->deserialize(filePath.parent_path()); |
| 127 | entry->emitSignal(); |
| 128 | return entry; |
| 129 | } |
| 130 | catch (const std::exception& e) |
| 131 | { |
| 132 | lg2::error( |
| 133 | "Dump deserialization failed for path: {PATH}, error: {ERROR}", |
| 134 | "PATH", filePath, "ERROR", e.what()); |
| 135 | return nullptr; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | private: |
| 140 | /** |
| 141 | * @brief A minimal private constructor for the Dump Entry Object |
| 142 | * @param[in] bus - Bus to attach to. |
| 143 | * @param[in] objPath - Object path to attach to |
| 144 | * @param[in] dumpId - Dump id. |
| 145 | * @param[in] file - Absolute path to the dump file. |
| 146 | * @param[in] parent - The dump entry's parent. |
| 147 | */ |
| 148 | Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId, |
| 149 | const std::filesystem::path& file, phosphor::dump::Manager& parent) : |
| 150 | phosphor::dump::Entry(bus, objPath.c_str(), dumpId, 0, 0, file, |
| 151 | OperationStatus::InProgress, "", |
| 152 | originatorTypes::Internal, parent), |
| 153 | EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit) |
| 154 | {} |
| 155 | |
| 156 | /** |
| 157 | * @brief Emit object added signal |
| 158 | */ |
| 159 | void emitSignal() |
| 160 | { |
| 161 | this->phosphor::dump::bmc::EntryIfaces::emit_object_added(); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 162 | } |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | } // namespace bmc |
| 166 | } // namespace dump |
| 167 | } // namespace phosphor |