blob: 3a6b31386432c34619f145eb837897e3753fec91 [file] [log] [blame]
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06001#pragma once
2
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06003#include "xyz/openbmc_project/Logging/Entry/server.hpp"
Deepak Kodihalli36db46c2017-03-31 06:28:44 -05004#include "xyz/openbmc_project/Object/Delete/server.hpp"
Matt Spinler375ac9b2018-05-01 15:20:55 -05005#include "xyz/openbmc_project/Software/Version/server.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07006
7#include <sdbusplus/bus.hpp>
8#include <sdbusplus/server/object.hpp>
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -06009#include <sdeventplus/event.hpp>
10#include <sdeventplus/source/event.hpp>
John Wang27d82812019-09-11 16:39:36 +080011#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Adriana Kobylak1ff95ef2020-12-03 13:52:19 -060012#include <xyz/openbmc_project/Common/FilePath/server.hpp>
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060013
14namespace phosphor
15{
16namespace logging
17{
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060018
Deepak Kodihallib388da62017-02-27 00:47:12 -060019using EntryIfaces = sdbusplus::server::object::object<
20 sdbusplus::xyz::openbmc_project::Logging::server::Entry,
Deepak Kodihalli36db46c2017-03-31 06:28:44 -050021 sdbusplus::xyz::openbmc_project::Object::server::Delete,
John Wang27d82812019-09-11 16:39:36 +080022 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
Adriana Kobylak1ff95ef2020-12-03 13:52:19 -060023 sdbusplus::xyz::openbmc_project::Software::server::Version,
24 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060025
Deepak Kodihalli35b46372017-02-27 04:58:18 -060026using AssociationList =
Patrick Venturef18bf832018-10-26 18:14:00 -070027 std::vector<std::tuple<std::string, std::string, std::string>>;
Deepak Kodihalli35b46372017-02-27 04:58:18 -060028
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050029namespace internal
30{
Deepak Kodihalli8110ca62017-04-10 02:11:54 -050031class Manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050032}
Deepak Kodihalli8110ca62017-04-10 02:11:54 -050033
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060034/** @class Entry
35 * @brief OpenBMC logging entry implementation.
36 * @details A concrete implementation for the
Deepak Kodihallib388da62017-02-27 00:47:12 -060037 * xyz.openbmc_project.Logging.Entry and
John Wang27d82812019-09-11 16:39:36 +080038 * xyz.openbmc_project.Associations.Definitions DBus APIs.
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060039 */
Deepak Kodihallib388da62017-02-27 00:47:12 -060040class Entry : public EntryIfaces
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060041{
Patrick Venturef18bf832018-10-26 18:14:00 -070042 public:
43 Entry() = delete;
44 Entry(const Entry&) = delete;
45 Entry& operator=(const Entry&) = delete;
46 Entry(Entry&&) = delete;
47 Entry& operator=(Entry&&) = delete;
48 virtual ~Entry() = default;
Adriana Kobylak88d7cf82017-01-24 12:30:15 -060049
Patrick Venturef18bf832018-10-26 18:14:00 -070050 /** @brief Constructor to put object onto bus at a dbus path.
51 * Defer signal registration (pass true for deferSignal to the
52 * base class) until after the properties are set.
53 * @param[in] bus - Bus to attach to.
54 * @param[in] path - Path to attach at.
55 * @param[in] idErr - The error entry id.
56 * @param[in] timestampErr - The commit timestamp.
57 * @param[in] severityErr - The severity of the error.
58 * @param[in] msgErr - The message of the error.
59 * @param[in] additionalDataErr - The error metadata.
60 * @param[in] objects - The list of associations.
61 * @param[in] fwVersion - The BMC code version.
62 * @param[in] parent - The error's parent.
63 */
64 Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t idErr,
65 uint64_t timestampErr, Level severityErr, std::string&& msgErr,
66 std::vector<std::string>&& additionalDataErr,
67 AssociationList&& objects, 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);
Matt Spinler1e71a4d2020-03-04 13:40:22 -060075 updateTimestamp(timestampErr);
Patrick Venturef18bf832018-10-26 18:14:00 -070076 message(std::move(msgErr));
77 additionalData(std::move(additionalDataErr));
78 associations(std::move(objects));
79 // Store a copy of associations in case we need to recreate
80 assocs = associations();
81 sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved(
82 false);
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060083
Patrick Venturef18bf832018-10-26 18:14:00 -070084 version(fwVersion);
85 purpose(VersionPurpose::BMC);
Matt Spinler375ac9b2018-05-01 15:20:55 -050086
Patrick Venturef18bf832018-10-26 18:14:00 -070087 // Emit deferred signal.
88 this->emit_object_added();
89 };
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060090
Patrick Venturef18bf832018-10-26 18:14:00 -070091 /** @brief Constructor that puts an "empty" error object on the bus,
92 * with only the id property populated. Rest of the properties
93 * to be set by the caller. Caller should emit the added signal.
94 * @param[in] bus - Bus to attach to.
95 * @param[in] path - Path to attach at.
96 * @param[in] id - The error entry id.
97 * @param[in] parent - The error's parent.
98 */
99 Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t entryId,
100 internal::Manager& parent) :
101 EntryIfaces(bus, path.c_str(), true),
102 parent(parent)
103 {
104 id(entryId);
105 };
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500106
Patrick Venturef18bf832018-10-26 18:14:00 -0700107 /** @brief Set resolution status of the error.
108 * @param[in] value - boolean indicating resolution
109 * status (true = resolved)
110 * @returns value of 'Resolved' property
111 */
112 bool resolved(bool value) override;
Deepak Kodihalli90abed62017-03-27 03:56:44 -0500113
Patrick Venturef18bf832018-10-26 18:14:00 -0700114 using sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved;
Deepak Kodihalli90abed62017-03-27 03:56:44 -0500115
Vijay Lobod354a392021-06-01 16:21:02 -0500116 /** @brief Update eventId string of the error.
117 * @param[in] value - The eventID
118 * @returns New property value
119 */
120 std::string eventId(std::string value) override;
121
122 using sdbusplus::xyz::openbmc_project::Logging::server::Entry::eventId;
123
Vijay Lobo593a4c62021-06-16 14:25:26 -0500124 /** @brief Update resolution string of the error.
125 * @param[in] value - The resolution
126 * @returns New property value
127 */
128 std::string resolution(std::string value) override;
129
130 using sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolution;
131
Patrick Venturef18bf832018-10-26 18:14:00 -0700132 /** @brief Delete this d-bus object.
133 */
134 void delete_() override;
Deepak Kodihalli36db46c2017-03-31 06:28:44 -0500135
Patrick Venturef18bf832018-10-26 18:14:00 -0700136 /** @brief Severity level to check in cap.
137 * @details Errors with severity lesser than this will be
138 * considered as low priority and maximum ERROR_INFO_CAP
139 * number errors of this category will be captured.
140 */
141 static constexpr auto sevLowerLimit = Entry::Level::Informational;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500142
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600143 /**
144 * @brief Returns the file descriptor to the Entry file.
145 * @return unix_fd - File descriptor to the Entry file.
146 */
147 sdbusplus::message::unix_fd getEntry() override;
148
Patrick Venturef18bf832018-10-26 18:14:00 -0700149 private:
150 /** @brief This entry's associations */
151 AssociationList assocs = {};
Deepak Kodihalli8110ca62017-04-10 02:11:54 -0500152
Patrick Venturef18bf832018-10-26 18:14:00 -0700153 /** @brief This entry's parent */
154 internal::Manager& parent;
Adriana Kobylakeb5d3f22021-02-04 14:03:28 -0600155
156 /**
157 * @brief The event source for closing the Entry file descriptor after it
158 * has been returned from the getEntry D-Bus method.
159 */
160 std::unique_ptr<sdeventplus::source::Defer> fdCloseEventSource;
161
162 /**
163 * @brief Closes the file descriptor passed in.
164 * @details This is called from the event loop to close FDs returned from
165 * getEntry().
166 * @param[in] fd - The file descriptor to close
167 * @param[in] source - The event source object used
168 */
169 void closeFD(int fd, sdeventplus::source::EventBase& source);
Adriana Kobylak88d7cf82017-01-24 12:30:15 -0600170};
171
172} // namespace logging
173} // namespace phosphor