Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/bus/match.hpp> |
| 5 | |
| 6 | namespace openpower |
| 7 | { |
| 8 | namespace pels |
| 9 | { |
| 10 | |
| 11 | using DBusValue = sdbusplus::message::variant<std::string>; |
| 12 | using DBusProperty = std::string; |
| 13 | using DBusInterface = std::string; |
| 14 | using DBusService = std::string; |
| 15 | using DBusPath = std::string; |
| 16 | using DBusInterfaceList = std::vector<DBusInterface>; |
| 17 | using DBusPropertyMap = std::map<DBusProperty, DBusValue>; |
| 18 | |
| 19 | /** |
| 20 | * @class DataInterface |
| 21 | * |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame^] | 22 | * A base class for gathering data about the system for use |
| 23 | * in PELs. Implemented this way to facilitate mocking. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 24 | */ |
| 25 | class DataInterfaceBase |
| 26 | { |
| 27 | public: |
| 28 | DataInterfaceBase() = default; |
| 29 | virtual ~DataInterfaceBase() = default; |
| 30 | DataInterfaceBase(const DataInterfaceBase&) = default; |
| 31 | DataInterfaceBase& operator=(const DataInterfaceBase&) = default; |
| 32 | DataInterfaceBase(DataInterfaceBase&&) = default; |
| 33 | DataInterfaceBase& operator=(DataInterfaceBase&&) = default; |
| 34 | |
| 35 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame^] | 36 | * @brief Returns the machine Type/Model |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 37 | * |
| 38 | * @return string - The machine Type/Model string |
| 39 | */ |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame^] | 40 | virtual std::string getMachineTypeModel() const |
| 41 | { |
| 42 | return _machineTypeModel; |
| 43 | } |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 44 | |
| 45 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame^] | 46 | * @brief Returns the machine serial number |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 47 | * |
| 48 | * @return string - The machine serial number |
| 49 | */ |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame^] | 50 | virtual std::string getMachineSerialNumber() const |
| 51 | { |
| 52 | return _machineSerialNumber; |
| 53 | } |
| 54 | |
| 55 | protected: |
| 56 | /** |
| 57 | * @brief The machine type-model. Always kept up to date |
| 58 | */ |
| 59 | std::string _machineTypeModel; |
| 60 | |
| 61 | /** |
| 62 | * @brief The machine serial number. Always kept up to date |
| 63 | */ |
| 64 | std::string _machineSerialNumber; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * @class DataInterface |
| 69 | * |
| 70 | * Concrete implementation of DataInterfaceBase. |
| 71 | */ |
| 72 | class DataInterface : public DataInterfaceBase |
| 73 | { |
| 74 | public: |
| 75 | DataInterface() = delete; |
| 76 | ~DataInterface() = default; |
| 77 | DataInterface(const DataInterface&) = default; |
| 78 | DataInterface& operator=(const DataInterface&) = default; |
| 79 | DataInterface(DataInterface&&) = default; |
| 80 | DataInterface& operator=(DataInterface&&) = default; |
| 81 | |
| 82 | /** |
| 83 | * @brief Constructor |
| 84 | * |
| 85 | * @param[in] bus - The sdbusplus bus object |
| 86 | */ |
| 87 | explicit DataInterface(sdbusplus::bus::bus& bus); |
| 88 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 89 | private: |
| 90 | /** |
| 91 | * @brief Reads the machine type/model and SN from D-Bus. |
| 92 | * |
| 93 | * Looks for them on the 'system' inventory object, and also |
| 94 | * places a properties changed watch on them to obtain any changes |
| 95 | * (or read them for the first time if the inventory isn't ready |
| 96 | * when this function runs.) |
| 97 | */ |
| 98 | void readMTMS(); |
| 99 | |
| 100 | /** |
| 101 | * @brief Finds the D-Bus service name that hosts the |
| 102 | * passed in path and interface. |
| 103 | * |
| 104 | * @param[in] objectPath - The D-Bus object path |
| 105 | * @param[in] interface - The D-Bus interface |
| 106 | */ |
| 107 | DBusService getService(const std::string& objectPath, |
| 108 | const std::string& interface); |
| 109 | /** |
| 110 | * @brief Wrapper for the 'GetAll' properties method call |
| 111 | * |
| 112 | * @param[in] service - The D-Bus service to call it on |
| 113 | * @param[in] objectPath - The D-Bus object path |
| 114 | * @param[in] interface - The interface to get the props on |
| 115 | * |
| 116 | * @return DBusPropertyMap - The property results |
| 117 | */ |
| 118 | DBusPropertyMap getAllProperties(const std::string& service, |
| 119 | const std::string& objectPath, |
| 120 | const std::string& interface); |
| 121 | |
| 122 | /** |
| 123 | * @brief The properties changed callback for the Asset iface |
| 124 | * on the system inventory object. |
| 125 | * |
| 126 | * @param[in] msg - The sdbusplus message of the signal |
| 127 | */ |
| 128 | void sysAssetPropChanged(sdbusplus::message::message& msg); |
| 129 | |
| 130 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 131 | * @brief The match object for the system path's properties |
| 132 | */ |
| 133 | std::unique_ptr<sdbusplus::bus::match_t> _sysInventoryPropMatch; |
| 134 | |
| 135 | /** |
| 136 | * @brief The sdbusplus bus object for making D-Bus calls. |
| 137 | */ |
| 138 | sdbusplus::bus::bus& _bus; |
| 139 | }; |
| 140 | |
| 141 | } // namespace pels |
| 142 | } // namespace openpower |