blob: d09d1031fe77c95a14f65c942ec5e39f22b60dfe [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 Spinler433bead2018-04-23 11:08:03 -050045 /**
46 * Deletes the entry with the specified path
47 *
48 * @param[in] objectPath - the entry object path
49 */
50 void erase(const std::string& objectPath);
51
Matt Spinler2cfceb42018-04-23 11:13:04 -050052 /**
53 * Erases all entries
54 */
55 void eraseAll();
56
Matt Spinler259e7272018-03-29 10:57:17 -050057 private:
58 /**
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 Spinler259e7272018-03-29 10:57:17 -050069 * Creates the IBM interfaces for all existing error log
70 * entries.
71 */
72 void createAll();
Matt Spinlere0017eb2018-03-27 11:17:38 -050073
Matt Spinler259e7272018-03-29 10:57:17 -050074 /**
75 * Creates the IBM interface(s) for a single error log.
76 *
77 * @param[in] objectPath - object path of the error log
78 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
79 * properties
80 */
81 void create(const std::string& objectPath,
Matt Spinler54bfa7e2018-03-27 11:28:59 -050082 const DbusPropertyMap& properties);
83
Matt Spinler259e7272018-03-29 10:57:17 -050084 /**
85 * Creates the IBM policy interface for a single error log
86 * and saves it in the list of interfaces.
87 *
88 * @param[in] objectPath - object path of the error log
89 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
90 * properties
91 */
Matt Spinler4a6ea6a2018-03-27 14:25:12 -050092#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -050093 void createPolicyInterface(const std::string& objectPath,
94 const DbusPropertyMap& properties);
Matt Spinler4a6ea6a2018-03-27 14:25:12 -050095#endif
96
Matt Spinler259e7272018-03-29 10:57:17 -050097 /**
Matt Spinler433bead2018-04-23 11:08:03 -050098 * Creates the Delete interface for a single error log
99 * and saves it in the list of interfaces.
100 *
101 * @param[in] objectPath - object path of the error log
102 */
103 void createDeleteInterface(const std::string& objectPath);
104
105 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500106 * Returns the entry ID for a log
107 *
108 * @param[in] objectPath - the object path of the log
109 *
110 * @return uint32_t - the ID
111 */
112 inline uint32_t getEntryID(const std::string& objectPath)
113 {
114 std::experimental::filesystem::path path(objectPath);
115 return std::stoul(path.filename());
116 }
Matt Spinlere0017eb2018-03-27 11:17:38 -0500117
Matt Spinler259e7272018-03-29 10:57:17 -0500118 /**
Matt Spinler491fc6f2018-04-23 11:00:52 -0500119 * Adds an interface object to the entries map
120 *
121 * @param[in] objectPath - the object path of the log
122 * @param[in] type - the interface type being added
123 * @param[in] object - the interface object
124 */
125 void addInterface(const std::string& objectPath, InterfaceType type,
126 std::experimental::any& object);
127
128 /**
Matt Spinler259e7272018-03-29 10:57:17 -0500129 * The sdbusplus bus object
130 */
131 sdbusplus::bus::bus& bus;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500132
Matt Spinler259e7272018-03-29 10:57:17 -0500133 /**
134 * The match object for interfacesAdded
135 */
136 sdbusplus::bus::match_t addMatch;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500137
Matt Spinler259e7272018-03-29 10:57:17 -0500138 using EntryID = uint32_t;
139 using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
140 using EntryMap = std::map<EntryID, InterfaceMap>;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500141
Matt Spinler259e7272018-03-29 10:57:17 -0500142 /**
143 * A map of the error log IDs to their IBM interface objects.
144 * There may be multiple interfaces per ID.
145 */
146 EntryMap entries;
Matt Spinler743e5822018-03-27 13:44:50 -0500147
148#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500149 /**
150 * The class the wraps the IBM error logging policy table.
151 */
152 policy::Table policies;
Matt Spinler743e5822018-03-27 13:44:50 -0500153#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500154};
Matt Spinlere0017eb2018-03-27 11:17:38 -0500155}
156}