xref: /openbmc/ibm-logging/manager.hpp (revision e6a515901b745e0445a389e0fbfacf09b2984269)
1e0017ebbSMatt Spinler #pragma once
2e0017ebbSMatt Spinler 
3e0017ebbSMatt Spinler #include <experimental/any>
4e0017ebbSMatt Spinler #include <experimental/filesystem>
5e0017ebbSMatt Spinler #include <map>
6e0017ebbSMatt Spinler #include <sdbusplus/bus.hpp>
7743e5822SMatt Spinler #include "config.h"
8e0017ebbSMatt Spinler #include "dbus.hpp"
9e0017ebbSMatt Spinler #include "interfaces.hpp"
10743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
11743e5822SMatt Spinler #include "policy_table.hpp"
12743e5822SMatt Spinler #endif
13e0017ebbSMatt Spinler 
14e0017ebbSMatt Spinler namespace ibm
15e0017ebbSMatt Spinler {
16e0017ebbSMatt Spinler namespace logging
17e0017ebbSMatt Spinler {
18e0017ebbSMatt Spinler 
19e0017ebbSMatt Spinler /**
20e0017ebbSMatt Spinler  * @class Manager
21e0017ebbSMatt Spinler  *
22e0017ebbSMatt Spinler  * This class hosts IBM specific interfaces for the error logging
23e0017ebbSMatt Spinler  * entry objects.  It watches for interfaces added and removed
24e0017ebbSMatt Spinler  * signals to know when to create and delete objects.  Handling the
25e0017ebbSMatt Spinler  * xyz.openbmc_project.Logging service going away is done at the
26e0017ebbSMatt Spinler  * systemd service level where this app will be stopped too.
27e0017ebbSMatt Spinler  */
28e0017ebbSMatt Spinler class Manager
29e0017ebbSMatt Spinler {
30e0017ebbSMatt Spinler   public:
31e0017ebbSMatt Spinler     Manager() = delete;
32e0017ebbSMatt Spinler     ~Manager() = default;
33e0017ebbSMatt Spinler     Manager(const Manager&) = delete;
34e0017ebbSMatt Spinler     Manager& operator=(const Manager&) = delete;
35e0017ebbSMatt Spinler     Manager(Manager&&) = delete;
36e0017ebbSMatt Spinler     Manager& operator=(Manager&&) = delete;
37e0017ebbSMatt Spinler 
38e0017ebbSMatt Spinler     /**
39e0017ebbSMatt Spinler      * Constructor
40e0017ebbSMatt Spinler      *
41e0017ebbSMatt Spinler      * @param[in] bus - the D-Bus bus object
42e0017ebbSMatt Spinler      */
43e0017ebbSMatt Spinler     explicit Manager(sdbusplus::bus::bus& bus);
44e0017ebbSMatt Spinler 
45e0017ebbSMatt Spinler   private:
46a1390353SMatt Spinler     using EntryID = uint32_t;
47a1390353SMatt Spinler     using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
48a1390353SMatt Spinler     using EntryMap = std::map<EntryID, InterfaceMap>;
49a1390353SMatt Spinler 
50677143bbSMatt Spinler     using ObjectList = std::vector<std::experimental::any>;
51677143bbSMatt Spinler     using InterfaceMapMulti = std::map<InterfaceType, ObjectList>;
52677143bbSMatt Spinler     using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>;
53677143bbSMatt Spinler 
54a1390353SMatt Spinler     /**
55a1390353SMatt Spinler      * Deletes the entry and any child entries with
56a1390353SMatt Spinler      * the specified ID.
57a1390353SMatt Spinler      *
58a1390353SMatt Spinler      * @param[in] id - the entry ID
59a1390353SMatt Spinler      */
60a1390353SMatt Spinler     void erase(EntryID id);
61a1390353SMatt Spinler 
62e0017ebbSMatt Spinler     /**
63e0017ebbSMatt Spinler      * The callback for an interfaces added signal
64e0017ebbSMatt Spinler      *
65e0017ebbSMatt Spinler      * Creates the IBM interfaces for the log entry
66e0017ebbSMatt Spinler      * that was just created.
67e0017ebbSMatt Spinler      *
68e0017ebbSMatt Spinler      * @param[in] msg - the sdbusplus message
69e0017ebbSMatt Spinler      */
70e0017ebbSMatt Spinler     void interfaceAdded(sdbusplus::message::message& msg);
71e0017ebbSMatt Spinler 
72e0017ebbSMatt Spinler     /**
73055da3bdSMatt Spinler      * The callback for an interfaces removed signal
74055da3bdSMatt Spinler      *
75055da3bdSMatt Spinler      * Removes the IBM interfaces for the log entry
76055da3bdSMatt Spinler      * that was just removed.
77055da3bdSMatt Spinler      *
78055da3bdSMatt Spinler      * @param[in] msg - the sdbusplus message
79055da3bdSMatt Spinler      */
80055da3bdSMatt Spinler     void interfaceRemoved(sdbusplus::message::message& msg);
81055da3bdSMatt Spinler 
82055da3bdSMatt Spinler     /**
8354bfa7e7SMatt Spinler      * Creates the IBM interfaces for all existing error log
8454bfa7e7SMatt Spinler      * entries.
8554bfa7e7SMatt Spinler      */
8654bfa7e7SMatt Spinler     void createAll();
8754bfa7e7SMatt Spinler 
8854bfa7e7SMatt Spinler     /**
89*e6a51590SMatt Spinler      * Creates the IBM interface(s) for a single new error log.
90*e6a51590SMatt Spinler      *
91*e6a51590SMatt Spinler      * Any interfaces that require serialization will be created
92*e6a51590SMatt Spinler      * and serialized here.
9354bfa7e7SMatt Spinler      *
9454bfa7e7SMatt Spinler      * @param[in] objectPath - object path of the error log
95*e6a51590SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
96*e6a51590SMatt Spinler      *                         on a phosphor-logging error log
9754bfa7e7SMatt Spinler      */
98259e7277SMatt Spinler     void create(const std::string& objectPath,
99*e6a51590SMatt Spinler                 const DbusInterfaceMap& interfaces);
100*e6a51590SMatt Spinler 
101*e6a51590SMatt Spinler     /**
102*e6a51590SMatt Spinler      * Creates the IBM interface(s) for a single error log after
103*e6a51590SMatt Spinler      * the application is restarted.
104*e6a51590SMatt Spinler      *
105*e6a51590SMatt Spinler      * Interfaces that were persisted will be restored from their
106*e6a51590SMatt Spinler      * previously saved filesystem data.
107*e6a51590SMatt Spinler      *
108*e6a51590SMatt Spinler      * @param[in] objectPath - object path of the error log
109*e6a51590SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
110*e6a51590SMatt Spinler      *                         on a phosphor-logging error log
111*e6a51590SMatt Spinler      */
112*e6a51590SMatt Spinler     void createWithRestore(const std::string& objectPath,
113*e6a51590SMatt Spinler                            const DbusInterfaceMap& interfaces);
114*e6a51590SMatt Spinler 
115*e6a51590SMatt Spinler     /**
116*e6a51590SMatt Spinler      * Creates the IBM interfaces for a single error log that
117*e6a51590SMatt Spinler      * do not persist across app restarts.
118*e6a51590SMatt Spinler      *
119*e6a51590SMatt Spinler      * @param[in] objectPath - object path of the error log
120*e6a51590SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
121*e6a51590SMatt Spinler      *                         on a phosphor-logging error log
122*e6a51590SMatt Spinler      */
123*e6a51590SMatt Spinler     void createObject(const std::string& objectPath,
124*e6a51590SMatt Spinler                       const DbusInterfaceMap& interfaces);
12554bfa7e7SMatt Spinler 
12654bfa7e7SMatt Spinler     /**
1274a6ea6afSMatt Spinler      * Creates the IBM policy interface for a single error log
1284a6ea6afSMatt Spinler      * and saves it in the list of interfaces.
1294a6ea6afSMatt Spinler      *
1304a6ea6afSMatt Spinler      * @param[in] objectPath - object path of the error log
1314a6ea6afSMatt Spinler      * @param[in] properties - the xyz.openbmc_project.Logging.Entry
1324a6ea6afSMatt Spinler      *                         properties
1334a6ea6afSMatt Spinler      */
1344a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE
135259e7277SMatt Spinler     void createPolicyInterface(const std::string& objectPath,
1364a6ea6afSMatt Spinler                                const DbusPropertyMap& properties);
1374a6ea6afSMatt Spinler #endif
1384a6ea6afSMatt Spinler 
1394a6ea6afSMatt Spinler     /**
140e0017ebbSMatt Spinler      * Returns the entry ID for a log
141e0017ebbSMatt Spinler      *
142e0017ebbSMatt Spinler      * @param[in] objectPath - the object path of the log
143e0017ebbSMatt Spinler      *
144e0017ebbSMatt Spinler      * @return uint32_t - the ID
145e0017ebbSMatt Spinler      */
146e0017ebbSMatt Spinler     inline uint32_t getEntryID(const std::string& objectPath)
147e0017ebbSMatt Spinler     {
148e0017ebbSMatt Spinler         std::experimental::filesystem::path path(objectPath);
149e0017ebbSMatt Spinler         return std::stoul(path.filename());
150e0017ebbSMatt Spinler     }
151e0017ebbSMatt Spinler 
152e0017ebbSMatt Spinler     /**
153491fc6f1SMatt Spinler      * Adds an interface object to the entries map
154491fc6f1SMatt Spinler      *
155491fc6f1SMatt Spinler      * @param[in] objectPath - the object path of the log
156491fc6f1SMatt Spinler      * @param[in] type - the interface type being added
157491fc6f1SMatt Spinler      * @param[in] object - the interface object
158491fc6f1SMatt Spinler      */
159491fc6f1SMatt Spinler     void addInterface(const std::string& objectPath, InterfaceType type,
160491fc6f1SMatt Spinler                       std::experimental::any& object);
161491fc6f1SMatt Spinler 
162491fc6f1SMatt Spinler     /**
163677143bbSMatt Spinler      * Adds an interface to a child object, which is an object that
164677143bbSMatt Spinler      * relates to the main ...logging/entry/X object but has a different path.
165677143bbSMatt Spinler      * The object is stored in the childEntries map.
166677143bbSMatt Spinler      *
167677143bbSMatt Spinler      * There can be multiple instances of a child object per type per
168677143bbSMatt Spinler      * logging object.
169677143bbSMatt Spinler      *
170677143bbSMatt Spinler      * @param[in] objectPath - the object path of the log
171677143bbSMatt Spinler      * @param[in] type - the interface type being added.
172677143bbSMatt Spinler      * @param[in] object - the interface object
173677143bbSMatt Spinler      */
174677143bbSMatt Spinler     void addChildInterface(const std::string& objectPath, InterfaceType type,
175677143bbSMatt Spinler                            std::experimental::any& object);
176677143bbSMatt Spinler 
177677143bbSMatt Spinler     /**
178e0017ebbSMatt Spinler      * The sdbusplus bus object
179e0017ebbSMatt Spinler      */
180e0017ebbSMatt Spinler     sdbusplus::bus::bus& bus;
181e0017ebbSMatt Spinler 
182e0017ebbSMatt Spinler     /**
183e0017ebbSMatt Spinler      * The match object for interfacesAdded
184e0017ebbSMatt Spinler      */
185e0017ebbSMatt Spinler     sdbusplus::bus::match_t addMatch;
186e0017ebbSMatt Spinler 
187055da3bdSMatt Spinler     /**
188055da3bdSMatt Spinler      * The match object for interfacesRemoved
189055da3bdSMatt Spinler      */
190055da3bdSMatt Spinler     sdbusplus::bus::match_t removeMatch;
191055da3bdSMatt Spinler 
192e0017ebbSMatt Spinler     /**
193e0017ebbSMatt Spinler      * A map of the error log IDs to their IBM interface objects.
194e0017ebbSMatt Spinler      * There may be multiple interfaces per ID.
195e0017ebbSMatt Spinler      */
196e0017ebbSMatt Spinler     EntryMap entries;
197743e5822SMatt Spinler 
198677143bbSMatt Spinler     /**
199677143bbSMatt Spinler      * A map of the error log IDs to their interface objects which
200677143bbSMatt Spinler      * are children of the logging objects.
201677143bbSMatt Spinler      *
202677143bbSMatt Spinler      * These objects have the same lifespan as their parent objects.
203677143bbSMatt Spinler      *
204677143bbSMatt Spinler      * There may be multiple interfaces per ID, and also multiple
205677143bbSMatt Spinler      * interface instances per interface type.
206677143bbSMatt Spinler      */
207677143bbSMatt Spinler     EntryMapMulti childEntries;
208677143bbSMatt Spinler 
209743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
210743e5822SMatt Spinler     /**
211743e5822SMatt Spinler      * The class the wraps the IBM error logging policy table.
212743e5822SMatt Spinler      */
213743e5822SMatt Spinler     policy::Table policies;
214743e5822SMatt Spinler #endif
215e0017ebbSMatt Spinler };
216e0017ebbSMatt Spinler }
217e0017ebbSMatt Spinler }
218