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> |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
| 5 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
| 6 | |
| 7 | namespace open_power |
| 8 | { |
| 9 | namespace occ |
| 10 | { |
| 11 | namespace dbus |
| 12 | { |
| 13 | |
| 14 | using ObjectPath = std::string; |
| 15 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 16 | using SensorIntf = sdbusplus::server::object_t< |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 17 | sdbusplus::xyz::openbmc_project::Sensor::server::Value>; |
| 18 | using OperationalStatusIntf = |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 19 | sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State:: |
| 20 | Decorator::server::OperationalStatus>; |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 21 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 22 | // Note: Not using object<> so the PropertiesVariant ctor is available. |
| 23 | using AssociationIntf = |
| 24 | sdbusplus::xyz::openbmc_project::Association::server::Definitions; |
| 25 | |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 26 | /** @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 | */ |
| 30 | class OccDBusSensors |
| 31 | { |
| 32 | private: |
| 33 | OccDBusSensors() |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 34 | {} |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 35 | |
| 36 | public: |
| 37 | OccDBusSensors(const OccDBusSensors&) = delete; |
| 38 | OccDBusSensors(OccDBusSensors&&) = delete; |
| 39 | OccDBusSensors& operator=(const OccDBusSensors&) = delete; |
| 40 | OccDBusSensors& operator=(OccDBusSensors&&) = delete; |
| 41 | ~OccDBusSensors() = default; |
| 42 | |
| 43 | static OccDBusSensors& getOccDBus() |
| 44 | { |
| 45 | static OccDBusSensors customDBus; |
| 46 | return customDBus; |
| 47 | } |
| 48 | |
| 49 | public: |
| 50 | /** @brief Set the max value of the Sensor |
| 51 | * |
| 52 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 53 | * @param[in] value - The value of the MaxValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 54 | * |
| 55 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 56 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 57 | bool setMaxValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 58 | |
| 59 | /** @brief Get the max value of the Sensor |
| 60 | * |
| 61 | * @param[in] path - The object path |
| 62 | * |
| 63 | * @return bool - The value of the MaxValue property |
| 64 | */ |
| 65 | double getMaxValue(const std::string& path) const; |
| 66 | |
| 67 | /** @brief Set the min value of the Sensor |
| 68 | * |
| 69 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 70 | * @param[in] value - The value of the MinValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 71 | * |
| 72 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 73 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 74 | bool setMinValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 75 | |
| 76 | /** @brief Get the min value of the Sensor |
| 77 | * |
| 78 | * @param[in] path - The object path |
| 79 | * |
| 80 | * @return bool - The value of the MinValue property |
| 81 | */ |
| 82 | double getMinValue(const std::string& path) const; |
| 83 | |
| 84 | /** @brief Set the value of the Sensor |
| 85 | * |
| 86 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 87 | * @param[in] value - The value of the Value property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 88 | * |
| 89 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 90 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 91 | bool setValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 92 | |
| 93 | /** @brief Get the value of the Sensor |
| 94 | * |
| 95 | * @param[in] path - The object path |
| 96 | * |
| 97 | * @return bool - The value of the Value property |
| 98 | */ |
| 99 | double getValue(const std::string& path) const; |
| 100 | |
| 101 | /** @brief Set the unit of the Sensor |
| 102 | * |
| 103 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 104 | * @param[in] value - The value of the Unit property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 105 | * |
| 106 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 107 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 108 | bool setUnit(const std::string& path, const std::string& value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 109 | |
| 110 | /** @brief Get the unit of the Sensor |
| 111 | * |
| 112 | * @param[in] path - The object path |
| 113 | * |
| 114 | * @return std::string - The value of the Unit property |
| 115 | */ |
| 116 | std::string getUnit(const std::string& path) const; |
| 117 | |
| 118 | /** @brief Set the Functional property |
| 119 | * |
| 120 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 121 | * @param[in] value - PLDM operational fault status |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 122 | * |
| 123 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 124 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 125 | bool setOperationalStatus(const std::string& path, bool value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 126 | |
| 127 | /** @brief Get the Functional property |
| 128 | * |
| 129 | * @param[in] path - The object path |
| 130 | * |
| 131 | * @return status - PLDM operational fault status |
| 132 | */ |
| 133 | bool getOperationalStatus(const std::string& path) const; |
| 134 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 135 | /** @brief Returns the Chassis inventory path |
| 136 | * |
| 137 | * @return path - The chassis D-Bus path |
| 138 | */ |
| 139 | std::string getChassisPath(); |
| 140 | |
| 141 | /** @brief Set the association to the chassis |
| 142 | * |
| 143 | * @param[in] path - The object path |
| 144 | */ |
| 145 | void setChassisAssociation(const std::string& path); |
| 146 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 147 | /** @brief Set the value of the DVFS temp sensor |
| 148 | * |
| 149 | * @param[in] path - The object path |
| 150 | * @param[in] value - The value of the Value property |
| 151 | */ |
| 152 | void setDvfsTemp(const std::string& path, double value); |
| 153 | |
| 154 | /** @brief Says if the DVFS temp sensor is already present |
| 155 | * |
| 156 | * @param[in] value - The value of the Value property |
| 157 | * @return bool - If the sensor is already present |
| 158 | */ |
| 159 | bool hasDvfsTemp(const std::string& path) const; |
| 160 | |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 161 | private: |
| 162 | std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors; |
| 163 | |
| 164 | std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>> |
| 165 | operationalStatus; |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 166 | |
| 167 | std::map<ObjectPath, std::unique_ptr<AssociationIntf>> chassisAssociations; |
| 168 | |
| 169 | std::string chassisPath; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 170 | |
| 171 | /** @brief Map of DVFS (Dynamic Voltage and Frequency Slewing) temps |
| 172 | * |
| 173 | * These do not have associations and do not get set to NaN when the OCC |
| 174 | * isn't active. |
| 175 | */ |
| 176 | std::map<std::string, std::unique_ptr<SensorIntf>> dvfsTemps; |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } // namespace dbus |
| 180 | } // namespace occ |
| 181 | } // namespace open_power |