xref: /openbmc/ibm-logging/manager.hpp (revision 055da3bdf05c26804fc0bef1f66796efa0f98244)
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 
45433beadcSMatt Spinler     /**
46433beadcSMatt Spinler      * Deletes the entry with the specified path
47433beadcSMatt Spinler      *
48433beadcSMatt Spinler      * @param[in] objectPath - the entry object path
49433beadcSMatt Spinler      */
50433beadcSMatt Spinler     void erase(const std::string& objectPath);
51433beadcSMatt Spinler 
522cfceb46SMatt Spinler     /**
532cfceb46SMatt Spinler      * Erases all entries
542cfceb46SMatt Spinler      */
552cfceb46SMatt Spinler     void eraseAll();
562cfceb46SMatt Spinler 
57e0017ebbSMatt Spinler   private:
58e0017ebbSMatt Spinler     /**
59e0017ebbSMatt Spinler      * The callback for an interfaces added signal
60e0017ebbSMatt Spinler      *
61e0017ebbSMatt Spinler      * Creates the IBM interfaces for the log entry
62e0017ebbSMatt Spinler      * that was just created.
63e0017ebbSMatt Spinler      *
64e0017ebbSMatt Spinler      * @param[in] msg - the sdbusplus message
65e0017ebbSMatt Spinler      */
66e0017ebbSMatt Spinler     void interfaceAdded(sdbusplus::message::message& msg);
67e0017ebbSMatt Spinler 
68e0017ebbSMatt Spinler     /**
69*055da3bdSMatt Spinler      * The callback for an interfaces removed signal
70*055da3bdSMatt Spinler      *
71*055da3bdSMatt Spinler      * Removes the IBM interfaces for the log entry
72*055da3bdSMatt Spinler      * that was just removed.
73*055da3bdSMatt Spinler      *
74*055da3bdSMatt Spinler      * @param[in] msg - the sdbusplus message
75*055da3bdSMatt Spinler      */
76*055da3bdSMatt Spinler     void interfaceRemoved(sdbusplus::message::message& msg);
77*055da3bdSMatt Spinler 
78*055da3bdSMatt Spinler     /**
7954bfa7e7SMatt Spinler      * Creates the IBM interfaces for all existing error log
8054bfa7e7SMatt Spinler      * entries.
8154bfa7e7SMatt Spinler      */
8254bfa7e7SMatt Spinler     void createAll();
8354bfa7e7SMatt Spinler 
8454bfa7e7SMatt Spinler     /**
8554bfa7e7SMatt Spinler      * Creates the IBM interface(s) for a single error log.
8654bfa7e7SMatt Spinler      *
8754bfa7e7SMatt Spinler      * @param[in] objectPath - object path of the error log
8854bfa7e7SMatt Spinler      * @param[in] properties - the xyz.openbmc_project.Logging.Entry
8954bfa7e7SMatt Spinler      *                         properties
9054bfa7e7SMatt Spinler      */
91259e7277SMatt Spinler     void create(const std::string& objectPath,
9254bfa7e7SMatt Spinler                 const DbusPropertyMap& properties);
9354bfa7e7SMatt Spinler 
9454bfa7e7SMatt Spinler     /**
954a6ea6afSMatt Spinler      * Creates the IBM policy interface for a single error log
964a6ea6afSMatt Spinler      * and saves it in the list of interfaces.
974a6ea6afSMatt Spinler      *
984a6ea6afSMatt Spinler      * @param[in] objectPath - object path of the error log
994a6ea6afSMatt Spinler      * @param[in] properties - the xyz.openbmc_project.Logging.Entry
1004a6ea6afSMatt Spinler      *                         properties
1014a6ea6afSMatt Spinler      */
1024a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE
103259e7277SMatt Spinler     void createPolicyInterface(const std::string& objectPath,
1044a6ea6afSMatt Spinler                                const DbusPropertyMap& properties);
1054a6ea6afSMatt Spinler #endif
1064a6ea6afSMatt Spinler 
1074a6ea6afSMatt Spinler     /**
108433beadcSMatt Spinler      * Creates the Delete interface for a single error log
109433beadcSMatt Spinler      * and saves it in the list of interfaces.
110433beadcSMatt Spinler      *
111433beadcSMatt Spinler      * @param[in] objectPath - object path of the error log
112433beadcSMatt Spinler      */
113433beadcSMatt Spinler     void createDeleteInterface(const std::string& objectPath);
114433beadcSMatt Spinler 
115433beadcSMatt Spinler     /**
116e0017ebbSMatt Spinler      * Returns the entry ID for a log
117e0017ebbSMatt Spinler      *
118e0017ebbSMatt Spinler      * @param[in] objectPath - the object path of the log
119e0017ebbSMatt Spinler      *
120e0017ebbSMatt Spinler      * @return uint32_t - the ID
121e0017ebbSMatt Spinler      */
122e0017ebbSMatt Spinler     inline uint32_t getEntryID(const std::string& objectPath)
123e0017ebbSMatt Spinler     {
124e0017ebbSMatt Spinler         std::experimental::filesystem::path path(objectPath);
125e0017ebbSMatt Spinler         return std::stoul(path.filename());
126e0017ebbSMatt Spinler     }
127e0017ebbSMatt Spinler 
128e0017ebbSMatt Spinler     /**
129491fc6f1SMatt Spinler      * Adds an interface object to the entries map
130491fc6f1SMatt Spinler      *
131491fc6f1SMatt Spinler      * @param[in] objectPath - the object path of the log
132491fc6f1SMatt Spinler      * @param[in] type - the interface type being added
133491fc6f1SMatt Spinler      * @param[in] object - the interface object
134491fc6f1SMatt Spinler      */
135491fc6f1SMatt Spinler     void addInterface(const std::string& objectPath, InterfaceType type,
136491fc6f1SMatt Spinler                       std::experimental::any& object);
137491fc6f1SMatt Spinler 
138491fc6f1SMatt Spinler     /**
139e0017ebbSMatt Spinler      * The sdbusplus bus object
140e0017ebbSMatt Spinler      */
141e0017ebbSMatt Spinler     sdbusplus::bus::bus& bus;
142e0017ebbSMatt Spinler 
143e0017ebbSMatt Spinler     /**
144e0017ebbSMatt Spinler      * The match object for interfacesAdded
145e0017ebbSMatt Spinler      */
146e0017ebbSMatt Spinler     sdbusplus::bus::match_t addMatch;
147e0017ebbSMatt Spinler 
148*055da3bdSMatt Spinler     /**
149*055da3bdSMatt Spinler      * The match object for interfacesRemoved
150*055da3bdSMatt Spinler      */
151*055da3bdSMatt Spinler     sdbusplus::bus::match_t removeMatch;
152*055da3bdSMatt Spinler 
153e0017ebbSMatt Spinler     using EntryID = uint32_t;
154e0017ebbSMatt Spinler     using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
155e0017ebbSMatt Spinler     using EntryMap = std::map<EntryID, InterfaceMap>;
156e0017ebbSMatt Spinler 
157e0017ebbSMatt Spinler     /**
158e0017ebbSMatt Spinler      * A map of the error log IDs to their IBM interface objects.
159e0017ebbSMatt Spinler      * There may be multiple interfaces per ID.
160e0017ebbSMatt Spinler      */
161e0017ebbSMatt Spinler     EntryMap entries;
162743e5822SMatt Spinler 
163743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
164743e5822SMatt Spinler     /**
165743e5822SMatt Spinler      * The class the wraps the IBM error logging policy table.
166743e5822SMatt Spinler      */
167743e5822SMatt Spinler     policy::Table policies;
168743e5822SMatt Spinler #endif
169e0017ebbSMatt Spinler };
170e0017ebbSMatt Spinler }
171e0017ebbSMatt Spinler }
172