1e0017ebbSMatt Spinler #pragma once 2e0017ebbSMatt Spinler 3e0017ebbSMatt Spinler #include <experimental/any> 4e0017ebbSMatt Spinler #include <experimental/filesystem> 5e0017ebbSMatt Spinler #include <map> 6e0017ebbSMatt Spinler #include <sdbusplus/bus.hpp> 7743e5822SMatt Spinler #include "config.h" 8e0017ebbSMatt Spinler #include "dbus.hpp" 9e0017ebbSMatt Spinler #include "interfaces.hpp" 10743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE 11743e5822SMatt Spinler #include "policy_table.hpp" 12743e5822SMatt Spinler #endif 13e0017ebbSMatt Spinler 14e0017ebbSMatt Spinler namespace ibm 15e0017ebbSMatt Spinler { 16e0017ebbSMatt Spinler namespace logging 17e0017ebbSMatt Spinler { 18e0017ebbSMatt Spinler 19e0017ebbSMatt Spinler /** 20e0017ebbSMatt Spinler * @class Manager 21e0017ebbSMatt Spinler * 22e0017ebbSMatt Spinler * This class hosts IBM specific interfaces for the error logging 23e0017ebbSMatt Spinler * entry objects. It watches for interfaces added and removed 24e0017ebbSMatt Spinler * signals to know when to create and delete objects. Handling the 25e0017ebbSMatt Spinler * xyz.openbmc_project.Logging service going away is done at the 26e0017ebbSMatt Spinler * systemd service level where this app will be stopped too. 27e0017ebbSMatt Spinler */ 28e0017ebbSMatt Spinler class Manager 29e0017ebbSMatt Spinler { 30e0017ebbSMatt Spinler public: 31e0017ebbSMatt Spinler Manager() = delete; 32e0017ebbSMatt Spinler ~Manager() = default; 33e0017ebbSMatt Spinler Manager(const Manager&) = delete; 34e0017ebbSMatt Spinler Manager& operator=(const Manager&) = delete; 35e0017ebbSMatt Spinler Manager(Manager&&) = delete; 36e0017ebbSMatt Spinler Manager& operator=(Manager&&) = delete; 37e0017ebbSMatt Spinler 38e0017ebbSMatt Spinler /** 39e0017ebbSMatt Spinler * Constructor 40e0017ebbSMatt Spinler * 41e0017ebbSMatt Spinler * @param[in] bus - the D-Bus bus object 42e0017ebbSMatt Spinler */ 43e0017ebbSMatt Spinler explicit Manager(sdbusplus::bus::bus& bus); 44e0017ebbSMatt Spinler 45e0017ebbSMatt Spinler private: 46a1390353SMatt Spinler using EntryID = uint32_t; 47a1390353SMatt Spinler using InterfaceMap = std::map<InterfaceType, std::experimental::any>; 48a1390353SMatt Spinler using EntryMap = std::map<EntryID, InterfaceMap>; 49a1390353SMatt Spinler 50677143bbSMatt Spinler using ObjectList = std::vector<std::experimental::any>; 51677143bbSMatt Spinler using InterfaceMapMulti = std::map<InterfaceType, ObjectList>; 52677143bbSMatt Spinler using EntryMapMulti = std::map<EntryID, InterfaceMapMulti>; 53677143bbSMatt Spinler 54a1390353SMatt Spinler /** 55a1390353SMatt Spinler * Deletes the entry and any child entries with 56a1390353SMatt Spinler * the specified ID. 57a1390353SMatt Spinler * 58a1390353SMatt Spinler * @param[in] id - the entry ID 59a1390353SMatt Spinler */ 60a1390353SMatt Spinler void erase(EntryID id); 61a1390353SMatt Spinler 62e0017ebbSMatt Spinler /** 63e0017ebbSMatt Spinler * The callback for an interfaces added signal 64e0017ebbSMatt Spinler * 65e0017ebbSMatt Spinler * Creates the IBM interfaces for the log entry 66e0017ebbSMatt Spinler * that was just created. 67e0017ebbSMatt Spinler * 68e0017ebbSMatt Spinler * @param[in] msg - the sdbusplus message 69e0017ebbSMatt Spinler */ 70e0017ebbSMatt Spinler void interfaceAdded(sdbusplus::message::message& msg); 71e0017ebbSMatt Spinler 72e0017ebbSMatt Spinler /** 73055da3bdSMatt Spinler * The callback for an interfaces removed signal 74055da3bdSMatt Spinler * 75055da3bdSMatt Spinler * Removes the IBM interfaces for the log entry 76055da3bdSMatt Spinler * that was just removed. 77055da3bdSMatt Spinler * 78055da3bdSMatt Spinler * @param[in] msg - the sdbusplus message 79055da3bdSMatt Spinler */ 80055da3bdSMatt Spinler void interfaceRemoved(sdbusplus::message::message& msg); 81055da3bdSMatt Spinler 82055da3bdSMatt Spinler /** 8354bfa7e7SMatt Spinler * Creates the IBM interfaces for all existing error log 8454bfa7e7SMatt Spinler * entries. 8554bfa7e7SMatt Spinler */ 8654bfa7e7SMatt Spinler void createAll(); 8754bfa7e7SMatt Spinler 8854bfa7e7SMatt Spinler /** 89e6a51590SMatt Spinler * Creates the IBM interface(s) for a single new error log. 90e6a51590SMatt Spinler * 91e6a51590SMatt Spinler * Any interfaces that require serialization will be created 92e6a51590SMatt Spinler * and serialized here. 9354bfa7e7SMatt Spinler * 9454bfa7e7SMatt Spinler * @param[in] objectPath - object path of the error log 95e6a51590SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 96e6a51590SMatt Spinler * on a phosphor-logging error log 9754bfa7e7SMatt Spinler */ 98259e7277SMatt Spinler void create(const std::string& objectPath, 99e6a51590SMatt Spinler const DbusInterfaceMap& interfaces); 100e6a51590SMatt Spinler 101e6a51590SMatt Spinler /** 102e6a51590SMatt Spinler * Creates the IBM interface(s) for a single error log after 103e6a51590SMatt Spinler * the application is restarted. 104e6a51590SMatt Spinler * 105e6a51590SMatt Spinler * Interfaces that were persisted will be restored from their 106e6a51590SMatt Spinler * previously saved filesystem data. 107e6a51590SMatt Spinler * 108e6a51590SMatt Spinler * @param[in] objectPath - object path of the error log 109e6a51590SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 110e6a51590SMatt Spinler * on a phosphor-logging error log 111e6a51590SMatt Spinler */ 112e6a51590SMatt Spinler void createWithRestore(const std::string& objectPath, 113e6a51590SMatt Spinler const DbusInterfaceMap& interfaces); 114e6a51590SMatt Spinler 115e6a51590SMatt Spinler /** 116e6a51590SMatt Spinler * Creates the IBM interfaces for a single error log that 117e6a51590SMatt Spinler * do not persist across app restarts. 118e6a51590SMatt Spinler * 119e6a51590SMatt Spinler * @param[in] objectPath - object path of the error log 120e6a51590SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 121e6a51590SMatt Spinler * on a phosphor-logging error log 122e6a51590SMatt Spinler */ 123e6a51590SMatt Spinler void createObject(const std::string& objectPath, 124e6a51590SMatt Spinler const DbusInterfaceMap& interfaces); 12554bfa7e7SMatt Spinler 12654bfa7e7SMatt Spinler /** 12752ee71bdSMatt Spinler * Returns the error log timestamp property value from 12852ee71bdSMatt Spinler * the passed in map of all interfaces and property names/values 12952ee71bdSMatt Spinler * on an error log D-Bus object. 13052ee71bdSMatt Spinler * 13152ee71bdSMatt Spinler * @param[in] interfaces - map of all interfaces and properties 13252ee71bdSMatt Spinler * on a phosphor-logging error log. 13352ee71bdSMatt Spinler * 13452ee71bdSMatt Spinler * @return uint64_t - the timestamp 13552ee71bdSMatt Spinler */ 13652ee71bdSMatt Spinler uint64_t getLogTimestamp(const DbusInterfaceMap& interfaces); 13752ee71bdSMatt Spinler 13852ee71bdSMatt Spinler /** 13952ee71bdSMatt Spinler * Returns the filesystem directory to use for persisting 14052ee71bdSMatt Spinler * information about a particular error log. 14152ee71bdSMatt Spinler * 14252ee71bdSMatt Spinler * @param[in] id - the error log ID 14352ee71bdSMatt Spinler * @return path - the directory path 14452ee71bdSMatt Spinler */ 14552ee71bdSMatt Spinler std::experimental::filesystem::path getSaveDir(EntryID id); 14652ee71bdSMatt Spinler 14752ee71bdSMatt Spinler /** 14852ee71bdSMatt Spinler * Returns the directory to use to save the callout information in 14952ee71bdSMatt Spinler * 15052ee71bdSMatt Spinler * @param[in] id - the error log ID 15152ee71bdSMatt Spinler * 15252ee71bdSMatt Spinler * @return path - the directory path 15352ee71bdSMatt Spinler */ 15452ee71bdSMatt Spinler std::experimental::filesystem::path getCalloutSaveDir(EntryID id); 15552ee71bdSMatt Spinler 15652ee71bdSMatt Spinler /** 15752ee71bdSMatt Spinler * Returns the D-Bus object path to use for a callout D-Bus object. 15852ee71bdSMatt Spinler * 15952ee71bdSMatt Spinler * @param[in] objectPath - the object path for the error log 16052ee71bdSMatt Spinler * @param[in] calloutNum - the callout instance number 16152ee71bdSMatt Spinler * 16252ee71bdSMatt Spinler * @return path - the object path to use for a callout object 16352ee71bdSMatt Spinler */ 16452ee71bdSMatt Spinler std::string getCalloutObjectPath(const std::string& objectPath, 16552ee71bdSMatt Spinler uint32_t calloutNum); 16652ee71bdSMatt Spinler 16752ee71bdSMatt Spinler /** 1684a6ea6afSMatt Spinler * Creates the IBM policy interface for a single error log 1694a6ea6afSMatt Spinler * and saves it in the list of interfaces. 1704a6ea6afSMatt Spinler * 1714a6ea6afSMatt Spinler * @param[in] objectPath - object path of the error log 1724a6ea6afSMatt Spinler * @param[in] properties - the xyz.openbmc_project.Logging.Entry 1734a6ea6afSMatt Spinler * properties 1744a6ea6afSMatt Spinler */ 1754a6ea6afSMatt Spinler #ifdef USE_POLICY_INTERFACE 176259e7277SMatt Spinler void createPolicyInterface(const std::string& objectPath, 1774a6ea6afSMatt Spinler const DbusPropertyMap& properties); 1784a6ea6afSMatt Spinler #endif 1794a6ea6afSMatt Spinler 1804a6ea6afSMatt Spinler /** 18152ee71bdSMatt Spinler * Creates D-Bus objects for any callouts in an error log 18252ee71bdSMatt Spinler * that map to an inventory object with an Asset interface. 18352ee71bdSMatt Spinler * 18452ee71bdSMatt Spinler * The created object will also host the Asset interface. 18552ee71bdSMatt Spinler * 18652ee71bdSMatt Spinler * A callout object path would look like: 18752ee71bdSMatt Spinler * /xyz/openbmc_project/logging/entry/5/callouts/0. 18852ee71bdSMatt Spinler * 18952ee71bdSMatt Spinler * Any objects created are serialized so the asset information 19052ee71bdSMatt Spinler * can always be restored. 19152ee71bdSMatt Spinler * 19252ee71bdSMatt Spinler * @param[in] objectPath - object path of the error log 19352ee71bdSMatt Spinler * @param[in] interfaces - map of all interfaces and properties 19452ee71bdSMatt Spinler * on a phosphor-logging error log. 19552ee71bdSMatt Spinler */ 19652ee71bdSMatt Spinler void createCalloutObjects(const std::string& objectPath, 19752ee71bdSMatt Spinler const DbusInterfaceMap& interfaces); 19852ee71bdSMatt Spinler 19952ee71bdSMatt Spinler /** 200*60f53d86SMatt Spinler * Restores callout objects for a particular error log that 201*60f53d86SMatt Spinler * have previously been saved by reading their data out of 202*60f53d86SMatt Spinler * the filesystem using Cereal. 203*60f53d86SMatt Spinler * 204*60f53d86SMatt Spinler * @param[in] objectPath - object path of the error log 205*60f53d86SMatt Spinler * @param[in] interfaces - map of all interfaces and properties 206*60f53d86SMatt Spinler * on a phosphor-logging error log. 207*60f53d86SMatt Spinler */ 208*60f53d86SMatt Spinler void restoreCalloutObjects(const std::string& objectPath, 209*60f53d86SMatt Spinler const DbusInterfaceMap& interfaces); 210*60f53d86SMatt Spinler 211*60f53d86SMatt Spinler /** 212e0017ebbSMatt Spinler * Returns the entry ID for a log 213e0017ebbSMatt Spinler * 214e0017ebbSMatt Spinler * @param[in] objectPath - the object path of the log 215e0017ebbSMatt Spinler * 216e0017ebbSMatt Spinler * @return uint32_t - the ID 217e0017ebbSMatt Spinler */ 218e0017ebbSMatt Spinler inline uint32_t getEntryID(const std::string& objectPath) 219e0017ebbSMatt Spinler { 220e0017ebbSMatt Spinler std::experimental::filesystem::path path(objectPath); 221e0017ebbSMatt Spinler return std::stoul(path.filename()); 222e0017ebbSMatt Spinler } 223e0017ebbSMatt Spinler 224e0017ebbSMatt Spinler /** 225491fc6f1SMatt Spinler * Adds an interface object to the entries map 226491fc6f1SMatt Spinler * 227491fc6f1SMatt Spinler * @param[in] objectPath - the object path of the log 228491fc6f1SMatt Spinler * @param[in] type - the interface type being added 229491fc6f1SMatt Spinler * @param[in] object - the interface object 230491fc6f1SMatt Spinler */ 231491fc6f1SMatt Spinler void addInterface(const std::string& objectPath, InterfaceType type, 232491fc6f1SMatt Spinler std::experimental::any& object); 233491fc6f1SMatt Spinler 234491fc6f1SMatt Spinler /** 235677143bbSMatt Spinler * Adds an interface to a child object, which is an object that 236677143bbSMatt Spinler * relates to the main ...logging/entry/X object but has a different path. 237677143bbSMatt Spinler * The object is stored in the childEntries map. 238677143bbSMatt Spinler * 239677143bbSMatt Spinler * There can be multiple instances of a child object per type per 240677143bbSMatt Spinler * logging object. 241677143bbSMatt Spinler * 242677143bbSMatt Spinler * @param[in] objectPath - the object path of the log 243677143bbSMatt Spinler * @param[in] type - the interface type being added. 244677143bbSMatt Spinler * @param[in] object - the interface object 245677143bbSMatt Spinler */ 246677143bbSMatt Spinler void addChildInterface(const std::string& objectPath, InterfaceType type, 247677143bbSMatt Spinler std::experimental::any& object); 248677143bbSMatt Spinler 249677143bbSMatt Spinler /** 250e0017ebbSMatt Spinler * The sdbusplus bus object 251e0017ebbSMatt Spinler */ 252e0017ebbSMatt Spinler sdbusplus::bus::bus& bus; 253e0017ebbSMatt Spinler 254e0017ebbSMatt Spinler /** 255e0017ebbSMatt Spinler * The match object for interfacesAdded 256e0017ebbSMatt Spinler */ 257e0017ebbSMatt Spinler sdbusplus::bus::match_t addMatch; 258e0017ebbSMatt Spinler 259055da3bdSMatt Spinler /** 260055da3bdSMatt Spinler * The match object for interfacesRemoved 261055da3bdSMatt Spinler */ 262055da3bdSMatt Spinler sdbusplus::bus::match_t removeMatch; 263055da3bdSMatt Spinler 264e0017ebbSMatt Spinler /** 265e0017ebbSMatt Spinler * A map of the error log IDs to their IBM interface objects. 266e0017ebbSMatt Spinler * There may be multiple interfaces per ID. 267e0017ebbSMatt Spinler */ 268e0017ebbSMatt Spinler EntryMap entries; 269743e5822SMatt Spinler 270677143bbSMatt Spinler /** 271677143bbSMatt Spinler * A map of the error log IDs to their interface objects which 272677143bbSMatt Spinler * are children of the logging objects. 273677143bbSMatt Spinler * 274677143bbSMatt Spinler * These objects have the same lifespan as their parent objects. 275677143bbSMatt Spinler * 276677143bbSMatt Spinler * There may be multiple interfaces per ID, and also multiple 277677143bbSMatt Spinler * interface instances per interface type. 278677143bbSMatt Spinler */ 279677143bbSMatt Spinler EntryMapMulti childEntries; 280677143bbSMatt Spinler 281743e5822SMatt Spinler #ifdef USE_POLICY_INTERFACE 282743e5822SMatt Spinler /** 283743e5822SMatt Spinler * The class the wraps the IBM error logging policy table. 284743e5822SMatt Spinler */ 285743e5822SMatt Spinler policy::Table policies; 286743e5822SMatt Spinler #endif 287e0017ebbSMatt Spinler }; 288e0017ebbSMatt Spinler } 289e0017ebbSMatt Spinler } 290