George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
| 4 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
| 5 | |
| 6 | namespace open_power |
| 7 | { |
| 8 | namespace occ |
| 9 | { |
| 10 | namespace dbus |
| 11 | { |
| 12 | |
| 13 | using ObjectPath = std::string; |
| 14 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 15 | using SensorIntf = sdbusplus::server::object::object< |
| 16 | sdbusplus::xyz::openbmc_project::Sensor::server::Value>; |
| 17 | using OperationalStatusIntf = |
| 18 | sdbusplus::server::object::object<sdbusplus::xyz::openbmc_project::State:: |
| 19 | Decorator::server::OperationalStatus>; |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 20 | |
| 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 | */ |
| 25 | class OccDBusSensors |
| 26 | { |
| 27 | private: |
| 28 | OccDBusSensors() |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 29 | {} |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 30 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 48 | * @param[in] value - The value of the MaxValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 49 | * |
| 50 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 51 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 52 | bool setMaxValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 53 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 65 | * @param[in] value - The value of the MinValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 66 | * |
| 67 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 68 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 69 | bool setMinValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 70 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 82 | * @param[in] value - The value of the Value property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 83 | * |
| 84 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 85 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 86 | bool setValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 87 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 99 | * @param[in] value - The value of the Unit property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 100 | * |
| 101 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 102 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 103 | bool setUnit(const std::string& path, const std::string& value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 104 | |
| 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 Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 116 | * @param[in] value - PLDM operational fault status |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 117 | * |
| 118 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 119 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 120 | bool setOperationalStatus(const std::string& path, bool value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 121 | |
| 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 |