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