1 #pragma once 2 3 #include "xyz/openbmc_project/Logging/Entry/server.hpp" 4 #include "xyz/openbmc_project/Object/Delete/server.hpp" 5 #include "xyz/openbmc_project/Software/Version/server.hpp" 6 7 #include <sdbusplus/bus.hpp> 8 #include <sdbusplus/server/object.hpp> 9 #include <sdeventplus/event.hpp> 10 #include <sdeventplus/source/event.hpp> 11 #include <xyz/openbmc_project/Association/Definitions/server.hpp> 12 #include <xyz/openbmc_project/Common/FilePath/server.hpp> 13 14 namespace phosphor 15 { 16 namespace logging 17 { 18 19 using EntryIfaces = sdbusplus::server::object::object< 20 sdbusplus::xyz::openbmc_project::Logging::server::Entry, 21 sdbusplus::xyz::openbmc_project::Object::server::Delete, 22 sdbusplus::xyz::openbmc_project::Association::server::Definitions, 23 sdbusplus::xyz::openbmc_project::Software::server::Version, 24 sdbusplus::xyz::openbmc_project::Common::server::FilePath>; 25 26 using AssociationList = 27 std::vector<std::tuple<std::string, std::string, std::string>>; 28 29 namespace internal 30 { 31 class Manager; 32 } 33 34 /** @class Entry 35 * @brief OpenBMC logging entry implementation. 36 * @details A concrete implementation for the 37 * xyz.openbmc_project.Logging.Entry and 38 * xyz.openbmc_project.Associations.Definitions DBus APIs. 39 */ 40 class Entry : public EntryIfaces 41 { 42 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; 49 50 /** @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); 75 updateTimestamp(timestampErr); 76 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); 83 84 version(fwVersion); 85 purpose(VersionPurpose::BMC); 86 87 // Emit deferred signal. 88 this->emit_object_added(); 89 }; 90 91 /** @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 }; 106 107 /** @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; 113 114 using sdbusplus::xyz::openbmc_project::Logging::server::Entry::resolved; 115 116 /** @brief Delete this d-bus object. 117 */ 118 void delete_() override; 119 120 /** @brief Severity level to check in cap. 121 * @details Errors with severity lesser than this will be 122 * considered as low priority and maximum ERROR_INFO_CAP 123 * number errors of this category will be captured. 124 */ 125 static constexpr auto sevLowerLimit = Entry::Level::Informational; 126 127 /** 128 * @brief Returns the file descriptor to the Entry file. 129 * @return unix_fd - File descriptor to the Entry file. 130 */ 131 sdbusplus::message::unix_fd getEntry() override; 132 133 private: 134 /** @brief This entry's associations */ 135 AssociationList assocs = {}; 136 137 /** @brief This entry's parent */ 138 internal::Manager& parent; 139 140 /** 141 * @brief The event source for closing the Entry file descriptor after it 142 * has been returned from the getEntry D-Bus method. 143 */ 144 std::unique_ptr<sdeventplus::source::Defer> fdCloseEventSource; 145 146 /** 147 * @brief Closes the file descriptor passed in. 148 * @details This is called from the event loop to close FDs returned from 149 * getEntry(). 150 * @param[in] fd - The file descriptor to close 151 * @param[in] source - The event source object used 152 */ 153 void closeFD(int fd, sdeventplus::source::EventBase& source); 154 }; 155 156 } // namespace logging 157 } // namespace phosphor 158