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> |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 7 | #include "config.h" |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 8 | #include "dbus.hpp" |
| 9 | #include "interfaces.hpp" |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 10 | #ifdef USE_POLICY_INTERFACE |
| 11 | #include "policy_table.hpp" |
| 12 | #endif |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 13 | |
| 14 | namespace ibm |
| 15 | { |
| 16 | namespace logging |
| 17 | { |
| 18 | |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 19 | /** |
| 20 | * @class Manager |
| 21 | * |
| 22 | * This class hosts IBM specific interfaces for the error logging |
| 23 | * entry objects. It watches for interfaces added and removed |
| 24 | * signals to know when to create and delete objects. Handling the |
| 25 | * xyz.openbmc_project.Logging service going away is done at the |
| 26 | * systemd service level where this app will be stopped too. |
| 27 | */ |
| 28 | class Manager |
| 29 | { |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 30 | public: |
| 31 | Manager() = delete; |
| 32 | ~Manager() = default; |
| 33 | Manager(const Manager&) = delete; |
| 34 | Manager& operator=(const Manager&) = delete; |
| 35 | Manager(Manager&&) = delete; |
| 36 | Manager& operator=(Manager&&) = delete; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 37 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * @param[in] bus - the D-Bus bus object |
| 42 | */ |
| 43 | explicit Manager(sdbusplus::bus::bus& bus); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 44 | |
Matt Spinler | 433bead | 2018-04-23 11:08:03 -0500 | [diff] [blame^] | 45 | /** |
| 46 | * Deletes the entry with the specified path |
| 47 | * |
| 48 | * @param[in] objectPath - the entry object path |
| 49 | */ |
| 50 | void erase(const std::string& objectPath); |
| 51 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 52 | private: |
| 53 | /** |
| 54 | * The callback for an interfaces added signal |
| 55 | * |
| 56 | * Creates the IBM interfaces for the log entry |
| 57 | * that was just created. |
| 58 | * |
| 59 | * @param[in] msg - the sdbusplus message |
| 60 | */ |
| 61 | void interfaceAdded(sdbusplus::message::message& msg); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 62 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 63 | /** |
| 64 | * The callback for an interfaces removed signal |
| 65 | * |
| 66 | * Removes the IBM interfaces for the log entry |
| 67 | * that was just removed. |
| 68 | * |
| 69 | * @param[in] msg - the sdbusplus message |
| 70 | */ |
| 71 | void interfaceRemoved(sdbusplus::message::message& msg); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 72 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 73 | /** |
| 74 | * Creates the IBM interfaces for all existing error log |
| 75 | * entries. |
| 76 | */ |
| 77 | void createAll(); |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 78 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 79 | /** |
| 80 | * Creates the IBM interface(s) for a single error log. |
| 81 | * |
| 82 | * @param[in] objectPath - object path of the error log |
| 83 | * @param[in] properties - the xyz.openbmc_project.Logging.Entry |
| 84 | * properties |
| 85 | */ |
| 86 | void create(const std::string& objectPath, |
Matt Spinler | 54bfa7e | 2018-03-27 11:28:59 -0500 | [diff] [blame] | 87 | const DbusPropertyMap& properties); |
| 88 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 89 | /** |
| 90 | * Creates the IBM policy interface for a single error log |
| 91 | * and saves it in the list of interfaces. |
| 92 | * |
| 93 | * @param[in] objectPath - object path of the error log |
| 94 | * @param[in] properties - the xyz.openbmc_project.Logging.Entry |
| 95 | * properties |
| 96 | */ |
Matt Spinler | 4a6ea6a | 2018-03-27 14:25:12 -0500 | [diff] [blame] | 97 | #ifdef USE_POLICY_INTERFACE |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 98 | void createPolicyInterface(const std::string& objectPath, |
| 99 | const DbusPropertyMap& properties); |
Matt Spinler | 4a6ea6a | 2018-03-27 14:25:12 -0500 | [diff] [blame] | 100 | #endif |
| 101 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 102 | /** |
Matt Spinler | 433bead | 2018-04-23 11:08:03 -0500 | [diff] [blame^] | 103 | * Creates the Delete interface for a single error log |
| 104 | * and saves it in the list of interfaces. |
| 105 | * |
| 106 | * @param[in] objectPath - object path of the error log |
| 107 | */ |
| 108 | void createDeleteInterface(const std::string& objectPath); |
| 109 | |
| 110 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 111 | * Returns the entry ID for a log |
| 112 | * |
| 113 | * @param[in] objectPath - the object path of the log |
| 114 | * |
| 115 | * @return uint32_t - the ID |
| 116 | */ |
| 117 | inline uint32_t getEntryID(const std::string& objectPath) |
| 118 | { |
| 119 | std::experimental::filesystem::path path(objectPath); |
| 120 | return std::stoul(path.filename()); |
| 121 | } |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 122 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 123 | /** |
Matt Spinler | 491fc6f | 2018-04-23 11:00:52 -0500 | [diff] [blame] | 124 | * Adds an interface object to the entries map |
| 125 | * |
| 126 | * @param[in] objectPath - the object path of the log |
| 127 | * @param[in] type - the interface type being added |
| 128 | * @param[in] object - the interface object |
| 129 | */ |
| 130 | void addInterface(const std::string& objectPath, InterfaceType type, |
| 131 | std::experimental::any& object); |
| 132 | |
| 133 | /** |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 134 | * The sdbusplus bus object |
| 135 | */ |
| 136 | sdbusplus::bus::bus& bus; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 137 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 138 | /** |
| 139 | * The match object for interfacesAdded |
| 140 | */ |
| 141 | sdbusplus::bus::match_t addMatch; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 142 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 143 | /** |
| 144 | * The match object for interfacesRemoved |
| 145 | */ |
| 146 | sdbusplus::bus::match_t removeMatch; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 147 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 148 | using EntryID = uint32_t; |
| 149 | using InterfaceMap = std::map<InterfaceType, std::experimental::any>; |
| 150 | using EntryMap = std::map<EntryID, InterfaceMap>; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 151 | |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 152 | /** |
| 153 | * A map of the error log IDs to their IBM interface objects. |
| 154 | * There may be multiple interfaces per ID. |
| 155 | */ |
| 156 | EntryMap entries; |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 157 | |
| 158 | #ifdef USE_POLICY_INTERFACE |
Matt Spinler | 259e727 | 2018-03-29 10:57:17 -0500 | [diff] [blame] | 159 | /** |
| 160 | * The class the wraps the IBM error logging policy table. |
| 161 | */ |
| 162 | policy::Table policies; |
Matt Spinler | 743e582 | 2018-03-27 13:44:50 -0500 | [diff] [blame] | 163 | #endif |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 164 | }; |
Matt Spinler | e0017eb | 2018-03-27 11:17:38 -0500 | [diff] [blame] | 165 | } |
| 166 | } |