xref: /openbmc/phosphor-logging/elog_entry.hpp (revision 109b4a5c1f1a9cad8176a05dc2066a61e5cf22ea)
1 #pragma once
2 
3 #include "util.hpp"
4 #include "xyz/openbmc_project/Logging/Entry/server.hpp"
5 #include "xyz/openbmc_project/Object/Delete/server.hpp"
6 #include "xyz/openbmc_project/Software/Version/server.hpp"
7 
8 #include <sdbusplus/bus.hpp>
9 #include <sdbusplus/server/object.hpp>
10 #include <sdeventplus/event.hpp>
11 #include <sdeventplus/source/event.hpp>
12 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
13 #include <xyz/openbmc_project/Common/FilePath/server.hpp>
14 
15 namespace phosphor
16 {
17 namespace logging
18 {
19 
20 using EntryIfaces = sdbusplus::server::object_t<
21     sdbusplus::server::xyz::openbmc_project::logging::Entry,
22     sdbusplus::server::xyz::openbmc_project::object::Delete,
23     sdbusplus::server::xyz::openbmc_project::association::Definitions,
24     sdbusplus::server::xyz::openbmc_project::software::Version,
25     sdbusplus::server::xyz::openbmc_project::common::FilePath>;
26 
27 using AssociationList =
28     std::vector<std::tuple<std::string, std::string, std::string>>;
29 
30 namespace internal
31 {
32 class Manager;
33 }
34 
35 /** @class Entry
36  *  @brief OpenBMC logging entry implementation.
37  *  @details A concrete implementation for the
38  *  xyz.openbmc_project.Logging.Entry and
39  *  xyz.openbmc_project.Associations.Definitions DBus APIs.
40  */
41 class Entry : public EntryIfaces
42 {
43   public:
44     Entry() = delete;
45     Entry(const Entry&) = delete;
46     Entry& operator=(const Entry&) = delete;
47     Entry(Entry&&) = delete;
48     Entry& operator=(Entry&&) = delete;
49     virtual ~Entry() = default;
50 
51     /** @brief Constructor to put object onto bus at a dbus path.
52      *         Defer signal registration (pass true for deferSignal to the
53      *         base class) until after the properties are set.
54      *  @param[in] bus - Bus to attach to.
55      *  @param[in] objectPath - Path to attach at.
56      *  @param[in] idErr - The error entry id.
57      *  @param[in] timestampErr - The commit timestamp.
58      *  @param[in] severityErr - The severity of the error.
59      *  @param[in] msgErr - The message of the error.
60      *  @param[in] additionalDataErr - The error metadata.
61      *  @param[in] objects - The list of associations.
62      *  @param[in] fwVersion - The BMC code version.
63      *  @param[in] filePath - Serialization path
64      *  @param[in] parent - The error's parent.
65      */
Entry(sdbusplus::bus_t & bus,const std::string & objectPath,uint32_t idErr,uint64_t timestampErr,Level severityErr,std::string && msgErr,std::map<std::string,std::string> && additionalDataErr,AssociationList && objects,const std::string & fwVersion,const std::string & filePath,internal::Manager & parent)66     Entry(sdbusplus::bus_t& bus, const std::string& objectPath, uint32_t idErr,
67           uint64_t timestampErr, Level severityErr, std::string&& msgErr,
68           std::map<std::string, std::string>&& additionalDataErr,
69           AssociationList&& objects, const std::string& fwVersion,
70           const std::string& filePath, internal::Manager& parent) :
71         EntryIfaces(bus, objectPath.c_str(), EntryIfaces::action::defer_emit),
72         parent(parent)
73     {
74         id(idErr, true);
75         severity(severityErr, true);
76         timestamp(timestampErr, true);
77         updateTimestamp(timestampErr, true);
78         message(std::move(msgErr), true);
79         additionalData(std::move(additionalDataErr), true);
80         associations(std::move(objects), true);
81         // Store a copy of associations in case we need to recreate
82         assocs = associations();
83         sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(
84             false, true);
85 
86         version(fwVersion, true);
87         purpose(VersionPurpose::BMC, true);
88         path(filePath, true);
89 
90         // Emit deferred signal.
91         this->emit_object_added();
92     };
93 
94     /** @brief Constructor that puts an "empty" error object on the bus,
95      *         with only the id property populated. Rest of the properties
96      *         to be set by the caller. Caller should emit the added signal.
97      *  @param[in] bus - Bus to attach to.
98      *  @param[in] path - Path to attach at.
99      *  @param[in] id - The error entry id.
100      *  @param[in] parent - The error's parent.
101      */
Entry(sdbusplus::bus_t & bus,const std::string & path,uint32_t entryId,internal::Manager & parent)102     Entry(sdbusplus::bus_t& bus, const std::string& path, uint32_t entryId,
103           internal::Manager& parent) :
104         EntryIfaces(bus, path.c_str(), EntryIfaces::action::defer_emit),
105         parent(parent)
106     {
107         id(entryId, true);
108     };
109 
110     /** @brief Set resolution status of the error.
111      *  @param[in] value - boolean indicating resolution
112      *  status (true = resolved)
113      *  @returns value of 'Resolved' property
114      */
115     bool resolved(bool value) override;
116 
117     using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved;
118 
119     /** @brief Update eventId string of the error.
120      *  @param[in] value - The eventID
121      *  @returns New property value
122      */
123     std::string eventId(std::string value) override;
124 
125     using sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId;
126 
127     /** @brief Update resolution string of the error.
128      *  @param[in] value - The resolution
129      *  @returns New property value
130      */
131     std::string resolution(std::string value) override;
132 
133     using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution;
134 
135     /** @brief Delete this d-bus object.
136      */
137     void delete_() override;
138 
139     /** @brief Severity level to check in cap.
140      *  @details Errors with severity lesser than this will be
141      *           considered as low priority and maximum ERROR_INFO_CAP
142      *           number errors of this category will be captured.
143      */
144     static constexpr auto sevLowerLimit = Entry::Level::Informational;
145 
146     /**
147      * @brief Returns the file descriptor to the Entry file.
148      * @return unix_fd - File descriptor to the Entry file.
149      */
150     sdbusplus::message::unix_fd getEntry() override;
151 
152   private:
153     /** @brief This entry's associations */
154     AssociationList assocs = {};
155 
156     /** @brief This entry's parent */
157     internal::Manager& parent;
158 
159     /**
160      * @brief The event source for closing the Entry file descriptor after it
161      *        has been returned from the getEntry D-Bus method.
162      */
163     std::unique_ptr<sdeventplus::source::Defer> fdCloseEventSource;
164 
165     /**
166      * @brief Closes the file descriptor passed in.
167      * @details This is called from the event loop to close FDs returned from
168      * getEntry().
169      * @param[in] fd - The file descriptor to close
170      * @param[in] source - The event source object used
171      */
172     void closeFD(int fd, sdeventplus::source::EventBase& source);
173 };
174 
175 } // namespace logging
176 } // namespace phosphor
177