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/CPUSensor.cpp b/sensors/src/CPUSensor.cpp
index ce9e60b..98201b1 100644
--- a/sensors/src/CPUSensor.cpp
+++ b/sensors/src/CPUSensor.cpp
@@ -27,7 +27,7 @@
#include <sdbusplus/asio/object_server.hpp>
#include <string>
-static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+static constexpr size_t warnAfterErrorCount = 10;
CPUSensor::CPUSensor(const std::string &path, const std::string &objectType,
sdbusplus::asio::object_server &objectServer,
@@ -40,137 +40,137 @@
name(boost::replace_all_copy(sensorName, " ", "_")), dbusConnection(conn),
configuration(sensorConfiguration),
- input_dev(io, open(path.c_str(), O_RDONLY)), wait_timer(io), err_count(0),
+ inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), errCount(0),
// todo, get these from config
- max_value(127), min_value(-128)
+ maxValue(127), minValue(-128)
{
thresholds = std::move(_thresholds);
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/temperature/" + name,
"xyz.openbmc_project.Sensor.Value");
- if (thresholds::HasWarningInterface(thresholds))
+ if (thresholds::hasWarningInterface(thresholds))
{
thresholdInterfaceWarning = objectServer.add_interface(
"/xyz/openbmc_project/sensors/temperature/" + name,
"xyz.openbmc_project.Sensor.Threshold.Warning");
}
- if (thresholds::HasCriticalInterface(thresholds))
+ if (thresholds::hasCriticalInterface(thresholds))
{
thresholdInterfaceCritical = objectServer.add_interface(
"/xyz/openbmc_project/sensors/temperature/" + name,
"xyz.openbmc_project.Sensor.Threshold.Critical");
}
- set_initial_properties(conn);
+ setInitialProperties(conn);
isPowerOn(dbusConnection); // first call initializes
- setup_read();
+ setupRead();
}
CPUSensor::~CPUSensor()
{
// 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 CPUSensor::setup_read(void)
+void CPUSensor::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 CPUSensor::handle_response(const boost::system::error_code &err)
+void CPUSensor::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;
try
{
- std::getline(response_stream, response);
+ std::getline(responseStream, response);
float nvalue = std::stof(response);
- response_stream.clear();
- nvalue /= CPUSensor::SENSOR_SCALE_FACTOR;
+ responseStream.clear();
+ nvalue /= CPUSensor::sensorScaleFactor;
if (nvalue != value)
{
- update_value(nvalue);
+ updateValue(nvalue);
}
- err_count = 0;
+ errCount = 0;
}
catch (const std::invalid_argument &)
{
- err_count++;
+ errCount++;
}
}
else
{
- err_count++;
+ errCount++;
}
// only send value update once
- if (err_count == WARN_AFTER_ERROR_COUNT)
+ if (errCount == warnAfterErrorCount)
{
// only an error if power is on
if (isPowerOn(dbusConnection))
{
std::cerr << "Failure to read sensor " << name << " at " << path
<< "\n";
- update_value(0);
- err_count++;
+ updateValue(0);
+ errCount++;
}
else
{
- err_count = 0; // check power again in 10 cycles
+ errCount = 0; // check power again in 10 cycles
sensorInterface->set_property(
"Value", std::numeric_limits<double>::quiet_NaN());
}
}
- 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(CPUSensor::SENSOR_POLL_MS));
- wait_timer.async_wait([&](const boost::system::error_code &ec) {
+ inputDev.assign(fd);
+ waitTimer.expires_from_now(
+ boost::posix_time::milliseconds(CPUSensor::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 CPUSensor::check_thresholds(void)
+void CPUSensor::checkThresholds(void)
{
thresholds::checkThresholds(this);
}
-void CPUSensor::update_value(const double &new_value)
+void CPUSensor::updateValue(const double &newValue)
{
- sensorInterface->set_property("Value", new_value);
- value = new_value;
- check_thresholds();
+ sensorInterface->set_property("Value", newValue);
+ value = newValue;
+ checkThresholds();
}
-void CPUSensor::set_initial_properties(
+void CPUSensor::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)