blob: b3891ac0a76cdc798e20a0576cdc283f61d15058 [file] [log] [blame]
Matt Spinlere0017eb2018-03-27 11:17:38 -05001#pragma once
2
3#include <experimental/any>
4#include <experimental/filesystem>
5#include <map>
6#include <sdbusplus/bus.hpp>
Matt Spinler743e5822018-03-27 13:44:50 -05007#include "config.h"
Matt Spinlere0017eb2018-03-27 11:17:38 -05008#include "dbus.hpp"
9#include "interfaces.hpp"
Matt Spinler743e5822018-03-27 13:44:50 -050010#ifdef USE_POLICY_INTERFACE
11#include "policy_table.hpp"
12#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -050013
14namespace ibm
15{
16namespace logging
17{
18
Matt Spinlere0017eb2018-03-27 11:17:38 -050019/**
20 * @class Manager
21 *
22 * This class hosts IBM specific interfaces for the error logging
23 * entry objects. It watches for interfaces added and removed
24 * signals to know when to create and delete objects. Handling the
25 * xyz.openbmc_project.Logging service going away is done at the
26 * systemd service level where this app will be stopped too.
27 */
28class Manager
29{
Matt Spinler259e7272018-03-29 10:57:17 -050030 public:
31 Manager() = delete;
32 ~Manager() = default;
33 Manager(const Manager&) = delete;
34 Manager& operator=(const Manager&) = delete;
35 Manager(Manager&&) = delete;
36 Manager& operator=(Manager&&) = delete;
Matt Spinlere0017eb2018-03-27 11:17:38 -050037
Matt Spinler259e7272018-03-29 10:57:17 -050038 /**
39 * Constructor
40 *
41 * @param[in] bus - the D-Bus bus object
42 */
43 explicit Manager(sdbusplus::bus::bus& bus);
Matt Spinlere0017eb2018-03-27 11:17:38 -050044
Matt Spinler259e7272018-03-29 10:57:17 -050045 private:
Matt Spinlera1390352018-05-23 10:48:19 -050046 using EntryID = uint32_t;
47 using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
48 using EntryMap = std::map<EntryID, InterfaceMap>;
49
50 /**
51 * Deletes the entry and any child entries with
52 * the specified ID.
53 *
54 * @param[in] id - the entry ID
55 */
56 void erase(EntryID id);
57
Matt Spinler259e7272018-03-29 10:57:17 -050058 /**
59 * The callback for an interfaces added signal
60 *
61 * Creates the IBM interfaces for the log entry
62 * that was just created.
63 *
64 * @param[in] msg - the sdbusplus message
65 */
66 void interfaceAdded(sdbusplus::message::message& msg);
Matt Spinlere0017eb2018-03-27 11:17:38 -050067
Matt Spinler259e7272018-03-29 10:57:17 -050068 /**
Matt Spinler055da3b2018-05-09 15:51:20 -050069 * The callback for an interfaces removed signal
70 *
71 * Removes the IBM interfaces for the log entry
72 * that was just removed.
73 *
74 * @param[in] msg - the sdbusplus message
75 */
76 void interfaceRemoved(sdbusplus::message::message& msg);
77
78 /**
Matt Spinler259e7272018-03-29 10:57:17 -050079 * Creates the IBM interfaces for all existing error log
80 * entries.
81 */
82 void createAll();
Matt Spinlere0017eb2018-03-27 11:17:38 -050083
Matt Spinler259e7272018-03-29 10:57:17 -050084 /**
85 * Creates the IBM interface(s) for a single error log.
86 *
87 * @param[in] objectPath - object path of the error log
88 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
89 * properties
90 */
91 void create(const std::string& objectPath,
Matt Spinler54bfa7e2018-03-27 11:28:59 -050092 const DbusPropertyMap& properties);
93
Matt Spinler259e7272018-03-29 10:57:17 -050094 /**
95 * Creates the IBM policy interface for a single error log
96 * and saves it in the list of interfaces.
97 *
98 * @param[in] objectPath - object path of the error log
99 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
100 * properties
101 */
Matt Spinler4a6ea6a2018-03-27 14:25:12 -0500102#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500103 void createPolicyInterface(const std::string& objectPath,
104 const DbusPropertyMap& properties);
Matt Spinler4a6ea6a2018-03-27 14:25:12 -0500105#endif
106
Matt Spinler259e7272018-03-29 10:57:17 -0500107 /**
108 * Returns the entry ID for a log
109 *
110 * @param[in] objectPath - the object path of the log
111 *
112 * @return uint32_t - the ID
113 */
114 inline uint32_t getEntryID(const std::string& objectPath)
115 {
116 std::experimental::filesystem::path path(objectPath);
117 return std::stoul(path.filename());
118 }
Matt Spinlere0017eb2018-03-27 11:17:38 -0500119
Matt Spinler259e7272018-03-29 10:57:17 -0500120 /**
Matt Spinler491fc6f2018-04-23 11:00:52 -0500121 * Adds an interface object to the entries map
122 *
123 * @param[in] objectPath - the object path of the log
124 * @param[in] type - the interface type being added
125 * @param[in] object - the interface object
126 */
127 void addInterface(const std::string& objectPath, InterfaceType type,
128 std::experimental::any& object);
129
130 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500131 * The sdbusplus bus object
132 */
133 sdbusplus::bus::bus& bus;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500134
Matt Spinler259e7272018-03-29 10:57:17 -0500135 /**
136 * The match object for interfacesAdded
137 */
138 sdbusplus::bus::match_t addMatch;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500139
Matt Spinler055da3b2018-05-09 15:51:20 -0500140 /**
141 * The match object for interfacesRemoved
142 */
143 sdbusplus::bus::match_t removeMatch;
144
Matt Spinler259e7272018-03-29 10:57:17 -0500145 /**
146 * A map of the error log IDs to their IBM interface objects.
147 * There may be multiple interfaces per ID.
148 */
149 EntryMap entries;
Matt Spinler743e5822018-03-27 13:44:50 -0500150
151#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500152 /**
153 * The class the wraps the IBM error logging policy table.
154 */
155 policy::Table policies;
Matt Spinler743e5822018-03-27 13:44:50 -0500156#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500157};
Matt Spinlere0017eb2018-03-27 11:17:38 -0500158}
159}