blob: f20ffc3bc60d71a1feb95d12f1d74035fc147751 [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>
George Liu6f777cd2021-06-10 09:16:28 +08004#include <xyz/openbmc_project/Sensor/Value/server.hpp>
5#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
6
7namespace open_power
8{
9namespace occ
10{
11namespace dbus
12{
13
14using ObjectPath = std::string;
15
Patrick Williamsaf408082022-07-22 19:26:54 -050016using SensorIntf = sdbusplus::server::object_t<
Chicago Duanbb895cb2021-06-18 19:37:16 +080017 sdbusplus::xyz::openbmc_project::Sensor::server::Value>;
18using OperationalStatusIntf =
Patrick Williamsaf408082022-07-22 19:26:54 -050019 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
20 Decorator::server::OperationalStatus>;
George Liu6f777cd2021-06-10 09:16:28 +080021
Matt Spinler5901abd2021-09-23 13:50:03 -050022// Note: Not using object<> so the PropertiesVariant ctor is available.
23using AssociationIntf =
24 sdbusplus::xyz::openbmc_project::Association::server::Definitions;
25
George Liu6f777cd2021-06-10 09:16:28 +080026/** @class OccDBusSensors
27 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
28 * the corresponding properties value.
29 */
30class OccDBusSensors
31{
32 private:
Patrick Williamsa49c9872023-05-10 07:50:35 -050033 OccDBusSensors() {}
George Liu6f777cd2021-06-10 09:16:28 +080034
35 public:
36 OccDBusSensors(const OccDBusSensors&) = delete;
37 OccDBusSensors(OccDBusSensors&&) = delete;
38 OccDBusSensors& operator=(const OccDBusSensors&) = delete;
39 OccDBusSensors& operator=(OccDBusSensors&&) = delete;
40 ~OccDBusSensors() = default;
41
42 static OccDBusSensors& getOccDBus()
43 {
44 static OccDBusSensors customDBus;
45 return customDBus;
46 }
47
48 public:
49 /** @brief Set the max value of the Sensor
50 *
51 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080052 * @param[in] value - The value of the MaxValue property
George Liu0ad9dd82021-06-22 14:46:14 +080053 *
54 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080055 */
George Liu0ad9dd82021-06-22 14:46:14 +080056 bool setMaxValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080057
58 /** @brief Get the max value of the Sensor
59 *
60 * @param[in] path - The object path
61 *
62 * @return bool - The value of the MaxValue property
63 */
64 double getMaxValue(const std::string& path) const;
65
66 /** @brief Set the min value of the Sensor
67 *
68 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080069 * @param[in] value - The value of the MinValue property
George Liu0ad9dd82021-06-22 14:46:14 +080070 *
71 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080072 */
George Liu0ad9dd82021-06-22 14:46:14 +080073 bool setMinValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080074
75 /** @brief Get the min value of the Sensor
76 *
77 * @param[in] path - The object path
78 *
79 * @return bool - The value of the MinValue property
80 */
81 double getMinValue(const std::string& path) const;
82
83 /** @brief Set the value of the Sensor
84 *
85 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080086 * @param[in] value - The value of the Value property
George Liu0ad9dd82021-06-22 14:46:14 +080087 *
88 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080089 */
George Liu0ad9dd82021-06-22 14:46:14 +080090 bool setValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080091
92 /** @brief Get the value of the Sensor
93 *
94 * @param[in] path - The object path
95 *
96 * @return bool - The value of the Value property
97 */
98 double getValue(const std::string& path) const;
99
100 /** @brief Set the unit of the Sensor
101 *
102 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +0800103 * @param[in] value - The value of the Unit property
George Liu0ad9dd82021-06-22 14:46:14 +0800104 *
105 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +0800106 */
George Liu0ad9dd82021-06-22 14:46:14 +0800107 bool setUnit(const std::string& path, const std::string& value);
George Liu6f777cd2021-06-10 09:16:28 +0800108
109 /** @brief Get the unit of the Sensor
110 *
111 * @param[in] path - The object path
112 *
113 * @return std::string - The value of the Unit property
114 */
115 std::string getUnit(const std::string& path) const;
116
117 /** @brief Set the Functional property
118 *
119 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +0800120 * @param[in] value - PLDM operational fault status
George Liu0ad9dd82021-06-22 14:46:14 +0800121 *
122 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +0800123 */
George Liu0ad9dd82021-06-22 14:46:14 +0800124 bool setOperationalStatus(const std::string& path, bool value);
George Liu6f777cd2021-06-10 09:16:28 +0800125
126 /** @brief Get the Functional property
127 *
128 * @param[in] path - The object path
129 *
130 * @return status - PLDM operational fault status
131 */
132 bool getOperationalStatus(const std::string& path) const;
133
Matt Spinler5901abd2021-09-23 13:50:03 -0500134 /** @brief Returns the Chassis inventory path
135 *
136 * @return path - The chassis D-Bus path
137 */
138 std::string getChassisPath();
139
140 /** @brief Set the association to the chassis
141 *
142 * @param[in] path - The object path
143 */
144 void setChassisAssociation(const std::string& path);
145
Matt Spinlerace67d82021-10-18 13:41:57 -0500146 /** @brief Set the value of the DVFS temp sensor
147 *
148 * @param[in] path - The object path
149 * @param[in] value - The value of the Value property
150 */
151 void setDvfsTemp(const std::string& path, double value);
152
153 /** @brief Says if the DVFS temp sensor is already present
154 *
155 * @param[in] value - The value of the Value property
156 * @return bool - If the sensor is already present
157 */
158 bool hasDvfsTemp(const std::string& path) const;
159
George Liu6f777cd2021-06-10 09:16:28 +0800160 private:
161 std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors;
162
163 std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>>
164 operationalStatus;
Matt Spinler5901abd2021-09-23 13:50:03 -0500165
166 std::map<ObjectPath, std::unique_ptr<AssociationIntf>> chassisAssociations;
167
168 std::string chassisPath;
Matt Spinlerace67d82021-10-18 13:41:57 -0500169
170 /** @brief Map of DVFS (Dynamic Voltage and Frequency Slewing) temps
171 *
172 * These do not have associations and do not get set to NaN when the OCC
173 * isn't active.
174 */
175 std::map<std::string, std::unique_ptr<SensorIntf>> dvfsTemps;
George Liu6f777cd2021-06-10 09:16:28 +0800176};
177
178} // namespace dbus
179} // namespace occ
180} // namespace open_power