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 */ 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 additionalData2(additionalData(), true); 81 associations(std::move(objects), true); 82 // Store a copy of associations in case we need to recreate 83 assocs = associations(); 84 sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved( 85 false, true); 86 87 version(fwVersion, true); 88 purpose(VersionPurpose::BMC, true); 89 path(filePath, true); 90 91 // Emit deferred signal. 92 this->emit_object_added(); 93 }; 94 95 /** @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 */ 103 Entry(sdbusplus::bus_t& bus, const std::string& path, uint32_t entryId, 104 internal::Manager& parent) : 105 EntryIfaces(bus, path.c_str(), EntryIfaces::action::defer_emit), 106 parent(parent) 107 { 108 id(entryId, true); 109 }; 110 111 /** @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; 117 118 using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved; 119 120 /** @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 126 using sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId; 127 128 /** @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 134 using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution; 135 136 /** @brief Delete this d-bus object. 137 */ 138 void delete_() override; 139 140 /** @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; 146 147 /** 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 153 private: 154 /** @brief This entry's associations */ 155 AssociationList assocs = {}; 156 157 /** @brief This entry's parent */ 158 internal::Manager& parent; 159 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); 174 }; 175 176 } // namespace logging 177 } // namespace phosphor 178