blob: 0c8a095ceb61386085580786314782c6ad1aeb8c [file] [log] [blame]
Matt Spinlere0017eb2018-03-27 11:17:38 -05001#pragma once
2
3#include <experimental/any>
4#include <experimental/filesystem>
5#include <map>
6#include <sdbusplus/bus.hpp>
Matt Spinler743e5822018-03-27 13:44:50 -05007#include "config.h"
Matt Spinlere0017eb2018-03-27 11:17:38 -05008#include "dbus.hpp"
9#include "interfaces.hpp"
Matt Spinler743e5822018-03-27 13:44:50 -050010#ifdef USE_POLICY_INTERFACE
11#include "policy_table.hpp"
12#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -050013
14namespace ibm
15{
16namespace logging
17{
18
Matt Spinlere0017eb2018-03-27 11:17:38 -050019/**
20 * @class Manager
21 *
22 * This class hosts IBM specific interfaces for the error logging
23 * entry objects. It watches for interfaces added and removed
24 * signals to know when to create and delete objects. Handling the
25 * xyz.openbmc_project.Logging service going away is done at the
26 * systemd service level where this app will be stopped too.
27 */
28class Manager
29{
Matt Spinler259e7272018-03-29 10:57:17 -050030 public:
31 Manager() = delete;
32 ~Manager() = default;
33 Manager(const Manager&) = delete;
34 Manager& operator=(const Manager&) = delete;
35 Manager(Manager&&) = delete;
36 Manager& operator=(Manager&&) = delete;
Matt Spinlere0017eb2018-03-27 11:17:38 -050037
Matt Spinler259e7272018-03-29 10:57:17 -050038 /**
39 * Constructor
40 *
41 * @param[in] bus - the D-Bus bus object
42 */
43 explicit Manager(sdbusplus::bus::bus& bus);
Matt Spinlere0017eb2018-03-27 11:17:38 -050044
Matt Spinler259e7272018-03-29 10:57:17 -050045 private:
Matt Spinlera1390352018-05-23 10:48:19 -050046 using EntryID = uint32_t;
47 using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
48 using EntryMap = std::map<EntryID, InterfaceMap>;
49
Matt Spinler677143b2018-05-23 10:53:27 -050050 using ObjectList = std::vector<std::experimental::any>;
51 using InterfaceMapMulti = std::map<InterfaceType, ObjectList>;
52 using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>;
53
Matt Spinlera1390352018-05-23 10:48:19 -050054 /**
55 * Deletes the entry and any child entries with
56 * the specified ID.
57 *
58 * @param[in] id - the entry ID
59 */
60 void erase(EntryID id);
61
Matt Spinler259e7272018-03-29 10:57:17 -050062 /**
63 * The callback for an interfaces added signal
64 *
65 * Creates the IBM interfaces for the log entry
66 * that was just created.
67 *
68 * @param[in] msg - the sdbusplus message
69 */
70 void interfaceAdded(sdbusplus::message::message& msg);
Matt Spinlere0017eb2018-03-27 11:17:38 -050071
Matt Spinler259e7272018-03-29 10:57:17 -050072 /**
Matt Spinler055da3b2018-05-09 15:51:20 -050073 * The callback for an interfaces removed signal
74 *
75 * Removes the IBM interfaces for the log entry
76 * that was just removed.
77 *
78 * @param[in] msg - the sdbusplus message
79 */
80 void interfaceRemoved(sdbusplus::message::message& msg);
81
82 /**
Matt Spinler259e7272018-03-29 10:57:17 -050083 * Creates the IBM interfaces for all existing error log
84 * entries.
85 */
86 void createAll();
Matt Spinlere0017eb2018-03-27 11:17:38 -050087
Matt Spinler259e7272018-03-29 10:57:17 -050088 /**
Matt Spinlere6a51592018-05-23 12:47:10 -050089 * Creates the IBM interface(s) for a single new error log.
90 *
91 * Any interfaces that require serialization will be created
92 * and serialized here.
Matt Spinler259e7272018-03-29 10:57:17 -050093 *
94 * @param[in] objectPath - object path of the error log
Matt Spinlere6a51592018-05-23 12:47:10 -050095 * @param[in] interfaces - map of all interfaces and properties
96 * on a phosphor-logging error log
Matt Spinler259e7272018-03-29 10:57:17 -050097 */
98 void create(const std::string& objectPath,
Matt Spinlere6a51592018-05-23 12:47:10 -050099 const DbusInterfaceMap& interfaces);
100
101 /**
102 * Creates the IBM interface(s) for a single error log after
103 * the application is restarted.
104 *
105 * Interfaces that were persisted will be restored from their
106 * previously saved filesystem data.
107 *
108 * @param[in] objectPath - object path of the error log
109 * @param[in] interfaces - map of all interfaces and properties
110 * on a phosphor-logging error log
111 */
112 void createWithRestore(const std::string& objectPath,
113 const DbusInterfaceMap& interfaces);
114
115 /**
116 * Creates the IBM interfaces for a single error log that
117 * do not persist across app restarts.
118 *
119 * @param[in] objectPath - object path of the error log
120 * @param[in] interfaces - map of all interfaces and properties
121 * on a phosphor-logging error log
122 */
123 void createObject(const std::string& objectPath,
124 const DbusInterfaceMap& interfaces);
Matt Spinler54bfa7e2018-03-27 11:28:59 -0500125
Matt Spinler259e7272018-03-29 10:57:17 -0500126 /**
127 * Creates the IBM policy interface for a single error log
128 * and saves it in the list of interfaces.
129 *
130 * @param[in] objectPath - object path of the error log
131 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
132 * properties
133 */
Matt Spinler4a6ea6a2018-03-27 14:25:12 -0500134#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500135 void createPolicyInterface(const std::string& objectPath,
136 const DbusPropertyMap& properties);
Matt Spinler4a6ea6a2018-03-27 14:25:12 -0500137#endif
138
Matt Spinler259e7272018-03-29 10:57:17 -0500139 /**
140 * Returns the entry ID for a log
141 *
142 * @param[in] objectPath - the object path of the log
143 *
144 * @return uint32_t - the ID
145 */
146 inline uint32_t getEntryID(const std::string& objectPath)
147 {
148 std::experimental::filesystem::path path(objectPath);
149 return std::stoul(path.filename());
150 }
Matt Spinlere0017eb2018-03-27 11:17:38 -0500151
Matt Spinler259e7272018-03-29 10:57:17 -0500152 /**
Matt Spinler491fc6f2018-04-23 11:00:52 -0500153 * Adds an interface object to the entries map
154 *
155 * @param[in] objectPath - the object path of the log
156 * @param[in] type - the interface type being added
157 * @param[in] object - the interface object
158 */
159 void addInterface(const std::string& objectPath, InterfaceType type,
160 std::experimental::any& object);
161
162 /**
Matt Spinler677143b2018-05-23 10:53:27 -0500163 * Adds an interface to a child object, which is an object that
164 * relates to the main ...logging/entry/X object but has a different path.
165 * The object is stored in the childEntries map.
166 *
167 * There can be multiple instances of a child object per type per
168 * logging object.
169 *
170 * @param[in] objectPath - the object path of the log
171 * @param[in] type - the interface type being added.
172 * @param[in] object - the interface object
173 */
174 void addChildInterface(const std::string& objectPath, InterfaceType type,
175 std::experimental::any& object);
176
177 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500178 * The sdbusplus bus object
179 */
180 sdbusplus::bus::bus& bus;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500181
Matt Spinler259e7272018-03-29 10:57:17 -0500182 /**
183 * The match object for interfacesAdded
184 */
185 sdbusplus::bus::match_t addMatch;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500186
Matt Spinler055da3b2018-05-09 15:51:20 -0500187 /**
188 * The match object for interfacesRemoved
189 */
190 sdbusplus::bus::match_t removeMatch;
191
Matt Spinler259e7272018-03-29 10:57:17 -0500192 /**
193 * A map of the error log IDs to their IBM interface objects.
194 * There may be multiple interfaces per ID.
195 */
196 EntryMap entries;
Matt Spinler743e5822018-03-27 13:44:50 -0500197
Matt Spinler677143b2018-05-23 10:53:27 -0500198 /**
199 * A map of the error log IDs to their interface objects which
200 * are children of the logging objects.
201 *
202 * These objects have the same lifespan as their parent objects.
203 *
204 * There may be multiple interfaces per ID, and also multiple
205 * interface instances per interface type.
206 */
207 EntryMapMulti childEntries;
208
Matt Spinler743e5822018-03-27 13:44:50 -0500209#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500210 /**
211 * The class the wraps the IBM error logging policy table.
212 */
213 policy::Table policies;
Matt Spinler743e5822018-03-27 13:44:50 -0500214#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500215};
Matt Spinlere0017eb2018-03-27 11:17:38 -0500216}
217}