xref: /openbmc/ibm-logging/manager.hpp (revision 62011e26)
1 #pragma once
2 
3 #include <experimental/any>
4 #include <experimental/filesystem>
5 #include <map>
6 #include <sdbusplus/bus.hpp>
7 #include "config.h"
8 #include "dbus.hpp"
9 #include "interfaces.hpp"
10 #ifdef USE_POLICY_INTERFACE
11 #include "policy_table.hpp"
12 #endif
13 
14 namespace ibm
15 {
16 namespace logging
17 {
18 
19 
20 /**
21  * @class Manager
22  *
23  * This class hosts IBM specific interfaces for the error logging
24  * entry objects.  It watches for interfaces added and removed
25  * signals to know when to create and delete objects.  Handling the
26  * xyz.openbmc_project.Logging service going away is done at the
27  * systemd service level where this app will be stopped too.
28  */
29 class Manager
30 {
31     public:
32 
33         Manager() = delete;
34         ~Manager() = default;
35         Manager(const Manager&) = delete;
36         Manager& operator=(const Manager&) = delete;
37         Manager(Manager&&) = delete;
38         Manager& operator=(Manager&&) = delete;
39 
40         /**
41          * Constructor
42          *
43          * @param[in] bus - the D-Bus bus object
44          */
45         explicit Manager(sdbusplus::bus::bus& bus);
46 
47     private:
48 
49         /**
50          * The callback for an interfaces added signal
51          *
52          * Creates the IBM interfaces for the log entry
53          * that was just created.
54          *
55          * @param[in] msg - the sdbusplus message
56          */
57         void interfaceAdded(sdbusplus::message::message& msg);
58 
59         /**
60          * The callback for an interfaces removed signal
61          *
62          * Removes the IBM interfaces for the log entry
63          * that was just removed.
64          *
65          * @param[in] msg - the sdbusplus message
66          */
67         void interfaceRemoved(sdbusplus::message::message& msg);
68 
69         /**
70          * Creates the IBM interfaces for all existing error log
71          * entries.
72          */
73         void createAll();
74 
75         /**
76          * Creates the IBM interface(s) for a single error log.
77          *
78          * @param[in] objectPath - object path of the error log
79          * @param[in] properties - the xyz.openbmc_project.Logging.Entry
80          *                         properties
81          */
82         void create(
83                 const std::string& objectPath,
84                 const DbusPropertyMap& properties);
85 
86         /**
87          * Creates the IBM policy interface for a single error log
88          * and saves it in the list of interfaces.
89          *
90          * @param[in] objectPath - object path of the error log
91          * @param[in] properties - the xyz.openbmc_project.Logging.Entry
92          *                         properties
93          */
94 #ifdef USE_POLICY_INTERFACE
95         void createPolicyInterface(
96                 const std::string& objectPath,
97                 const DbusPropertyMap& properties);
98 #endif
99 
100         /**
101          * Returns the entry ID for a log
102          *
103          * @param[in] objectPath - the object path of the log
104          *
105          * @return uint32_t - the ID
106          */
107         inline uint32_t getEntryID(const std::string& objectPath)
108         {
109             std::experimental::filesystem::path path(objectPath);
110             return std::stoul(path.filename());
111         }
112 
113         /**
114          * The sdbusplus bus object
115          */
116         sdbusplus::bus::bus& bus;
117 
118         /**
119          * The match object for interfacesAdded
120          */
121         sdbusplus::bus::match_t addMatch;
122 
123         /**
124          * The match object for interfacesRemoved
125          */
126         sdbusplus::bus::match_t removeMatch;
127 
128         using EntryID = uint32_t;
129         using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
130         using EntryMap = std::map<EntryID, InterfaceMap>;
131 
132         /**
133          * A map of the error log IDs to their IBM interface objects.
134          * There may be multiple interfaces per ID.
135          */
136         EntryMap entries;
137 
138 #ifdef USE_POLICY_INTERFACE
139         /**
140          * The class the wraps the IBM error logging policy table.
141          */
142         policy::Table policies;
143 #endif
144 };
145 
146 }
147 }
148