Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <experimental/any> |
| 4 | #include <experimental/filesystem> |
| 5 | #include <map> |
| 6 | #include <sdbusplus/bus.hpp> |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 7 | #include "config.h" |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 8 | #include "dbus.hpp" |
| 9 | #include "interfaces.hpp" |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 10 | #ifdef USE_POLICY_INTERFACE |
| 11 | #include "policy_table.hpp" |
| 12 | #endif |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 13 | |
| 14 | namespace ibm |
| 15 | { |
| 16 | namespace logging |
| 17 | { |
| 18 | |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 19 | /** |
| 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 | */ |
| 28 | class Manager |
| 29 | { |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 30 | 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 Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 37 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * @param[in] bus - the D-Bus bus object |
| 42 | */ |
| 43 | explicit Manager(sdbusplus::bus::bus& bus); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 44 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 45 | private: |
Matt Spinler | a139035 | 2018-05-23 10:48:19 -0500 | [diff] [blame] | 46 | using EntryID = uint32_t; |
| 47 | using InterfaceMap = std::map<InterfaceType, std::experimental::any>; |
| 48 | using EntryMap = std::map<EntryID, InterfaceMap>; |
| 49 | |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 50 | using ObjectList = std::vector<std::experimental::any>; |
| 51 | using InterfaceMapMulti = std::map<InterfaceType, ObjectList>; |
| 52 | using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>; |
| 53 | |
Matt Spinler | a139035 | 2018-05-23 10:48:19 -0500 | [diff] [blame] | 54 | /** |
| 55 | * Deletes the entry and any child entries with |
| 56 | * the specified ID. |
| 57 | * |
| 58 | * @param[in] id - the entry ID |
| 59 | */ |
| 60 | void erase(EntryID id); |
| 61 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 62 | /** |
| 63 | * The callback for an interfaces added signal |
| 64 | * |
| 65 | * Creates the IBM interfaces for the log entry |
| 66 | * that was just created. |
| 67 | * |
| 68 | * @param[in] msg - the sdbusplus message |
| 69 | */ |
| 70 | void interfaceAdded(sdbusplus::message::message& msg); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 71 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 72 | /** |
Matt Spinler | 055da3b | 2018-05-09 15:51:20 -0500 | [diff] [blame] | 73 | * The callback for an interfaces removed signal |
| 74 | * |
| 75 | * Removes the IBM interfaces for the log entry |
| 76 | * that was just removed. |
| 77 | * |
| 78 | * @param[in] msg - the sdbusplus message |
| 79 | */ |
| 80 | void interfaceRemoved(sdbusplus::message::message& msg); |
| 81 | |
| 82 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 83 | * Creates the IBM interfaces for all existing error log |
| 84 | * entries. |
| 85 | */ |
| 86 | void createAll(); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 87 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 88 | /** |
| 89 | * Creates the IBM interface(s) for a single error log. |
| 90 | * |
| 91 | * @param[in] objectPath - object path of the error log |
| 92 | * @param[in] properties - the xyz.openbmc_project.Logging.Entry |
| 93 | * properties |
| 94 | */ |
| 95 | void create(const std::string& objectPath, |
Matt Spinler | 54bfa7e | 2018-03-27 11:28:59 -0500 | [diff] [blame] | 96 | const DbusPropertyMap& properties); |
| 97 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 98 | /** |
| 99 | * Creates the IBM policy interface for a single error log |
| 100 | * and saves it in the list of interfaces. |
| 101 | * |
| 102 | * @param[in] objectPath - object path of the error log |
| 103 | * @param[in] properties - the xyz.openbmc_project.Logging.Entry |
| 104 | * properties |
| 105 | */ |
Matt Spinler | 4a6ea6a | 2018-03-27 14:25:12 -0500 | [diff] [blame] | 106 | #ifdef USE_POLICY_INTERFACE |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 107 | void createPolicyInterface(const std::string& objectPath, |
| 108 | const DbusPropertyMap& properties); |
Matt Spinler | 4a6ea6a | 2018-03-27 14:25:12 -0500 | [diff] [blame] | 109 | #endif |
| 110 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 111 | /** |
| 112 | * Returns the entry ID for a log |
| 113 | * |
| 114 | * @param[in] objectPath - the object path of the log |
| 115 | * |
| 116 | * @return uint32_t - the ID |
| 117 | */ |
| 118 | inline uint32_t getEntryID(const std::string& objectPath) |
| 119 | { |
| 120 | std::experimental::filesystem::path path(objectPath); |
| 121 | return std::stoul(path.filename()); |
| 122 | } |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 123 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 124 | /** |
Matt Spinler | 491fc6f | 2018-04-23 11:00:52 -0500 | [diff] [blame] | 125 | * Adds an interface object to the entries map |
| 126 | * |
| 127 | * @param[in] objectPath - the object path of the log |
| 128 | * @param[in] type - the interface type being added |
| 129 | * @param[in] object - the interface object |
| 130 | */ |
| 131 | void addInterface(const std::string& objectPath, InterfaceType type, |
| 132 | std::experimental::any& object); |
| 133 | |
| 134 | /** |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 135 | * Adds an interface to a child object, which is an object that |
| 136 | * relates to the main ...logging/entry/X object but has a different path. |
| 137 | * The object is stored in the childEntries map. |
| 138 | * |
| 139 | * There can be multiple instances of a child object per type per |
| 140 | * logging object. |
| 141 | * |
| 142 | * @param[in] objectPath - the object path of the log |
| 143 | * @param[in] type - the interface type being added. |
| 144 | * @param[in] object - the interface object |
| 145 | */ |
| 146 | void addChildInterface(const std::string& objectPath, InterfaceType type, |
| 147 | std::experimental::any& object); |
| 148 | |
| 149 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 150 | * The sdbusplus bus object |
| 151 | */ |
| 152 | sdbusplus::bus::bus& bus; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 153 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 154 | /** |
| 155 | * The match object for interfacesAdded |
| 156 | */ |
| 157 | sdbusplus::bus::match_t addMatch; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 158 | |
Matt Spinler | 055da3b | 2018-05-09 15:51:20 -0500 | [diff] [blame] | 159 | /** |
| 160 | * The match object for interfacesRemoved |
| 161 | */ |
| 162 | sdbusplus::bus::match_t removeMatch; |
| 163 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 164 | /** |
| 165 | * A map of the error log IDs to their IBM interface objects. |
| 166 | * There may be multiple interfaces per ID. |
| 167 | */ |
| 168 | EntryMap entries; |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 169 | |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 170 | /** |
| 171 | * A map of the error log IDs to their interface objects which |
| 172 | * are children of the logging objects. |
| 173 | * |
| 174 | * These objects have the same lifespan as their parent objects. |
| 175 | * |
| 176 | * There may be multiple interfaces per ID, and also multiple |
| 177 | * interface instances per interface type. |
| 178 | */ |
| 179 | EntryMapMulti childEntries; |
| 180 | |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 181 | #ifdef USE_POLICY_INTERFACE |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 182 | /** |
| 183 | * The class the wraps the IBM error logging policy table. |
| 184 | */ |
| 185 | policy::Table policies; |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 186 | #endif |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 187 | }; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 188 | } |
| 189 | } |