xref: /openbmc/phosphor-debug-collector/dump-extensions/openpower-dumps/resource_dump_entry.hpp (revision d73a663c79943ae97194347ca1ee3f8d454f6bfa)
1 #pragma once
2 
3 #include "com/ibm/Dump/Entry/Resource/server.hpp"
4 #include "dump_entry.hpp"
5 
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server/object.hpp>
8 
9 #include <chrono>
10 
11 namespace openpower
12 {
13 namespace dump
14 {
15 namespace resource
16 {
17 template <typename T>
18 using ServerObject = typename sdbusplus::server::object_t<T>;
19 
20 using EntryIfaces = sdbusplus::server::object_t<
21     sdbusplus::com::ibm::Dump::Entry::server::Resource>;
22 
23 using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server::
24     OriginatedBy::OriginatorTypes;
25 
26 class Manager;
27 
28 /** @class Entry
29  *  @brief Resource Dump Entry implementation.
30  *  @details An extension to Dump::Entry class and
31  *  A concrete implementation for the
32  *  com::ibm::Dump::Entry::Resource DBus API
33  */
34 class Entry : virtual public EntryIfaces, virtual public phosphor::dump::Entry
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 resource 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] dumpSize - Dump size in bytes.
51      *  @param[in] sourceId - DumpId provided by the source.
52      *  @param[in] vspStr- Input to host to generate the resource dump.
53      *  @param[in] pwd - Password needed by host to validate the request.
54      *  @param[in] status - status  of the dump.
55      *  @param[in] originatorId - Id of the originator of the dump
56      *  @param[in] originatorType - Originator type
57      *  @param[in] parent - The dump entry's parent.
58      */
59     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
60           uint64_t timeStamp, uint64_t dumpSize, const uint32_t sourceId,
61           std::string vspStr, std::string pwd,
62           phosphor::dump::OperationStatus status, std::string originatorId,
63           originatorTypes originatorType, phosphor::dump::Manager& parent) :
64         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::defer_emit),
65         phosphor::dump::Entry(bus, objPath.c_str(), dumpId, timeStamp, dumpSize,
66                               std::string(), status, originatorId,
67                               originatorType, parent)
68     {
69         sourceDumpId(sourceId);
70         vspString(vspStr);
71         password(pwd);
72         // Emit deferred signal.
73         this->openpower::dump::resource::EntryIfaces::emit_object_added();
74     };
75 
76     /** @brief Method to initiate the offload of dump
77      *  @param[in] uri - URI to offload dump.
78      */
79     void initiateOffload(std::string uri) override;
80 
81     /** @brief Method to update an existing dump entry
82      *  @param[in] timeStamp - Dump creation timestamp
83      *  @param[in] dumpSize - Dump size in bytes.
84      *  @param[in] sourceId - The id of dump in the origin.
85      */
86     void update(uint64_t timeStamp, uint64_t dumpSize, uint32_t sourceId)
87     {
88         sourceDumpId(sourceId);
89         elapsed(timeStamp);
90         size(dumpSize);
91         // TODO: Handled dump failure case with
92         // #bm-openbmc/2808
93         status(OperationStatus::Completed);
94         completedTime(timeStamp);
95     }
96 
97     /**
98      * @brief Delete resource dump in host memory and the entry dbus object
99      */
100     void delete_() override;
101 };
102 
103 } // namespace resource
104 } // namespace dump
105 } // namespace openpower
106