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