xref: /openbmc/ibm-logging/manager.hpp (revision 259e7277e6af53d2c4862cd48c14131c0b22bb81)
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:
46e0017ebbSMatt Spinler     /**
47e0017ebbSMatt Spinler      * The callback for an interfaces added signal
48e0017ebbSMatt Spinler      *
49e0017ebbSMatt Spinler      * Creates the IBM interfaces for the log entry
50e0017ebbSMatt Spinler      * that was just created.
51e0017ebbSMatt Spinler      *
52e0017ebbSMatt Spinler      * @param[in] msg - the sdbusplus message
53e0017ebbSMatt Spinler      */
54e0017ebbSMatt Spinler     void interfaceAdded(sdbusplus::message::message& msg);
55e0017ebbSMatt Spinler 
56e0017ebbSMatt Spinler     /**
57e0017ebbSMatt Spinler      * The callback for an interfaces removed signal
58e0017ebbSMatt Spinler      *
59e0017ebbSMatt Spinler      * Removes the IBM interfaces for the log entry
60e0017ebbSMatt Spinler      * that was just removed.
61e0017ebbSMatt Spinler      *
62e0017ebbSMatt Spinler      * @param[in] msg - the sdbusplus message
63e0017ebbSMatt Spinler      */
64e0017ebbSMatt Spinler     void interfaceRemoved(sdbusplus::message::message& msg);
65e0017ebbSMatt Spinler 
66e0017ebbSMatt Spinler     /**
6754bfa7e7SMatt Spinler      * Creates the IBM interfaces for all existing error log
6854bfa7e7SMatt Spinler      * entries.
6954bfa7e7SMatt Spinler      */
7054bfa7e7SMatt Spinler     void createAll();
7154bfa7e7SMatt Spinler 
7254bfa7e7SMatt Spinler     /**
7354bfa7e7SMatt Spinler      * Creates the IBM interface(s) for a single error log.
7454bfa7e7SMatt Spinler      *
7554bfa7e7SMatt Spinler      * @param[in] objectPath - object path of the error log
7654bfa7e7SMatt Spinler      * @param[in] properties - the xyz.openbmc_project.Logging.Entry
7754bfa7e7SMatt Spinler      *                         properties
7854bfa7e7SMatt Spinler      */
79*259e7277SMatt Spinler     void create(const std::string& objectPath,
8054bfa7e7SMatt Spinler                 const DbusPropertyMap& properties);
8154bfa7e7SMatt Spinler 
8254bfa7e7SMatt Spinler     /**
834a6ea6afSMatt Spinler      * Creates the IBM policy interface for a single error log
844a6ea6afSMatt Spinler      * and saves it in the list of interfaces.
854a6ea6afSMatt Spinler      *
864a6ea6afSMatt Spinler      * @param[in] objectPath - object path of the error log
874a6ea6afSMatt Spinler      * @param[in] properties - the xyz.openbmc_project.Logging.Entry
884a6ea6afSMatt Spinler      *                         properties
894a6ea6afSMatt Spinler      */
904a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE
91*259e7277SMatt Spinler     void createPolicyInterface(const std::string& objectPath,
924a6ea6afSMatt Spinler                                const DbusPropertyMap& properties);
934a6ea6afSMatt Spinler #endif
944a6ea6afSMatt Spinler 
954a6ea6afSMatt Spinler     /**
96e0017ebbSMatt Spinler      * Returns the entry ID for a log
97e0017ebbSMatt Spinler      *
98e0017ebbSMatt Spinler      * @param[in] objectPath - the object path of the log
99e0017ebbSMatt Spinler      *
100e0017ebbSMatt Spinler      * @return uint32_t - the ID
101e0017ebbSMatt Spinler      */
102e0017ebbSMatt Spinler     inline uint32_t getEntryID(const std::string& objectPath)
103e0017ebbSMatt Spinler     {
104e0017ebbSMatt Spinler         std::experimental::filesystem::path path(objectPath);
105e0017ebbSMatt Spinler         return std::stoul(path.filename());
106e0017ebbSMatt Spinler     }
107e0017ebbSMatt Spinler 
108e0017ebbSMatt Spinler     /**
109e0017ebbSMatt Spinler      * The sdbusplus bus object
110e0017ebbSMatt Spinler      */
111e0017ebbSMatt Spinler     sdbusplus::bus::bus& bus;
112e0017ebbSMatt Spinler 
113e0017ebbSMatt Spinler     /**
114e0017ebbSMatt Spinler      * The match object for interfacesAdded
115e0017ebbSMatt Spinler      */
116e0017ebbSMatt Spinler     sdbusplus::bus::match_t addMatch;
117e0017ebbSMatt Spinler 
118e0017ebbSMatt Spinler     /**
119e0017ebbSMatt Spinler      * The match object for interfacesRemoved
120e0017ebbSMatt Spinler      */
121e0017ebbSMatt Spinler     sdbusplus::bus::match_t removeMatch;
122e0017ebbSMatt Spinler 
123e0017ebbSMatt Spinler     using EntryID = uint32_t;
124e0017ebbSMatt Spinler     using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
125e0017ebbSMatt Spinler     using EntryMap = std::map<EntryID, InterfaceMap>;
126e0017ebbSMatt Spinler 
127e0017ebbSMatt Spinler     /**
128e0017ebbSMatt Spinler      * A map of the error log IDs to their IBM interface objects.
129e0017ebbSMatt Spinler      * There may be multiple interfaces per ID.
130e0017ebbSMatt Spinler      */
131e0017ebbSMatt Spinler     EntryMap entries;
132743e5822SMatt Spinler 
133743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
134743e5822SMatt Spinler     /**
135743e5822SMatt Spinler      * The class the wraps the IBM error logging policy table.
136743e5822SMatt Spinler      */
137743e5822SMatt Spinler     policy::Table policies;
138743e5822SMatt Spinler #endif
139e0017ebbSMatt Spinler };
140e0017ebbSMatt Spinler }
141e0017ebbSMatt Spinler }
142