Sensor.Value: use PDI constants
Use PDI constants instead of local definitions.
Tested: Unit Tests Pass
Change-Id: I6b513155afa760da52dc7421eedcfe78ff3a816d
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index 546dff0..8ba2a1b 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -33,6 +33,7 @@
#include <sdbusplus/message.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <xyz/openbmc_project/ObjectMapper/common.hpp>
+#include <xyz/openbmc_project/Sensor/Value/client.hpp>
#include <algorithm>
#include <array>
@@ -52,6 +53,7 @@
#include <vector>
using ObjectMapper = sdbusplus::common::xyz::openbmc_project::ObjectMapper;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
namespace pid_control
{
@@ -66,7 +68,6 @@
"xyz.openbmc_project.Configuration.Stepwise";
constexpr const char* thermalControlIface =
"xyz.openbmc_project.Control.ThermalMode";
-constexpr const char* sensorInterface = "xyz.openbmc_project.Sensor.Value";
constexpr const char* defaultPwmInterface =
"xyz.openbmc_project.Control.FanPwm";
@@ -458,7 +459,7 @@
std::array<const char*, 6>{
objectManagerInterface, pidConfigurationInterface,
pidZoneConfigurationInterface, stepwiseConfigurationInterface,
- sensorInterface, defaultPwmInterface});
+ SensorValue::interface, defaultPwmInterface});
std::unordered_map<
std::string, std::unordered_map<std::string, std::vector<std::string>>>
respData;
@@ -499,11 +500,11 @@
{
owner.first = true;
}
- if (interface == sensorInterface ||
+ if (interface == SensorValue::interface ||
interface == defaultPwmInterface)
{
// we're not interested in pwm sensors, just pwm control
- if (interface == sensorInterface &&
+ if (interface == SensorValue::interface &&
objectPair.first.find("pwm") != std::string::npos)
{
continue;
@@ -836,14 +837,15 @@
config.unavailableAsFailed = unavailableAsFailed;
}
- if (dbusInterface != sensorInterface)
+ if (dbusInterface != SensorValue::interface)
{
/* all expected inputs in the configuration are expected
* to be sensor interfaces
*/
throw std::runtime_error(std::format(
"sensor at dbus path [{}] has an interface [{}] that does not match the expected interface of {}",
- inputSensorPath, dbusInterface, sensorInterface));
+ inputSensorPath, dbusInterface,
+ SensorValue::interface));
}
}
@@ -863,14 +865,14 @@
missingAcceptableSensorNames.push_back(
missingAcceptableSensorName);
- if (dbusInterface != sensorInterface)
+ if (dbusInterface != SensorValue::interface)
{
/* MissingIsAcceptable same error checking as Inputs
*/
throw std::runtime_error(std::format(
"sensor at dbus path [{}] has an interface [{}] that does not match the expected interface of {}",
missingAcceptableSensorPath, dbusInterface,
- sensorInterface));
+ SensorValue::interface));
}
}
diff --git a/dbus/dbushelper.cpp b/dbus/dbushelper.cpp
index 7e604b8..4a692cb 100644
--- a/dbus/dbushelper.cpp
+++ b/dbus/dbushelper.cpp
@@ -12,6 +12,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/ObjectMapper/common.hpp>
+#include <xyz/openbmc_project/Sensor/Value/client.hpp>
#include <cstdint>
#include <map>
@@ -21,6 +22,7 @@
#include <vector>
using ObjectMapper = sdbusplus::common::xyz::openbmc_project::ObjectMapper;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
namespace pid_control
{
@@ -73,7 +75,7 @@
auto pimMsg = _bus.new_method_call(service.c_str(), path.c_str(),
propertiesintf, "GetAll");
- pimMsg.append(sensorintf);
+ pimMsg.append(SensorValue::interface);
PropertyMap propMap;
@@ -97,14 +99,16 @@
// "Scale" x -3
// If no error was set, the values should all be there.
- auto findUnit = propMap.find("Unit");
+ auto findUnit = propMap.find(SensorValue::property_names::unit);
if (findUnit != propMap.end())
{
prop->unit = std::get<std::string>(findUnit->second);
}
+ // TODO: in PDI there is no such 'Scale' property on the Sensor.Value
+ // interface
auto findScale = propMap.find("Scale");
- auto findMax = propMap.find("MaxValue");
- auto findMin = propMap.find("MinValue");
+ auto findMax = propMap.find(SensorValue::property_names::max_value);
+ auto findMin = propMap.find(SensorValue::property_names::min_value);
prop->min = 0;
prop->max = 0;
@@ -122,7 +126,8 @@
prop->min = std::visit(VariantToDoubleVisitor(), findMin->second);
}
- prop->value = std::visit(VariantToDoubleVisitor(), propMap["Value"]);
+ prop->value = std::visit(VariantToDoubleVisitor(),
+ propMap[SensorValue::property_names::value]);
bool available = true;
try
diff --git a/dbus/dbushelper.hpp b/dbus/dbushelper.hpp
index 59ccef2..43a9d3a 100644
--- a/dbus/dbushelper.hpp
+++ b/dbus/dbushelper.hpp
@@ -15,7 +15,6 @@
class DbusHelper : public DbusHelperInterface
{
public:
- static constexpr char sensorintf[] = "xyz.openbmc_project.Sensor.Value";
static constexpr char propertiesintf[] = "org.freedesktop.DBus.Properties";
static constexpr char criticalThreshInf[] =
"xyz.openbmc_project.Sensor.Threshold.Critical";
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index 3cbc677..3e56b52 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -17,6 +17,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
+#include <xyz/openbmc_project/Sensor/Value/client.hpp>
#include <chrono>
#include <cmath>
@@ -33,6 +34,8 @@
#include "failsafeloggers/failsafe_logger.cpp"
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
+
namespace pid_control
{
@@ -69,7 +72,7 @@
try
{
- service = helper->getService(sensorintf, path);
+ service = helper->getService(SensorValue::interface, path);
}
catch (const std::exception& e)
{
@@ -389,9 +392,9 @@
msg.read(msgSensor, msgData);
- if (msgSensor == "xyz.openbmc_project.Sensor.Value")
+ if (msgSensor == SensorValue::interface)
{
- auto valPropMap = msgData.find("Value");
+ auto valPropMap = msgData.find(SensorValue::property_names::value);
if (valPropMap != msgData.end())
{
double value =
diff --git a/setsensor.cpp b/setsensor.cpp
index faca6b7..3933e5d 100644
--- a/setsensor.cpp
+++ b/setsensor.cpp
@@ -1,6 +1,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/message.hpp>
+#include <xyz/openbmc_project/Sensor/Value/client.hpp>
#include <cstdint>
#include <cstdio>
@@ -14,12 +15,12 @@
static constexpr auto property = "Manual";
using Value = std::variant<bool>;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
+
/* Host Sensor. */
static constexpr auto sobjectPath =
"/xyz/openbmc_project/extsensors/margin/sluggish0";
static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
-static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value";
-static constexpr auto sproperty = "Value";
using sValue = std::variant<int64_t>;
static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
@@ -36,8 +37,8 @@
auto pimMsg = PropertyWriteBus.new_method_call(
busname.c_str(), path.c_str(), propertiesintf, "Set");
- pimMsg.append(sintf);
- pimMsg.append(sproperty);
+ pimMsg.append(SensorValue::interface);
+ pimMsg.append(SensorValue::property_names::value);
pimMsg.append(v);
try
diff --git a/util.hpp b/util.hpp
index 1eb683c..75433cb 100644
--- a/util.hpp
+++ b/util.hpp
@@ -28,7 +28,6 @@
double upperThreshold = std::numeric_limits<double>::quiet_NaN();
};
-const std::string sensorintf = "xyz.openbmc_project.Sensor.Value";
const std::string criticalThreshInf =
"xyz.openbmc_project.Sensor.Threshold.Critical";
const std::string propertiesintf = "org.freedesktop.DBus.Properties";