blob: 0f44a2be2d6a5d81018bc3cfcc41030c5b0665d2 [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 Spinlere0017eb2018-03-27 11:17:38 -050087 * Returns the entry ID for a log
88 *
89 * @param[in] objectPath - the object path of the log
90 *
91 * @return uint32_t - the ID
92 */
93 inline uint32_t getEntryID(const std::string& objectPath)
94 {
95 std::experimental::filesystem::path path(objectPath);
96 return std::stoul(path.filename());
97 }
98
99 /**
100 * The sdbusplus bus object
101 */
102 sdbusplus::bus::bus& bus;
103
104 /**
105 * The match object for interfacesAdded
106 */
107 sdbusplus::bus::match_t addMatch;
108
109 /**
110 * The match object for interfacesRemoved
111 */
112 sdbusplus::bus::match_t removeMatch;
113
114 using EntryID = uint32_t;
115 using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
116 using EntryMap = std::map<EntryID, InterfaceMap>;
117
118 /**
119 * A map of the error log IDs to their IBM interface objects.
120 * There may be multiple interfaces per ID.
121 */
122 EntryMap entries;
Matt Spinler743e5822018-03-27 13:44:50 -0500123
124#ifdef USE_POLICY_INTERFACE
125 /**
126 * The class the wraps the IBM error logging policy table.
127 */
128 policy::Table policies;
129#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -0500130};
131
132}
133}