Sensor.Value: use PDI constants
Use PDI constants instead of local definitions.
Tested: Inspection only.
Change-Id: I42c4f33a7e2f98a1adbac5a92aea4df952442990
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/dbus-sdr/sdrutils.cpp b/dbus-sdr/sdrutils.cpp
index a544dc1..e7f6566 100644
--- a/dbus-sdr/sdrutils.cpp
+++ b/dbus-sdr/sdrutils.cpp
@@ -20,12 +20,14 @@
#include <nlohmann/json.hpp>
#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/ObjectMapper/common.hpp>
+#include <xyz/openbmc_project/Sensor/Value/common.hpp>
#include <fstream>
#include <optional>
#include <unordered_set>
using ObjectMapper = sdbusplus::common::xyz::openbmc_project::ObjectMapper;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
#ifdef FEATURE_HYBRID_SENSORS
@@ -170,8 +172,7 @@
// Add sensors to SensorTree
static constexpr const std::array sensorInterfaces = {
- "xyz.openbmc_project.Sensor.Value",
- "xyz.openbmc_project.Sensor.ValueMutability",
+ SensorValue::interface, "xyz.openbmc_project.Sensor.ValueMutability",
"xyz.openbmc_project.Sensor.Threshold.Warning",
"xyz.openbmc_project.Sensor.Threshold.Critical"};
static constexpr const std::array vrInterfaces = {
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 83b2dc4..1c4930f 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -31,6 +31,7 @@
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <user_channel/channel_layer.hpp>
+#include <xyz/openbmc_project/Sensor/Value/common.hpp>
#include <algorithm>
#include <array>
@@ -45,6 +46,8 @@
#include <utility>
#include <variant>
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
+
#ifdef FEATURE_HYBRID_SENSORS
#include "sensordatahandler.hpp"
@@ -247,8 +250,6 @@
{
static constexpr const char* vrInterface =
"xyz.openbmc_project.Control.VoltageRegulatorMode";
-static constexpr const char* sensorInterface =
- "xyz.openbmc_project.Sensor.Value";
} // namespace sensor
static void getSensorMaxMin(const DbusInterfaceMap& sensorMap, double& max,
@@ -257,7 +258,7 @@
max = 127;
min = -128;
- auto sensorObject = sensorMap.find(sensor::sensorInterface);
+ auto sensorObject = sensorMap.find(SensorValue::interface);
auto critical =
sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
auto warning =
@@ -265,8 +266,10 @@
if (sensorObject != sensorMap.end())
{
- auto maxMap = sensorObject->second.find("MaxValue");
- auto minMap = sensorObject->second.find("MinValue");
+ auto maxMap =
+ sensorObject->second.find(SensorValue::property_names::max_value);
+ auto minMap =
+ sensorObject->second.find(SensorValue::property_names::min_value);
if (maxMap != sensorObject->second.end())
{
@@ -475,7 +478,8 @@
uint8_t reading, const ipmi::DbusInterfaceMap& sensorMap,
const ipmi::DbusInterfaceMap::mapped_type& valueObject)
{
- if (valueObject.find("Value") == valueObject.end())
+ if (valueObject.find(SensorValue::property_names::value) ==
+ valueObject.end())
{
lg2::error("Missing the required Value property");
return std::nullopt;
@@ -562,7 +566,7 @@
{
lg2::error("Failed to get Selected, path: {PATH}, "
"interface: {INTERFACE}, error: {ERROR}",
- "PATH", path, "INTERFACE", sensor::sensorInterface, "ERROR",
+ "PATH", path, "INTERFACE", SensorValue::interface, "ERROR",
ec.message());
return false;
}
@@ -792,14 +796,14 @@
// we can tell the sensor type by its interface type
if (std::find(interfaces.begin(), interfaces.end(),
- sensor::sensorInterface) != interfaces.end())
+ SensorValue::interface) != interfaces.end())
{
DbusInterfaceMap sensorMap;
if (!getSensorMap(ctx, connection, path, sensorMap))
{
return ipmi::responseResponseError();
}
- auto sensorObject = sensorMap.find(sensor::sensorInterface);
+ auto sensorObject = sensorMap.find(SensorValue::interface);
if (sensorObject == sensorMap.end())
{
return ipmi::responseResponseError();
@@ -827,9 +831,9 @@
"VALUE", *value);
}
- boost::system::error_code ec =
- setDbusProperty(ctx, connection, path, sensor::sensorInterface,
- "Value", ipmi::Value(*value));
+ boost::system::error_code ec = setDbusProperty(
+ ctx, connection, path, SensorValue::interface,
+ SensorValue::property_names::value, ipmi::Value(*value));
// setDbusProperty intended to resolve dbus exception/rc within the
// function but failed to achieve that. Catch exception in the ipmi
@@ -838,7 +842,7 @@
{
lg2::error("Failed to set Value, path: {PATH}, "
"interface: {INTERFACE}, ERROR: {ERROR}",
- "PATH", path, "INTERFACE", sensor::sensorInterface,
+ "PATH", path, "INTERFACE", SensorValue::interface,
"ERROR", ec.message());
return ipmi::responseResponseError();
}
@@ -877,7 +881,7 @@
{
lg2::error("Failed to set Selected, path: {PATH}, "
"interface: {INTERFACE}, ERROR: {ERROR}",
- "PATH", path, "INTERFACE", sensor::sensorInterface,
+ "PATH", path, "INTERFACE", SensorValue::interface,
"ERROR", ec.message());
}
return ipmi::responseSuccess();
@@ -956,14 +960,16 @@
{
return ipmi::responseResponseError();
}
- auto sensorObject = sensorMap.find(sensor::sensorInterface);
+ auto sensorObject = sensorMap.find(SensorValue::interface);
if (sensorObject == sensorMap.end() ||
- sensorObject->second.find("Value") == sensorObject->second.end())
+ sensorObject->second.find(SensorValue::property_names::value) ==
+ sensorObject->second.end())
{
return ipmi::responseResponseError();
}
- auto& valueVariant = sensorObject->second["Value"];
+ auto& valueVariant =
+ sensorObject->second[SensorValue::property_names::value];
double reading = std::visit(VariantToDoubleVisitor(), valueVariant);
double max = 0;
@@ -1261,7 +1267,7 @@
if ((warningInterface != sensorMap.end()) ||
(criticalInterface != sensorMap.end()))
{
- auto sensorPair = sensorMap.find(sensor::sensorInterface);
+ auto sensorPair = sensorMap.find(SensorValue::interface);
if (sensorPair == sensorMap.end())
{
@@ -1818,7 +1824,7 @@
record.body.eventReadingType = getSensorEventTypeFromPath(path);
- auto sensorObject = sensorMap.find(sensor::sensorInterface);
+ auto sensorObject = sensorMap.find(SensorValue::interface);
if (sensorObject == sensorMap.end())
{
lg2::error("constructSensorSdr: sensorObject error");
@@ -2192,7 +2198,7 @@
// Construct full record (SDR type 1) for the threshold sensors
if (std::find(interfaces.begin(), interfaces.end(),
- sensor::sensorInterface) != interfaces.end())
+ SensorValue::interface) != interfaces.end())
{
get_sdr::SensorDataFullRecord record = {};
@@ -2619,7 +2625,7 @@
{
std::string service{};
boost::system::error_code ec =
- ipmi::getService(ctx, sensor::sensorInterface, objectPath, service);
+ ipmi::getService(ctx, SensorValue::interface, objectPath, service);
if (ec.value())
{
return std::make_tuple(false, 0, false);
@@ -2627,7 +2633,7 @@
ipmi::PropertyMap properties{};
ec = ipmi::getAllDbusProperties(ctx, service, objectPath,
- sensor::sensorInterface, properties);
+ SensorValue::interface, properties);
if (ec.value())
{
return std::make_tuple(false, 0, false);
@@ -2640,7 +2646,7 @@
scaleVal = std::visit(ipmi::VariantToDoubleVisitor(), scaleIt->second);
}
- auto tempValIt = properties.find("Value");
+ auto tempValIt = properties.find(SensorValue::property_names::value);
double tempVal = 0.0;
if (tempValIt == properties.end())
{
diff --git a/dcmihandler.cpp b/dcmihandler.cpp
index c02c407..eb141f5 100644
--- a/dcmihandler.cpp
+++ b/dcmihandler.cpp
@@ -12,6 +12,7 @@
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
+#include <xyz/openbmc_project/Sensor/Value/common.hpp>
#include <bitset>
#include <cmath>
@@ -24,6 +25,8 @@
using InternalFailure =
sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
+
void registerNetFnDcmiFunctions() __attribute__((constructor));
constexpr auto pcapInterface = "xyz.openbmc_project.Control.Power.Cap";
@@ -46,8 +49,6 @@
constexpr uint8_t parameterRevision = 2;
constexpr uint8_t specMajorVersion = 1;
constexpr uint8_t specMinorVersion = 5;
-constexpr auto sensorValueIntf = "xyz.openbmc_project.Sensor.Value";
-constexpr auto sensorValueProp = "Value";
constexpr uint8_t configParameterRevision = 1;
constexpr auto option12Mask = 0x01;
constexpr auto activateDhcpReply = 0x00;
@@ -1077,13 +1078,14 @@
ipmi::PropertyMap result{};
boost::system::error_code ec = ipmi::getAllDbusProperties(
- ctx, dbusService, dbusPath, "xyz.openbmc_project.Sensor.Value", result);
+ ctx, dbusService, dbusPath, SensorValue::interface, result);
if (ec.value())
{
return std::make_tuple(false, false, 0);
}
auto temperature =
- std::visit(ipmi::VariantToDoubleVisitor(), result.at("Value"));
+ std::visit(ipmi::VariantToDoubleVisitor(),
+ result.at(SensorValue::property_names::value));
double absTemp = std::abs(temperature);
auto findFactor = result.find("Scale");
@@ -1132,8 +1134,8 @@
std::string path = j.value("dbus", "");
std::string service{};
- boost::system::error_code ec = ipmi::getService(
- ctx, "xyz.openbmc_project.Sensor.Value", path, service);
+ boost::system::error_code ec =
+ ipmi::getService(ctx, SensorValue::interface, path, service);
if (ec.value())
{
// not found on dbus
@@ -1341,26 +1343,26 @@
// Return default value if failed to read from D-Bus object
std::string service{};
boost::system::error_code ec =
- ipmi::getService(ctx, dcmi::sensorValueIntf, objectPath, service);
+ ipmi::getService(ctx, SensorValue::interface, objectPath, service);
if (ec.value())
{
lg2::error("Failed to fetch service for D-Bus object, "
"object path: {OBJECT_PATH}, interface: {INTERFACE}",
"OBJECT_PATH", objectPath, "INTERFACE",
- dcmi::sensorValueIntf);
+ SensorValue::interface);
return std::nullopt;
}
// Read the sensor value and scale properties
double value{};
- ec = ipmi::getDbusProperty(ctx, service, objectPath, dcmi::sensorValueIntf,
- dcmi::sensorValueProp, value);
+ ec = ipmi::getDbusProperty(ctx, service, objectPath, SensorValue::interface,
+ SensorValue::property_names::value, value);
if (ec.value())
{
lg2::error("Failed to read power value from D-Bus object, "
"object path: {OBJECT_PATH}, interface: {INTERFACE}",
"OBJECT_PATH", objectPath, "INTERFACE",
- dcmi::sensorValueIntf);
+ SensorValue::interface);
return std::nullopt;
}
auto power = static_cast<uint16_t>(value);
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index 0b27090..6b716d5 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -10,6 +10,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/message/types.hpp>
+#include <xyz/openbmc_project/Sensor/Value/common.hpp>
#include <cmath>
@@ -39,6 +40,8 @@
using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>;
using PropertyMap = ipmi::PropertyMap;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
+
using namespace phosphor::logging;
/** @brief Make assertion set from input data
@@ -221,8 +224,7 @@
#ifdef UPDATE_FUNCTIONAL_ON_FAIL
// Check the OperationalStatus interface for functional property
- if (sensorInfo.propertyInterfaces.begin()->first ==
- "xyz.openbmc_project.Sensor.Value")
+ if (sensorInfo.propertyInterfaces.begin()->first == SensorValue::interface)
{
bool functional = true;
try
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index cb6942f..1acdf7e 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -42,6 +42,8 @@
using InternalFailure =
sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
+using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
+
void registerNetFnSenFunctions() __attribute__((constructor));
struct sensorTypemap_t
@@ -444,7 +446,7 @@
}
const std::set<std::string> analogSensorInterfaces = {
- "xyz.openbmc_project.Sensor.Value",
+ SensorValue::interface,
"xyz.openbmc_project.Control.FanPwm",
};
@@ -829,8 +831,6 @@
>
ipmiSensorGetSensorThresholds(ipmi::Context::ptr& ctx, uint8_t sensorNum)
{
- constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
-
const auto iter = ipmi::sensor::sensors.find(sensorNum);
if (iter == ipmi::sensor::sensors.end())
{
@@ -840,7 +840,7 @@
const auto info = iter->second;
// Proceed only if the sensor value interface is implemented.
- if (info.propertyInterfaces.find(valueInterface) ==
+ if (info.propertyInterfaces.find(SensorValue::interface) ==
info.propertyInterfaces.end())
{
// return with valid mask as 0
@@ -911,8 +911,6 @@
return ipmi::responseSuccess();
}
- constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
-
const auto iter = ipmi::sensor::sensors.find(sensorNum);
if (iter == ipmi::sensor::sensors.end())
{
@@ -922,7 +920,7 @@
const auto& info = iter->second;
// Proceed only if the sensor value interface is implemented.
- if (info.propertyInterfaces.find(valueInterface) ==
+ if (info.propertyInterfaces.find(SensorValue::interface) ==
info.propertyInterfaces.end())
{
// return with valid mask as 0