blob: af176f96f3f8139582938d66807255f8c19be916 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#pragma once
2
Adriana Kobylakf477fe22017-01-06 11:56:41 -06003#include <sdbusplus/bus.hpp>
Adriana Kobylakd722b3a2017-02-28 12:10:44 -06004#include <phosphor-logging/log.hpp>
Adriana Kobylakdf995fa2017-01-08 15:14:02 -06005#include "elog_entry.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06006#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -05007#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06008
9namespace phosphor
10{
11namespace logging
12{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060013
14extern const std::map<std::string,std::vector<std::string>> g_errMetaMap;
15extern const std::map<std::string,level> g_errLevelMap;
16
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050017using DeleteAllIface = sdbusplus::server::object::object <
18 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >;
19
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060020namespace details
21{
22
23template <typename T>
24using ServerObject = typename sdbusplus::server::object::object<T>;
25
26using ManagerIface =
27 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
28
29} // namespace details
30
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050031namespace internal
32{
33
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060034/** @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 Kobylakf477fe22017-01-06 11:56:41 -060039class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060040{
41 public:
42 Manager() = delete;
43 Manager(const Manager&) = delete;
44 Manager& operator=(const Manager&) = delete;
Adriana Kobylakf477fe22017-01-06 11:56:41 -060045 Manager(Manager&&) = delete;
46 Manager& operator=(Manager&&) = delete;
47 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060048
Adriana Kobylakf477fe22017-01-06 11:56:41 -060049 /** @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 Kobylak8f7941e2016-11-14 14:46:23 -060052 */
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060053 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
54 details::ServerObject<details::ManagerIface>(bus, objPath),
55 busLog(bus),
Marri Devender Rao7656fba2017-08-06 05:42:52 -050056 entryId(0),
57 capped(false) {};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060058
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 Kobylakdf995fa2017-01-08 15:14:02 -060070
71
Deepak Kodihalli99a85492017-03-31 06:01:57 -050072 /** @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 Kodihalli72654f12017-06-12 04:33:29 -050078 /** @brief Construct error d-bus objects from their persisted
79 * representations.
80 */
81 void restore();
82
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050083 /** @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 Kobylakdf995fa2017-01-08 15:14:02 -060097 private:
Deepak Kodihallia87c1572017-02-28 07:40:34 -060098 /** @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 Kobylakdf995fa2017-01-08 15:14:02 -0600108 /** @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 Kobylak4ea7f312017-01-10 12:52:34 -0600113
114 /** @brief Id of last error log entry */
115 uint32_t entryId;
Marri Devender Rao7656fba2017-08-06 05:42:52 -0500116
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 Kobylak8f7941e2016-11-14 14:46:23 -0600126};
127
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500128} //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 */
135class 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 Kobylak8f7941e2016-11-14 14:46:23 -0600169} // namespace logging
170} // namespace phosphor