blob: 8576ec41048aba746e3c97b73c43d15677719afb [file] [log] [blame]
Matt Spinlere0017eb2018-03-27 11:17:38 -05001#pragma once
2
Matt Spinler66e07072018-09-12 10:36:14 -05003#include "config.h"
4
5#include "dbus.hpp"
6#include "interfaces.hpp"
7
Patrick Williams6a2b8952023-05-10 07:50:35 -05008#include <sdbusplus/bus.hpp>
9
Matt Spinler54ea3ad2018-10-23 10:40:09 -050010#include <any>
Matt Spinlere0017eb2018-03-27 11:17:38 -050011#include <experimental/filesystem>
12#include <map>
Andrew Geissler29c2ec62020-05-16 13:48:44 -050013#include <string>
Matt Spinler743e5822018-03-27 13:44:50 -050014#ifdef USE_POLICY_INTERFACE
15#include "policy_table.hpp"
16#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -050017
18namespace ibm
19{
20namespace logging
21{
22
Matt Spinlere0017eb2018-03-27 11:17:38 -050023/**
24 * @class Manager
25 *
26 * This class hosts IBM specific interfaces for the error logging
27 * entry objects. It watches for interfaces added and removed
28 * signals to know when to create and delete objects. Handling the
29 * xyz.openbmc_project.Logging service going away is done at the
30 * systemd service level where this app will be stopped too.
31 */
32class Manager
33{
Matt Spinler259e7272018-03-29 10:57:17 -050034 public:
35 Manager() = delete;
36 ~Manager() = default;
37 Manager(const Manager&) = delete;
38 Manager& operator=(const Manager&) = delete;
39 Manager(Manager&&) = delete;
40 Manager& operator=(Manager&&) = delete;
Matt Spinlere0017eb2018-03-27 11:17:38 -050041
Matt Spinler259e7272018-03-29 10:57:17 -050042 /**
43 * Constructor
44 *
45 * @param[in] bus - the D-Bus bus object
46 */
Patrick Williams8123a712022-07-22 19:26:53 -050047 explicit Manager(sdbusplus::bus_t& bus);
Matt Spinlere0017eb2018-03-27 11:17:38 -050048
Matt Spinler259e7272018-03-29 10:57:17 -050049 private:
Matt Spinlera1390352018-05-23 10:48:19 -050050 using EntryID = uint32_t;
Matt Spinler54ea3ad2018-10-23 10:40:09 -050051 using InterfaceMap = std::map<InterfaceType, std::any>;
Matt Spinlera1390352018-05-23 10:48:19 -050052 using EntryMap = std::map<EntryID, InterfaceMap>;
53
Matt Spinler54ea3ad2018-10-23 10:40:09 -050054 using ObjectList = std::vector<std::any>;
Matt Spinler677143b2018-05-23 10:53:27 -050055 using InterfaceMapMulti = std::map<InterfaceType, ObjectList>;
56 using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>;
57
Matt Spinlera1390352018-05-23 10:48:19 -050058 /**
59 * Deletes the entry and any child entries with
60 * the specified ID.
61 *
62 * @param[in] id - the entry ID
63 */
64 void erase(EntryID id);
65
Matt Spinler259e7272018-03-29 10:57:17 -050066 /**
67 * The callback for an interfaces added signal
68 *
69 * Creates the IBM interfaces for the log entry
70 * that was just created.
71 *
72 * @param[in] msg - the sdbusplus message
73 */
Patrick Williams8123a712022-07-22 19:26:53 -050074 void interfaceAdded(sdbusplus::message_t& msg);
Matt Spinlere0017eb2018-03-27 11:17:38 -050075
Matt Spinler259e7272018-03-29 10:57:17 -050076 /**
Matt Spinler055da3b2018-05-09 15:51:20 -050077 * The callback for an interfaces removed signal
78 *
79 * Removes the IBM interfaces for the log entry
80 * that was just removed.
81 *
82 * @param[in] msg - the sdbusplus message
83 */
Patrick Williams8123a712022-07-22 19:26:53 -050084 void interfaceRemoved(sdbusplus::message_t& msg);
Matt Spinler055da3b2018-05-09 15:51:20 -050085
86 /**
Matt Spinler259e7272018-03-29 10:57:17 -050087 * Creates the IBM interfaces for all existing error log
88 * entries.
89 */
90 void createAll();
Matt Spinlere0017eb2018-03-27 11:17:38 -050091
Matt Spinler259e7272018-03-29 10:57:17 -050092 /**
Matt Spinlere6a51592018-05-23 12:47:10 -050093 * Creates the IBM interface(s) for a single new error log.
94 *
95 * Any interfaces that require serialization will be created
96 * and serialized here.
Matt Spinler259e7272018-03-29 10:57:17 -050097 *
98 * @param[in] objectPath - object path of the error log
Matt Spinlere6a51592018-05-23 12:47:10 -050099 * @param[in] interfaces - map of all interfaces and properties
100 * on a phosphor-logging error log
Matt Spinler259e7272018-03-29 10:57:17 -0500101 */
102 void create(const std::string& objectPath,
Matt Spinlere6a51592018-05-23 12:47:10 -0500103 const DbusInterfaceMap& interfaces);
104
105 /**
106 * Creates the IBM interface(s) for a single error log after
107 * the application is restarted.
108 *
109 * Interfaces that were persisted will be restored from their
110 * previously saved filesystem data.
111 *
112 * @param[in] objectPath - object path of the error log
113 * @param[in] interfaces - map of all interfaces and properties
114 * on a phosphor-logging error log
115 */
116 void createWithRestore(const std::string& objectPath,
117 const DbusInterfaceMap& interfaces);
118
119 /**
120 * Creates the IBM interfaces for a single error log that
121 * do not persist across app restarts.
122 *
123 * @param[in] objectPath - object path of the error log
124 * @param[in] interfaces - map of all interfaces and properties
125 * on a phosphor-logging error log
126 */
127 void createObject(const std::string& objectPath,
128 const DbusInterfaceMap& interfaces);
Matt Spinler54bfa7e2018-03-27 11:28:59 -0500129
Matt Spinler259e7272018-03-29 10:57:17 -0500130 /**
Matt Spinler52ee71b2018-05-23 13:18:55 -0500131 * Returns the error log timestamp property value from
132 * the passed in map of all interfaces and property names/values
133 * on an error log D-Bus object.
134 *
135 * @param[in] interfaces - map of all interfaces and properties
136 * on a phosphor-logging error log.
137 *
138 * @return uint64_t - the timestamp
139 */
140 uint64_t getLogTimestamp(const DbusInterfaceMap& interfaces);
141
142 /**
143 * Returns the filesystem directory to use for persisting
144 * information about a particular error log.
145 *
146 * @param[in] id - the error log ID
147 * @return path - the directory path
148 */
149 std::experimental::filesystem::path getSaveDir(EntryID id);
150
151 /**
152 * Returns the directory to use to save the callout information in
153 *
154 * @param[in] id - the error log ID
155 *
156 * @return path - the directory path
157 */
158 std::experimental::filesystem::path getCalloutSaveDir(EntryID id);
159
160 /**
161 * Returns the D-Bus object path to use for a callout D-Bus object.
162 *
163 * @param[in] objectPath - the object path for the error log
164 * @param[in] calloutNum - the callout instance number
165 *
166 * @return path - the object path to use for a callout object
167 */
168 std::string getCalloutObjectPath(const std::string& objectPath,
169 uint32_t calloutNum);
170
171 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500172 * Creates the IBM policy interface for a single error log
173 * and saves it in the list of interfaces.
174 *
175 * @param[in] objectPath - object path of the error log
176 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
177 * properties
178 */
Matt Spinler4a6ea6a2018-03-27 14:25:12 -0500179#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500180 void createPolicyInterface(const std::string& objectPath,
181 const DbusPropertyMap& properties);
Matt Spinler4a6ea6a2018-03-27 14:25:12 -0500182#endif
183
Matt Spinler259e7272018-03-29 10:57:17 -0500184 /**
Matt Spinler52ee71b2018-05-23 13:18:55 -0500185 * Creates D-Bus objects for any callouts in an error log
186 * that map to an inventory object with an Asset interface.
187 *
188 * The created object will also host the Asset interface.
189 *
190 * A callout object path would look like:
191 * /xyz/openbmc_project/logging/entry/5/callouts/0.
192 *
193 * Any objects created are serialized so the asset information
194 * can always be restored.
195 *
196 * @param[in] objectPath - object path of the error log
197 * @param[in] interfaces - map of all interfaces and properties
198 * on a phosphor-logging error log.
199 */
200 void createCalloutObjects(const std::string& objectPath,
201 const DbusInterfaceMap& interfaces);
202
203 /**
Matt Spinler60f53d82018-05-23 13:23:09 -0500204 * Restores callout objects for a particular error log that
205 * have previously been saved by reading their data out of
206 * the filesystem using Cereal.
207 *
208 * @param[in] objectPath - object path of the error log
209 * @param[in] interfaces - map of all interfaces and properties
210 * on a phosphor-logging error log.
211 */
212 void restoreCalloutObjects(const std::string& objectPath,
213 const DbusInterfaceMap& interfaces);
214
215 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500216 * Returns the entry ID for a log
217 *
218 * @param[in] objectPath - the object path of the log
219 *
220 * @return uint32_t - the ID
221 */
222 inline uint32_t getEntryID(const std::string& objectPath)
223 {
224 std::experimental::filesystem::path path(objectPath);
225 return std::stoul(path.filename());
226 }
Matt Spinlere0017eb2018-03-27 11:17:38 -0500227
Matt Spinler259e7272018-03-29 10:57:17 -0500228 /**
Matt Spinler491fc6f2018-04-23 11:00:52 -0500229 * Adds an interface object to the entries map
230 *
231 * @param[in] objectPath - the object path of the log
232 * @param[in] type - the interface type being added
233 * @param[in] object - the interface object
234 */
235 void addInterface(const std::string& objectPath, InterfaceType type,
Matt Spinler54ea3ad2018-10-23 10:40:09 -0500236 std::any& object);
Matt Spinler491fc6f2018-04-23 11:00:52 -0500237
238 /**
Matt Spinler677143b2018-05-23 10:53:27 -0500239 * Adds an interface to a child object, which is an object that
240 * relates to the main ...logging/entry/X object but has a different path.
241 * The object is stored in the childEntries map.
242 *
243 * There can be multiple instances of a child object per type per
244 * logging object.
245 *
246 * @param[in] objectPath - the object path of the log
247 * @param[in] type - the interface type being added.
248 * @param[in] object - the interface object
249 */
250 void addChildInterface(const std::string& objectPath, InterfaceType type,
Matt Spinler54ea3ad2018-10-23 10:40:09 -0500251 std::any& object);
Matt Spinler677143b2018-05-23 10:53:27 -0500252
253 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500254 * The sdbusplus bus object
255 */
Patrick Williams8123a712022-07-22 19:26:53 -0500256 sdbusplus::bus_t& bus;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500257
Matt Spinler259e7272018-03-29 10:57:17 -0500258 /**
259 * The match object for interfacesAdded
260 */
261 sdbusplus::bus::match_t addMatch;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500262
Matt Spinler055da3b2018-05-09 15:51:20 -0500263 /**
264 * The match object for interfacesRemoved
265 */
266 sdbusplus::bus::match_t removeMatch;
267
Matt Spinler259e7272018-03-29 10:57:17 -0500268 /**
269 * A map of the error log IDs to their IBM interface objects.
270 * There may be multiple interfaces per ID.
271 */
272 EntryMap entries;
Matt Spinler743e5822018-03-27 13:44:50 -0500273
Matt Spinler677143b2018-05-23 10:53:27 -0500274 /**
275 * A map of the error log IDs to their interface objects which
276 * are children of the logging objects.
277 *
278 * These objects have the same lifespan as their parent objects.
279 *
280 * There may be multiple interfaces per ID, and also multiple
281 * interface instances per interface type.
282 */
283 EntryMapMulti childEntries;
284
Matt Spinler743e5822018-03-27 13:44:50 -0500285#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500286 /**
287 * The class the wraps the IBM error logging policy table.
288 */
289 policy::Table policies;
Matt Spinler743e5822018-03-27 13:44:50 -0500290#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500291};
Matt Spinler66e07072018-09-12 10:36:14 -0500292} // namespace logging
293} // namespace ibm