summaryrefslogtreecommitdiff
path: root/redfish-core/lib/sensors.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-02-27 11:09:02 +0300
committerEd Tanous <ed@tanous.net>2022-04-27 17:55:06 +0300
commit02da7c5a626a747ce93aead08ee050678a16c79b (patch)
treee58cf56a8cb0f283a350df58054ce3603d0256f2 /redfish-core/lib/sensors.hpp
parent49328a2b0d67861091678fe46f55bec57bd13990 (diff)
downloadbmcweb-02da7c5a626a747ce93aead08ee050678a16c79b.tar.xz
Simplify sensor path lookups
This commit drops 8k from the binary size. Tested: SensorCollection returns sensor values as expected, same as previously Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ife1dc40ff6745585ac6bc3f99cd5e6c4811baa56
Diffstat (limited to 'redfish-core/lib/sensors.hpp')
-rw-r--r--redfish-core/lib/sensors.hpp85
1 files changed, 48 insertions, 37 deletions
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 58e8891eb3..3a5c73bfb3 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -44,33 +44,44 @@ static constexpr std::string_view sensors = "Sensors";
static constexpr std::string_view thermal = "Thermal";
} // namespace node
+// clang-format off
namespace dbus
{
-
-static const boost::container::flat_map<std::string_view,
- std::vector<const char*>>
- paths = {{node::power,
- {"/xyz/openbmc_project/sensors/voltage",
- "/xyz/openbmc_project/sensors/power"}},
- {node::sensors,
- {"/xyz/openbmc_project/sensors/power",
- "/xyz/openbmc_project/sensors/current",
- "/xyz/openbmc_project/sensors/airflow",
+auto powerPaths = std::to_array<std::string_view>({
+ "/xyz/openbmc_project/sensors/voltage",
+ "/xyz/openbmc_project/sensors/power"
+});
+
+auto sensorPaths = std::to_array<std::string_view>({
+ "/xyz/openbmc_project/sensors/power",
+ "/xyz/openbmc_project/sensors/current",
+ "/xyz/openbmc_project/sensors/airflow",
"/xyz/openbmc_project/sensors/humidity",
#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM
- "/xyz/openbmc_project/sensors/voltage",
- "/xyz/openbmc_project/sensors/fan_tach",
- "/xyz/openbmc_project/sensors/temperature",
- "/xyz/openbmc_project/sensors/fan_pwm",
- "/xyz/openbmc_project/sensors/altitude",
- "/xyz/openbmc_project/sensors/energy",
+ "/xyz/openbmc_project/sensors/voltage",
+ "/xyz/openbmc_project/sensors/fan_tach",
+ "/xyz/openbmc_project/sensors/temperature",
+ "/xyz/openbmc_project/sensors/fan_pwm",
+ "/xyz/openbmc_project/sensors/altitude",
+ "/xyz/openbmc_project/sensors/energy",
#endif
- "/xyz/openbmc_project/sensors/utilization"}},
- {node::thermal,
- {"/xyz/openbmc_project/sensors/fan_tach",
- "/xyz/openbmc_project/sensors/temperature",
- "/xyz/openbmc_project/sensors/fan_pwm"}}};
+ "/xyz/openbmc_project/sensors/utilization"
+});
+
+auto thermalPaths = std::to_array<std::string_view>({
+ "/xyz/openbmc_project/sensors/fan_tach",
+ "/xyz/openbmc_project/sensors/temperature",
+ "/xyz/openbmc_project/sensors/fan_pwm"
+});
+
} // namespace dbus
+// clang-format on
+
+using sensorPair = std::pair<std::string_view, std::span<std::string_view>>;
+static constexpr std::array<sensorPair, 3> paths = {
+ {{node::power, std::span<std::string_view>(dbus::powerPaths)},
+ {node::sensors, std::span<std::string_view>(dbus::sensorPaths)},
+ {node::thermal, std::span<std::string_view>(dbus::thermalPaths)}}};
inline const char* toReadingType(const std::string& sensorType)
{
@@ -181,8 +192,8 @@ class SensorsAsyncResp
SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& chassisIdIn,
- const std::vector<const char*>& typesIn,
- const std::string_view& subNode) :
+ std::span<std::string_view> typesIn,
+ std::string_view subNode) :
asyncResp(asyncResp),
chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode),
efficientExpand(false)
@@ -191,8 +202,8 @@ class SensorsAsyncResp
// Store extra data about sensor mapping and return it in callback
SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& chassisIdIn,
- const std::vector<const char*>& typesIn,
- const std::string_view& subNode,
+ std::span<std::string_view> typesIn,
+ std::string_view subNode,
DataCompleteCb&& creationComplete) :
asyncResp(asyncResp),
chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode),
@@ -203,7 +214,7 @@ class SensorsAsyncResp
// sensor collections expand
SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& chassisIdIn,
- const std::vector<const char*>& typesIn,
+ const std::span<std::string_view> typesIn,
const std::string_view& subNode, bool efficientExpand) :
asyncResp(asyncResp),
chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode),
@@ -268,7 +279,7 @@ class SensorsAsyncResp
const std::shared_ptr<bmcweb::AsyncResp> asyncResp;
const std::string chassisId;
- const std::vector<const char*> types;
+ const std::span<std::string_view> types;
const std::string chassisSubNode;
const bool efficientExpand;
@@ -452,7 +463,7 @@ inline void reduceSensorList(
return;
}
- for (const char* type : sensorsAsyncResp->types)
+ for (std::string_view type : sensorsAsyncResp->types)
{
for (const std::string& sensor : *allSensors)
{
@@ -2948,8 +2959,10 @@ inline void retrieveUriToDbusMap(const std::string& chassis,
const std::string& node,
SensorsAsyncResp::DataCompleteCb&& mapComplete)
{
- auto pathIt = sensors::dbus::paths.find(node);
- if (pathIt == sensors::dbus::paths.end())
+ decltype(sensors::paths)::const_iterator pathIt =
+ std::find_if(sensors::paths.cbegin(), sensors::paths.cend(),
+ [&node](auto&& val) { return val.first == node; });
+ if (pathIt == sensors::paths.cend())
{
BMCWEB_LOG_ERROR << "Wrong node provided : " << node;
mapComplete(boost::beast::http::status::bad_request, {});
@@ -3026,8 +3039,7 @@ inline void requestRoutesSensorCollection(App& app)
{
// we perform efficient expand.
auto asyncResp = std::make_shared<SensorsAsyncResp>(
- aResp, chassisId,
- sensors::dbus::paths.at(sensors::node::sensors),
+ aResp, chassisId, sensors::dbus::sensorPaths,
sensors::node::sensors,
/*efficientExpand=*/true);
getChassisData(asyncResp);
@@ -3040,8 +3052,7 @@ inline void requestRoutesSensorCollection(App& app)
// if there's no efficient expand available, we use the default
// Query Parameters route
auto asyncResp = std::make_shared<SensorsAsyncResp>(
- aResp, chassisId,
- sensors::dbus::paths.at(sensors::node::sensors),
+ aResp, chassisId, sensors::dbus::sensorPaths,
sensors::node::sensors);
// We get all sensors as hyperlinkes in the chassis (this
@@ -3069,9 +3080,9 @@ inline void requestRoutesSensor(App& app)
}
BMCWEB_LOG_DEBUG << "Sensor doGet enter";
std::shared_ptr<SensorsAsyncResp> asyncResp =
- std::make_shared<SensorsAsyncResp>(aResp, chassisId,
- std::vector<const char*>(),
- sensors::node::sensors);
+ std::make_shared<SensorsAsyncResp>(
+ aResp, chassisId, std::span<std::string_view>(),
+ sensors::node::sensors);
const std::array<const char*, 1> interfaces = {
"xyz.openbmc_project.Sensor.Value"};