blob: 399a2435ebe568fdbb03862ad54e2d23ccbcc5e3 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#pragma once
2
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -05003#include <list>
Adriana Kobylakf477fe22017-01-06 11:56:41 -06004#include <sdbusplus/bus.hpp>
Adriana Kobylakd722b3a2017-02-28 12:10:44 -06005#include <phosphor-logging/log.hpp>
Adriana Kobylakdf995fa2017-01-08 15:14:02 -06006#include "elog_entry.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06007#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -05008#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06009
10namespace phosphor
11{
12namespace logging
13{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060014
15extern const std::map<std::string,std::vector<std::string>> g_errMetaMap;
16extern const std::map<std::string,level> g_errLevelMap;
17
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050018using DeleteAllIface = sdbusplus::server::object::object <
19 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >;
20
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060021namespace details
22{
23
24template <typename T>
25using ServerObject = typename sdbusplus::server::object::object<T>;
26
27using ManagerIface =
28 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
29
30} // namespace details
31
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050032namespace internal
33{
34
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060035/** @class Manager
36 * @brief OpenBMC logging manager implementation.
37 * @details A concrete implementation for the
38 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
39 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060040class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060041{
42 public:
43 Manager() = delete;
44 Manager(const Manager&) = delete;
45 Manager& operator=(const Manager&) = delete;
Adriana Kobylakf477fe22017-01-06 11:56:41 -060046 Manager(Manager&&) = delete;
47 Manager& operator=(Manager&&) = delete;
48 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060049
Adriana Kobylakf477fe22017-01-06 11:56:41 -060050 /** @brief Constructor to put object onto bus at a dbus path.
51 * @param[in] bus - Bus to attach to.
52 * @param[in] path - Path to attach at.
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060053 */
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060054 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
55 details::ServerObject<details::ManagerIface>(bus, objPath),
56 busLog(bus),
Marri Devender Rao7656fba2017-08-06 05:42:52 -050057 entryId(0),
58 capped(false) {};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060059
60 /*
61 * @fn commit()
62 * @brief sd_bus Commit method implementation callback.
63 * @details Create an error/event log based on transaction id and
64 * error message.
65 * @param[in] transactionId - Unique identifier of the journal entries
66 * to be committed.
67 * @param[in] errMsg - The error exception message associated with the
68 * error log to be committed.
69 */
70 void commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060071
72
Deepak Kodihalli99a85492017-03-31 06:01:57 -050073 /** @brief Erase specified entry d-bus object
74 *
75 * @param[in] entryId - unique identifier of the entry
76 */
77 void erase(uint32_t entryId);
78
Deepak Kodihalli72654f12017-06-12 04:33:29 -050079 /** @brief Construct error d-bus objects from their persisted
80 * representations.
81 */
82 void restore();
83
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050084 /** @brief Erase all error log entries
85 *
86 */
87 void eraseAll()
88 {
89 auto iter = entries.begin();
90 while (iter != entries.end())
91 {
92 auto entry = iter->first;
93 ++iter;
94 erase(entry);
95 }
96 }
97
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060098 private:
Deepak Kodihallia87c1572017-02-28 07:40:34 -060099 /** @brief Call metadata handler(s), if any. Handlers may create
100 * associations.
101 * @param[in] errorName - name of the error
102 * @param[in] additionalData - list of metadata (in key=value format)
103 * @param[out] objects - list of error's association objects
104 */
105 void processMetadata(const std::string& errorName,
106 const std::vector<std::string>& additionalData,
107 AssociationList& objects) const;
108
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600109 /** @brief Persistent sdbusplus DBus bus connection. */
110 sdbusplus::bus::bus& busLog;
111
112 /** @brief Persistent map of Entry dbus objects and their ID */
113 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600114
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500115 /** @brief List of error ids for Info(and below) severity */
116 std::list<uint32_t> infoErrors;
117
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600118 /** @brief Id of last error log entry */
119 uint32_t entryId;
Marri Devender Rao7656fba2017-08-06 05:42:52 -0500120
121 /**
122 * @brief Flag to log error for the first time when error cap is
123 * reached.
124 * @details Flag used to log error message for the first time when the
125 * error cap value is reached. It is reset when user delete's error
126 * entries and total entries existing is less than the error cap
127 * value.
128 */
129 bool capped;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600130};
131
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500132} //namespace internal
133
134/** @class Manager
135 * @brief Implementation for delete all error log entries.
136 * @details A concrete implementation for the
137 * xyz.openbmc_project.Collection.DeleteAll
138 */
139class Manager : public DeleteAllIface
140{
141 public:
142 Manager() = delete;
143 Manager(const Manager&) = delete;
144 Manager& operator=(const Manager&) = delete;
145 Manager(Manager&&) = delete;
146 Manager& operator=(Manager&&) = delete;
147 virtual ~Manager() = default;
148
149 /** @brief Constructor to put object onto bus at a dbus path.
150 * Defer signal registration (pass true for deferSignal to the
151 * base class) until after the properties are set.
152 * @param[in] bus - Bus to attach to.
153 * @param[in] path - Path to attach at.
154 * @param[in] manager - Reference to internal manager object.
155 */
156 Manager(sdbusplus::bus::bus& bus,
157 const std::string& path,
158 internal::Manager& manager) :
159 DeleteAllIface(bus, path.c_str(), true),
160 manager(manager) {};
161
162 /** @brief Delete all d-bus objects.
163 */
164 void deleteAll()
165 {
166 manager.eraseAll();
167 }
168 private:
169 /** @brief This is a reference to manager object */
170 internal::Manager& manager;
171};
172
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600173} // namespace logging
174} // namespace phosphor