188d7cf8dSAdriana Kobylak #pragma once 288d7cf8dSAdriana Kobylak 3e7e741eaSPatrick Williams #include "util.hpp" 488d7cf8dSAdriana Kobylak #include "xyz/openbmc_project/Logging/Entry/server.hpp" 536db46c2SDeepak Kodihalli #include "xyz/openbmc_project/Object/Delete/server.hpp" 6375ac9b9SMatt Spinler #include "xyz/openbmc_project/Software/Version/server.hpp" 7f18bf836SPatrick Venture 8f18bf836SPatrick Venture #include <sdbusplus/bus.hpp> 9f18bf836SPatrick Venture #include <sdbusplus/server/object.hpp> 10eb5d3f2fSAdriana Kobylak #include <sdeventplus/event.hpp> 11eb5d3f2fSAdriana Kobylak #include <sdeventplus/source/event.hpp> 1227d82814SJohn Wang #include <xyz/openbmc_project/Association/Definitions/server.hpp> 131ff95efeSAdriana Kobylak #include <xyz/openbmc_project/Common/FilePath/server.hpp> 1488d7cf8dSAdriana Kobylak 1588d7cf8dSAdriana Kobylak namespace phosphor 1688d7cf8dSAdriana Kobylak { 1788d7cf8dSAdriana Kobylak namespace logging 1888d7cf8dSAdriana Kobylak { 1988d7cf8dSAdriana Kobylak 2045e83521SPatrick Williams using EntryIfaces = sdbusplus::server::object_t< 216ddbf69eSWilly Tu sdbusplus::server::xyz::openbmc_project::logging::Entry, 226ddbf69eSWilly Tu sdbusplus::server::xyz::openbmc_project::object::Delete, 236ddbf69eSWilly Tu sdbusplus::server::xyz::openbmc_project::association::Definitions, 246ddbf69eSWilly Tu sdbusplus::server::xyz::openbmc_project::software::Version, 256ddbf69eSWilly Tu sdbusplus::server::xyz::openbmc_project::common::FilePath>; 2688d7cf8dSAdriana Kobylak 2735b46379SDeepak Kodihalli using AssociationList = 2835b46379SDeepak Kodihalli std::vector<std::tuple<std::string, std::string, std::string>>; 2935b46379SDeepak Kodihalli 3005aae8bcSNagaraju Goruganti namespace internal 3105aae8bcSNagaraju Goruganti { 328110ca6dSDeepak Kodihalli class Manager; 3305aae8bcSNagaraju Goruganti } 348110ca6dSDeepak Kodihalli 3588d7cf8dSAdriana Kobylak /** @class Entry 3688d7cf8dSAdriana Kobylak * @brief OpenBMC logging entry implementation. 3788d7cf8dSAdriana Kobylak * @details A concrete implementation for the 38b388da65SDeepak Kodihalli * xyz.openbmc_project.Logging.Entry and 3927d82814SJohn Wang * xyz.openbmc_project.Associations.Definitions DBus APIs. 4088d7cf8dSAdriana Kobylak */ 41b388da65SDeepak Kodihalli class Entry : public EntryIfaces 4288d7cf8dSAdriana Kobylak { 4388d7cf8dSAdriana Kobylak public: 4488d7cf8dSAdriana Kobylak Entry() = delete; 4588d7cf8dSAdriana Kobylak Entry(const Entry&) = delete; 4688d7cf8dSAdriana Kobylak Entry& operator=(const Entry&) = delete; 4788d7cf8dSAdriana Kobylak Entry(Entry&&) = delete; 4888d7cf8dSAdriana Kobylak Entry& operator=(Entry&&) = delete; 4988d7cf8dSAdriana Kobylak virtual ~Entry() = default; 5088d7cf8dSAdriana Kobylak 51df995fafSAdriana Kobylak /** @brief Constructor to put object onto bus at a dbus path. 524ea7f312SAdriana Kobylak * Defer signal registration (pass true for deferSignal to the 534ea7f312SAdriana Kobylak * base class) until after the properties are set. 54df995fafSAdriana Kobylak * @param[in] bus - Bus to attach to. 55fb978da4SMatt Spinler * @param[in] objectPath - Path to attach at. 56c5f0bbd9SAdriana Kobylak * @param[in] idErr - The error entry id. 57c5f0bbd9SAdriana Kobylak * @param[in] timestampErr - The commit timestamp. 58c5f0bbd9SAdriana Kobylak * @param[in] severityErr - The severity of the error. 59c5f0bbd9SAdriana Kobylak * @param[in] msgErr - The message of the error. 60c5f0bbd9SAdriana Kobylak * @param[in] additionalDataErr - The error metadata. 61375ac9b9SMatt Spinler * @param[in] objects - The list of associations. 62375ac9b9SMatt Spinler * @param[in] fwVersion - The BMC code version. 63fb978da4SMatt Spinler * @param[in] filePath - Serialization path 648110ca6dSDeepak Kodihalli * @param[in] parent - The error's parent. 6588d7cf8dSAdriana Kobylak */ 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)6645e83521SPatrick Williams Entry(sdbusplus::bus_t& bus, const std::string& objectPath, uint32_t idErr, 6745e83521SPatrick Williams uint64_t timestampErr, Level severityErr, std::string&& msgErr, 68ea21d995SPatrick Williams std::map<std::string, std::string>&& additionalDataErr, 69f18bf836SPatrick Venture AssociationList&& objects, const std::string& fwVersion, 70fb978da4SMatt Spinler const std::string& filePath, internal::Manager& parent) : 716ef6b25eSPatrick Williams EntryIfaces(bus, objectPath.c_str(), EntryIfaces::action::defer_emit), 728110ca6dSDeepak Kodihalli parent(parent) 734ea7f312SAdriana Kobylak { 74ef952af2SMatt Spinler id(idErr, true); 75ef952af2SMatt Spinler severity(severityErr, true); 76ef952af2SMatt Spinler timestamp(timestampErr, true); 77ef952af2SMatt Spinler updateTimestamp(timestampErr, true); 78ef952af2SMatt Spinler message(std::move(msgErr), true); 79*ea6d9c45SPatrick Williams additionalData(std::move(additionalDataErr), true); 80ef952af2SMatt Spinler associations(std::move(objects), true); 8116aed11dSDeepak Kodihalli // Store a copy of associations in case we need to recreate 8216aed11dSDeepak Kodihalli assocs = associations(); 83075c7923SPatrick Williams sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved( 84075c7923SPatrick Williams false, true); 854ea7f312SAdriana Kobylak 86ef952af2SMatt Spinler version(fwVersion, true); 87ef952af2SMatt Spinler purpose(VersionPurpose::BMC, true); 88fb978da4SMatt Spinler path(filePath, true); 89375ac9b9SMatt Spinler 904ea7f312SAdriana Kobylak // Emit deferred signal. 914ea7f312SAdriana Kobylak this->emit_object_added(); 924ea7f312SAdriana Kobylak }; 934ea7f312SAdriana Kobylak 9472654f10SDeepak Kodihalli /** @brief Constructor that puts an "empty" error object on the bus, 9572654f10SDeepak Kodihalli * with only the id property populated. Rest of the properties 9672654f10SDeepak Kodihalli * to be set by the caller. Caller should emit the added signal. 9772654f10SDeepak Kodihalli * @param[in] bus - Bus to attach to. 9872654f10SDeepak Kodihalli * @param[in] path - Path to attach at. 9972654f10SDeepak Kodihalli * @param[in] id - The error entry id. 10072654f10SDeepak Kodihalli * @param[in] parent - The error's parent. 10172654f10SDeepak Kodihalli */ Entry(sdbusplus::bus_t & bus,const std::string & path,uint32_t entryId,internal::Manager & parent)10245e83521SPatrick Williams Entry(sdbusplus::bus_t& bus, const std::string& path, uint32_t entryId, 10305aae8bcSNagaraju Goruganti internal::Manager& parent) : 1046ef6b25eSPatrick Williams EntryIfaces(bus, path.c_str(), EntryIfaces::action::defer_emit), 10572654f10SDeepak Kodihalli parent(parent) 10672654f10SDeepak Kodihalli { 107ef952af2SMatt Spinler id(entryId, true); 10872654f10SDeepak Kodihalli }; 10972654f10SDeepak Kodihalli 11090abed66SDeepak Kodihalli /** @brief Set resolution status of the error. 11190abed66SDeepak Kodihalli * @param[in] value - boolean indicating resolution 11290abed66SDeepak Kodihalli * status (true = resolved) 11390abed66SDeepak Kodihalli * @returns value of 'Resolved' property 11490abed66SDeepak Kodihalli */ 1159743189cSDeepak Kodihalli bool resolved(bool value) override; 11690abed66SDeepak Kodihalli 1176ddbf69eSWilly Tu using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolved; 11890abed66SDeepak Kodihalli 119d354a398SVijay Lobo /** @brief Update eventId string of the error. 120d354a398SVijay Lobo * @param[in] value - The eventID 121d354a398SVijay Lobo * @returns New property value 122d354a398SVijay Lobo */ 123d354a398SVijay Lobo std::string eventId(std::string value) override; 124d354a398SVijay Lobo 1256ddbf69eSWilly Tu using sdbusplus::server::xyz::openbmc_project::logging::Entry::eventId; 126d354a398SVijay Lobo 127593a4c66SVijay Lobo /** @brief Update resolution string of the error. 128593a4c66SVijay Lobo * @param[in] value - The resolution 129593a4c66SVijay Lobo * @returns New property value 130593a4c66SVijay Lobo */ 131593a4c66SVijay Lobo std::string resolution(std::string value) override; 132593a4c66SVijay Lobo 1336ddbf69eSWilly Tu using sdbusplus::server::xyz::openbmc_project::logging::Entry::resolution; 134593a4c66SVijay Lobo 13536db46c2SDeepak Kodihalli /** @brief Delete this d-bus object. 13636db46c2SDeepak Kodihalli */ 13736db46c2SDeepak Kodihalli void delete_() override; 13836db46c2SDeepak Kodihalli 139f8a5a797SNagaraju Goruganti /** @brief Severity level to check in cap. 140f8a5a797SNagaraju Goruganti * @details Errors with severity lesser than this will be 141f8a5a797SNagaraju Goruganti * considered as low priority and maximum ERROR_INFO_CAP 142f8a5a797SNagaraju Goruganti * number errors of this category will be captured. 143f8a5a797SNagaraju Goruganti */ 144f8a5a797SNagaraju Goruganti static constexpr auto sevLowerLimit = Entry::Level::Informational; 145f8a5a797SNagaraju Goruganti 146eb5d3f2fSAdriana Kobylak /** 147eb5d3f2fSAdriana Kobylak * @brief Returns the file descriptor to the Entry file. 148eb5d3f2fSAdriana Kobylak * @return unix_fd - File descriptor to the Entry file. 149eb5d3f2fSAdriana Kobylak */ 150eb5d3f2fSAdriana Kobylak sdbusplus::message::unix_fd getEntry() override; 151eb5d3f2fSAdriana Kobylak 15216aed11dSDeepak Kodihalli private: 15316aed11dSDeepak Kodihalli /** @brief This entry's associations */ 15416aed11dSDeepak Kodihalli AssociationList assocs = {}; 1558110ca6dSDeepak Kodihalli 1568110ca6dSDeepak Kodihalli /** @brief This entry's parent */ 15705aae8bcSNagaraju Goruganti internal::Manager& parent; 158eb5d3f2fSAdriana Kobylak 159eb5d3f2fSAdriana Kobylak /** 160eb5d3f2fSAdriana Kobylak * @brief The event source for closing the Entry file descriptor after it 161eb5d3f2fSAdriana Kobylak * has been returned from the getEntry D-Bus method. 162eb5d3f2fSAdriana Kobylak */ 163eb5d3f2fSAdriana Kobylak std::unique_ptr<sdeventplus::source::Defer> fdCloseEventSource; 164eb5d3f2fSAdriana Kobylak 165eb5d3f2fSAdriana Kobylak /** 166eb5d3f2fSAdriana Kobylak * @brief Closes the file descriptor passed in. 167eb5d3f2fSAdriana Kobylak * @details This is called from the event loop to close FDs returned from 168eb5d3f2fSAdriana Kobylak * getEntry(). 169eb5d3f2fSAdriana Kobylak * @param[in] fd - The file descriptor to close 170eb5d3f2fSAdriana Kobylak * @param[in] source - The event source object used 171eb5d3f2fSAdriana Kobylak */ 172eb5d3f2fSAdriana Kobylak void closeFD(int fd, sdeventplus::source::EventBase& source); 17388d7cf8dSAdriana Kobylak }; 17488d7cf8dSAdriana Kobylak 17588d7cf8dSAdriana Kobylak } // namespace logging 17688d7cf8dSAdriana Kobylak } // namespace phosphor 177