Add occ-dbus object
- The intent behind this commit is to add APIs for dynamically
createing D-Bus objects.
- When temperature values such as DIMM or Core are monitored, D-Bus
objects need to be dynamically created and the corresponding
attribute values updated. If the object path exists, only the
attribute value needs to be updated.
- Currently supports Sensor and OperationalStatus interfaces.
- Also, added Unit Test to occ_dbus file.
Tested: built openpower-occ-control successfully and UTest pass.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I1eac918d6a7a04d6b72b4e68fff868b04dde9c28
diff --git a/occ_dbus.hpp b/occ_dbus.hpp
new file mode 100644
index 0000000..2443a53
--- /dev/null
+++ b/occ_dbus.hpp
@@ -0,0 +1,133 @@
+#pragma once
+
+#include <xyz/openbmc_project/Sensor/Value/server.hpp>
+#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
+
+namespace open_power
+{
+namespace occ
+{
+namespace dbus
+{
+
+using ObjectPath = std::string;
+
+using SensorIntf = sdbusplus::xyz::openbmc_project::Sensor::server::Value;
+using OperationalStatusIntf = sdbusplus::xyz::openbmc_project::State::
+ Decorator::server::OperationalStatus;
+
+/** @class OccDBusSensors
+ * @brief This is a custom D-Bus object, used to add D-Bus interface and update
+ * the corresponding properties value.
+ */
+class OccDBusSensors
+{
+ private:
+ OccDBusSensors()
+ {
+ }
+
+ public:
+ OccDBusSensors(const OccDBusSensors&) = delete;
+ OccDBusSensors(OccDBusSensors&&) = delete;
+ OccDBusSensors& operator=(const OccDBusSensors&) = delete;
+ OccDBusSensors& operator=(OccDBusSensors&&) = delete;
+ ~OccDBusSensors() = default;
+
+ static OccDBusSensors& getOccDBus()
+ {
+ static OccDBusSensors customDBus;
+ return customDBus;
+ }
+
+ public:
+ /** @brief Set the max value of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - The value of the MaxValue property
+ */
+ void setMaxValue(const std::string& path, double value);
+
+ /** @brief Get the max value of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @return bool - The value of the MaxValue property
+ */
+ double getMaxValue(const std::string& path) const;
+
+ /** @brief Set the min value of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - The value of the MinValue property
+ */
+ void setMinValue(const std::string& path, double value);
+
+ /** @brief Get the min value of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @return bool - The value of the MinValue property
+ */
+ double getMinValue(const std::string& path) const;
+
+ /** @brief Set the value of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - The value of the Value property
+ */
+ void setValue(const std::string& path, double value);
+
+ /** @brief Get the value of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @return bool - The value of the Value property
+ */
+ double getValue(const std::string& path) const;
+
+ /** @brief Set the unit of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - The value of the Unit property
+ */
+ void setUnit(const std::string& path, const std::string& value);
+
+ /** @brief Get the unit of the Sensor
+ *
+ * @param[in] path - The object path
+ *
+ * @return std::string - The value of the Unit property
+ */
+ std::string getUnit(const std::string& path) const;
+
+ /** @brief Set the Functional property
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - PLDM operational fault status
+ */
+ void setOperationalStatus(const std::string& path, bool value);
+
+ /** @brief Get the Functional property
+ *
+ * @param[in] path - The object path
+ *
+ * @return status - PLDM operational fault status
+ */
+ bool getOperationalStatus(const std::string& path) const;
+
+ private:
+ std::map<ObjectPath, std::unique_ptr<SensorIntf>> sensors;
+
+ std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>>
+ operationalStatus;
+};
+
+} // namespace dbus
+} // namespace occ
+} // namespace open_power