1224882b0SJayanth Othayoth #pragma once
2224882b0SJayanth Othayoth 
3*74a1f39cSAsmitha Karunanithi #include "xyz/openbmc_project/Common/OriginatedBy/server.hpp"
4a6ab806dSDhruvaraj Subhashchandran #include "xyz/openbmc_project/Common/Progress/server.hpp"
5224882b0SJayanth Othayoth #include "xyz/openbmc_project/Dump/Entry/server.hpp"
6224882b0SJayanth Othayoth #include "xyz/openbmc_project/Object/Delete/server.hpp"
7224882b0SJayanth Othayoth #include "xyz/openbmc_project/Time/EpochTime/server.hpp"
8224882b0SJayanth Othayoth 
9cb65ffceSJayanth Othayoth #include <sdbusplus/bus.hpp>
10cb65ffceSJayanth Othayoth #include <sdbusplus/server/object.hpp>
11cb65ffceSJayanth Othayoth 
120af74a5eSJayanth Othayoth #include <filesystem>
130af74a5eSJayanth Othayoth 
14224882b0SJayanth Othayoth namespace phosphor
15224882b0SJayanth Othayoth {
16224882b0SJayanth Othayoth namespace dump
17224882b0SJayanth Othayoth {
18224882b0SJayanth Othayoth 
19224882b0SJayanth Othayoth template <typename T>
209b18bf2dSPatrick Williams using ServerObject = typename sdbusplus::server::object_t<T>;
21224882b0SJayanth Othayoth 
22a6ab806dSDhruvaraj Subhashchandran // TODO Revisit whether sdbusplus::xyz::openbmc_project::Time::server::EpochTime
23a6ab806dSDhruvaraj Subhashchandran // still needed in dump entry since start time and completed time are available
24a6ab806dSDhruvaraj Subhashchandran // from sdbusplus::xyz::openbmc_project::Common::server::Progress
25a6ab806dSDhruvaraj Subhashchandran // #ibm-openbmc/2809
269b18bf2dSPatrick Williams using EntryIfaces = sdbusplus::server::object_t<
27*74a1f39cSAsmitha Karunanithi     sdbusplus::xyz::openbmc_project::Common::server::OriginatedBy,
28a6ab806dSDhruvaraj Subhashchandran     sdbusplus::xyz::openbmc_project::Common::server::Progress,
29224882b0SJayanth Othayoth     sdbusplus::xyz::openbmc_project::Dump::server::Entry,
30224882b0SJayanth Othayoth     sdbusplus::xyz::openbmc_project::Object::server::Delete,
31224882b0SJayanth Othayoth     sdbusplus::xyz::openbmc_project::Time::server::EpochTime>;
32224882b0SJayanth Othayoth 
33a6ab806dSDhruvaraj Subhashchandran using OperationStatus =
34a6ab806dSDhruvaraj Subhashchandran     sdbusplus::xyz::openbmc_project::Common::server::Progress::OperationStatus;
35a320c7caSJayanth Othayoth 
36*74a1f39cSAsmitha Karunanithi using originatorTypes = sdbusplus::xyz::openbmc_project::Common::server::
37*74a1f39cSAsmitha Karunanithi     OriginatedBy::OriginatorTypes;
38*74a1f39cSAsmitha Karunanithi 
39a320c7caSJayanth Othayoth class Manager;
40a320c7caSJayanth Othayoth 
41224882b0SJayanth Othayoth /** @class Entry
42f140f665SDhruvaraj Subhashchandran  *  @brief Base Dump Entry implementation.
43224882b0SJayanth Othayoth  *  @details A concrete implementation for the
44224882b0SJayanth Othayoth  *  xyz.openbmc_project.Dump.Entry DBus API
45224882b0SJayanth Othayoth  */
46224882b0SJayanth Othayoth class Entry : public EntryIfaces
47224882b0SJayanth Othayoth {
48224882b0SJayanth Othayoth   public:
49224882b0SJayanth Othayoth     Entry() = delete;
50224882b0SJayanth Othayoth     Entry(const Entry&) = delete;
51224882b0SJayanth Othayoth     Entry& operator=(const Entry&) = delete;
52224882b0SJayanth Othayoth     Entry(Entry&&) = delete;
53224882b0SJayanth Othayoth     Entry& operator=(Entry&&) = delete;
54a320c7caSJayanth Othayoth     ~Entry() = default;
55224882b0SJayanth Othayoth 
56224882b0SJayanth Othayoth     /** @brief Constructor for the Dump Entry Object
57224882b0SJayanth Othayoth      *  @param[in] bus - Bus to attach to.
58a320c7caSJayanth Othayoth      *  @param[in] objPath - Object path to attach to
59a320c7caSJayanth Othayoth      *  @param[in] dumpId - Dump id.
60a320c7caSJayanth Othayoth      *  @param[in] timeStamp - Dump creation timestamp
61a320c7caSJayanth Othayoth      *             since the epoch.
624a98e8feSDhruvaraj Subhashchandran      *  @param[in] dumpSize - Dump file size in bytes.
63*74a1f39cSAsmitha Karunanithi      *  @param[in] originId - Id of the originator of the dump
64*74a1f39cSAsmitha Karunanithi      *  @param[in] originType - Originator type
65a320c7caSJayanth Othayoth      *  @param[in] parent - The dump entry's parent.
66224882b0SJayanth Othayoth      */
679b18bf2dSPatrick Williams     Entry(sdbusplus::bus_t& bus, const std::string& objPath, uint32_t dumpId,
68a6ab806dSDhruvaraj Subhashchandran           uint64_t timeStamp, uint64_t dumpSize, OperationStatus dumpStatus,
69*74a1f39cSAsmitha Karunanithi           std::string originId, originatorTypes originType, Manager& parent) :
7073f64076SPatrick Williams         EntryIfaces(bus, objPath.c_str(), EntryIfaces::action::emit_no_signals),
714a98e8feSDhruvaraj Subhashchandran         parent(parent), id(dumpId)
72a320c7caSJayanth Othayoth     {
73*74a1f39cSAsmitha Karunanithi         originatorId(originId);
74*74a1f39cSAsmitha Karunanithi         originatorType(originType);
75*74a1f39cSAsmitha Karunanithi 
764a98e8feSDhruvaraj Subhashchandran         size(dumpSize);
77a6ab806dSDhruvaraj Subhashchandran         status(dumpStatus);
78a6ab806dSDhruvaraj Subhashchandran 
79a6ab806dSDhruvaraj Subhashchandran         // If the object is created after the dump creation keep
80a6ab806dSDhruvaraj Subhashchandran         // all same as timeStamp
81a6ab806dSDhruvaraj Subhashchandran         // if the object created before the dump creation, update
82a6ab806dSDhruvaraj Subhashchandran         // only the start time. Completed and elapsed time will
83a6ab806dSDhruvaraj Subhashchandran         // be updated once the dump is completed.
84a6ab806dSDhruvaraj Subhashchandran         if (dumpStatus == OperationStatus::Completed)
85a6ab806dSDhruvaraj Subhashchandran         {
86a320c7caSJayanth Othayoth             elapsed(timeStamp);
87a6ab806dSDhruvaraj Subhashchandran             startTime(timeStamp);
88a6ab806dSDhruvaraj Subhashchandran             completedTime(timeStamp);
89a6ab806dSDhruvaraj Subhashchandran         }
90a6ab806dSDhruvaraj Subhashchandran         else
91a6ab806dSDhruvaraj Subhashchandran         {
92a6ab806dSDhruvaraj Subhashchandran             elapsed(0);
93a6ab806dSDhruvaraj Subhashchandran             startTime(timeStamp);
94a6ab806dSDhruvaraj Subhashchandran             completedTime(0);
95a6ab806dSDhruvaraj Subhashchandran         }
96a320c7caSJayanth Othayoth     };
97224882b0SJayanth Othayoth 
98224882b0SJayanth Othayoth     /** @brief Delete this d-bus object.
99224882b0SJayanth Othayoth      */
100224882b0SJayanth Othayoth     void delete_() override;
101224882b0SJayanth Othayoth 
1024a98e8feSDhruvaraj Subhashchandran     /** @brief Method to initiate the offload of dump
10369e6152fSDhruvaraj Subhashchandran      *  @param[in] uri - URI to offload dump
1044a98e8feSDhruvaraj Subhashchandran      */
10569e6152fSDhruvaraj Subhashchandran     void initiateOffload(std::string uri) override
1064a98e8feSDhruvaraj Subhashchandran     {
10769e6152fSDhruvaraj Subhashchandran         offloadUri(uri);
1084a98e8feSDhruvaraj Subhashchandran     }
109a320c7caSJayanth Othayoth 
110270355baSDhruvaraj Subhashchandran     /** @brief Returns the dump id
111270355baSDhruvaraj Subhashchandran      *  @return the id associated with entry
112270355baSDhruvaraj Subhashchandran      */
113270355baSDhruvaraj Subhashchandran     uint32_t getDumpId()
114270355baSDhruvaraj Subhashchandran     {
115270355baSDhruvaraj Subhashchandran         return id;
116270355baSDhruvaraj Subhashchandran     }
117270355baSDhruvaraj Subhashchandran 
1184a98e8feSDhruvaraj Subhashchandran   protected:
119a320c7caSJayanth Othayoth     /** @brief This entry's parent */
120a320c7caSJayanth Othayoth     Manager& parent;
121a320c7caSJayanth Othayoth 
122a320c7caSJayanth Othayoth     /** @brief This entry's id */
123a320c7caSJayanth Othayoth     uint32_t id;
124224882b0SJayanth Othayoth };
125224882b0SJayanth Othayoth 
126224882b0SJayanth Othayoth } // namespace dump
127224882b0SJayanth Othayoth } // namespace phosphor
128