xref: /openbmc/phosphor-debug-collector/bmc_dump_entry.hpp (revision 109e9948e23279e5821572c7806bf5a845b2283b)
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 Entry
304a98e8feSDhruvaraj Subhashchandran  *  @brief OpenBMC Dump Entry implementation.
314a98e8feSDhruvaraj Subhashchandran  *  @details A concrete implementation for the
324a98e8feSDhruvaraj Subhashchandran  *  xyz.openbmc_project.Dump.Entry DBus API
334a98e8feSDhruvaraj Subhashchandran  */
3405ef8163SLei YU class Entry : virtual public phosphor::dump::Entry, virtual public EntryIfaces
354a98e8feSDhruvaraj Subhashchandran {
364a98e8feSDhruvaraj Subhashchandran   public:
374a98e8feSDhruvaraj Subhashchandran     Entry() = delete;
384a98e8feSDhruvaraj Subhashchandran     Entry(const Entry&) = delete;
394a98e8feSDhruvaraj Subhashchandran     Entry& operator=(const Entry&) = delete;
404a98e8feSDhruvaraj Subhashchandran     Entry(Entry&&) = delete;
414a98e8feSDhruvaraj Subhashchandran     Entry& operator=(Entry&&) = delete;
424a98e8feSDhruvaraj Subhashchandran     ~Entry() = default;
434a98e8feSDhruvaraj Subhashchandran 
444a98e8feSDhruvaraj Subhashchandran     /** @brief Constructor for the Dump Entry Object
454a98e8feSDhruvaraj Subhashchandran      *  @param[in] bus - Bus to attach to.
464a98e8feSDhruvaraj Subhashchandran      *  @param[in] objPath - Object path to attach to
474a98e8feSDhruvaraj Subhashchandran      *  @param[in] dumpId - Dump id.
484a98e8feSDhruvaraj Subhashchandran      *  @param[in] timeStamp - Dump creation timestamp
494a98e8feSDhruvaraj Subhashchandran      *             since the epoch.
504a98e8feSDhruvaraj Subhashchandran      *  @param[in] fileSize - Dump file size in bytes.
5164f8da9eSDhruvaraj Subhashchandran      *  @param[in] file - Absolute path to the dump file.
52a6ab806dSDhruvaraj Subhashchandran      *  @param[in] status - status of the dump.
5374a1f39cSAsmitha Karunanithi      *  @param[in] originatorId - Id of the originator of the dump
5474a1f39cSAsmitha Karunanithi      *  @param[in] originatorType - Originator type
554a98e8feSDhruvaraj Subhashchandran      *  @param[in] parent - The dump entry's parent.
564a98e8feSDhruvaraj Subhashchandran      */
Entry(sdbusplus::bus_t & bus,const std::string & objPath,uint32_t dumpId,uint64_t timeStamp,uint64_t fileSize,const std::filesystem::path & file,phosphor::dump::OperationStatus status,std::string originatorId,originatorTypes originatorType,phosphor::dump::Manager & parent)579b18bf2dSPatrick Williams     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
583fc6df48SJayanth Othayoth           uint64_t timeStamp, uint64_t fileSize,
593fc6df48SJayanth Othayoth           const std::filesystem::path& file,
6074a1f39cSAsmitha Karunanithi           phosphor::dump::OperationStatus status, std::string originatorId,
6174a1f39cSAsmitha Karunanithi           originatorTypes originatorType, phosphor::dump::Manager& parent) :
624a98e8feSDhruvaraj Subhashchandran         phosphor::dump::Entry(bus, objPath.c_str(), dumpId, timeStamp, fileSize,
6364f8da9eSDhruvaraj Subhashchandran                               file, status, originatorId, originatorType,
6405ef8163SLei YU                               parent),
6505ef8163SLei YU         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit)
662f8e276cSDhruvaraj Subhashchandran     {
672f8e276cSDhruvaraj Subhashchandran         // Emit deferred signal.
682f8e276cSDhruvaraj Subhashchandran         this->phosphor::dump::bmc::EntryIfaces::emit_object_added();
692f8e276cSDhruvaraj Subhashchandran     }
704a98e8feSDhruvaraj Subhashchandran 
714a98e8feSDhruvaraj Subhashchandran     /** @brief Delete this d-bus object.
724a98e8feSDhruvaraj Subhashchandran      */
734a98e8feSDhruvaraj Subhashchandran     void delete_() override;
744a98e8feSDhruvaraj Subhashchandran 
75580d91ddSDhruvaraj Subhashchandran     /** @brief Method to initiate the offload of dump
76580d91ddSDhruvaraj Subhashchandran      *  @param[in] uri - URI to offload dump
77580d91ddSDhruvaraj Subhashchandran      */
78580d91ddSDhruvaraj Subhashchandran     void initiateOffload(std::string uri) override;
79580d91ddSDhruvaraj Subhashchandran 
806ccb50e1SDhruvaraj Subhashchandran     /** @brief Method to update an existing dump entry, once the dump creation
816ccb50e1SDhruvaraj Subhashchandran      *  is completed this function will be used to update the entry which got
826ccb50e1SDhruvaraj Subhashchandran      *  created during the dump request.
836ccb50e1SDhruvaraj Subhashchandran      *  @param[in] timeStamp - Dump creation timestamp
846ccb50e1SDhruvaraj Subhashchandran      *  @param[in] fileSize - Dump file size in bytes.
856ccb50e1SDhruvaraj Subhashchandran      *  @param[in] file - Name of dump file.
866ccb50e1SDhruvaraj Subhashchandran      */
update(uint64_t timeStamp,uint64_t fileSize,const std::filesystem::path & filePath)873fc6df48SJayanth Othayoth     void update(uint64_t timeStamp, uint64_t fileSize,
883fc6df48SJayanth Othayoth                 const std::filesystem::path& filePath)
896ccb50e1SDhruvaraj Subhashchandran     {
906ccb50e1SDhruvaraj Subhashchandran         elapsed(timeStamp);
916ccb50e1SDhruvaraj Subhashchandran         size(fileSize);
92a6ab806dSDhruvaraj Subhashchandran         // TODO: Handled dump failed case with #ibm-openbmc/2808
93a6ab806dSDhruvaraj Subhashchandran         status(OperationStatus::Completed);
946ccb50e1SDhruvaraj Subhashchandran         file = filePath;
95a6ab806dSDhruvaraj Subhashchandran         // TODO: serialization of this property will be handled with
96a6ab806dSDhruvaraj Subhashchandran         // #ibm-openbmc/2597
97a6ab806dSDhruvaraj Subhashchandran         completedTime(timeStamp);
98*93f06410SDhruvaraj Subhashchandran         serialize();
99*93f06410SDhruvaraj Subhashchandran     }
100*93f06410SDhruvaraj Subhashchandran 
101*93f06410SDhruvaraj Subhashchandran     /**
102*93f06410SDhruvaraj Subhashchandran      * @brief Update dump entry attributes from the file name.
103*93f06410SDhruvaraj Subhashchandran      *
104*93f06410SDhruvaraj Subhashchandran      * @param[in] dumpPath - The path to the dump directory.
105*93f06410SDhruvaraj Subhashchandran      */
106*93f06410SDhruvaraj Subhashchandran     void updateFromFile(const std::filesystem::path& dumpPath);
107*93f06410SDhruvaraj Subhashchandran 
108*93f06410SDhruvaraj Subhashchandran     /**
109*93f06410SDhruvaraj Subhashchandran      * @brief Deserialize and create an entry
110*93f06410SDhruvaraj Subhashchandran      * @param[in] bus - Bus to attach to.
111*93f06410SDhruvaraj Subhashchandran      * @param[in] id - Dump id.
112*93f06410SDhruvaraj Subhashchandran      * @param[in] objPath - Object path to attach to.
113*93f06410SDhruvaraj Subhashchandran      * @param[in] filePath - Path to the dump file.
114*93f06410SDhruvaraj Subhashchandran      * @param[in] parent - The dump entry's parent.
115*93f06410SDhruvaraj Subhashchandran      * @return A unique pointer to the created entry.
116*93f06410SDhruvaraj Subhashchandran      */
deserializeEntry(sdbusplus::bus_t & bus,uint32_t id,const std::string & objPath,const std::filesystem::path & filePath,phosphor::dump::Manager & parent)117*93f06410SDhruvaraj Subhashchandran     static std::unique_ptr<Entry> deserializeEntry(
118*93f06410SDhruvaraj Subhashchandran         sdbusplus::bus_t& bus, uint32_t id, const std::string& objPath,
119*93f06410SDhruvaraj Subhashchandran         const std::filesystem::path& filePath, phosphor::dump::Manager& parent)
120*93f06410SDhruvaraj Subhashchandran     {
121*93f06410SDhruvaraj Subhashchandran         try
122*93f06410SDhruvaraj Subhashchandran         {
123*93f06410SDhruvaraj Subhashchandran             auto entry = std::unique_ptr<Entry>(
124*93f06410SDhruvaraj Subhashchandran                 new Entry(bus, objPath, id, filePath, parent));
125*93f06410SDhruvaraj Subhashchandran             entry->updateFromFile(filePath);
126*93f06410SDhruvaraj Subhashchandran             entry->deserialize(filePath.parent_path());
127*93f06410SDhruvaraj Subhashchandran             entry->emitSignal();
128*93f06410SDhruvaraj Subhashchandran             return entry;
129*93f06410SDhruvaraj Subhashchandran         }
130*93f06410SDhruvaraj Subhashchandran         catch (const std::exception& e)
131*93f06410SDhruvaraj Subhashchandran         {
132*93f06410SDhruvaraj Subhashchandran             lg2::error(
133*93f06410SDhruvaraj Subhashchandran                 "Dump deserialization failed for path: {PATH}, error: {ERROR}",
134*93f06410SDhruvaraj Subhashchandran                 "PATH", filePath, "ERROR", e.what());
135*93f06410SDhruvaraj Subhashchandran             return nullptr;
136*93f06410SDhruvaraj Subhashchandran         }
137*93f06410SDhruvaraj Subhashchandran     }
138*93f06410SDhruvaraj Subhashchandran 
139*93f06410SDhruvaraj Subhashchandran   private:
140*93f06410SDhruvaraj Subhashchandran     /**
141*93f06410SDhruvaraj Subhashchandran      *  @brief A minimal private constructor for the Dump Entry Object
142*93f06410SDhruvaraj Subhashchandran      *  @param[in] bus - Bus to attach to.
143*93f06410SDhruvaraj Subhashchandran      *  @param[in] objPath - Object path to attach to
144*93f06410SDhruvaraj Subhashchandran      *  @param[in] dumpId - Dump id.
145*93f06410SDhruvaraj Subhashchandran      *  @param[in] file - Absolute path to the dump file.
146*93f06410SDhruvaraj Subhashchandran      *  @param[in] parent - The dump entry's parent.
147*93f06410SDhruvaraj Subhashchandran      */
Entry(sdbusplus::bus_t & bus,const std::string & objPath,uint32_t dumpId,const std::filesystem::path & file,phosphor::dump::Manager & parent)148*93f06410SDhruvaraj Subhashchandran     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
149*93f06410SDhruvaraj Subhashchandran           const std::filesystem::path& file, phosphor::dump::Manager& parent) :
150*93f06410SDhruvaraj Subhashchandran         phosphor::dump::Entry(bus, objPath.c_str(), dumpId, 0, 0, file,
151*93f06410SDhruvaraj Subhashchandran                               OperationStatus::InProgress, "",
152*93f06410SDhruvaraj Subhashchandran                               originatorTypes::Internal, parent),
153*93f06410SDhruvaraj Subhashchandran         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit)
154*93f06410SDhruvaraj Subhashchandran     {}
155*93f06410SDhruvaraj Subhashchandran 
156*93f06410SDhruvaraj Subhashchandran     /**
157*93f06410SDhruvaraj Subhashchandran      * @brief Emit object added signal
158*93f06410SDhruvaraj Subhashchandran      */
emitSignal()159*93f06410SDhruvaraj Subhashchandran     void emitSignal()
160*93f06410SDhruvaraj Subhashchandran     {
161*93f06410SDhruvaraj Subhashchandran         this->phosphor::dump::bmc::EntryIfaces::emit_object_added();
1626ccb50e1SDhruvaraj Subhashchandran     }
1634a98e8feSDhruvaraj Subhashchandran };
1644a98e8feSDhruvaraj Subhashchandran 
1654a98e8feSDhruvaraj Subhashchandran } // namespace bmc
1664a98e8feSDhruvaraj Subhashchandran } // namespace dump
1674a98e8feSDhruvaraj Subhashchandran } // namespace phosphor
168