Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | 66e0707 | 2018-09-12 10:36:14 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "dbus.hpp" |
| 6 | #include "interfaces.hpp" |
| 7 | |
Matt Spinler | 54ea3ad | 2018-10-23 10:40:09 -0500 | [diff] [blame] | 8 | #include <any> |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 9 | #include <experimental/filesystem> |
| 10 | #include <map> |
| 11 | #include <sdbusplus/bus.hpp> |
Andrew Geissler | 29c2ec6 | 2020-05-16 13:48:44 -0500 | [diff] [blame] | 12 | #include <string> |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 13 | #ifdef USE_POLICY_INTERFACE |
| 14 | #include "policy_table.hpp" |
| 15 | #endif |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 16 | |
| 17 | namespace ibm |
| 18 | { |
| 19 | namespace logging |
| 20 | { |
| 21 | |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 22 | /** |
| 23 | * @class Manager |
| 24 | * |
| 25 | * This class hosts IBM specific interfaces for the error logging |
| 26 | * entry objects. It watches for interfaces added and removed |
| 27 | * signals to know when to create and delete objects. Handling the |
| 28 | * xyz.openbmc_project.Logging service going away is done at the |
| 29 | * systemd service level where this app will be stopped too. |
| 30 | */ |
| 31 | class Manager |
| 32 | { |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 33 | public: |
| 34 | Manager() = delete; |
| 35 | ~Manager() = default; |
| 36 | Manager(const Manager&) = delete; |
| 37 | Manager& operator=(const Manager&) = delete; |
| 38 | Manager(Manager&&) = delete; |
| 39 | Manager& operator=(Manager&&) = delete; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 40 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 41 | /** |
| 42 | * Constructor |
| 43 | * |
| 44 | * @param[in] bus - the D-Bus bus object |
| 45 | */ |
Patrick Williams | 8123a71 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 46 | explicit Manager(sdbusplus::bus_t& bus); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 47 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 48 | private: |
Matt Spinler | a139035 | 2018-05-23 10:48:19 -0500 | [diff] [blame] | 49 | using EntryID = uint32_t; |
Matt Spinler | 54ea3ad | 2018-10-23 10:40:09 -0500 | [diff] [blame] | 50 | using InterfaceMap = std::map<InterfaceType, std::any>; |
Matt Spinler | a139035 | 2018-05-23 10:48:19 -0500 | [diff] [blame] | 51 | using EntryMap = std::map<EntryID, InterfaceMap>; |
| 52 | |
Matt Spinler | 54ea3ad | 2018-10-23 10:40:09 -0500 | [diff] [blame] | 53 | using ObjectList = std::vector<std::any>; |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 54 | using InterfaceMapMulti = std::map<InterfaceType, ObjectList>; |
| 55 | using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>; |
| 56 | |
Matt Spinler | a139035 | 2018-05-23 10:48:19 -0500 | [diff] [blame] | 57 | /** |
| 58 | * Deletes the entry and any child entries with |
| 59 | * the specified ID. |
| 60 | * |
| 61 | * @param[in] id - the entry ID |
| 62 | */ |
| 63 | void erase(EntryID id); |
| 64 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 65 | /** |
| 66 | * The callback for an interfaces added signal |
| 67 | * |
| 68 | * Creates the IBM interfaces for the log entry |
| 69 | * that was just created. |
| 70 | * |
| 71 | * @param[in] msg - the sdbusplus message |
| 72 | */ |
Patrick Williams | 8123a71 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 73 | void interfaceAdded(sdbusplus::message_t& msg); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 74 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 75 | /** |
Matt Spinler | 055da3b | 2018-05-09 15:51:20 -0500 | [diff] [blame] | 76 | * The callback for an interfaces removed signal |
| 77 | * |
| 78 | * Removes the IBM interfaces for the log entry |
| 79 | * that was just removed. |
| 80 | * |
| 81 | * @param[in] msg - the sdbusplus message |
| 82 | */ |
Patrick Williams | 8123a71 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 83 | void interfaceRemoved(sdbusplus::message_t& msg); |
Matt Spinler | 055da3b | 2018-05-09 15:51:20 -0500 | [diff] [blame] | 84 | |
| 85 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 86 | * Creates the IBM interfaces for all existing error log |
| 87 | * entries. |
| 88 | */ |
| 89 | void createAll(); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 90 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 91 | /** |
Matt Spinler | e6a5159 | 2018-05-23 12:47:10 -0500 | [diff] [blame] | 92 | * Creates the IBM interface(s) for a single new error log. |
| 93 | * |
| 94 | * Any interfaces that require serialization will be created |
| 95 | * and serialized here. |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 96 | * |
| 97 | * @param[in] objectPath - object path of the error log |
Matt Spinler | e6a5159 | 2018-05-23 12:47:10 -0500 | [diff] [blame] | 98 | * @param[in] interfaces - map of all interfaces and properties |
| 99 | * on a phosphor-logging error log |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 100 | */ |
| 101 | void create(const std::string& objectPath, |
Matt Spinler | e6a5159 | 2018-05-23 12:47:10 -0500 | [diff] [blame] | 102 | const DbusInterfaceMap& interfaces); |
| 103 | |
| 104 | /** |
| 105 | * Creates the IBM interface(s) for a single error log after |
| 106 | * the application is restarted. |
| 107 | * |
| 108 | * Interfaces that were persisted will be restored from their |
| 109 | * previously saved filesystem data. |
| 110 | * |
| 111 | * @param[in] objectPath - object path of the error log |
| 112 | * @param[in] interfaces - map of all interfaces and properties |
| 113 | * on a phosphor-logging error log |
| 114 | */ |
| 115 | void createWithRestore(const std::string& objectPath, |
| 116 | const DbusInterfaceMap& interfaces); |
| 117 | |
| 118 | /** |
| 119 | * Creates the IBM interfaces for a single error log that |
| 120 | * do not persist across app restarts. |
| 121 | * |
| 122 | * @param[in] objectPath - object path of the error log |
| 123 | * @param[in] interfaces - map of all interfaces and properties |
| 124 | * on a phosphor-logging error log |
| 125 | */ |
| 126 | void createObject(const std::string& objectPath, |
| 127 | const DbusInterfaceMap& interfaces); |
Matt Spinler | 54bfa7e | 2018-03-27 11:28:59 -0500 | [diff] [blame] | 128 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 129 | /** |
Matt Spinler | 52ee71b | 2018-05-23 13:18:55 -0500 | [diff] [blame] | 130 | * Returns the error log timestamp property value from |
| 131 | * the passed in map of all interfaces and property names/values |
| 132 | * on an error log D-Bus object. |
| 133 | * |
| 134 | * @param[in] interfaces - map of all interfaces and properties |
| 135 | * on a phosphor-logging error log. |
| 136 | * |
| 137 | * @return uint64_t - the timestamp |
| 138 | */ |
| 139 | uint64_t getLogTimestamp(const DbusInterfaceMap& interfaces); |
| 140 | |
| 141 | /** |
| 142 | * Returns the filesystem directory to use for persisting |
| 143 | * information about a particular error log. |
| 144 | * |
| 145 | * @param[in] id - the error log ID |
| 146 | * @return path - the directory path |
| 147 | */ |
| 148 | std::experimental::filesystem::path getSaveDir(EntryID id); |
| 149 | |
| 150 | /** |
| 151 | * Returns the directory to use to save the callout information in |
| 152 | * |
| 153 | * @param[in] id - the error log ID |
| 154 | * |
| 155 | * @return path - the directory path |
| 156 | */ |
| 157 | std::experimental::filesystem::path getCalloutSaveDir(EntryID id); |
| 158 | |
| 159 | /** |
| 160 | * Returns the D-Bus object path to use for a callout D-Bus object. |
| 161 | * |
| 162 | * @param[in] objectPath - the object path for the error log |
| 163 | * @param[in] calloutNum - the callout instance number |
| 164 | * |
| 165 | * @return path - the object path to use for a callout object |
| 166 | */ |
| 167 | std::string getCalloutObjectPath(const std::string& objectPath, |
| 168 | uint32_t calloutNum); |
| 169 | |
| 170 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 171 | * Creates the IBM policy interface for a single error log |
| 172 | * and saves it in the list of interfaces. |
| 173 | * |
| 174 | * @param[in] objectPath - object path of the error log |
| 175 | * @param[in] properties - the xyz.openbmc_project.Logging.Entry |
| 176 | * properties |
| 177 | */ |
Matt Spinler | 4a6ea6a | 2018-03-27 14:25:12 -0500 | [diff] [blame] | 178 | #ifdef USE_POLICY_INTERFACE |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 179 | void createPolicyInterface(const std::string& objectPath, |
| 180 | const DbusPropertyMap& properties); |
Matt Spinler | 4a6ea6a | 2018-03-27 14:25:12 -0500 | [diff] [blame] | 181 | #endif |
| 182 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 183 | /** |
Matt Spinler | 52ee71b | 2018-05-23 13:18:55 -0500 | [diff] [blame] | 184 | * Creates D-Bus objects for any callouts in an error log |
| 185 | * that map to an inventory object with an Asset interface. |
| 186 | * |
| 187 | * The created object will also host the Asset interface. |
| 188 | * |
| 189 | * A callout object path would look like: |
| 190 | * /xyz/openbmc_project/logging/entry/5/callouts/0. |
| 191 | * |
| 192 | * Any objects created are serialized so the asset information |
| 193 | * can always be restored. |
| 194 | * |
| 195 | * @param[in] objectPath - object path of the error log |
| 196 | * @param[in] interfaces - map of all interfaces and properties |
| 197 | * on a phosphor-logging error log. |
| 198 | */ |
| 199 | void createCalloutObjects(const std::string& objectPath, |
| 200 | const DbusInterfaceMap& interfaces); |
| 201 | |
| 202 | /** |
Matt Spinler | 60f53d8 | 2018-05-23 13:23:09 -0500 | [diff] [blame] | 203 | * Restores callout objects for a particular error log that |
| 204 | * have previously been saved by reading their data out of |
| 205 | * the filesystem using Cereal. |
| 206 | * |
| 207 | * @param[in] objectPath - object path of the error log |
| 208 | * @param[in] interfaces - map of all interfaces and properties |
| 209 | * on a phosphor-logging error log. |
| 210 | */ |
| 211 | void restoreCalloutObjects(const std::string& objectPath, |
| 212 | const DbusInterfaceMap& interfaces); |
| 213 | |
| 214 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 215 | * Returns the entry ID for a log |
| 216 | * |
| 217 | * @param[in] objectPath - the object path of the log |
| 218 | * |
| 219 | * @return uint32_t - the ID |
| 220 | */ |
| 221 | inline uint32_t getEntryID(const std::string& objectPath) |
| 222 | { |
| 223 | std::experimental::filesystem::path path(objectPath); |
| 224 | return std::stoul(path.filename()); |
| 225 | } |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 226 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 227 | /** |
Matt Spinler | 491fc6f | 2018-04-23 11:00:52 -0500 | [diff] [blame] | 228 | * Adds an interface object to the entries map |
| 229 | * |
| 230 | * @param[in] objectPath - the object path of the log |
| 231 | * @param[in] type - the interface type being added |
| 232 | * @param[in] object - the interface object |
| 233 | */ |
| 234 | void addInterface(const std::string& objectPath, InterfaceType type, |
Matt Spinler | 54ea3ad | 2018-10-23 10:40:09 -0500 | [diff] [blame] | 235 | std::any& object); |
Matt Spinler | 491fc6f | 2018-04-23 11:00:52 -0500 | [diff] [blame] | 236 | |
| 237 | /** |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 238 | * Adds an interface to a child object, which is an object that |
| 239 | * relates to the main ...logging/entry/X object but has a different path. |
| 240 | * The object is stored in the childEntries map. |
| 241 | * |
| 242 | * There can be multiple instances of a child object per type per |
| 243 | * logging object. |
| 244 | * |
| 245 | * @param[in] objectPath - the object path of the log |
| 246 | * @param[in] type - the interface type being added. |
| 247 | * @param[in] object - the interface object |
| 248 | */ |
| 249 | void addChildInterface(const std::string& objectPath, InterfaceType type, |
Matt Spinler | 54ea3ad | 2018-10-23 10:40:09 -0500 | [diff] [blame] | 250 | std::any& object); |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 251 | |
| 252 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 253 | * The sdbusplus bus object |
| 254 | */ |
Patrick Williams | 8123a71 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 255 | sdbusplus::bus_t& bus; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 256 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 257 | /** |
| 258 | * The match object for interfacesAdded |
| 259 | */ |
| 260 | sdbusplus::bus::match_t addMatch; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 261 | |
Matt Spinler | 055da3b | 2018-05-09 15:51:20 -0500 | [diff] [blame] | 262 | /** |
| 263 | * The match object for interfacesRemoved |
| 264 | */ |
| 265 | sdbusplus::bus::match_t removeMatch; |
| 266 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 267 | /** |
| 268 | * A map of the error log IDs to their IBM interface objects. |
| 269 | * There may be multiple interfaces per ID. |
| 270 | */ |
| 271 | EntryMap entries; |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 272 | |
Matt Spinler | 677143b | 2018-05-23 10:53:27 -0500 | [diff] [blame] | 273 | /** |
| 274 | * A map of the error log IDs to their interface objects which |
| 275 | * are children of the logging objects. |
| 276 | * |
| 277 | * These objects have the same lifespan as their parent objects. |
| 278 | * |
| 279 | * There may be multiple interfaces per ID, and also multiple |
| 280 | * interface instances per interface type. |
| 281 | */ |
| 282 | EntryMapMulti childEntries; |
| 283 | |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 284 | #ifdef USE_POLICY_INTERFACE |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 285 | /** |
| 286 | * The class the wraps the IBM error logging policy table. |
| 287 | */ |
| 288 | policy::Table policies; |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 289 | #endif |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 290 | }; |
Matt Spinler | 66e0707 | 2018-09-12 10:36:14 -0500 | [diff] [blame] | 291 | } // namespace logging |
| 292 | } // namespace ibm |