blob: 1446a4504dee71623d2799972d02f9b84b0ef109 [file] [log] [blame]
George Liu6f777cd2021-06-10 09:16:28 +08001#pragma once
2
Matt Spinler5901abd2021-09-23 13:50:03 -05003#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Chris Cainff0ce402025-01-17 10:54:55 -06004#include <xyz/openbmc_project/Sensor/Purpose/server.hpp>
George Liu6f777cd2021-06-10 09:16:28 +08005#include <xyz/openbmc_project/Sensor/Value/server.hpp>
6#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
7
8namespace open_power
9{
10namespace occ
11{
12namespace dbus
13{
14
15using ObjectPath = std::string;
16
Patrick Williamsaf408082022-07-22 19:26:54 -050017using SensorIntf = sdbusplus::server::object_t<
Chicago Duanbb895cb2021-06-18 19:37:16 +080018 sdbusplus::xyz::openbmc_project::Sensor::server::Value>;
19using OperationalStatusIntf =
Patrick Williamsaf408082022-07-22 19:26:54 -050020 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
21 Decorator::server::OperationalStatus>;
Chris Cainff0ce402025-01-17 10:54:55 -060022using PurposeIntf = sdbusplus::server::object_t<
23 sdbusplus::xyz::openbmc_project::Sensor::server::Purpose>;
George Liu6f777cd2021-06-10 09:16:28 +080024
Matt Spinler5901abd2021-09-23 13:50:03 -050025// Note: Not using object<> so the PropertiesVariant ctor is available.
26using AssociationIntf =
27 sdbusplus::xyz::openbmc_project::Association::server::Definitions;
28
George Liu6f777cd2021-06-10 09:16:28 +080029/** @class OccDBusSensors
30 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
31 * the corresponding properties value.
32 */
33class OccDBusSensors
34{
35 private:
Patrick Williamsa49c9872023-05-10 07:50:35 -050036 OccDBusSensors() {}
George Liu6f777cd2021-06-10 09:16:28 +080037
38 public:
39 OccDBusSensors(const OccDBusSensors&) = delete;
40 OccDBusSensors(OccDBusSensors&&) = delete;
41 OccDBusSensors& operator=(const OccDBusSensors&) = delete;
42 OccDBusSensors& operator=(OccDBusSensors&&) = delete;
43 ~OccDBusSensors() = default;
44
45 static OccDBusSensors& getOccDBus()
46 {
47 static OccDBusSensors customDBus;
48 return customDBus;
49 }
50
51 public:
52 /** @brief Set the max value of the Sensor
53 *
54 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080055 * @param[in] value - The value of the MaxValue property
George Liu0ad9dd82021-06-22 14:46:14 +080056 *
57 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080058 */
George Liu0ad9dd82021-06-22 14:46:14 +080059 bool setMaxValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080060
61 /** @brief Get the max value of the Sensor
62 *
63 * @param[in] path - The object path
64 *
65 * @return bool - The value of the MaxValue property
66 */
67 double getMaxValue(const std::string& path) const;
68
69 /** @brief Set the min value of the Sensor
70 *
71 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080072 * @param[in] value - The value of the MinValue property
George Liu0ad9dd82021-06-22 14:46:14 +080073 *
74 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080075 */
George Liu0ad9dd82021-06-22 14:46:14 +080076 bool setMinValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080077
78 /** @brief Get the min value of the Sensor
79 *
80 * @param[in] path - The object path
81 *
82 * @return bool - The value of the MinValue property
83 */
84 double getMinValue(const std::string& path) const;
85
86 /** @brief Set the value of the Sensor
87 *
88 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080089 * @param[in] value - The value of the Value property
George Liu0ad9dd82021-06-22 14:46:14 +080090 *
91 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080092 */
George Liu0ad9dd82021-06-22 14:46:14 +080093 bool setValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080094
95 /** @brief Get the value of the Sensor
96 *
97 * @param[in] path - The object path
98 *
99 * @return bool - The value of the Value property
100 */
101 double getValue(const std::string& path) const;
102
103 /** @brief Set the unit of the Sensor
104 *
105 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +0800106 * @param[in] value - The value of the Unit property
George Liu0ad9dd82021-06-22 14:46:14 +0800107 *
108 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +0800109 */
George Liu0ad9dd82021-06-22 14:46:14 +0800110 bool setUnit(const std::string& path, const std::string& value);
George Liu6f777cd2021-06-10 09:16:28 +0800111
112 /** @brief Get the unit of the Sensor
113 *
114 * @param[in] path - The object path
115 *
116 * @return std::string - The value of the Unit property
117 */
118 std::string getUnit(const std::string& path) const;
119
120 /** @brief Set the Functional property
121 *
122 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +0800123 * @param[in] value - PLDM operational fault status
George Liu0ad9dd82021-06-22 14:46:14 +0800124 *
125 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +0800126 */
George Liu0ad9dd82021-06-22 14:46:14 +0800127 bool setOperationalStatus(const std::string& path, bool value);
George Liu6f777cd2021-06-10 09:16:28 +0800128
129 /** @brief Get the Functional property
130 *
131 * @param[in] path - The object path
132 *
133 * @return status - PLDM operational fault status
134 */
135 bool getOperationalStatus(const std::string& path) const;
136
Matt Spinler5901abd2021-09-23 13:50:03 -0500137 /** @brief Returns the Chassis inventory path
138 *
139 * @return path - The chassis D-Bus path
140 */
141 std::string getChassisPath();
142
143 /** @brief Set the association to the chassis
144 *
Chris Cain3523cc02024-10-30 17:19:09 -0500145 * @param[in] path - The object path
146 * @param[in] fType - vector of forward types
Matt Spinler5901abd2021-09-23 13:50:03 -0500147 */
Chris Cain3523cc02024-10-30 17:19:09 -0500148 void setChassisAssociation(const std::string& path,
149 const std::vector<std::string>& fTypes);
Matt Spinler5901abd2021-09-23 13:50:03 -0500150
Matt Spinlerace67d82021-10-18 13:41:57 -0500151 /** @brief Set the value of the DVFS temp sensor
152 *
153 * @param[in] path - The object path
154 * @param[in] value - The value of the Value property
155 */
156 void setDvfsTemp(const std::string& path, double value);
157
158 /** @brief Says if the DVFS temp sensor is already present
159 *
160 * @param[in] value - The value of the Value property
161 * @return bool - If the sensor is already present
162 */
163 bool hasDvfsTemp(const std::string& path) const;
164
Chris Cainff0ce402025-01-17 10:54:55 -0600165 /** @brief Set the purpose of the Sensor
166 *
167 * @param[in] path - The object path
168 * @param[in] value - The value of the Purpose property
169 *
170 * @return true or false
171 */
172 bool setPurpose(const std::string& path, const std::string& value);
173
George Liu6f777cd2021-06-10 09:16:28 +0800174 private:
175 std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors;
Chris Cainff0ce402025-01-17 10:54:55 -0600176 std::map<ObjectPath, std::unique_ptr<PurposeIntf>> purposes;
George Liu6f777cd2021-06-10 09:16:28 +0800177
178 std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>>
179 operationalStatus;
Matt Spinler5901abd2021-09-23 13:50:03 -0500180
181 std::map<ObjectPath, std::unique_ptr<AssociationIntf>> chassisAssociations;
182
183 std::string chassisPath;
Matt Spinlerace67d82021-10-18 13:41:57 -0500184
185 /** @brief Map of DVFS (Dynamic Voltage and Frequency Slewing) temps
186 *
187 * These do not have associations and do not get set to NaN when the OCC
188 * isn't active.
189 */
190 std::map<std::string, std::unique_ptr<SensorIntf>> dvfsTemps;
George Liu6f777cd2021-06-10 09:16:28 +0800191};
192
193} // namespace dbus
194} // namespace occ
195} // namespace open_power