xref: /openbmc/phosphor-debug-collector/bmc_dump_entry.hpp (revision 93f064102cc060d913e7492f32d60757b6f100a4)
14a98e8feSDhruvaraj Subhashchandran #pragma once
24a98e8feSDhruvaraj Subhashchandran 
34a98e8feSDhruvaraj Subhashchandran #include "dump_entry.hpp"
44a98e8feSDhruvaraj Subhashchandran #include "xyz/openbmc_project/Dump/Entry/BMC/server.hpp"
54a98e8feSDhruvaraj Subhashchandran #include "xyz/openbmc_project/Dump/Entry/server.hpp"
64a98e8feSDhruvaraj Subhashchandran #include "xyz/openbmc_project/Object/Delete/server.hpp"
74a98e8feSDhruvaraj Subhashchandran #include "xyz/openbmc_project/Time/EpochTime/server.hpp"
84a98e8feSDhruvaraj Subhashchandran 
94a98e8feSDhruvaraj Subhashchandran #include <sdbusplus/bus.hpp>
104a98e8feSDhruvaraj Subhashchandran #include <sdbusplus/server/object.hpp>
114a98e8feSDhruvaraj Subhashchandran 
120af74a5eSJayanth Othayoth #include <filesystem>
130af74a5eSJayanth Othayoth 
144a98e8feSDhruvaraj Subhashchandran namespace phosphor
154a98e8feSDhruvaraj Subhashchandran {
164a98e8feSDhruvaraj Subhashchandran namespace dump
174a98e8feSDhruvaraj Subhashchandran {
184a98e8feSDhruvaraj Subhashchandran namespace bmc
194a98e8feSDhruvaraj Subhashchandran {
204a98e8feSDhruvaraj Subhashchandran template <typename T>
219b18bf2dSPatrick Williams using ServerObject = typename sdbusplus::server::object_t<T>;
224a98e8feSDhruvaraj Subhashchandran 
239b18bf2dSPatrick Williams using EntryIfaces = sdbusplus::server::object_t<
244a98e8feSDhruvaraj Subhashchandran     sdbusplus::xyz::openbmc_project::Dump::Entry::server::BMC>;
254a98e8feSDhruvaraj Subhashchandran 
2674a1f39cSAsmitha Karunanithi using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server::
2774a1f39cSAsmitha Karunanithi     OriginatedBy::OriginatorTypes;
2874a1f39cSAsmitha Karunanithi 
294a98e8feSDhruvaraj Subhashchandran class Manager;
304a98e8feSDhruvaraj Subhashchandran 
314a98e8feSDhruvaraj Subhashchandran /** @class Entry
324a98e8feSDhruvaraj Subhashchandran  *  @brief OpenBMC Dump Entry implementation.
334a98e8feSDhruvaraj Subhashchandran  *  @details A concrete implementation for the
344a98e8feSDhruvaraj Subhashchandran  *  xyz.openbmc_project.Dump.Entry DBus API
354a98e8feSDhruvaraj Subhashchandran  */
3605ef8163SLei YU class Entry : virtual public phosphor::dump::Entry, virtual public EntryIfaces
374a98e8feSDhruvaraj Subhashchandran {
384a98e8feSDhruvaraj Subhashchandran   public:
394a98e8feSDhruvaraj Subhashchandran     Entry() = delete;
404a98e8feSDhruvaraj Subhashchandran     Entry(const Entry&) = delete;
414a98e8feSDhruvaraj Subhashchandran     Entry& operator=(const Entry&) = delete;
424a98e8feSDhruvaraj Subhashchandran     Entry(Entry&&) = delete;
434a98e8feSDhruvaraj Subhashchandran     Entry& operator=(Entry&&) = delete;
444a98e8feSDhruvaraj Subhashchandran     ~Entry() = default;
454a98e8feSDhruvaraj Subhashchandran 
464a98e8feSDhruvaraj Subhashchandran     /** @brief Constructor for the Dump Entry Object
474a98e8feSDhruvaraj Subhashchandran      *  @param[in] bus - Bus to attach to.
484a98e8feSDhruvaraj Subhashchandran      *  @param[in] objPath - Object path to attach to
494a98e8feSDhruvaraj Subhashchandran      *  @param[in] dumpId - Dump id.
504a98e8feSDhruvaraj Subhashchandran      *  @param[in] timeStamp - Dump creation timestamp
514a98e8feSDhruvaraj Subhashchandran      *             since the epoch.
524a98e8feSDhruvaraj Subhashchandran      *  @param[in] fileSize - Dump file size in bytes.
5364f8da9eSDhruvaraj Subhashchandran      *  @param[in] file - Absolute path to the dump file.
54a6ab806dSDhruvaraj Subhashchandran      *  @param[in] status - status of the dump.
5574a1f39cSAsmitha Karunanithi      *  @param[in] originatorId - Id of the originator of the dump
5674a1f39cSAsmitha Karunanithi      *  @param[in] originatorType - Originator type
574a98e8feSDhruvaraj Subhashchandran      *  @param[in] parent - The dump entry's parent.
584a98e8feSDhruvaraj Subhashchandran      */
599b18bf2dSPatrick Williams     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
603fc6df48SJayanth Othayoth           uint64_t timeStamp, uint64_t fileSize,
613fc6df48SJayanth Othayoth           const std::filesystem::path& file,
6274a1f39cSAsmitha Karunanithi           phosphor::dump::OperationStatus status, std::string originatorId,
6374a1f39cSAsmitha Karunanithi           originatorTypes originatorType, phosphor::dump::Manager& parent) :
644a98e8feSDhruvaraj Subhashchandran         phosphor::dump::Entry(bus, objPath.c_str(), dumpId, timeStamp, fileSize,
6564f8da9eSDhruvaraj Subhashchandran                               file, status, originatorId, originatorType,
6605ef8163SLei YU                               parent),
6705ef8163SLei YU         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit)
682f8e276cSDhruvaraj Subhashchandran     {
692f8e276cSDhruvaraj Subhashchandran         // Emit deferred signal.
702f8e276cSDhruvaraj Subhashchandran         this->phosphor::dump::bmc::EntryIfaces::emit_object_added();
712f8e276cSDhruvaraj Subhashchandran     }
724a98e8feSDhruvaraj Subhashchandran 
734a98e8feSDhruvaraj Subhashchandran     /** @brief Delete this d-bus object.
744a98e8feSDhruvaraj Subhashchandran      */
754a98e8feSDhruvaraj Subhashchandran     void delete_() override;
764a98e8feSDhruvaraj Subhashchandran 
77580d91ddSDhruvaraj Subhashchandran     /** @brief Method to initiate the offload of dump
78580d91ddSDhruvaraj Subhashchandran      *  @param[in] uri - URI to offload dump
79580d91ddSDhruvaraj Subhashchandran      */
80580d91ddSDhruvaraj Subhashchandran     void initiateOffload(std::string uri) override;
81580d91ddSDhruvaraj Subhashchandran 
826ccb50e1SDhruvaraj Subhashchandran     /** @brief Method to update an existing dump entry, once the dump creation
836ccb50e1SDhruvaraj Subhashchandran      *  is completed this function will be used to update the entry which got
846ccb50e1SDhruvaraj Subhashchandran      *  created during the dump request.
856ccb50e1SDhruvaraj Subhashchandran      *  @param[in] timeStamp - Dump creation timestamp
866ccb50e1SDhruvaraj Subhashchandran      *  @param[in] fileSize - Dump file size in bytes.
876ccb50e1SDhruvaraj Subhashchandran      *  @param[in] file - Name of dump file.
886ccb50e1SDhruvaraj Subhashchandran      */
893fc6df48SJayanth Othayoth     void update(uint64_t timeStamp, uint64_t fileSize,
903fc6df48SJayanth Othayoth                 const std::filesystem::path& filePath)
916ccb50e1SDhruvaraj Subhashchandran     {
926ccb50e1SDhruvaraj Subhashchandran         elapsed(timeStamp);
936ccb50e1SDhruvaraj Subhashchandran         size(fileSize);
94a6ab806dSDhruvaraj Subhashchandran         // TODO: Handled dump failed case with #ibm-openbmc/2808
95a6ab806dSDhruvaraj Subhashchandran         status(OperationStatus::Completed);
966ccb50e1SDhruvaraj Subhashchandran         file = filePath;
97a6ab806dSDhruvaraj Subhashchandran         // TODO: serialization of this property will be handled with
98a6ab806dSDhruvaraj Subhashchandran         // #ibm-openbmc/2597
99a6ab806dSDhruvaraj Subhashchandran         completedTime(timeStamp);
100*93f06410SDhruvaraj Subhashchandran         serialize();
101*93f06410SDhruvaraj Subhashchandran     }
102*93f06410SDhruvaraj Subhashchandran 
103*93f06410SDhruvaraj Subhashchandran     /**
104*93f06410SDhruvaraj Subhashchandran      * @brief Update dump entry attributes from the file name.
105*93f06410SDhruvaraj Subhashchandran      *
106*93f06410SDhruvaraj Subhashchandran      * @param[in] dumpPath - The path to the dump directory.
107*93f06410SDhruvaraj Subhashchandran      */
108*93f06410SDhruvaraj Subhashchandran     void updateFromFile(const std::filesystem::path& dumpPath);
109*93f06410SDhruvaraj Subhashchandran 
110*93f06410SDhruvaraj Subhashchandran     /**
111*93f06410SDhruvaraj Subhashchandran      * @brief Deserialize and create an entry
112*93f06410SDhruvaraj Subhashchandran      * @param[in] bus - Bus to attach to.
113*93f06410SDhruvaraj Subhashchandran      * @param[in] id - Dump id.
114*93f06410SDhruvaraj Subhashchandran      * @param[in] objPath - Object path to attach to.
115*93f06410SDhruvaraj Subhashchandran      * @param[in] filePath - Path to the dump file.
116*93f06410SDhruvaraj Subhashchandran      * @param[in] parent - The dump entry's parent.
117*93f06410SDhruvaraj Subhashchandran      * @return A unique pointer to the created entry.
118*93f06410SDhruvaraj Subhashchandran      */
119*93f06410SDhruvaraj Subhashchandran     static std::unique_ptr<Entry> deserializeEntry(
120*93f06410SDhruvaraj Subhashchandran         sdbusplus::bus_t& bus, uint32_t id, const std::string& objPath,
121*93f06410SDhruvaraj Subhashchandran         const std::filesystem::path& filePath, phosphor::dump::Manager& parent)
122*93f06410SDhruvaraj Subhashchandran     {
123*93f06410SDhruvaraj Subhashchandran         try
124*93f06410SDhruvaraj Subhashchandran         {
125*93f06410SDhruvaraj Subhashchandran             auto entry = std::unique_ptr<Entry>(
126*93f06410SDhruvaraj Subhashchandran                 new Entry(bus, objPath, id, filePath, parent));
127*93f06410SDhruvaraj Subhashchandran             entry->updateFromFile(filePath);
128*93f06410SDhruvaraj Subhashchandran             entry->deserialize(filePath.parent_path());
129*93f06410SDhruvaraj Subhashchandran             entry->emitSignal();
130*93f06410SDhruvaraj Subhashchandran             return entry;
131*93f06410SDhruvaraj Subhashchandran         }
132*93f06410SDhruvaraj Subhashchandran         catch (const std::exception& e)
133*93f06410SDhruvaraj Subhashchandran         {
134*93f06410SDhruvaraj Subhashchandran             lg2::error(
135*93f06410SDhruvaraj Subhashchandran                 "Dump deserialization failed for path: {PATH}, error: {ERROR}",
136*93f06410SDhruvaraj Subhashchandran                 "PATH", filePath, "ERROR", e.what());
137*93f06410SDhruvaraj Subhashchandran             return nullptr;
138*93f06410SDhruvaraj Subhashchandran         }
139*93f06410SDhruvaraj Subhashchandran     }
140*93f06410SDhruvaraj Subhashchandran 
141*93f06410SDhruvaraj Subhashchandran   private:
142*93f06410SDhruvaraj Subhashchandran     /**
143*93f06410SDhruvaraj Subhashchandran      *  @brief A minimal private constructor for the Dump Entry Object
144*93f06410SDhruvaraj Subhashchandran      *  @param[in] bus - Bus to attach to.
145*93f06410SDhruvaraj Subhashchandran      *  @param[in] objPath - Object path to attach to
146*93f06410SDhruvaraj Subhashchandran      *  @param[in] dumpId - Dump id.
147*93f06410SDhruvaraj Subhashchandran      *  @param[in] file - Absolute path to the dump file.
148*93f06410SDhruvaraj Subhashchandran      *  @param[in] parent - The dump entry's parent.
149*93f06410SDhruvaraj Subhashchandran      */
150*93f06410SDhruvaraj Subhashchandran     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
151*93f06410SDhruvaraj Subhashchandran           const std::filesystem::path& file, phosphor::dump::Manager& parent) :
152*93f06410SDhruvaraj Subhashchandran         phosphor::dump::Entry(bus, objPath.c_str(), dumpId, 0, 0, file,
153*93f06410SDhruvaraj Subhashchandran                               OperationStatus::InProgress, "",
154*93f06410SDhruvaraj Subhashchandran                               originatorTypes::Internal, parent),
155*93f06410SDhruvaraj Subhashchandran         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit)
156*93f06410SDhruvaraj Subhashchandran     {}
157*93f06410SDhruvaraj Subhashchandran 
158*93f06410SDhruvaraj Subhashchandran     /**
159*93f06410SDhruvaraj Subhashchandran      * @brief Emit object added signal
160*93f06410SDhruvaraj Subhashchandran      */
161*93f06410SDhruvaraj Subhashchandran     void emitSignal()
162*93f06410SDhruvaraj Subhashchandran     {
163*93f06410SDhruvaraj Subhashchandran         this->phosphor::dump::bmc::EntryIfaces::emit_object_added();
1646ccb50e1SDhruvaraj Subhashchandran     }
1654a98e8feSDhruvaraj Subhashchandran };
1664a98e8feSDhruvaraj Subhashchandran 
1674a98e8feSDhruvaraj Subhashchandran } // namespace bmc
1684a98e8feSDhruvaraj Subhashchandran } // namespace dump
1694a98e8feSDhruvaraj Subhashchandran } // namespace phosphor
170