1 #pragma once 2 3 #include <xyz/openbmc_project/Association/Definitions/server.hpp> 4 #include <xyz/openbmc_project/Sensor/Purpose/server.hpp> 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 17 using SensorIntf = sdbusplus::server::object_t< 18 sdbusplus::xyz::openbmc_project::Sensor::server::Value>; 19 using OperationalStatusIntf = 20 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State:: 21 Decorator::server::OperationalStatus>; 22 using PurposeIntf = sdbusplus::server::object_t< 23 sdbusplus::xyz::openbmc_project::Sensor::server::Purpose>; 24 25 // Note: Not using object<> so the PropertiesVariant ctor is available. 26 using AssociationIntf = 27 sdbusplus::xyz::openbmc_project::Association::server::Definitions; 28 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: OccDBusSensors()36 OccDBusSensors() {} 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 getOccDBus()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 55 * @param[in] value - The value of the MaxValue property 56 * 57 * @return true or false 58 */ 59 bool setMaxValue(const std::string& path, double value); 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 72 * @param[in] value - The value of the MinValue property 73 * 74 * @return true or false 75 */ 76 bool setMinValue(const std::string& path, double value); 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 89 * @param[in] value - The value of the Value property 90 * 91 * @return true or false 92 */ 93 bool setValue(const std::string& path, double value); 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 106 * @param[in] value - The value of the Unit property 107 * 108 * @return true or false 109 */ 110 bool setUnit(const std::string& path, const std::string& value); 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 123 * @param[in] value - PLDM operational fault status 124 * 125 * @return true or false 126 */ 127 bool setOperationalStatus(const std::string& path, bool value); 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 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 * 145 * @param[in] path - The object path 146 * @param[in] fType - vector of forward types 147 */ 148 void setChassisAssociation(const std::string& path, 149 const std::vector<std::string>& fTypes); 150 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 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 174 private: 175 std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors; 176 std::map<ObjectPath, std::unique_ptr<PurposeIntf>> purposes; 177 178 std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>> 179 operationalStatus; 180 181 std::map<ObjectPath, std::unique_ptr<AssociationIntf>> chassisAssociations; 182 183 std::string chassisPath; 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; 191 }; 192 193 } // namespace dbus 194 } // namespace occ 195 } // namespace open_power 196