blob: 60b3d75e9bf454bf08d7e367baa834128647962c [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
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 */
29class 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 /**
Matt Spinler54bfa7e2018-03-27 11:28:59 -050070 * 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 /**
Matt Spinler4a6ea6a2018-03-27 14:25:12 -050087 * 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 /**
Matt Spinlere0017eb2018-03-27 11:17:38 -0500101 * 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;
Matt Spinler743e5822018-03-27 13:44:50 -0500137
138#ifdef USE_POLICY_INTERFACE
139 /**
140 * The class the wraps the IBM error logging policy table.
141 */
142 policy::Table policies;
143#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500144};
145
146}
147}