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