blob: 8f6cf2f3fb4b48d09c6eaba4626fbcefad45500c [file] [log] [blame]
Jayanth Othayoth224882b2017-05-04 05:46:45 -05001#pragma once
2
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -05003#include "xyz/openbmc_project/Common/OriginatedBy/server.hpp"
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -05004#include "xyz/openbmc_project/Common/Progress/server.hpp"
Jayanth Othayoth224882b2017-05-04 05:46:45 -05005#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
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05009#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/object.hpp>
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -060011#include <sdeventplus/event.hpp>
12#include <sdeventplus/source/event.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050013
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050014#include <filesystem>
15
Jayanth Othayoth224882b2017-05-04 05:46:45 -050016namespace phosphor
17{
18namespace dump
19{
20
21template <typename T>
Patrick Williams9b18bf22022-07-22 19:26:55 -050022using ServerObject = typename sdbusplus::server::object_t<T>;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050023
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050024// TODO Revisit whether sdbusplus::xyz::openbmc_project::Time::server::EpochTime
25// still needed in dump entry since start time and completed time are available
26// from sdbusplus::xyz::openbmc_project::Common::server::Progress
27// #ibm-openbmc/2809
Patrick Williams9b18bf22022-07-22 19:26:55 -050028using EntryIfaces = sdbusplus::server::object_t<
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050029 sdbusplus::xyz::openbmc_project::Common::server::OriginatedBy,
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050030 sdbusplus::xyz::openbmc_project::Common::server::Progress,
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050031 sdbusplus::xyz::openbmc_project::Dump::server::Entry,
32 sdbusplus::xyz::openbmc_project::Object::server::Delete,
33 sdbusplus::xyz::openbmc_project::Time::server::EpochTime>;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050034
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050035using OperationStatus =
36 sdbusplus::xyz::openbmc_project::Common::server::Progress::OperationStatus;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050037
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050038using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server::
39 OriginatedBy::OriginatorTypes;
40
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050041class Manager;
42
Jayanth Othayoth224882b2017-05-04 05:46:45 -050043/** @class Entry
Dhruvaraj Subhashchandranf140f662020-01-30 00:29:01 -060044 * @brief Base Dump Entry implementation.
Jayanth Othayoth224882b2017-05-04 05:46:45 -050045 * @details A concrete implementation for the
46 * xyz.openbmc_project.Dump.Entry DBus API
47 */
48class Entry : public EntryIfaces
49{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050050 public:
51 Entry() = delete;
52 Entry(const Entry&) = delete;
53 Entry& operator=(const Entry&) = delete;
54 Entry(Entry&&) = delete;
55 Entry& operator=(Entry&&) = delete;
56 ~Entry() = default;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050057
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050058 /** @brief Constructor for the Dump Entry Object
59 * @param[in] bus - Bus to attach to.
60 * @param[in] objPath - Object path to attach to
61 * @param[in] dumpId - Dump id.
62 * @param[in] timeStamp - Dump creation timestamp
63 * since the epoch.
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060064 * @param[in] dumpSize - Dump file size in bytes.
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050065 * @param[in] originId - Id of the originator of the dump
66 * @param[in] originType - Originator type
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050067 * @param[in] parent - The dump entry's parent.
68 */
Patrick Williams9b18bf22022-07-22 19:26:55 -050069 Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -060070 uint64_t timeStamp, uint64_t dumpSize,
71 const std::filesystem::path& file, OperationStatus dumpStatus,
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050072 std::string originId, originatorTypes originType, Manager& parent) :
Patrick Williams73f64072022-04-01 17:04:47 -050073 EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::emit_no_signals),
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -060074 parent(parent), id(dumpId), file(file)
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050075 {
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050076 originatorId(originId);
77 originatorType(originType);
78
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060079 size(dumpSize);
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050080 status(dumpStatus);
81
82 // If the object is created after the dump creation keep
83 // all same as timeStamp
84 // if the object created before the dump creation, update
85 // only the start time. Completed and elapsed time will
86 // be updated once the dump is completed.
87 if (dumpStatus == OperationStatus::Completed)
88 {
89 elapsed(timeStamp);
90 startTime(timeStamp);
91 completedTime(timeStamp);
92 }
93 else
94 {
95 elapsed(0);
96 startTime(timeStamp);
97 completedTime(0);
98 }
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050099 };
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500100
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500101 /** @brief Delete this d-bus object.
102 */
103 void delete_() override;
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500104
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -0600105 /** @brief Method to initiate the offload of dump
Dhruvaraj Subhashchandran69e61522020-02-04 06:39:11 -0600106 * @param[in] uri - URI to offload dump
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -0600107 */
Dhruvaraj Subhashchandran69e61522020-02-04 06:39:11 -0600108 void initiateOffload(std::string uri) override
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -0600109 {
Dhruvaraj Subhashchandran69e61522020-02-04 06:39:11 -0600110 offloadUri(uri);
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -0600111 }
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500112
Dhruvaraj Subhashchandran270355b2022-02-01 02:44:43 -0600113 /** @brief Returns the dump id
114 * @return the id associated with entry
115 */
116 uint32_t getDumpId()
117 {
118 return id;
119 }
120
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -0600121 /** @brief Method to get the file handle of the dump
122 * @returns A Unix file descriptor to the dump file
123 * @throws sdbusplus::xyz::openbmc_project::Common::File::Error::Open on
124 * failure to open the file
125 * @throws sdbusplus::xyz::openbmc_project::Common::Error::Unavailable if
126 * the file string is empty
127 */
128 sdbusplus::message::unix_fd getFileHandle() override;
129
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -0600130 protected:
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500131 /** @brief This entry's parent */
132 Manager& parent;
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500133
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500134 /** @brief This entry's id */
135 uint32_t id;
Dhruvaraj Subhashchandran64f8da92021-12-08 03:48:23 -0600136
137 /** @Dump file name */
138 std::filesystem::path file;
139
140 private:
141 /** @brief Closes the file descriptor and removes the corresponding event
142 * source.
143 *
144 */
145 void closeFD()
146 {
147 if (fdCloseEventSource)
148 {
149 close(fdCloseEventSource->first);
150 fdCloseEventSource.reset();
151 }
152 }
153
154 /* @brief A pair of file descriptor and corresponding event source. */
155 std::optional<std::pair<int, std::unique_ptr<sdeventplus::source::Defer>>>
156 fdCloseEventSource;
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500157};
158
159} // namespace dump
160} // namespace phosphor