blob: 14acd702d174410c33c1d7969a4d7460d07dc3a9 [file] [log] [blame]
Matt Spinlerc8705e22019-09-11 12:36:07 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/bus/match.hpp>
5
6namespace openpower
7{
8namespace pels
9{
10
11using DBusValue = sdbusplus::message::variant<std::string>;
12using DBusProperty = std::string;
13using DBusInterface = std::string;
14using DBusService = std::string;
15using DBusPath = std::string;
16using DBusInterfaceList = std::vector<DBusInterface>;
17using DBusPropertyMap = std::map<DBusProperty, DBusValue>;
18
19/**
20 * @class DataInterface
21 *
Matt Spinler19e89ce2019-11-06 13:02:23 -060022 * A base class for gathering data about the system for use
23 * in PELs. Implemented this way to facilitate mocking.
Matt Spinlerc8705e22019-09-11 12:36:07 -050024 */
25class 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 Spinler19e89ce2019-11-06 13:02:23 -060036 * @brief Returns the machine Type/Model
Matt Spinlerc8705e22019-09-11 12:36:07 -050037 *
38 * @return string - The machine Type/Model string
39 */
Matt Spinler19e89ce2019-11-06 13:02:23 -060040 virtual std::string getMachineTypeModel() const
41 {
42 return _machineTypeModel;
43 }
Matt Spinlerc8705e22019-09-11 12:36:07 -050044
45 /**
Matt Spinler19e89ce2019-11-06 13:02:23 -060046 * @brief Returns the machine serial number
Matt Spinlerc8705e22019-09-11 12:36:07 -050047 *
48 * @return string - The machine serial number
49 */
Matt Spinler19e89ce2019-11-06 13:02:23 -060050 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 Spinlerc8705e22019-09-11 12:36:07 -050065};
66
67/**
68 * @class DataInterface
69 *
70 * Concrete implementation of DataInterfaceBase.
71 */
72class 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 Spinlerc8705e22019-09-11 12:36:07 -050089 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 Spinlerc8705e22019-09-11 12:36:07 -0500131 * @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