blob: d042ea8648bdc9c91e4829cf87c79f3b08b71ef5 [file] [log] [blame]
George Liu6f777cd2021-06-10 09:16:28 +08001#pragma once
2
3#include <xyz/openbmc_project/Sensor/Value/server.hpp>
4#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
5
6namespace open_power
7{
8namespace occ
9{
10namespace dbus
11{
12
13using ObjectPath = std::string;
14
Chicago Duanbb895cb2021-06-18 19:37:16 +080015using SensorIntf = sdbusplus::server::object::object<
16 sdbusplus::xyz::openbmc_project::Sensor::server::Value>;
17using OperationalStatusIntf =
18 sdbusplus::server::object::object<sdbusplus::xyz::openbmc_project::State::
19 Decorator::server::OperationalStatus>;
George Liu6f777cd2021-06-10 09:16:28 +080020
21/** @class OccDBusSensors
22 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
23 * the corresponding properties value.
24 */
25class OccDBusSensors
26{
27 private:
28 OccDBusSensors()
George Liub5ca1012021-09-10 12:53:11 +080029 {}
George Liu6f777cd2021-06-10 09:16:28 +080030
31 public:
32 OccDBusSensors(const OccDBusSensors&) = delete;
33 OccDBusSensors(OccDBusSensors&&) = delete;
34 OccDBusSensors& operator=(const OccDBusSensors&) = delete;
35 OccDBusSensors& operator=(OccDBusSensors&&) = delete;
36 ~OccDBusSensors() = default;
37
38 static OccDBusSensors& getOccDBus()
39 {
40 static OccDBusSensors customDBus;
41 return customDBus;
42 }
43
44 public:
45 /** @brief Set the max value of the Sensor
46 *
47 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080048 * @param[in] value - The value of the MaxValue property
George Liu0ad9dd82021-06-22 14:46:14 +080049 *
50 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080051 */
George Liu0ad9dd82021-06-22 14:46:14 +080052 bool setMaxValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080053
54 /** @brief Get the max value of the Sensor
55 *
56 * @param[in] path - The object path
57 *
58 * @return bool - The value of the MaxValue property
59 */
60 double getMaxValue(const std::string& path) const;
61
62 /** @brief Set the min value of the Sensor
63 *
64 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080065 * @param[in] value - The value of the MinValue property
George Liu0ad9dd82021-06-22 14:46:14 +080066 *
67 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080068 */
George Liu0ad9dd82021-06-22 14:46:14 +080069 bool setMinValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080070
71 /** @brief Get the min value of the Sensor
72 *
73 * @param[in] path - The object path
74 *
75 * @return bool - The value of the MinValue property
76 */
77 double getMinValue(const std::string& path) const;
78
79 /** @brief Set the value of the Sensor
80 *
81 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080082 * @param[in] value - The value of the Value property
George Liu0ad9dd82021-06-22 14:46:14 +080083 *
84 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +080085 */
George Liu0ad9dd82021-06-22 14:46:14 +080086 bool setValue(const std::string& path, double value);
George Liu6f777cd2021-06-10 09:16:28 +080087
88 /** @brief Get the value of the Sensor
89 *
90 * @param[in] path - The object path
91 *
92 * @return bool - The value of the Value property
93 */
94 double getValue(const std::string& path) const;
95
96 /** @brief Set the unit of the Sensor
97 *
98 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +080099 * @param[in] value - The value of the Unit property
George Liu0ad9dd82021-06-22 14:46:14 +0800100 *
101 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +0800102 */
George Liu0ad9dd82021-06-22 14:46:14 +0800103 bool setUnit(const std::string& path, const std::string& value);
George Liu6f777cd2021-06-10 09:16:28 +0800104
105 /** @brief Get the unit of the Sensor
106 *
107 * @param[in] path - The object path
108 *
109 * @return std::string - The value of the Unit property
110 */
111 std::string getUnit(const std::string& path) const;
112
113 /** @brief Set the Functional property
114 *
115 * @param[in] path - The object path
George Liu6f777cd2021-06-10 09:16:28 +0800116 * @param[in] value - PLDM operational fault status
George Liu0ad9dd82021-06-22 14:46:14 +0800117 *
118 * @return true or false
George Liu6f777cd2021-06-10 09:16:28 +0800119 */
George Liu0ad9dd82021-06-22 14:46:14 +0800120 bool setOperationalStatus(const std::string& path, bool value);
George Liu6f777cd2021-06-10 09:16:28 +0800121
122 /** @brief Get the Functional property
123 *
124 * @param[in] path - The object path
125 *
126 * @return status - PLDM operational fault status
127 */
128 bool getOperationalStatus(const std::string& path) const;
129
130 private:
131 std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors;
132
133 std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>>
134 operationalStatus;
135};
136
137} // namespace dbus
138} // namespace occ
139} // namespace open_power