Clean up codes
This commit cleans up codes to follow coding style and conventions
of OpenBMC.
Change-Id: Ib2a9b2589b839db6eb0f31b392b3fa54aef3a8c6
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/sensors/src/Thresholds.cpp b/sensors/src/Thresholds.cpp
index 32244d7..ee4f7d0 100644
--- a/sensors/src/Thresholds.cpp
+++ b/sensors/src/Thresholds.cpp
@@ -7,7 +7,7 @@
#include <sensor.hpp>
static constexpr bool DEBUG = false;
-constexpr size_t MAX_THRESHOLDS = 4;
+static constexpr size_t maxThresholds = 4;
namespace variant_ns = sdbusplus::message::variant_ns;
namespace thresholds
@@ -50,7 +50,7 @@
}
}
-bool ParseThresholdsFromConfig(
+bool parseThresholdsFromConfig(
const SensorData &sensorData,
std::vector<thresholds::Threshold> &thresholdVector,
const std::string *matchLabel)
@@ -112,7 +112,7 @@
const thresholds::Threshold &threshold,
std::shared_ptr<sdbusplus::asio::connection> &conn)
{
- for (int ii = 0; ii < MAX_THRESHOLDS; ii++)
+ for (int ii = 0; ii < maxThresholds; ii++)
{
std::string thresholdInterface =
baseInterface + ".Thresholds" + std::to_string(ii);
@@ -155,11 +155,10 @@
<< "\n";
}
},
- ENTITY_MANAGER_NAME, path,
- "org.freedesktop.DBus.Properties", "Set",
- thresholdInterface, "Value", value);
+ entityManagerName, path, "org.freedesktop.DBus.Properties",
+ "Set", thresholdInterface, "Value", value);
},
- ENTITY_MANAGER_NAME, path, "org.freedesktop.DBus.Properties",
+ entityManagerName, path, "org.freedesktop.DBus.Properties",
"GetAll", thresholdInterface);
}
}
@@ -249,62 +248,78 @@
interface->set_property(property, assert);
}
-static constexpr std::array<const char *, 4> ATTR_TYPES = {"lcrit", "min",
- "max", "crit"};
+static constexpr std::array<const char *, 4> attrTypes = {"lcrit", "min", "max",
+ "crit"};
-bool ParseThresholdsFromAttr(
- std::vector<thresholds::Threshold> &threshold_vector,
- const std::string &input_path, const double &scale_factor)
+bool parseThresholdsFromAttr(
+ std::vector<thresholds::Threshold> &thresholdVector,
+ const std::string &inputPath, const double &scaleFactor)
{
- for (auto &type : ATTR_TYPES)
+ for (auto &type : attrTypes)
{
- auto attr_path = boost::replace_all_copy(input_path, "input", type);
- std::ifstream attr_file(attr_path);
- if (!attr_file.good())
+ auto attrPath = boost::replace_all_copy(inputPath, "input", type);
+ std::ifstream attrFile(attrPath);
+ if (!attrFile.good())
+ {
continue;
+ }
std::string attr;
- std::getline(attr_file, attr);
- attr_file.close();
+ std::getline(attrFile, attr);
+ attrFile.close();
Level level;
Direction direction;
- double val = std::stod(attr) / scale_factor;
+ double val = std::stod(attr) / scaleFactor;
if (type == "min" || type == "max")
+ {
level = Level::WARNING;
+ }
else
+ {
level = Level::CRITICAL;
+ }
if (type == "min" || type == "lcrit")
+ {
direction = Direction::LOW;
+ }
else
+ {
direction = Direction::HIGH;
+ }
if (DEBUG)
- std::cout << "Threshold: " << attr_path << ": " << val << "\n";
+ {
+ std::cout << "Threshold: " << attrPath << ": " << val << "\n";
+ }
- threshold_vector.emplace_back(level, direction, val);
+ thresholdVector.emplace_back(level, direction, val);
}
// no thresholds is allowed, not an error so return true always
return true;
}
-bool HasCriticalInterface(
- const std::vector<thresholds::Threshold> &threshold_vector)
+bool hasCriticalInterface(
+ const std::vector<thresholds::Threshold> &thresholdVector)
{
- for (auto &threshold : threshold_vector)
+ for (auto &threshold : thresholdVector)
{
if (threshold.level == Level::CRITICAL)
+ {
return true;
+ }
}
return false;
}
-bool HasWarningInterface(
- const std::vector<thresholds::Threshold> &threshold_vector)
+bool hasWarningInterface(
+ const std::vector<thresholds::Threshold> &thresholdVector)
{
- for (auto &threshold : threshold_vector)
+ for (auto &threshold : thresholdVector)
{
if (threshold.level == Level::WARNING)
+ {
return true;
+ }
}
return false;
}