1 #pragma once
2 
3 #include "xyz/openbmc_project/Common/OriginatedBy/server.hpp"
4 #include "xyz/openbmc_project/Common/Progress/server.hpp"
5 #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 
9 #include <sdbusplus/bus.hpp>
10 #include <sdbusplus/server/object.hpp>
11 
12 #include <filesystem>
13 
14 namespace phosphor
15 {
16 namespace dump
17 {
18 
19 template <typename T>
20 using ServerObject = typename sdbusplus::server::object_t<T>;
21 
22 // TODO Revisit whether sdbusplus::xyz::openbmc_project::Time::server::EpochTime
23 // still needed in dump entry since start time and completed time are available
24 // from sdbusplus::xyz::openbmc_project::Common::server::Progress
25 // #ibm-openbmc/2809
26 using EntryIfaces = sdbusplus::server::object_t<
27     sdbusplus::xyz::openbmc_project::Common::server::OriginatedBy,
28     sdbusplus::xyz::openbmc_project::Common::server::Progress,
29     sdbusplus::xyz::openbmc_project::Dump::server::Entry,
30     sdbusplus::xyz::openbmc_project::Object::server::Delete,
31     sdbusplus::xyz::openbmc_project::Time::server::EpochTime>;
32 
33 using OperationStatus =
34     sdbusplus::xyz::openbmc_project::Common::server::Progress::OperationStatus;
35 
36 using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server::
37     OriginatedBy::OriginatorTypes;
38 
39 class Manager;
40 
41 /** @class Entry
42  *  @brief Base Dump Entry implementation.
43  *  @details A concrete implementation for the
44  *  xyz.openbmc_project.Dump.Entry DBus API
45  */
46 class Entry : public EntryIfaces
47 {
48   public:
49     Entry() = delete;
50     Entry(const Entry&) = delete;
51     Entry& operator=(const Entry&) = delete;
52     Entry(Entry&&) = delete;
53     Entry& operator=(Entry&&) = delete;
54     ~Entry() = default;
55 
56     /** @brief Constructor for the Dump Entry Object
57      *  @param[in] bus - Bus to attach to.
58      *  @param[in] objPath - Object path to attach to
59      *  @param[in] dumpId - Dump id.
60      *  @param[in] timeStamp - Dump creation timestamp
61      *             since the epoch.
62      *  @param[in] dumpSize - Dump file size in bytes.
63      *  @param[in] originId - Id of the originator of the dump
64      *  @param[in] originType - Originator type
65      *  @param[in] parent - The dump entry's parent.
66      */
67     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
68           uint64_t timeStamp, uint64_t dumpSize, OperationStatus dumpStatus,
69           std::string originId, originatorTypes originType, Manager& parent) :
70         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::emit_no_signals),
71         parent(parent), id(dumpId)
72     {
73         originatorId(originId);
74         originatorType(originType);
75 
76         size(dumpSize);
77         status(dumpStatus);
78 
79         // If the object is created after the dump creation keep
80         // all same as timeStamp
81         // if the object created before the dump creation, update
82         // only the start time. Completed and elapsed time will
83         // be updated once the dump is completed.
84         if (dumpStatus == OperationStatus::Completed)
85         {
86             elapsed(timeStamp);
87             startTime(timeStamp);
88             completedTime(timeStamp);
89         }
90         else
91         {
92             elapsed(0);
93             startTime(timeStamp);
94             completedTime(0);
95         }
96     };
97 
98     /** @brief Delete this d-bus object.
99      */
100     void delete_() override;
101 
102     /** @brief Method to initiate the offload of dump
103      *  @param[in] uri - URI to offload dump
104      */
105     void initiateOffload(std::string uri) override
106     {
107         offloadUri(uri);
108     }
109 
110     /** @brief Returns the dump id
111      *  @return the id associated with entry
112      */
113     uint32_t getDumpId()
114     {
115         return id;
116     }
117 
118   protected:
119     /** @brief This entry's parent */
120     Manager& parent;
121 
122     /** @brief This entry's id */
123     uint32_t id;
124 };
125 
126 } // namespace dump
127 } // namespace phosphor
128