1e0017ebbSMatt Spinler #pragma once 2e0017ebbSMatt Spinler 3*66e07073SMatt Spinler #include "config.h" 4*66e07073SMatt Spinler 5*66e07073SMatt Spinler #include "dbus.hpp" 6*66e07073SMatt Spinler #include "interfaces.hpp" 7*66e07073SMatt Spinler 8e0017ebbSMatt Spinler #include <experimental/any> 9e0017ebbSMatt Spinler #include <experimental/filesystem> 10e0017ebbSMatt Spinler #include <map> 11e0017ebbSMatt Spinler #include <sdbusplus/bus.hpp> 12743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE 13743e5822SMatt Spinler #include "policy_table.hpp" 14743e5822SMatt Spinler #endif 15e0017ebbSMatt Spinler 16e0017ebbSMatt Spinler namespace ibm 17e0017ebbSMatt Spinler { 18e0017ebbSMatt Spinler namespace logging 19e0017ebbSMatt Spinler { 20e0017ebbSMatt Spinler 21e0017ebbSMatt Spinler /** 22e0017ebbSMatt Spinler * @class Manager 23e0017ebbSMatt Spinler * 24e0017ebbSMatt Spinler * This class hosts IBM specific interfaces for the error logging 25e0017ebbSMatt Spinler * entry objects. It watches for interfaces added and removed 26e0017ebbSMatt Spinler * signals to know when to create and delete objects. Handling the 27e0017ebbSMatt Spinler * xyz.openbmc_project.Logging service going away is done at the 28e0017ebbSMatt Spinler * systemd service level where this app will be stopped too. 29e0017ebbSMatt Spinler */ 30e0017ebbSMatt Spinler class Manager 31e0017ebbSMatt Spinler { 32e0017ebbSMatt Spinler public: 33e0017ebbSMatt Spinler Manager() = delete; 34e0017ebbSMatt Spinler ~Manager() = default; 35e0017ebbSMatt Spinler Manager(const Manager&) = delete; 36e0017ebbSMatt Spinler Manager& operator=(const Manager&) = delete; 37e0017ebbSMatt Spinler Manager(Manager&&) = delete; 38e0017ebbSMatt Spinler Manager& operator=(Manager&&) = delete; 39e0017ebbSMatt Spinler 40e0017ebbSMatt Spinler /** 41e0017ebbSMatt Spinler * Constructor 42e0017ebbSMatt Spinler * 43e0017ebbSMatt Spinler * @param[in] bus - the D-Bus bus object 44e0017ebbSMatt Spinler */ 45e0017ebbSMatt Spinler explicit Manager(sdbusplus::bus::bus& bus); 46e0017ebbSMatt Spinler 47e0017ebbSMatt Spinler private: 48a1390353SMatt Spinler using EntryID = uint32_t; 49a1390353SMatt Spinler using InterfaceMap = std::map<InterfaceType, std::experimental::any>; 50a1390353SMatt Spinler using EntryMap = std::map<EntryID, InterfaceMap>; 51a1390353SMatt Spinler 52677143bbSMatt Spinler using ObjectList = std::vector<std::experimental::any>; 53677143bbSMatt Spinler using InterfaceMapMulti = std::map<InterfaceType, ObjectList>; 54677143bbSMatt Spinler using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>; 55677143bbSMatt Spinler 56a1390353SMatt Spinler /** 57a1390353SMatt Spinler * Deletes the entry and any child entries with 58a1390353SMatt Spinler * the specified ID. 59a1390353SMatt Spinler * 60a1390353SMatt Spinler * @param[in] id - the entry ID 61a1390353SMatt Spinler */ 62a1390353SMatt Spinler void erase(EntryID id); 63a1390353SMatt Spinler 64e0017ebbSMatt Spinler /** 65e0017ebbSMatt Spinler * The callback for an interfaces added signal 66e0017ebbSMatt Spinler * 67e0017ebbSMatt Spinler * Creates the IBM interfaces for the log entry 68e0017ebbSMatt Spinler * that was just created. 69e0017ebbSMatt Spinler * 70e0017ebbSMatt Spinler * @param[in] msg - the sdbusplus message 71e0017ebbSMatt Spinler */ 72e0017ebbSMatt Spinler void interfaceAdded(sdbusplus::message::message& msg); 73e0017ebbSMatt Spinler 74e0017ebbSMatt Spinler /** 75055da3bdSMatt Spinler * The callback for an interfaces removed signal 76055da3bdSMatt Spinler * 77055da3bdSMatt Spinler * Removes the IBM interfaces for the log entry 78055da3bdSMatt Spinler * that was just removed. 79055da3bdSMatt Spinler * 80055da3bdSMatt Spinler * @param[in] msg - the sdbusplus message 81055da3bdSMatt Spinler */ 82055da3bdSMatt Spinler void interfaceRemoved(sdbusplus::message::message& msg); 83055da3bdSMatt Spinler 84055da3bdSMatt Spinler /** 8554bfa7e7SMatt Spinler * Creates the IBM interfaces for all existing error log 8654bfa7e7SMatt Spinler * entries. 8754bfa7e7SMatt Spinler */ 8854bfa7e7SMatt Spinler void createAll(); 8954bfa7e7SMatt Spinler 9054bfa7e7SMatt Spinler /** 91e6a51590SMatt Spinler * Creates the IBM interface(s) for a single new error log. 92e6a51590SMatt Spinler * 93e6a51590SMatt Spinler * Any interfaces that require serialization will be created 94e6a51590SMatt Spinler * and serialized here. 9554bfa7e7SMatt Spinler * 9654bfa7e7SMatt Spinler * @param[in] objectPath - object path of the error log 97e6a51590SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 98e6a51590SMatt Spinler * on a phosphor-logging error log 9954bfa7e7SMatt Spinler */ 100259e7277SMatt Spinler void create(const std::string& objectPath, 101e6a51590SMatt Spinler const DbusInterfaceMap& interfaces); 102e6a51590SMatt Spinler 103e6a51590SMatt Spinler /** 104e6a51590SMatt Spinler * Creates the IBM interface(s) for a single error log after 105e6a51590SMatt Spinler * the application is restarted. 106e6a51590SMatt Spinler * 107e6a51590SMatt Spinler * Interfaces that were persisted will be restored from their 108e6a51590SMatt Spinler * previously saved filesystem data. 109e6a51590SMatt Spinler * 110e6a51590SMatt Spinler * @param[in] objectPath - object path of the error log 111e6a51590SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 112e6a51590SMatt Spinler * on a phosphor-logging error log 113e6a51590SMatt Spinler */ 114e6a51590SMatt Spinler void createWithRestore(const std::string& objectPath, 115e6a51590SMatt Spinler const DbusInterfaceMap& interfaces); 116e6a51590SMatt Spinler 117e6a51590SMatt Spinler /** 118e6a51590SMatt Spinler * Creates the IBM interfaces for a single error log that 119e6a51590SMatt Spinler * do not persist across app restarts. 120e6a51590SMatt Spinler * 121e6a51590SMatt Spinler * @param[in] objectPath - object path of the error log 122e6a51590SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 123e6a51590SMatt Spinler * on a phosphor-logging error log 124e6a51590SMatt Spinler */ 125e6a51590SMatt Spinler void createObject(const std::string& objectPath, 126e6a51590SMatt Spinler const DbusInterfaceMap& interfaces); 12754bfa7e7SMatt Spinler 12854bfa7e7SMatt Spinler /** 12952ee71bdSMatt Spinler * Returns the error log timestamp property value from 13052ee71bdSMatt Spinler * the passed in map of all interfaces and property names/values 13152ee71bdSMatt Spinler * on an error log D-Bus object. 13252ee71bdSMatt Spinler * 13352ee71bdSMatt Spinler * @param[in] interfaces - map of all interfaces and properties 13452ee71bdSMatt Spinler * on a phosphor-logging error log. 13552ee71bdSMatt Spinler * 13652ee71bdSMatt Spinler * @return uint64_t - the timestamp 13752ee71bdSMatt Spinler */ 13852ee71bdSMatt Spinler uint64_t getLogTimestamp(const DbusInterfaceMap& interfaces); 13952ee71bdSMatt Spinler 14052ee71bdSMatt Spinler /** 14152ee71bdSMatt Spinler * Returns the filesystem directory to use for persisting 14252ee71bdSMatt Spinler * information about a particular error log. 14352ee71bdSMatt Spinler * 14452ee71bdSMatt Spinler * @param[in] id - the error log ID 14552ee71bdSMatt Spinler * @return path - the directory path 14652ee71bdSMatt Spinler */ 14752ee71bdSMatt Spinler std::experimental::filesystem::path getSaveDir(EntryID id); 14852ee71bdSMatt Spinler 14952ee71bdSMatt Spinler /** 15052ee71bdSMatt Spinler * Returns the directory to use to save the callout information in 15152ee71bdSMatt Spinler * 15252ee71bdSMatt Spinler * @param[in] id - the error log ID 15352ee71bdSMatt Spinler * 15452ee71bdSMatt Spinler * @return path - the directory path 15552ee71bdSMatt Spinler */ 15652ee71bdSMatt Spinler std::experimental::filesystem::path getCalloutSaveDir(EntryID id); 15752ee71bdSMatt Spinler 15852ee71bdSMatt Spinler /** 15952ee71bdSMatt Spinler * Returns the D-Bus object path to use for a callout D-Bus object. 16052ee71bdSMatt Spinler * 16152ee71bdSMatt Spinler * @param[in] objectPath - the object path for the error log 16252ee71bdSMatt Spinler * @param[in] calloutNum - the callout instance number 16352ee71bdSMatt Spinler * 16452ee71bdSMatt Spinler * @return path - the object path to use for a callout object 16552ee71bdSMatt Spinler */ 16652ee71bdSMatt Spinler std::string getCalloutObjectPath(const std::string& objectPath, 16752ee71bdSMatt Spinler uint32_t calloutNum); 16852ee71bdSMatt Spinler 16952ee71bdSMatt Spinler /** 1704a6ea6afSMatt Spinler * Creates the IBM policy interface for a single error log 1714a6ea6afSMatt Spinler * and saves it in the list of interfaces. 1724a6ea6afSMatt Spinler * 1734a6ea6afSMatt Spinler * @param[in] objectPath - object path of the error log 1744a6ea6afSMatt Spinler * @param[in] properties - the xyz.openbmc_project.Logging.Entry 1754a6ea6afSMatt Spinler * properties 1764a6ea6afSMatt Spinler */ 1774a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE 178259e7277SMatt Spinler void createPolicyInterface(const std::string& objectPath, 1794a6ea6afSMatt Spinler const DbusPropertyMap& properties); 1804a6ea6afSMatt Spinler #endif 1814a6ea6afSMatt Spinler 1824a6ea6afSMatt Spinler /** 18352ee71bdSMatt Spinler * Creates D-Bus objects for any callouts in an error log 18452ee71bdSMatt Spinler * that map to an inventory object with an Asset interface. 18552ee71bdSMatt Spinler * 18652ee71bdSMatt Spinler * The created object will also host the Asset interface. 18752ee71bdSMatt Spinler * 18852ee71bdSMatt Spinler * A callout object path would look like: 18952ee71bdSMatt Spinler * /xyz/openbmc_project/logging/entry/5/callouts/0. 19052ee71bdSMatt Spinler * 19152ee71bdSMatt Spinler * Any objects created are serialized so the asset information 19252ee71bdSMatt Spinler * can always be restored. 19352ee71bdSMatt Spinler * 19452ee71bdSMatt Spinler * @param[in] objectPath - object path of the error log 19552ee71bdSMatt Spinler * @param[in] interfaces - map of all interfaces and properties 19652ee71bdSMatt Spinler * on a phosphor-logging error log. 19752ee71bdSMatt Spinler */ 19852ee71bdSMatt Spinler void createCalloutObjects(const std::string& objectPath, 19952ee71bdSMatt Spinler const DbusInterfaceMap& interfaces); 20052ee71bdSMatt Spinler 20152ee71bdSMatt Spinler /** 20260f53d86SMatt Spinler * Restores callout objects for a particular error log that 20360f53d86SMatt Spinler * have previously been saved by reading their data out of 20460f53d86SMatt Spinler * the filesystem using Cereal. 20560f53d86SMatt Spinler * 20660f53d86SMatt Spinler * @param[in] objectPath - object path of the error log 20760f53d86SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 20860f53d86SMatt Spinler * on a phosphor-logging error log. 20960f53d86SMatt Spinler */ 21060f53d86SMatt Spinler void restoreCalloutObjects(const std::string& objectPath, 21160f53d86SMatt Spinler const DbusInterfaceMap& interfaces); 21260f53d86SMatt Spinler 21360f53d86SMatt Spinler /** 214e0017ebbSMatt Spinler * Returns the entry ID for a log 215e0017ebbSMatt Spinler * 216e0017ebbSMatt Spinler * @param[in] objectPath - the object path of the log 217e0017ebbSMatt Spinler * 218e0017ebbSMatt Spinler * @return uint32_t - the ID 219e0017ebbSMatt Spinler */ 220e0017ebbSMatt Spinler inline uint32_t getEntryID(const std::string& objectPath) 221e0017ebbSMatt Spinler { 222e0017ebbSMatt Spinler std::experimental::filesystem::path path(objectPath); 223e0017ebbSMatt Spinler return std::stoul(path.filename()); 224e0017ebbSMatt Spinler } 225e0017ebbSMatt Spinler 226e0017ebbSMatt Spinler /** 227491fc6f1SMatt Spinler * Adds an interface object to the entries map 228491fc6f1SMatt Spinler * 229491fc6f1SMatt Spinler * @param[in] objectPath - the object path of the log 230491fc6f1SMatt Spinler * @param[in] type - the interface type being added 231491fc6f1SMatt Spinler * @param[in] object - the interface object 232491fc6f1SMatt Spinler */ 233491fc6f1SMatt Spinler void addInterface(const std::string& objectPath, InterfaceType type, 234491fc6f1SMatt Spinler std::experimental::any& object); 235491fc6f1SMatt Spinler 236491fc6f1SMatt Spinler /** 237677143bbSMatt Spinler * Adds an interface to a child object, which is an object that 238677143bbSMatt Spinler * relates to the main ...logging/entry/X object but has a different path. 239677143bbSMatt Spinler * The object is stored in the childEntries map. 240677143bbSMatt Spinler * 241677143bbSMatt Spinler * There can be multiple instances of a child object per type per 242677143bbSMatt Spinler * logging object. 243677143bbSMatt Spinler * 244677143bbSMatt Spinler * @param[in] objectPath - the object path of the log 245677143bbSMatt Spinler * @param[in] type - the interface type being added. 246677143bbSMatt Spinler * @param[in] object - the interface object 247677143bbSMatt Spinler */ 248677143bbSMatt Spinler void addChildInterface(const std::string& objectPath, InterfaceType type, 249677143bbSMatt Spinler std::experimental::any& object); 250677143bbSMatt Spinler 251677143bbSMatt Spinler /** 252e0017ebbSMatt Spinler * The sdbusplus bus object 253e0017ebbSMatt Spinler */ 254e0017ebbSMatt Spinler sdbusplus::bus::bus& bus; 255e0017ebbSMatt Spinler 256e0017ebbSMatt Spinler /** 257e0017ebbSMatt Spinler * The match object for interfacesAdded 258e0017ebbSMatt Spinler */ 259e0017ebbSMatt Spinler sdbusplus::bus::match_t addMatch; 260e0017ebbSMatt Spinler 261055da3bdSMatt Spinler /** 262055da3bdSMatt Spinler * The match object for interfacesRemoved 263055da3bdSMatt Spinler */ 264055da3bdSMatt Spinler sdbusplus::bus::match_t removeMatch; 265055da3bdSMatt Spinler 266e0017ebbSMatt Spinler /** 267e0017ebbSMatt Spinler * A map of the error log IDs to their IBM interface objects. 268e0017ebbSMatt Spinler * There may be multiple interfaces per ID. 269e0017ebbSMatt Spinler */ 270e0017ebbSMatt Spinler EntryMap entries; 271743e5822SMatt Spinler 272677143bbSMatt Spinler /** 273677143bbSMatt Spinler * A map of the error log IDs to their interface objects which 274677143bbSMatt Spinler * are children of the logging objects. 275677143bbSMatt Spinler * 276677143bbSMatt Spinler * These objects have the same lifespan as their parent objects. 277677143bbSMatt Spinler * 278677143bbSMatt Spinler * There may be multiple interfaces per ID, and also multiple 279677143bbSMatt Spinler * interface instances per interface type. 280677143bbSMatt Spinler */ 281677143bbSMatt Spinler EntryMapMulti childEntries; 282677143bbSMatt Spinler 283743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE 284743e5822SMatt Spinler /** 285743e5822SMatt Spinler * The class the wraps the IBM error logging policy table. 286743e5822SMatt Spinler */ 287743e5822SMatt Spinler policy::Table policies; 288743e5822SMatt Spinler #endif 289e0017ebbSMatt Spinler }; 290*66e07073SMatt Spinler } // namespace logging 291*66e07073SMatt Spinler } // namespace ibm 292