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/ADCSensor.cpp b/sensors/src/ADCSensor.cpp
index b72f5c1..0955994 100644
--- a/sensors/src/ADCSensor.cpp
+++ b/sensors/src/ADCSensor.cpp
@@ -26,95 +26,94 @@
#include <sdbusplus/asio/object_server.hpp>
#include <string>
-static constexpr unsigned int SENSOR_POLL_MS = 500;
-static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+static constexpr unsigned int sensorPollMs = 500;
+static constexpr size_t warnAfterErrorCount = 10;
// scaling factor from hwmon
-static constexpr unsigned int SENSOR_SCALE_FACTOR = 1000;
+static constexpr unsigned int sensorScaleFactor = 1000;
ADCSensor::ADCSensor(const std::string &path,
sdbusplus::asio::object_server &objectServer,
std::shared_ptr<sdbusplus::asio::connection> &conn,
- boost::asio::io_service &io,
- const std::string &sensor_name,
+ boost::asio::io_service &io, const std::string &sensorName,
std::vector<thresholds::Threshold> &&_thresholds,
- const double scale_factor,
+ const double scaleFactor,
const std::string &sensorConfiguration) :
Sensor(),
path(path), objServer(objectServer), configuration(sensorConfiguration),
- name(boost::replace_all_copy(sensor_name, " ", "_")),
- scale_factor(scale_factor), input_dev(io, open(path.c_str(), O_RDONLY)),
- wait_timer(io), err_count(0),
+ name(boost::replace_all_copy(sensorName, " ", "_")),
+ scaleFactor(scaleFactor), inputDev(io, open(path.c_str(), O_RDONLY)),
+ waitTimer(io), errCount(0),
// todo, get these from config
- max_value(20), min_value(0)
+ maxValue(20), minValue(0)
{
thresholds = std::move(_thresholds);
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/voltage/" + name,
"xyz.openbmc_project.Sensor.Value");
- if (thresholds::HasWarningInterface(thresholds))
+ if (thresholds::hasWarningInterface(thresholds))
{
thresholdInterfaceWarning = objectServer.add_interface(
"/xyz/openbmc_project/sensors/voltage/" + name,
"xyz.openbmc_project.Sensor.Threshold.Warning");
}
- if (thresholds::HasCriticalInterface(thresholds))
+ if (thresholds::hasCriticalInterface(thresholds))
{
thresholdInterfaceCritical = objectServer.add_interface(
"/xyz/openbmc_project/sensors/voltage/" + name,
"xyz.openbmc_project.Sensor.Threshold.Critical");
}
- set_initial_properties(conn);
- setup_read();
+ setInitialProperties(conn);
+ setupRead();
}
ADCSensor::~ADCSensor()
{
// close the input dev to cancel async operations
- input_dev.close();
- wait_timer.cancel();
+ inputDev.close();
+ waitTimer.cancel();
objServer.remove_interface(thresholdInterfaceWarning);
objServer.remove_interface(thresholdInterfaceCritical);
objServer.remove_interface(sensorInterface);
}
-void ADCSensor::setup_read(void)
+void ADCSensor::setupRead(void)
{
boost::asio::async_read_until(
- input_dev, read_buf, '\n',
+ inputDev, readBuf, '\n',
[&](const boost::system::error_code &ec,
- std::size_t /*bytes_transfered*/) { handle_response(ec); });
+ std::size_t /*bytes_transfered*/) { handleResponse(ec); });
}
-void ADCSensor::handle_response(const boost::system::error_code &err)
+void ADCSensor::handleResponse(const boost::system::error_code &err)
{
if (err == boost::system::errc::bad_file_descriptor)
{
return; // we're being destroyed
}
- std::istream response_stream(&read_buf);
+ std::istream responseStream(&readBuf);
if (!err)
{
std::string response;
- std::getline(response_stream, response);
+ std::getline(responseStream, response);
// todo read scaling factors from configuration
try
{
float nvalue = std::stof(response);
- nvalue = (nvalue / SENSOR_SCALE_FACTOR) / scale_factor;
+ nvalue = (nvalue / sensorScaleFactor) / scaleFactor;
if (nvalue != value)
{
- update_value(nvalue);
+ updateValue(nvalue);
}
- err_count = 0;
+ errCount = 0;
}
catch (std::invalid_argument)
{
- err_count++;
+ errCount++;
}
}
else
@@ -122,52 +121,51 @@
std::cerr << "Failure to read sensor " << name << " at " << path
<< " ec:" << err << "\n";
- err_count++;
+ errCount++;
}
// only send value update once
- if (err_count == WARN_AFTER_ERROR_COUNT)
+ if (errCount == warnAfterErrorCount)
{
- update_value(0);
+ updateValue(0);
}
- response_stream.clear();
- input_dev.close();
+ responseStream.clear();
+ inputDev.close();
int fd = open(path.c_str(), O_RDONLY);
if (fd <= 0)
{
return; // we're no longer valid
}
- input_dev.assign(fd);
- wait_timer.expires_from_now(
- boost::posix_time::milliseconds(SENSOR_POLL_MS));
- wait_timer.async_wait([&](const boost::system::error_code &ec) {
+ inputDev.assign(fd);
+ waitTimer.expires_from_now(boost::posix_time::milliseconds(sensorPollMs));
+ waitTimer.async_wait([&](const boost::system::error_code &ec) {
if (ec == boost::asio::error::operation_aborted)
{
return; // we're being canceled
}
- setup_read();
+ setupRead();
});
}
-void ADCSensor::check_thresholds(void)
+void ADCSensor::checkThresholds(void)
{
thresholds::checkThresholds(this);
}
-void ADCSensor::update_value(const double &new_value)
+void ADCSensor::updateValue(const double &newValue)
{
- bool ret = sensorInterface->set_property("Value", new_value);
- value = new_value;
- check_thresholds();
+ bool ret = sensorInterface->set_property("Value", newValue);
+ value = newValue;
+ checkThresholds();
}
-void ADCSensor::set_initial_properties(
+void ADCSensor::setInitialProperties(
std::shared_ptr<sdbusplus::asio::connection> &conn)
{
// todo, get max and min from configuration
- sensorInterface->register_property("MaxValue", max_value);
- sensorInterface->register_property("MinValue", min_value);
+ sensorInterface->register_property("MaxValue", maxValue);
+ sensorInterface->register_property("MinValue", minValue);
sensorInterface->register_property("Value", value);
for (auto &threshold : thresholds)