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