| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
| Adriana Kobylak | f477fe2 | 2017-01-06 11:56:41 -0600 | [diff] [blame] | 3 | #include <sdbusplus/bus.hpp> | 
| Adriana Kobylak | d722b3a | 2017-02-28 12:10:44 -0600 | [diff] [blame] | 4 | #include <phosphor-logging/log.hpp> | 
| Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 5 | #include "elog_entry.hpp" | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp" | 
| Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 8 |  | 
|  | 9 | namespace phosphor | 
|  | 10 | { | 
|  | 11 | namespace logging | 
|  | 12 | { | 
| Adriana Kobylak | d722b3a | 2017-02-28 12:10:44 -0600 | [diff] [blame] | 13 |  | 
|  | 14 | extern const std::map<std::string,std::vector<std::string>> g_errMetaMap; | 
|  | 15 | extern const std::map<std::string,level> g_errLevelMap; | 
|  | 16 |  | 
| Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 17 | using DeleteAllIface = sdbusplus::server::object::object < | 
|  | 18 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >; | 
|  | 19 |  | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 20 | namespace details | 
|  | 21 | { | 
|  | 22 |  | 
|  | 23 | template <typename T> | 
|  | 24 | using ServerObject = typename sdbusplus::server::object::object<T>; | 
|  | 25 |  | 
|  | 26 | using ManagerIface = | 
|  | 27 | sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager; | 
|  | 28 |  | 
|  | 29 | } // namespace details | 
|  | 30 |  | 
| Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 31 | namespace internal | 
|  | 32 | { | 
|  | 33 |  | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 34 | /** @class Manager | 
|  | 35 | *  @brief OpenBMC logging manager implementation. | 
|  | 36 | *  @details A concrete implementation for the | 
|  | 37 | *  xyz.openbmc_project.Logging.Internal.Manager DBus API. | 
|  | 38 | */ | 
| Adriana Kobylak | f477fe2 | 2017-01-06 11:56:41 -0600 | [diff] [blame] | 39 | class Manager : public details::ServerObject<details::ManagerIface> | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 40 | { | 
|  | 41 | public: | 
|  | 42 | Manager() = delete; | 
|  | 43 | Manager(const Manager&) = delete; | 
|  | 44 | Manager& operator=(const Manager&) = delete; | 
| Adriana Kobylak | f477fe2 | 2017-01-06 11:56:41 -0600 | [diff] [blame] | 45 | Manager(Manager&&) = delete; | 
|  | 46 | Manager& operator=(Manager&&) = delete; | 
|  | 47 | virtual ~Manager() = default; | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 48 |  | 
| Adriana Kobylak | f477fe2 | 2017-01-06 11:56:41 -0600 | [diff] [blame] | 49 | /** @brief Constructor to put object onto bus at a dbus path. | 
|  | 50 | *  @param[in] bus - Bus to attach to. | 
|  | 51 | *  @param[in] path - Path to attach at. | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 52 | */ | 
| Adriana Kobylak | 4ea7f31 | 2017-01-10 12:52:34 -0600 | [diff] [blame] | 53 | Manager(sdbusplus::bus::bus& bus, const char* objPath) : | 
|  | 54 | details::ServerObject<details::ManagerIface>(bus, objPath), | 
|  | 55 | busLog(bus), | 
| Marri Devender Rao | 7656fba | 2017-08-06 05:42:52 -0500 | [diff] [blame] | 56 | entryId(0), | 
|  | 57 | capped(false) {}; | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 58 |  | 
|  | 59 | /* | 
|  | 60 | * @fn commit() | 
|  | 61 | * @brief sd_bus Commit method implementation callback. | 
|  | 62 | * @details Create an error/event log based on transaction id and | 
|  | 63 | *          error message. | 
|  | 64 | * @param[in] transactionId - Unique identifier of the journal entries | 
|  | 65 | *                            to be committed. | 
|  | 66 | * @param[in] errMsg - The error exception message associated with the | 
|  | 67 | *                     error log to be committed. | 
|  | 68 | */ | 
|  | 69 | void commit(uint64_t transactionId, std::string errMsg) override; | 
| Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 70 |  | 
|  | 71 |  | 
| Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 72 | /** @brief Erase specified entry d-bus object | 
|  | 73 | * | 
|  | 74 | * @param[in] entryId - unique identifier of the entry | 
|  | 75 | */ | 
|  | 76 | void erase(uint32_t entryId); | 
|  | 77 |  | 
| Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 78 | /** @brief Construct error d-bus objects from their persisted | 
|  | 79 | *         representations. | 
|  | 80 | */ | 
|  | 81 | void restore(); | 
|  | 82 |  | 
| Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 83 | /** @brief  Erase all error log entries | 
|  | 84 | * | 
|  | 85 | */ | 
|  | 86 | void eraseAll() | 
|  | 87 | { | 
|  | 88 | auto iter = entries.begin(); | 
|  | 89 | while (iter != entries.end()) | 
|  | 90 | { | 
|  | 91 | auto entry = iter->first; | 
|  | 92 | ++iter; | 
|  | 93 | erase(entry); | 
|  | 94 | } | 
|  | 95 | } | 
|  | 96 |  | 
| Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 97 | private: | 
| Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 98 | /** @brief Call metadata handler(s), if any. Handlers may create | 
|  | 99 | *         associations. | 
|  | 100 | *  @param[in] errorName - name of the error | 
|  | 101 | *  @param[in] additionalData - list of metadata (in key=value format) | 
|  | 102 | *  @param[out] objects - list of error's association objects | 
|  | 103 | */ | 
|  | 104 | void processMetadata(const std::string& errorName, | 
|  | 105 | const std::vector<std::string>& additionalData, | 
|  | 106 | AssociationList& objects) const; | 
|  | 107 |  | 
| Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 108 | /** @brief Persistent sdbusplus DBus bus connection. */ | 
|  | 109 | sdbusplus::bus::bus& busLog; | 
|  | 110 |  | 
|  | 111 | /** @brief Persistent map of Entry dbus objects and their ID */ | 
|  | 112 | std::map<uint32_t, std::unique_ptr<Entry>> entries; | 
| Adriana Kobylak | 4ea7f31 | 2017-01-10 12:52:34 -0600 | [diff] [blame] | 113 |  | 
|  | 114 | /** @brief Id of last error log entry */ | 
|  | 115 | uint32_t entryId; | 
| Marri Devender Rao | 7656fba | 2017-08-06 05:42:52 -0500 | [diff] [blame] | 116 |  | 
|  | 117 | /** | 
|  | 118 | * @brief Flag to log error for the first time when error cap is | 
|  | 119 | *      reached. | 
|  | 120 | * @details Flag used to log error message for the first time when the | 
|  | 121 | *      error cap value is reached. It is reset when user delete's error | 
|  | 122 | *      entries and total entries existing is less than the error cap | 
|  | 123 | *      value. | 
|  | 124 | */ | 
|  | 125 | bool capped; | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 126 | }; | 
|  | 127 |  | 
| Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 128 | } //namespace internal | 
|  | 129 |  | 
|  | 130 | /** @class Manager | 
|  | 131 | *  @brief Implementation for delete all error log entries. | 
|  | 132 | *  @details A concrete implementation for the | 
|  | 133 | *  xyz.openbmc_project.Collection.DeleteAll | 
|  | 134 | */ | 
|  | 135 | class Manager : public DeleteAllIface | 
|  | 136 | { | 
|  | 137 | public: | 
|  | 138 | Manager() = delete; | 
|  | 139 | Manager(const Manager&) = delete; | 
|  | 140 | Manager& operator=(const Manager&) = delete; | 
|  | 141 | Manager(Manager&&) = delete; | 
|  | 142 | Manager& operator=(Manager&&) = delete; | 
|  | 143 | virtual ~Manager() = default; | 
|  | 144 |  | 
|  | 145 | /** @brief Constructor to put object onto bus at a dbus path. | 
|  | 146 | *         Defer signal registration (pass true for deferSignal to the | 
|  | 147 | *         base class) until after the properties are set. | 
|  | 148 | *  @param[in] bus - Bus to attach to. | 
|  | 149 | *  @param[in] path - Path to attach at. | 
|  | 150 | *  @param[in] manager - Reference to internal manager object. | 
|  | 151 | */ | 
|  | 152 | Manager(sdbusplus::bus::bus& bus, | 
|  | 153 | const std::string& path, | 
|  | 154 | internal::Manager& manager) : | 
|  | 155 | DeleteAllIface(bus, path.c_str(), true), | 
|  | 156 | manager(manager) {}; | 
|  | 157 |  | 
|  | 158 | /** @brief Delete all d-bus objects. | 
|  | 159 | */ | 
|  | 160 | void deleteAll() | 
|  | 161 | { | 
|  | 162 | manager.eraseAll(); | 
|  | 163 | } | 
|  | 164 | private: | 
|  | 165 | /** @brief This is a reference to manager object */ | 
|  | 166 | internal::Manager& manager; | 
|  | 167 | }; | 
|  | 168 |  | 
| Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 169 | } // namespace logging | 
|  | 170 | } // namespace phosphor |