blob: 4290a501a9c2ed8e327164fc4d9cb94d96d9fae7 [file] [log] [blame]
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06001#pragma once
2
Patrick Williamse7e741e2024-11-21 16:21:56 -05003#include "util.hpp"
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06004#include "xyz/openbmc_project/Logging/Entry/server.hpp"
Deepak Kodihalli36db46c2017-03-31 06:28:44 -05005#include "xyz/openbmc_project/Object/Delete/server.hpp"
Matt Spinler375ac9b2018-05-01 15:20:55 -05006#include "xyz/openbmc_project/Software/Version/server.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07007
8#include <sdbusplus/bus.hpp>
9#include <sdbusplus/server/object.hpp>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -060010#include <sdeventplus/event.hpp>
11#include <sdeventplus/source/event.hpp>
John Wang27d82812019-09-11 16:39:36 +080012#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Adriana Kobylak1ff95ef2020-12-03 13:52:19 -060013#include <xyz/openbmc_project/Common/FilePath/server.hpp>
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060014
15namespace phosphor
16{
17namespace logging
18{
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060019
Patrick Williams45e83522022-07-22 19:26:52 -050020using EntryIfaces = sdbusplus::server::object_t<
Willy Tu6ddbf692023-09-05 10:54:16 -070021 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>;
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060026
Deepak Kodihalli35b46372017-02-27 04:58:18 -060027using AssociationList =
Patrick Venturef18bf832018-10-26 18:14:00 -070028 std::vector<std::tuple<std::string, std::string, std::string>>;
Deepak Kodihalli35b46372017-02-27 04:58:18 -060029
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050030namespace internal
31{
Deepak Kodihalli8110ca62017-04-10 02:11:54 -050032class Manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050033}
Deepak Kodihalli8110ca62017-04-10 02:11:54 -050034
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060035/** @class Entry
36 * @brief OpenBMC logging entry implementation.
37 * @details A concrete implementation for the
Deepak Kodihallib388da62017-02-27 00:47:12 -060038 * xyz.openbmc_project.Logging.Entry and
John Wang27d82812019-09-11 16:39:36 +080039 * xyz.openbmc_project.Associations.Definitions DBus APIs.
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060040 */
Deepak Kodihallib388da62017-02-27 00:47:12 -060041class Entry : public EntryIfaces
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060042{
Patrick Venturef18bf832018-10-26 18:14:00 -070043 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;
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060050
Patrick Venturef18bf832018-10-26 18:14:00 -070051 /** @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.
Matt Spinlerfb978da2022-01-21 08:42:24 -060055 * @param[in] objectPath - Path to attach at.
Patrick Venturef18bf832018-10-26 18:14:00 -070056 * @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.
Matt Spinlerfb978da2022-01-21 08:42:24 -060063 * @param[in] filePath - Serialization path
Patrick Venturef18bf832018-10-26 18:14:00 -070064 * @param[in] parent - The error's parent.
65 */
Patrick Williams45e83522022-07-22 19:26:52 -050066 Entry(sdbusplus::bus_t& bus, const std::string& objectPath, uint32_t idErr,
67 uint64_t timestampErr, Level severityErr, std::string&& msgErr,
68 std::vector<std::string>&& additionalDataErr,
Patrick Venturef18bf832018-10-26 18:14:00 -070069 AssociationList&& objects, const std::string& fwVersion,
Matt Spinlerfb978da2022-01-21 08:42:24 -060070 const std::string& filePath, internal::Manager& parent) :
Patrick Williams6ef6b252022-03-30 14:28:27 -050071 EntryIfaces(bus, objectPath.c_str(), EntryIfaces::action::defer_emit),
Patrick Venturef18bf832018-10-26 18:14:00 -070072 parent(parent)
73 {
Matt Spinleref952af2021-08-19 10:23:05 -050074 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);
Patrick Williamse7e741e2024-11-21 16:21:56 -050080 additionalData2(util::additional_data::parse(additionalData()), true);
Matt Spinleref952af2021-08-19 10:23:05 -050081 associations(std::move(objects), true);
Patrick Venturef18bf832018-10-26 18:14:00 -070082 // Store a copy of associations in case we need to recreate
83 assocs = associations();
Patrick Williams075c7922024-08-16 15:19:49 -040084 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved(
85 false, true);
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060086
Matt Spinleref952af2021-08-19 10:23:05 -050087 version(fwVersion, true);
88 purpose(VersionPurpose::BMC, true);
Matt Spinlerfb978da2022-01-21 08:42:24 -060089 path(filePath, true);
Matt Spinler375ac9b2018-05-01 15:20:55 -050090
Patrick Venturef18bf832018-10-26 18:14:00 -070091 // Emit deferred signal.
92 this->emit_object_added();
93 };
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060094
Patrick Venturef18bf832018-10-26 18:14:00 -070095 /** @brief Constructor that puts an "empty" error object on the bus,
96 * with only the id property populated. Rest of the properties
97 * to be set by the caller. Caller should emit the added signal.
98 * @param[in] bus - Bus to attach to.
99 * @param[in] path - Path to attach at.
100 * @param[in] id - The error entry id.
101 * @param[in] parent - The error's parent.
102 */
Patrick Williams45e83522022-07-22 19:26:52 -0500103 Entry(sdbusplus::bus_t& bus, const std::string& path, uint32_t entryId,
Patrick Venturef18bf832018-10-26 18:14:00 -0700104 internal::Manager& parent) :
Patrick Williams6ef6b252022-03-30 14:28:27 -0500105 EntryIfaces(bus, path.c_str(), EntryIfaces::action::defer_emit),
Patrick Venturef18bf832018-10-26 18:14:00 -0700106 parent(parent)
107 {
Matt Spinleref952af2021-08-19 10:23:05 -0500108 id(entryId, true);
Patrick Venturef18bf832018-10-26 18:14:00 -0700109 };
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500110
Patrick Venturef18bf832018-10-26 18:14:00 -0700111 /** @brief Set resolution status of the error.
112 * @param[in] value - boolean indicating resolution
113 * status (true = resolved)
114 * @returns value of 'Resolved' property
115 */
116 bool resolved(bool value) override;
Deepak Kodihalli90abed62017-03-27 03:56:44 -0500117
Willy Tu6ddbf692023-09-05 10:54:16 -0700118 using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved;
Deepak Kodihalli90abed62017-03-27 03:56:44 -0500119
Vijay Lobod354a392021-06-01 16:21:02 -0500120 /** @brief Update eventId string of the error.
121 * @param[in] value - The eventID
122 * @returns New property value
123 */
124 std::string eventId(std::string value) override;
125
Willy Tu6ddbf692023-09-05 10:54:16 -0700126 using sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId;
Vijay Lobod354a392021-06-01 16:21:02 -0500127
Vijay Lobo593a4c62021-06-16 14:25:26 -0500128 /** @brief Update resolution string of the error.
129 * @param[in] value - The resolution
130 * @returns New property value
131 */
132 std::string resolution(std::string value) override;
133
Willy Tu6ddbf692023-09-05 10:54:16 -0700134 using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution;
Vijay Lobo593a4c62021-06-16 14:25:26 -0500135
Patrick Venturef18bf832018-10-26 18:14:00 -0700136 /** @brief Delete this d-bus object.
137 */
138 void delete_() override;
Deepak Kodihalli36db46c2017-03-31 06:28:44 -0500139
Patrick Venturef18bf832018-10-26 18:14:00 -0700140 /** @brief Severity level to check in cap.
141 * @details Errors with severity lesser than this will be
142 * considered as low priority and maximum ERROR_INFO_CAP
143 * number errors of this category will be captured.
144 */
145 static constexpr auto sevLowerLimit = Entry::Level::Informational;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500146
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600147 /**
148 * @brief Returns the file descriptor to the Entry file.
149 * @return unix_fd - File descriptor to the Entry file.
150 */
151 sdbusplus::message::unix_fd getEntry() override;
152
Patrick Venturef18bf832018-10-26 18:14:00 -0700153 private:
154 /** @brief This entry's associations */
155 AssociationList assocs = {};
Deepak Kodihalli8110ca62017-04-10 02:11:54 -0500156
Patrick Venturef18bf832018-10-26 18:14:00 -0700157 /** @brief This entry's parent */
158 internal::Manager& parent;
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600159
160 /**
161 * @brief The event source for closing the Entry file descriptor after it
162 * has been returned from the getEntry D-Bus method.
163 */
164 std::unique_ptr<sdeventplus::source::Defer> fdCloseEventSource;
165
166 /**
167 * @brief Closes the file descriptor passed in.
168 * @details This is called from the event loop to close FDs returned from
169 * getEntry().
170 * @param[in] fd - The file descriptor to close
171 * @param[in] source - The event source object used
172 */
173 void closeFD(int fd, sdeventplus::source::EventBase& source);
Adriana Kobylak88d7cf82017-01-24 12:30:15 -0600174};
175
176} // namespace logging
177} // namespace phosphor