Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <experimental/any> |
| 4 | #include <experimental/filesystem> |
| 5 | #include <map> |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include "dbus.hpp" |
| 8 | #include "interfaces.hpp" |
| 9 | |
| 10 | namespace ibm |
| 11 | { |
| 12 | namespace logging |
| 13 | { |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * @class Manager |
| 18 | * |
| 19 | * This class hosts IBM specific interfaces for the error logging |
| 20 | * entry objects. It watches for interfaces added and removed |
| 21 | * signals to know when to create and delete objects. Handling the |
| 22 | * xyz.openbmc_project.Logging service going away is done at the |
| 23 | * systemd service level where this app will be stopped too. |
| 24 | */ |
| 25 | class Manager |
| 26 | { |
| 27 | public: |
| 28 | |
| 29 | Manager() = delete; |
| 30 | ~Manager() = default; |
| 31 | Manager(const Manager&) = delete; |
| 32 | Manager& operator=(const Manager&) = delete; |
| 33 | Manager(Manager&&) = delete; |
| 34 | Manager& operator=(Manager&&) = delete; |
| 35 | |
| 36 | /** |
| 37 | * Constructor |
| 38 | * |
| 39 | * @param[in] bus - the D-Bus bus object |
| 40 | */ |
| 41 | explicit Manager(sdbusplus::bus::bus& bus); |
| 42 | |
| 43 | private: |
| 44 | |
| 45 | /** |
| 46 | * The callback for an interfaces added signal |
| 47 | * |
| 48 | * Creates the IBM interfaces for the log entry |
| 49 | * that was just created. |
| 50 | * |
| 51 | * @param[in] msg - the sdbusplus message |
| 52 | */ |
| 53 | void interfaceAdded(sdbusplus::message::message& msg); |
| 54 | |
| 55 | /** |
| 56 | * The callback for an interfaces removed signal |
| 57 | * |
| 58 | * Removes the IBM interfaces for the log entry |
| 59 | * that was just removed. |
| 60 | * |
| 61 | * @param[in] msg - the sdbusplus message |
| 62 | */ |
| 63 | void interfaceRemoved(sdbusplus::message::message& msg); |
| 64 | |
| 65 | /** |
Matt Spinler | 54bfa7e | 2018-03-27 11:28:59 -0500 | [diff] [blame] | 66 | * Creates the IBM interfaces for all existing error log |
| 67 | * entries. |
| 68 | */ |
| 69 | void createAll(); |
| 70 | |
| 71 | /** |
| 72 | * Creates the IBM interface(s) for a single error log. |
| 73 | * |
| 74 | * @param[in] objectPath - object path of the error log |
| 75 | * @param[in] properties - the xyz.openbmc_project.Logging.Entry |
| 76 | * properties |
| 77 | */ |
| 78 | void create( |
| 79 | const std::string& objectPath, |
| 80 | const DbusPropertyMap& properties); |
| 81 | |
| 82 | /** |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 83 | * Returns the entry ID for a log |
| 84 | * |
| 85 | * @param[in] objectPath - the object path of the log |
| 86 | * |
| 87 | * @return uint32_t - the ID |
| 88 | */ |
| 89 | inline uint32_t getEntryID(const std::string& objectPath) |
| 90 | { |
| 91 | std::experimental::filesystem::path path(objectPath); |
| 92 | return std::stoul(path.filename()); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * The sdbusplus bus object |
| 97 | */ |
| 98 | sdbusplus::bus::bus& bus; |
| 99 | |
| 100 | /** |
| 101 | * The match object for interfacesAdded |
| 102 | */ |
| 103 | sdbusplus::bus::match_t addMatch; |
| 104 | |
| 105 | /** |
| 106 | * The match object for interfacesRemoved |
| 107 | */ |
| 108 | sdbusplus::bus::match_t removeMatch; |
| 109 | |
| 110 | using EntryID = uint32_t; |
| 111 | using InterfaceMap = std::map<InterfaceType, std::experimental::any>; |
| 112 | using EntryMap = std::map<EntryID, InterfaceMap>; |
| 113 | |
| 114 | /** |
| 115 | * A map of the error log IDs to their IBM interface objects. |
| 116 | * There may be multiple interfaces per ID. |
| 117 | */ |
| 118 | EntryMap entries; |
| 119 | }; |
| 120 | |
| 121 | } |
| 122 | } |