xref: /openbmc/ibm-logging/manager.hpp (revision 6a2b8956487404dd2f7e4aa06055c24a2b7271e1)
1e0017ebbSMatt Spinler #pragma once
2e0017ebbSMatt Spinler 
366e07073SMatt Spinler #include "config.h"
466e07073SMatt Spinler 
566e07073SMatt Spinler #include "dbus.hpp"
666e07073SMatt Spinler #include "interfaces.hpp"
766e07073SMatt Spinler 
8*6a2b8956SPatrick Williams #include <sdbusplus/bus.hpp>
9*6a2b8956SPatrick Williams 
1054ea3ad8SMatt Spinler #include <any>
11e0017ebbSMatt Spinler #include <experimental/filesystem>
12e0017ebbSMatt Spinler #include <map>
1329c2ec6dSAndrew Geissler #include <string>
14743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
15743e5822SMatt Spinler #include "policy_table.hpp"
16743e5822SMatt Spinler #endif
17e0017ebbSMatt Spinler 
18e0017ebbSMatt Spinler namespace ibm
19e0017ebbSMatt Spinler {
20e0017ebbSMatt Spinler namespace logging
21e0017ebbSMatt Spinler {
22e0017ebbSMatt Spinler 
23e0017ebbSMatt Spinler /**
24e0017ebbSMatt Spinler  * @class Manager
25e0017ebbSMatt Spinler  *
26e0017ebbSMatt Spinler  * This class hosts IBM specific interfaces for the error logging
27e0017ebbSMatt Spinler  * entry objects.  It watches for interfaces added and removed
28e0017ebbSMatt Spinler  * signals to know when to create and delete objects.  Handling the
29e0017ebbSMatt Spinler  * xyz.openbmc_project.Logging service going away is done at the
30e0017ebbSMatt Spinler  * systemd service level where this app will be stopped too.
31e0017ebbSMatt Spinler  */
32e0017ebbSMatt Spinler class Manager
33e0017ebbSMatt Spinler {
34e0017ebbSMatt Spinler   public:
35e0017ebbSMatt Spinler     Manager() = delete;
36e0017ebbSMatt Spinler     ~Manager() = default;
37e0017ebbSMatt Spinler     Manager(const Manager&) = delete;
38e0017ebbSMatt Spinler     Manager& operator=(const Manager&) = delete;
39e0017ebbSMatt Spinler     Manager(Manager&&) = delete;
40e0017ebbSMatt Spinler     Manager& operator=(Manager&&) = delete;
41e0017ebbSMatt Spinler 
42e0017ebbSMatt Spinler     /**
43e0017ebbSMatt Spinler      * Constructor
44e0017ebbSMatt Spinler      *
45e0017ebbSMatt Spinler      * @param[in] bus - the D-Bus bus object
46e0017ebbSMatt Spinler      */
478123a713SPatrick Williams     explicit Manager(sdbusplus::bus_t& bus);
48e0017ebbSMatt Spinler 
49e0017ebbSMatt Spinler   private:
50a1390353SMatt Spinler     using EntryID = uint32_t;
5154ea3ad8SMatt Spinler     using InterfaceMap = std::map<InterfaceType, std::any>;
52a1390353SMatt Spinler     using EntryMap = std::map<EntryID, InterfaceMap>;
53a1390353SMatt Spinler 
5454ea3ad8SMatt Spinler     using ObjectList = std::vector<std::any>;
55677143bbSMatt Spinler     using InterfaceMapMulti = std::map<InterfaceType, ObjectList>;
56677143bbSMatt Spinler     using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>;
57677143bbSMatt Spinler 
58a1390353SMatt Spinler     /**
59a1390353SMatt Spinler      * Deletes the entry and any child entries with
60a1390353SMatt Spinler      * the specified ID.
61a1390353SMatt Spinler      *
62a1390353SMatt Spinler      * @param[in] id - the entry ID
63a1390353SMatt Spinler      */
64a1390353SMatt Spinler     void erase(EntryID id);
65a1390353SMatt Spinler 
66e0017ebbSMatt Spinler     /**
67e0017ebbSMatt Spinler      * The callback for an interfaces added signal
68e0017ebbSMatt Spinler      *
69e0017ebbSMatt Spinler      * Creates the IBM interfaces for the log entry
70e0017ebbSMatt Spinler      * that was just created.
71e0017ebbSMatt Spinler      *
72e0017ebbSMatt Spinler      * @param[in] msg - the sdbusplus message
73e0017ebbSMatt Spinler      */
748123a713SPatrick Williams     void interfaceAdded(sdbusplus::message_t& msg);
75e0017ebbSMatt Spinler 
76e0017ebbSMatt Spinler     /**
77055da3bdSMatt Spinler      * The callback for an interfaces removed signal
78055da3bdSMatt Spinler      *
79055da3bdSMatt Spinler      * Removes the IBM interfaces for the log entry
80055da3bdSMatt Spinler      * that was just removed.
81055da3bdSMatt Spinler      *
82055da3bdSMatt Spinler      * @param[in] msg - the sdbusplus message
83055da3bdSMatt Spinler      */
848123a713SPatrick Williams     void interfaceRemoved(sdbusplus::message_t& msg);
85055da3bdSMatt Spinler 
86055da3bdSMatt Spinler     /**
8754bfa7e7SMatt Spinler      * Creates the IBM interfaces for all existing error log
8854bfa7e7SMatt Spinler      * entries.
8954bfa7e7SMatt Spinler      */
9054bfa7e7SMatt Spinler     void createAll();
9154bfa7e7SMatt Spinler 
9254bfa7e7SMatt Spinler     /**
93e6a51590SMatt Spinler      * Creates the IBM interface(s) for a single new error log.
94e6a51590SMatt Spinler      *
95e6a51590SMatt Spinler      * Any interfaces that require serialization will be created
96e6a51590SMatt Spinler      * and serialized here.
9754bfa7e7SMatt Spinler      *
9854bfa7e7SMatt Spinler      * @param[in] objectPath - object path of the error log
99e6a51590SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
100e6a51590SMatt Spinler      *                         on a phosphor-logging error log
10154bfa7e7SMatt Spinler      */
102259e7277SMatt Spinler     void create(const std::string& objectPath,
103e6a51590SMatt Spinler                 const DbusInterfaceMap& interfaces);
104e6a51590SMatt Spinler 
105e6a51590SMatt Spinler     /**
106e6a51590SMatt Spinler      * Creates the IBM interface(s) for a single error log after
107e6a51590SMatt Spinler      * the application is restarted.
108e6a51590SMatt Spinler      *
109e6a51590SMatt Spinler      * Interfaces that were persisted will be restored from their
110e6a51590SMatt Spinler      * previously saved filesystem data.
111e6a51590SMatt Spinler      *
112e6a51590SMatt Spinler      * @param[in] objectPath - object path of the error log
113e6a51590SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
114e6a51590SMatt Spinler      *                         on a phosphor-logging error log
115e6a51590SMatt Spinler      */
116e6a51590SMatt Spinler     void createWithRestore(const std::string& objectPath,
117e6a51590SMatt Spinler                            const DbusInterfaceMap& interfaces);
118e6a51590SMatt Spinler 
119e6a51590SMatt Spinler     /**
120e6a51590SMatt Spinler      * Creates the IBM interfaces for a single error log that
121e6a51590SMatt Spinler      * do not persist across app restarts.
122e6a51590SMatt Spinler      *
123e6a51590SMatt Spinler      * @param[in] objectPath - object path of the error log
124e6a51590SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
125e6a51590SMatt Spinler      *                         on a phosphor-logging error log
126e6a51590SMatt Spinler      */
127e6a51590SMatt Spinler     void createObject(const std::string& objectPath,
128e6a51590SMatt Spinler                       const DbusInterfaceMap& interfaces);
12954bfa7e7SMatt Spinler 
13054bfa7e7SMatt Spinler     /**
13152ee71bdSMatt Spinler      * Returns the error log timestamp property value from
13252ee71bdSMatt Spinler      * the passed in map of all interfaces and property names/values
13352ee71bdSMatt Spinler      * on an error log D-Bus object.
13452ee71bdSMatt Spinler      *
13552ee71bdSMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
13652ee71bdSMatt Spinler      *                         on a phosphor-logging error log.
13752ee71bdSMatt Spinler      *
13852ee71bdSMatt Spinler      * @return uint64_t - the timestamp
13952ee71bdSMatt Spinler      */
14052ee71bdSMatt Spinler     uint64_t getLogTimestamp(const DbusInterfaceMap& interfaces);
14152ee71bdSMatt Spinler 
14252ee71bdSMatt Spinler     /**
14352ee71bdSMatt Spinler      * Returns the filesystem directory to use for persisting
14452ee71bdSMatt Spinler      * information about a particular error log.
14552ee71bdSMatt Spinler      *
14652ee71bdSMatt Spinler      * @param[in] id - the error log ID
14752ee71bdSMatt Spinler      * @return path - the directory path
14852ee71bdSMatt Spinler      */
14952ee71bdSMatt Spinler     std::experimental::filesystem::path getSaveDir(EntryID id);
15052ee71bdSMatt Spinler 
15152ee71bdSMatt Spinler     /**
15252ee71bdSMatt Spinler      * Returns the directory to use to save the callout information in
15352ee71bdSMatt Spinler      *
15452ee71bdSMatt Spinler      * @param[in] id - the error log ID
15552ee71bdSMatt Spinler      *
15652ee71bdSMatt Spinler      * @return path - the directory path
15752ee71bdSMatt Spinler      */
15852ee71bdSMatt Spinler     std::experimental::filesystem::path getCalloutSaveDir(EntryID id);
15952ee71bdSMatt Spinler 
16052ee71bdSMatt Spinler     /**
16152ee71bdSMatt Spinler      * Returns the D-Bus object path to use for a callout D-Bus object.
16252ee71bdSMatt Spinler      *
16352ee71bdSMatt Spinler      * @param[in] objectPath - the object path for the error log
16452ee71bdSMatt Spinler      * @param[in] calloutNum - the callout instance number
16552ee71bdSMatt Spinler      *
16652ee71bdSMatt Spinler      * @return path - the object path to use for a callout object
16752ee71bdSMatt Spinler      */
16852ee71bdSMatt Spinler     std::string getCalloutObjectPath(const std::string& objectPath,
16952ee71bdSMatt Spinler                                      uint32_t calloutNum);
17052ee71bdSMatt Spinler 
17152ee71bdSMatt Spinler     /**
1724a6ea6afSMatt Spinler      * Creates the IBM policy interface for a single error log
1734a6ea6afSMatt Spinler      * and saves it in the list of interfaces.
1744a6ea6afSMatt Spinler      *
1754a6ea6afSMatt Spinler      * @param[in] objectPath - object path of the error log
1764a6ea6afSMatt Spinler      * @param[in] properties - the xyz.openbmc_project.Logging.Entry
1774a6ea6afSMatt Spinler      *                         properties
1784a6ea6afSMatt Spinler      */
1794a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE
180259e7277SMatt Spinler     void createPolicyInterface(const std::string& objectPath,
1814a6ea6afSMatt Spinler                                const DbusPropertyMap& properties);
1824a6ea6afSMatt Spinler #endif
1834a6ea6afSMatt Spinler 
1844a6ea6afSMatt Spinler     /**
18552ee71bdSMatt Spinler      * Creates D-Bus objects for any callouts in an error log
18652ee71bdSMatt Spinler      * that map to an inventory object with an Asset interface.
18752ee71bdSMatt Spinler      *
18852ee71bdSMatt Spinler      * The created object will also host the Asset interface.
18952ee71bdSMatt Spinler      *
19052ee71bdSMatt Spinler      * A callout object path would look like:
19152ee71bdSMatt Spinler      * /xyz/openbmc_project/logging/entry/5/callouts/0.
19252ee71bdSMatt Spinler      *
19352ee71bdSMatt Spinler      * Any objects created are serialized so the asset information
19452ee71bdSMatt Spinler      * can always be restored.
19552ee71bdSMatt Spinler      *
19652ee71bdSMatt Spinler      * @param[in] objectPath - object path of the error log
19752ee71bdSMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
19852ee71bdSMatt Spinler      *                         on a phosphor-logging error log.
19952ee71bdSMatt Spinler      */
20052ee71bdSMatt Spinler     void createCalloutObjects(const std::string& objectPath,
20152ee71bdSMatt Spinler                               const DbusInterfaceMap& interfaces);
20252ee71bdSMatt Spinler 
20352ee71bdSMatt Spinler     /**
20460f53d86SMatt Spinler      * Restores callout objects for a particular error log that
20560f53d86SMatt Spinler      * have previously been saved by reading their data out of
20660f53d86SMatt Spinler      * the filesystem using Cereal.
20760f53d86SMatt Spinler      *
20860f53d86SMatt Spinler      * @param[in] objectPath - object path of the error log
20960f53d86SMatt Spinler      * @param[in] interfaces - map of all interfaces and properties
21060f53d86SMatt Spinler      *                         on a phosphor-logging error log.
21160f53d86SMatt Spinler      */
21260f53d86SMatt Spinler     void restoreCalloutObjects(const std::string& objectPath,
21360f53d86SMatt Spinler                                const DbusInterfaceMap& interfaces);
21460f53d86SMatt Spinler 
21560f53d86SMatt Spinler     /**
216e0017ebbSMatt Spinler      * Returns the entry ID for a log
217e0017ebbSMatt Spinler      *
218e0017ebbSMatt Spinler      * @param[in] objectPath - the object path of the log
219e0017ebbSMatt Spinler      *
220e0017ebbSMatt Spinler      * @return uint32_t - the ID
221e0017ebbSMatt Spinler      */
getEntryID(const std::string & objectPath)222e0017ebbSMatt Spinler     inline uint32_t getEntryID(const std::string& objectPath)
223e0017ebbSMatt Spinler     {
224e0017ebbSMatt Spinler         std::experimental::filesystem::path path(objectPath);
225e0017ebbSMatt Spinler         return std::stoul(path.filename());
226e0017ebbSMatt Spinler     }
227e0017ebbSMatt Spinler 
228e0017ebbSMatt Spinler     /**
229491fc6f1SMatt Spinler      * Adds an interface object to the entries map
230491fc6f1SMatt Spinler      *
231491fc6f1SMatt Spinler      * @param[in] objectPath - the object path of the log
232491fc6f1SMatt Spinler      * @param[in] type - the interface type being added
233491fc6f1SMatt Spinler      * @param[in] object - the interface object
234491fc6f1SMatt Spinler      */
235491fc6f1SMatt Spinler     void addInterface(const std::string& objectPath, InterfaceType type,
23654ea3ad8SMatt Spinler                       std::any& object);
237491fc6f1SMatt Spinler 
238491fc6f1SMatt Spinler     /**
239677143bbSMatt Spinler      * Adds an interface to a child object, which is an object that
240677143bbSMatt Spinler      * relates to the main ...logging/entry/X object but has a different path.
241677143bbSMatt Spinler      * The object is stored in the childEntries map.
242677143bbSMatt Spinler      *
243677143bbSMatt Spinler      * There can be multiple instances of a child object per type per
244677143bbSMatt Spinler      * logging object.
245677143bbSMatt Spinler      *
246677143bbSMatt Spinler      * @param[in] objectPath - the object path of the log
247677143bbSMatt Spinler      * @param[in] type - the interface type being added.
248677143bbSMatt Spinler      * @param[in] object - the interface object
249677143bbSMatt Spinler      */
250677143bbSMatt Spinler     void addChildInterface(const std::string& objectPath, InterfaceType type,
25154ea3ad8SMatt Spinler                            std::any& object);
252677143bbSMatt Spinler 
253677143bbSMatt Spinler     /**
254e0017ebbSMatt Spinler      * The sdbusplus bus object
255e0017ebbSMatt Spinler      */
2568123a713SPatrick Williams     sdbusplus::bus_t& bus;
257e0017ebbSMatt Spinler 
258e0017ebbSMatt Spinler     /**
259e0017ebbSMatt Spinler      * The match object for interfacesAdded
260e0017ebbSMatt Spinler      */
261e0017ebbSMatt Spinler     sdbusplus::bus::match_t addMatch;
262e0017ebbSMatt Spinler 
263055da3bdSMatt Spinler     /**
264055da3bdSMatt Spinler      * The match object for interfacesRemoved
265055da3bdSMatt Spinler      */
266055da3bdSMatt Spinler     sdbusplus::bus::match_t removeMatch;
267055da3bdSMatt Spinler 
268e0017ebbSMatt Spinler     /**
269e0017ebbSMatt Spinler      * A map of the error log IDs to their IBM interface objects.
270e0017ebbSMatt Spinler      * There may be multiple interfaces per ID.
271e0017ebbSMatt Spinler      */
272e0017ebbSMatt Spinler     EntryMap entries;
273743e5822SMatt Spinler 
274677143bbSMatt Spinler     /**
275677143bbSMatt Spinler      * A map of the error log IDs to their interface objects which
276677143bbSMatt Spinler      * are children of the logging objects.
277677143bbSMatt Spinler      *
278677143bbSMatt Spinler      * These objects have the same lifespan as their parent objects.
279677143bbSMatt Spinler      *
280677143bbSMatt Spinler      * There may be multiple interfaces per ID, and also multiple
281677143bbSMatt Spinler      * interface instances per interface type.
282677143bbSMatt Spinler      */
283677143bbSMatt Spinler     EntryMapMulti childEntries;
284677143bbSMatt Spinler 
285743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
286743e5822SMatt Spinler     /**
287743e5822SMatt Spinler      * The class the wraps the IBM error logging policy table.
288743e5822SMatt Spinler      */
289743e5822SMatt Spinler     policy::Table policies;
290743e5822SMatt Spinler #endif
291e0017ebbSMatt Spinler };
29266e07073SMatt Spinler } // namespace logging
29366e07073SMatt Spinler } // namespace ibm
294