1 #pragma once
2 
3 #include "xyz/openbmc_project/Logging/Entry/server.hpp"
4 #include "xyz/openbmc_project/Object/Delete/server.hpp"
5 #include "xyz/openbmc_project/Software/Version/server.hpp"
6 
7 #include <sdbusplus/bus.hpp>
8 #include <sdbusplus/server/object.hpp>
9 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
10 
11 namespace phosphor
12 {
13 namespace logging
14 {
15 
16 using EntryIfaces = sdbusplus::server::object::object<
17     sdbusplus::xyz::openbmc_project::Logging::server::Entry,
18     sdbusplus::xyz::openbmc_project::Object::server::Delete,
19     sdbusplus::xyz::openbmc_project::Association::server::Definitions,
20     sdbusplus::xyz::openbmc_project::Software::server::Version>;
21 
22 using AssociationList =
23     std::vector<std::tuple<std::string, std::string, std::string>>;
24 
25 namespace internal
26 {
27 class Manager;
28 }
29 
30 /** @class Entry
31  *  @brief OpenBMC logging entry implementation.
32  *  @details A concrete implementation for the
33  *  xyz.openbmc_project.Logging.Entry and
34  *  xyz.openbmc_project.Associations.Definitions DBus APIs.
35  */
36 class Entry : public EntryIfaces
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     virtual ~Entry() = default;
45 
46     /** @brief Constructor to put object onto bus at a dbus path.
47      *         Defer signal registration (pass true for deferSignal to the
48      *         base class) until after the properties are set.
49      *  @param[in] bus - Bus to attach to.
50      *  @param[in] path - Path to attach at.
51      *  @param[in] idErr - The error entry id.
52      *  @param[in] timestampErr - The commit timestamp.
53      *  @param[in] severityErr - The severity of the error.
54      *  @param[in] msgErr - The message of the error.
55      *  @param[in] additionalDataErr - The error metadata.
56      *  @param[in] objects - The list of associations.
57      *  @param[in] fwVersion - The BMC code version.
58      *  @param[in] parent - The error's parent.
59      */
60     Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t idErr,
61           uint64_t timestampErr, Level severityErr, std::string&& msgErr,
62           std::vector<std::string>&& additionalDataErr,
63           AssociationList&& objects, const std::string& fwVersion,
64           internal::Manager& parent) :
65         EntryIfaces(bus, path.c_str(), true),
66         parent(parent)
67     {
68         id(idErr);
69         severity(severityErr);
70         timestamp(timestampErr);
71         message(std::move(msgErr));
72         additionalData(std::move(additionalDataErr));
73         associations(std::move(objects));
74         // Store a copy of associations in case we need to recreate
75         assocs = associations();
76         sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
77             false);
78 
79         version(fwVersion);
80         purpose(VersionPurpose::BMC);
81 
82         // Emit deferred signal.
83         this->emit_object_added();
84     };
85 
86     /** @brief Constructor that puts an "empty" error object on the bus,
87      *         with only the id property populated. Rest of the properties
88      *         to be set by the caller. Caller should emit the added signal.
89      *  @param[in] bus - Bus to attach to.
90      *  @param[in] path - Path to attach at.
91      *  @param[in] id - The error entry id.
92      *  @param[in] parent - The error's parent.
93      */
94     Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t entryId,
95           internal::Manager& parent) :
96         EntryIfaces(bus, path.c_str(), true),
97         parent(parent)
98     {
99         id(entryId);
100     };
101 
102     /** @brief Set resolution status of the error.
103      *  @param[in] value - boolean indicating resolution
104      *  status (true = resolved)
105      *  @returns value of 'Resolved' property
106      */
107     bool resolved(bool value) override;
108 
109     using sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved;
110 
111     /** @brief Delete this d-bus object.
112      */
113     void delete_() override;
114 
115     /** @brief Severity level to check in cap.
116      *  @details Errors with severity lesser than this will be
117      *           considered as low priority and maximum ERROR_INFO_CAP
118      *           number errors of this category will be captured.
119      */
120     static constexpr auto sevLowerLimit = Entry::Level::Informational;
121 
122   private:
123     /** @brief This entry's associations */
124     AssociationList assocs = {};
125 
126     /** @brief This entry's parent */
127     internal::Manager& parent;
128 };
129 
130 } // namespace logging
131 } // namespace phosphor
132