xref: /openbmc/ibm-logging/manager.hpp (revision 4a6ea6af06b4db29120b9419e9ec002584e46125)
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 /**
21e0017ebbSMatt Spinler  * @class Manager
22e0017ebbSMatt Spinler  *
23e0017ebbSMatt Spinler  * This class hosts IBM specific interfaces for the error logging
24e0017ebbSMatt Spinler  * entry objects.  It watches for interfaces added and removed
25e0017ebbSMatt Spinler  * signals to know when to create and delete objects.  Handling the
26e0017ebbSMatt Spinler  * xyz.openbmc_project.Logging service going away is done at the
27e0017ebbSMatt Spinler  * systemd service level where this app will be stopped too.
28e0017ebbSMatt Spinler  */
29e0017ebbSMatt Spinler class Manager
30e0017ebbSMatt Spinler {
31e0017ebbSMatt Spinler     public:
32e0017ebbSMatt Spinler 
33e0017ebbSMatt Spinler         Manager() = delete;
34e0017ebbSMatt Spinler         ~Manager() = default;
35e0017ebbSMatt Spinler         Manager(const Manager&) = delete;
36e0017ebbSMatt Spinler         Manager& operator=(const Manager&) = delete;
37e0017ebbSMatt Spinler         Manager(Manager&&) = delete;
38e0017ebbSMatt Spinler         Manager& operator=(Manager&&) = delete;
39e0017ebbSMatt Spinler 
40e0017ebbSMatt Spinler         /**
41e0017ebbSMatt Spinler          * Constructor
42e0017ebbSMatt Spinler          *
43e0017ebbSMatt Spinler          * @param[in] bus - the D-Bus bus object
44e0017ebbSMatt Spinler          */
45e0017ebbSMatt Spinler         explicit Manager(sdbusplus::bus::bus& bus);
46e0017ebbSMatt Spinler 
47e0017ebbSMatt Spinler     private:
48e0017ebbSMatt Spinler 
49e0017ebbSMatt Spinler         /**
50e0017ebbSMatt Spinler          * The callback for an interfaces added signal
51e0017ebbSMatt Spinler          *
52e0017ebbSMatt Spinler          * Creates the IBM interfaces for the log entry
53e0017ebbSMatt Spinler          * that was just created.
54e0017ebbSMatt Spinler          *
55e0017ebbSMatt Spinler          * @param[in] msg - the sdbusplus message
56e0017ebbSMatt Spinler          */
57e0017ebbSMatt Spinler         void interfaceAdded(sdbusplus::message::message& msg);
58e0017ebbSMatt Spinler 
59e0017ebbSMatt Spinler         /**
60e0017ebbSMatt Spinler          * The callback for an interfaces removed signal
61e0017ebbSMatt Spinler          *
62e0017ebbSMatt Spinler          * Removes the IBM interfaces for the log entry
63e0017ebbSMatt Spinler          * that was just removed.
64e0017ebbSMatt Spinler          *
65e0017ebbSMatt Spinler          * @param[in] msg - the sdbusplus message
66e0017ebbSMatt Spinler          */
67e0017ebbSMatt Spinler         void interfaceRemoved(sdbusplus::message::message& msg);
68e0017ebbSMatt Spinler 
69e0017ebbSMatt Spinler         /**
7054bfa7e7SMatt Spinler          * Creates the IBM interfaces for all existing error log
7154bfa7e7SMatt Spinler          * entries.
7254bfa7e7SMatt Spinler          */
7354bfa7e7SMatt Spinler         void createAll();
7454bfa7e7SMatt Spinler 
7554bfa7e7SMatt Spinler         /**
7654bfa7e7SMatt Spinler          * Creates the IBM interface(s) for a single error log.
7754bfa7e7SMatt Spinler          *
7854bfa7e7SMatt Spinler          * @param[in] objectPath - object path of the error log
7954bfa7e7SMatt Spinler          * @param[in] properties - the xyz.openbmc_project.Logging.Entry
8054bfa7e7SMatt Spinler          *                         properties
8154bfa7e7SMatt Spinler          */
8254bfa7e7SMatt Spinler         void create(
8354bfa7e7SMatt Spinler                 const std::string& objectPath,
8454bfa7e7SMatt Spinler                 const DbusPropertyMap& properties);
8554bfa7e7SMatt Spinler 
8654bfa7e7SMatt Spinler         /**
87*4a6ea6afSMatt Spinler          * Creates the IBM policy interface for a single error log
88*4a6ea6afSMatt Spinler          * and saves it in the list of interfaces.
89*4a6ea6afSMatt Spinler          *
90*4a6ea6afSMatt Spinler          * @param[in] objectPath - object path of the error log
91*4a6ea6afSMatt Spinler          * @param[in] properties - the xyz.openbmc_project.Logging.Entry
92*4a6ea6afSMatt Spinler          *                         properties
93*4a6ea6afSMatt Spinler          */
94*4a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE
95*4a6ea6afSMatt Spinler         void createPolicyInterface(
96*4a6ea6afSMatt Spinler                 const std::string& objectPath,
97*4a6ea6afSMatt Spinler                 const DbusPropertyMap& properties);
98*4a6ea6afSMatt Spinler #endif
99*4a6ea6afSMatt Spinler 
100*4a6ea6afSMatt Spinler         /**
101e0017ebbSMatt Spinler          * Returns the entry ID for a log
102e0017ebbSMatt Spinler          *
103e0017ebbSMatt Spinler          * @param[in] objectPath - the object path of the log
104e0017ebbSMatt Spinler          *
105e0017ebbSMatt Spinler          * @return uint32_t - the ID
106e0017ebbSMatt Spinler          */
107e0017ebbSMatt Spinler         inline uint32_t getEntryID(const std::string& objectPath)
108e0017ebbSMatt Spinler         {
109e0017ebbSMatt Spinler             std::experimental::filesystem::path path(objectPath);
110e0017ebbSMatt Spinler             return std::stoul(path.filename());
111e0017ebbSMatt Spinler         }
112e0017ebbSMatt Spinler 
113e0017ebbSMatt Spinler         /**
114e0017ebbSMatt Spinler          * The sdbusplus bus object
115e0017ebbSMatt Spinler          */
116e0017ebbSMatt Spinler         sdbusplus::bus::bus& bus;
117e0017ebbSMatt Spinler 
118e0017ebbSMatt Spinler         /**
119e0017ebbSMatt Spinler          * The match object for interfacesAdded
120e0017ebbSMatt Spinler          */
121e0017ebbSMatt Spinler         sdbusplus::bus::match_t addMatch;
122e0017ebbSMatt Spinler 
123e0017ebbSMatt Spinler         /**
124e0017ebbSMatt Spinler          * The match object for interfacesRemoved
125e0017ebbSMatt Spinler          */
126e0017ebbSMatt Spinler         sdbusplus::bus::match_t removeMatch;
127e0017ebbSMatt Spinler 
128e0017ebbSMatt Spinler         using EntryID = uint32_t;
129e0017ebbSMatt Spinler         using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
130e0017ebbSMatt Spinler         using EntryMap = std::map<EntryID, InterfaceMap>;
131e0017ebbSMatt Spinler 
132e0017ebbSMatt Spinler         /**
133e0017ebbSMatt Spinler          * A map of the error log IDs to their IBM interface objects.
134e0017ebbSMatt Spinler          * There may be multiple interfaces per ID.
135e0017ebbSMatt Spinler          */
136e0017ebbSMatt Spinler         EntryMap entries;
137743e5822SMatt Spinler 
138743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE
139743e5822SMatt Spinler         /**
140743e5822SMatt Spinler          * The class the wraps the IBM error logging policy table.
141743e5822SMatt Spinler          */
142743e5822SMatt Spinler         policy::Table policies;
143743e5822SMatt Spinler #endif
144e0017ebbSMatt Spinler };
145e0017ebbSMatt Spinler 
146e0017ebbSMatt Spinler }
147e0017ebbSMatt Spinler }
148