blob: 55d6f5c3189e3e0dbfdf83cd0fe489a628106b7b [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:
46 /**
47 * The callback for an interfaces added signal
48 *
49 * Creates the IBM interfaces for the log entry
50 * that was just created.
51 *
52 * @param[in] msg - the sdbusplus message
53 */
54 void interfaceAdded(sdbusplus::message::message& msg);
Matt Spinlere0017eb2018-03-27 11:17:38 -050055
Matt Spinler259e7272018-03-29 10:57:17 -050056 /**
57 * The callback for an interfaces removed signal
58 *
59 * Removes the IBM interfaces for the log entry
60 * that was just removed.
61 *
62 * @param[in] msg - the sdbusplus message
63 */
64 void interfaceRemoved(sdbusplus::message::message& msg);
Matt Spinlere0017eb2018-03-27 11:17:38 -050065
Matt Spinler259e7272018-03-29 10:57:17 -050066 /**
67 * Creates the IBM interfaces for all existing error log
68 * entries.
69 */
70 void createAll();
Matt Spinlere0017eb2018-03-27 11:17:38 -050071
Matt Spinler259e7272018-03-29 10:57:17 -050072 /**
73 * Creates the IBM interface(s) for a single error log.
74 *
75 * @param[in] objectPath - object path of the error log
76 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
77 * properties
78 */
79 void create(const std::string& objectPath,
Matt Spinler54bfa7e2018-03-27 11:28:59 -050080 const DbusPropertyMap& properties);
81
Matt Spinler259e7272018-03-29 10:57:17 -050082 /**
83 * Creates the IBM policy interface for a single error log
84 * and saves it in the list of interfaces.
85 *
86 * @param[in] objectPath - object path of the error log
87 * @param[in] properties - the xyz.openbmc_project.Logging.Entry
88 * properties
89 */
Matt Spinler4a6ea6a2018-03-27 14:25:12 -050090#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -050091 void createPolicyInterface(const std::string& objectPath,
92 const DbusPropertyMap& properties);
Matt Spinler4a6ea6a2018-03-27 14:25:12 -050093#endif
94
Matt Spinler259e7272018-03-29 10:57:17 -050095 /**
96 * Returns the entry ID for a log
97 *
98 * @param[in] objectPath - the object path of the log
99 *
100 * @return uint32_t - the ID
101 */
102 inline uint32_t getEntryID(const std::string& objectPath)
103 {
104 std::experimental::filesystem::path path(objectPath);
105 return std::stoul(path.filename());
106 }
Matt Spinlere0017eb2018-03-27 11:17:38 -0500107
Matt Spinler259e7272018-03-29 10:57:17 -0500108 /**
109 * The sdbusplus bus object
110 */
111 sdbusplus::bus::bus& bus;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500112
Matt Spinler259e7272018-03-29 10:57:17 -0500113 /**
114 * The match object for interfacesAdded
115 */
116 sdbusplus::bus::match_t addMatch;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500117
Matt Spinler259e7272018-03-29 10:57:17 -0500118 /**
119 * The match object for interfacesRemoved
120 */
121 sdbusplus::bus::match_t removeMatch;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500122
Matt Spinler259e7272018-03-29 10:57:17 -0500123 using EntryID = uint32_t;
124 using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
125 using EntryMap = std::map<EntryID, InterfaceMap>;
Matt Spinlere0017eb2018-03-27 11:17:38 -0500126
Matt Spinler259e7272018-03-29 10:57:17 -0500127 /**
128 * A map of the error log IDs to their IBM interface objects.
129 * There may be multiple interfaces per ID.
130 */
131 EntryMap entries;
Matt Spinler743e5822018-03-27 13:44:50 -0500132
133#ifdef USE_POLICY_INTERFACE
Matt Spinler259e7272018-03-29 10:57:17 -0500134 /**
135 * The class the wraps the IBM error logging policy table.
136 */
137 policy::Table policies;
Matt Spinler743e5822018-03-27 13:44:50 -0500138#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500139};
Matt Spinlere0017eb2018-03-27 11:17:38 -0500140}
141}