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() |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | public: |
| 33 | OccDBusSensors(const OccDBusSensors&) = delete; |
| 34 | OccDBusSensors(OccDBusSensors&&) = delete; |
| 35 | OccDBusSensors& operator=(const OccDBusSensors&) = delete; |
| 36 | OccDBusSensors& operator=(OccDBusSensors&&) = delete; |
| 37 | ~OccDBusSensors() = default; |
| 38 | |
| 39 | static OccDBusSensors& getOccDBus() |
| 40 | { |
| 41 | static OccDBusSensors customDBus; |
| 42 | return customDBus; |
| 43 | } |
| 44 | |
| 45 | public: |
| 46 | /** @brief Set the max value of the Sensor |
| 47 | * |
| 48 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 49 | * @param[in] value - The value of the MaxValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 50 | * |
| 51 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 52 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 53 | bool setMaxValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 54 | |
| 55 | /** @brief Get the max value of the Sensor |
| 56 | * |
| 57 | * @param[in] path - The object path |
| 58 | * |
| 59 | * @return bool - The value of the MaxValue property |
| 60 | */ |
| 61 | double getMaxValue(const std::string& path) const; |
| 62 | |
| 63 | /** @brief Set the min value of the Sensor |
| 64 | * |
| 65 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 66 | * @param[in] value - The value of the MinValue property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 67 | * |
| 68 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 69 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 70 | bool setMinValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 71 | |
| 72 | /** @brief Get the min value of the Sensor |
| 73 | * |
| 74 | * @param[in] path - The object path |
| 75 | * |
| 76 | * @return bool - The value of the MinValue property |
| 77 | */ |
| 78 | double getMinValue(const std::string& path) const; |
| 79 | |
| 80 | /** @brief Set the value of the Sensor |
| 81 | * |
| 82 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 83 | * @param[in] value - The value of the Value property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 84 | * |
| 85 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 86 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 87 | bool setValue(const std::string& path, double value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 88 | |
| 89 | /** @brief Get the value of the Sensor |
| 90 | * |
| 91 | * @param[in] path - The object path |
| 92 | * |
| 93 | * @return bool - The value of the Value property |
| 94 | */ |
| 95 | double getValue(const std::string& path) const; |
| 96 | |
| 97 | /** @brief Set the unit of the Sensor |
| 98 | * |
| 99 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 100 | * @param[in] value - The value of the Unit property |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 101 | * |
| 102 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 103 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 104 | bool setUnit(const std::string& path, const std::string& value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 105 | |
| 106 | /** @brief Get the unit of the Sensor |
| 107 | * |
| 108 | * @param[in] path - The object path |
| 109 | * |
| 110 | * @return std::string - The value of the Unit property |
| 111 | */ |
| 112 | std::string getUnit(const std::string& path) const; |
| 113 | |
| 114 | /** @brief Set the Functional property |
| 115 | * |
| 116 | * @param[in] path - The object path |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 117 | * @param[in] value - PLDM operational fault status |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 118 | * |
| 119 | * @return true or false |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 120 | */ |
George Liu | 0ad9dd8 | 2021-06-22 14:46:14 +0800 | [diff] [blame] | 121 | bool setOperationalStatus(const std::string& path, bool value); |
George Liu | 6f777cd | 2021-06-10 09:16:28 +0800 | [diff] [blame] | 122 | |
| 123 | /** @brief Get the Functional property |
| 124 | * |
| 125 | * @param[in] path - The object path |
| 126 | * |
| 127 | * @return status - PLDM operational fault status |
| 128 | */ |
| 129 | bool getOperationalStatus(const std::string& path) const; |
| 130 | |
| 131 | private: |
| 132 | std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors; |
| 133 | |
| 134 | std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>> |
| 135 | operationalStatus; |
| 136 | }; |
| 137 | |
| 138 | } // namespace dbus |
| 139 | } // namespace occ |
| 140 | } // namespace open_power |