blob: 58d970263f1ea618cc0eba4b958e60ea0f47d677 [file] [log] [blame]
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -06001#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 Subhashchandran4a98e8f2020-01-29 07:11:08 -06009#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
11
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050012#include <filesystem>
13
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060014namespace phosphor
15{
16namespace dump
17{
18namespace bmc
19{
20template <typename T>
Patrick Williams9b18bf22022-07-22 19:26:55 -050021using ServerObject = typename sdbusplus::server::object_t<T>;
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060022
Patrick Williams9b18bf22022-07-22 19:26:55 -050023using EntryIfaces = sdbusplus::server::object_t<
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060024 sdbusplus::xyz::openbmc_project::Dump::Entry::server::BMC>;
25
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050026using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server::
27 OriginatedBy::OriginatorTypes;
28
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060029class Manager;
30
31/** @class Entry
32 * @brief OpenBMC Dump Entry implementation.
33 * @details A concrete implementation for the
34 * xyz.openbmc_project.Dump.Entry DBus API
35 */
Lei YU05ef8162022-11-23 13:49:53 +080036class Entry : virtual public phosphor::dump::Entry, virtual public EntryIfaces
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060037{
38 public:
39 Entry() = delete;
40 Entry(const Entry&) = delete;
41 Entry& operator=(const Entry&) = delete;
42 Entry(Entry&&) = delete;
43 Entry& operator=(Entry&&) = delete;
44 ~Entry() = default;
45
46 /** @brief Constructor for the Dump Entry Object
47 * @param[in] bus - Bus to attach to.
48 * @param[in] objPath - Object path to attach to
49 * @param[in] dumpId - Dump id.
50 * @param[in] timeStamp - Dump creation timestamp
51 * since the epoch.
52 * @param[in] fileSize - Dump file size in bytes.
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -060053 * @param[in] file - Absolute path to the dump file.
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050054 * @param[in] status - status of the dump.
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050055 * @param[in] originatorId - Id of the originator of the dump
56 * @param[in] originatorType - Originator type
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060057 * @param[in] parent - The dump entry's parent.
58 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050059 Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050060 uint64_t timeStamp, uint64_t fileSize,
61 const std::filesystem::path& file,
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050062 phosphor::dump::OperationStatus status, std::string originatorId,
63 originatorTypes originatorType, phosphor::dump::Manager& parent) :
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060064 phosphor::dump::Entry(bus, objPath.c_str(), dumpId, timeStamp, fileSize,
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -060065 file, status, originatorId, originatorType,
Lei YU05ef8162022-11-23 13:49:53 +080066 parent),
67 EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit)
Dhruvaraj Subhashchandran2f8e2762021-02-11 07:22:35 -060068 {
69 // Emit deferred signal.
70 this->phosphor::dump::bmc::EntryIfaces::emit_object_added();
71 }
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060072
73 /** @brief Delete this d-bus object.
74 */
75 void delete_() override;
76
Dhruvaraj Subhashchandran580d91d2020-04-22 12:29:18 -050077 /** @brief Method to initiate the offload of dump
78 * @param[in] uri - URI to offload dump
79 */
80 void initiateOffload(std::string uri) override;
81
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050082 /** @brief Method to update an existing dump entry, once the dump creation
83 * is completed this function will be used to update the entry which got
84 * created during the dump request.
85 * @param[in] timeStamp - Dump creation timestamp
86 * @param[in] fileSize - Dump file size in bytes.
87 * @param[in] file - Name of dump file.
88 */
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050089 void update(uint64_t timeStamp, uint64_t fileSize,
90 const std::filesystem::path& filePath)
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050091 {
92 elapsed(timeStamp);
93 size(fileSize);
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050094 // TODO: Handled dump failed case with #ibm-openbmc/2808
95 status(OperationStatus::Completed);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050096 file = filePath;
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050097 // TODO: serialization of this property will be handled with
98 // #ibm-openbmc/2597
99 completedTime(timeStamp);
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -0500100 serialize();
101 }
102
103 /**
104 * @brief Update dump entry attributes from the file name.
105 *
106 * @param[in] dumpPath - The path to the dump directory.
107 */
108 void updateFromFile(const std::filesystem::path& dumpPath);
109
110 /**
111 * @brief Deserialize and create an entry
112 * @param[in] bus - Bus to attach to.
113 * @param[in] id - Dump id.
114 * @param[in] objPath - Object path to attach to.
115 * @param[in] filePath - Path to the dump file.
116 * @param[in] parent - The dump entry's parent.
117 * @return A unique pointer to the created entry.
118 */
119 static std::unique_ptr<Entry> deserializeEntry(
120 sdbusplus::bus_t& bus, uint32_t id, const std::string& objPath,
121 const std::filesystem::path& filePath, phosphor::dump::Manager& parent)
122 {
123 try
124 {
125 auto entry = std::unique_ptr<Entry>(
126 new Entry(bus, objPath, id, filePath, parent));
127 entry->updateFromFile(filePath);
128 entry->deserialize(filePath.parent_path());
129 entry->emitSignal();
130 return entry;
131 }
132 catch (const std::exception& e)
133 {
134 lg2::error(
135 "Dump deserialization failed for path: {PATH}, error: {ERROR}",
136 "PATH", filePath, "ERROR", e.what());
137 return nullptr;
138 }
139 }
140
141 private:
142 /**
143 * @brief A minimal private constructor for the Dump Entry Object
144 * @param[in] bus - Bus to attach to.
145 * @param[in] objPath - Object path to attach to
146 * @param[in] dumpId - Dump id.
147 * @param[in] file - Absolute path to the dump file.
148 * @param[in] parent - The dump entry's parent.
149 */
150 Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
151 const std::filesystem::path& file, phosphor::dump::Manager& parent) :
152 phosphor::dump::Entry(bus, objPath.c_str(), dumpId, 0, 0, file,
153 OperationStatus::InProgress, "",
154 originatorTypes::Internal, parent),
155 EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit)
156 {}
157
158 /**
159 * @brief Emit object added signal
160 */
161 void emitSignal()
162 {
163 this->phosphor::dump::bmc::EntryIfaces::emit_object_added();
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500164 }
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -0600165};
166
167} // namespace bmc
168} // namespace dump
169} // namespace phosphor