George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 3 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Chris Cain | ff0ce40 | 2025-01-17 10:54:55 -0600 | [diff] [blame^] | 4 | #include <xyz/openbmc_project/Sensor/Purpose/server.hpp> |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
| 6 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
| 7 | |
| 8 | namespace open_power |
| 9 | { |
| 10 | namespace occ |
| 11 | { |
| 12 | namespace dbus |
| 13 | { |
| 14 | |
| 15 | using ObjectPath = std::string; |
| 16 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 17 | using SensorIntf = sdbusplus::server::object_t< |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 18 | sdbusplus::xyz::openbmc_project::Sensor::server::Value>; |
| 19 | using OperationalStatusIntf = |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 20 | sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State:: |
| 21 | Decorator::server::OperationalStatus>; |
Chris Cain | ff0ce40 | 2025-01-17 10:54:55 -0600 | [diff] [blame^] | 22 | using PurposeIntf = sdbusplus::server::object_t< |
| 23 | sdbusplus::xyz::openbmc_project::Sensor::server::Purpose>; |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 24 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 25 | // Note: Not using object<> so the PropertiesVariant ctor is available. |
| 26 | using AssociationIntf = |
| 27 | sdbusplus::xyz::openbmc_project::Association::server::Definitions; |
| 28 | |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 29 | /** @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 | */ |
| 33 | class OccDBusSensors |
| 34 | { |
| 35 | private: |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 36 | OccDBusSensors() {} |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 37 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 55 | * @param[in] value - The value of the MaxValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 56 | * |
| 57 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 58 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 59 | bool setMaxValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 60 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 72 | * @param[in] value - The value of the MinValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 73 | * |
| 74 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 75 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 76 | bool setMinValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 77 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 89 | * @param[in] value - The value of the Value property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 90 | * |
| 91 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 92 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 93 | bool setValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 94 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 106 | * @param[in] value - The value of the Unit property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 107 | * |
| 108 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 109 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 110 | bool setUnit(const std::string& path, const std::string& value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 111 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 123 | * @param[in] value - PLDM operational fault status |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 124 | * |
| 125 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 126 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 127 | bool setOperationalStatus(const std::string& path, bool value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 128 | |
| 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 Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 137 | /** @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 Cain | 3523cc0 | 2024-10-30 17:19:09 -0500 | [diff] [blame] | 145 | * @param[in] path - The object path |
| 146 | * @param[in] fType - vector of forward types |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 147 | */ |
Chris Cain | 3523cc0 | 2024-10-30 17:19:09 -0500 | [diff] [blame] | 148 | void setChassisAssociation(const std::string& path, |
| 149 | const std::vector<std::string>& fTypes); |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 150 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 151 | /** @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 Cain | ff0ce40 | 2025-01-17 10:54:55 -0600 | [diff] [blame^] | 165 | /** @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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 174 | private: |
| 175 | std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors; |
Chris Cain | ff0ce40 | 2025-01-17 10:54:55 -0600 | [diff] [blame^] | 176 | std::map<ObjectPath, std::unique_ptr<PurposeIntf>> purposes; |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 177 | |
| 178 | std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>> |
| 179 | operationalStatus; |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 180 | |
| 181 | std::map<ObjectPath, std::unique_ptr<AssociationIntf>> chassisAssociations; |
| 182 | |
| 183 | std::string chassisPath; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 184 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | } // namespace dbus |
| 194 | } // namespace occ |
| 195 | } // namespace open_power |