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)
diff --git a/sensors/src/ADCSensorMain.cpp b/sensors/src/ADCSensorMain.cpp
index 47edd5c..4fff81a 100644
--- a/sensors/src/ADCSensorMain.cpp
+++ b/sensors/src/ADCSensorMain.cpp
@@ -30,9 +30,9 @@
namespace fs = std::experimental::filesystem;
namespace variant_ns = sdbusplus::message::variant_ns;
-static constexpr std::array<const char*, 1> SENSOR_TYPES = {
+static constexpr std::array<const char*, 1> sensorTypes = {
"xyz.openbmc_project.Configuration.ADC"};
-static std::regex INPUT_REGEX(R"(in(\d+)_input)");
+static std::regex inputRegex(R"(in(\d+)_input)");
void createSensors(
boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
@@ -46,7 +46,7 @@
// use new data the first time, then refresh
ManagedObjectType sensorConfigurations;
bool useCache = false;
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
if (!getSensorConfiguration(type, dbusConnection, sensorConfigurations,
useCache))
@@ -57,7 +57,7 @@
useCache = true;
}
std::vector<fs::path> paths;
- if (!find_files(fs::path("/sys/class/hwmon"), R"(in\d+_input)", paths))
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)", paths))
{
std::cerr << "No temperature sensors in system\n";
return;
@@ -70,21 +70,23 @@
std::smatch match;
std::string pathStr = path.string();
- std::regex_search(pathStr, match, INPUT_REGEX);
+ std::regex_search(pathStr, match, inputRegex);
std::string indexStr = *(match.begin() + 1);
auto directory = path.parent_path();
// convert to 0 based
size_t index = std::stoul(indexStr) - 1;
- auto oem_name_path =
+ auto oemNamePath =
directory.string() + R"(/of_node/oemname)" + std::to_string(index);
if (DEBUG)
- std::cout << "Checking path " << oem_name_path << "\n";
- std::ifstream nameFile(oem_name_path);
+ {
+ std::cout << "Checking path " << oemNamePath << "\n";
+ }
+ std::ifstream nameFile(oemNamePath);
if (!nameFile.good())
{
- std::cerr << "Failure reading " << oem_name_path << "\n";
+ std::cerr << "Failure reading " << oemNamePath << "\n";
continue;
}
std::string oemName;
@@ -118,7 +120,7 @@
const std::pair<std::string, boost::container::flat_map<
std::string, BasicVariantType>>*
baseConfiguration = nullptr;
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto sensorBase = sensorData->find(type);
if (sensorBase != sensorData->end())
@@ -168,7 +170,7 @@
}
}
std::vector<thresholds::Threshold> sensorThresholds;
- if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds))
+ if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
{
std::cerr << "error populating thresholds for " << sensorName
<< "\n";
@@ -230,12 +232,12 @@
});
};
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto match = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
"type='signal',member='PropertiesChanged',path_namespace='" +
- std::string(INVENTORY_PATH) + "',arg0namespace='" + type + "'",
+ std::string(inventoryPath) + "',arg0namespace='" + type + "'",
eventHandler);
matches.emplace_back(std::move(match));
}
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)
diff --git a/sensors/src/CPUSensorMain.cpp b/sensors/src/CPUSensorMain.cpp
index fb0ede4..7231453 100644
--- a/sensors/src/CPUSensorMain.cpp
+++ b/sensors/src/CPUSensorMain.cpp
@@ -59,18 +59,16 @@
}
};
-static constexpr const char* PECI_DEV = "/dev/peci-0";
-static constexpr const unsigned int RANK_NUM_MAX = 8;
+static constexpr const char* peciDev = "/dev/peci-0";
+static constexpr const unsigned int rankNumMax = 8;
namespace fs = std::experimental::filesystem;
namespace variant_ns = sdbusplus::message::variant_ns;
-static constexpr const char* CONFIG_PREFIX =
+static constexpr const char* configPrefix =
"xyz.openbmc_project.Configuration.";
-static constexpr std::array<const char*, 3> SENSOR_TYPES = {
+static constexpr std::array<const char*, 3> sensorTypes = {
"SkylakeCPU", "BroadwellCPU", "HaswellCPU"};
-const static std::regex ILLEGAL_NAME_REGEX("[^A-Za-z0-9_]");
-
bool createSensors(
boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>>&
@@ -95,9 +93,9 @@
// use new data the first time, then refresh
ManagedObjectType sensorConfigurations;
bool useCache = false;
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
- if (!getSensorConfiguration(CONFIG_PREFIX + std::string(type),
+ if (!getSensorConfiguration(configPrefix + std::string(type),
dbusConnection, sensorConfigurations,
useCache))
{
@@ -107,9 +105,9 @@
}
std::vector<fs::path> hwmonNamePaths;
- if (!find_files(fs::path(R"(/sys/bus/peci/devices)"),
- R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
- hwmonNamePaths, 1))
+ if (!findFiles(fs::path(R"(/sys/bus/peci/devices)"),
+ R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
+ hwmonNamePaths, 1))
{
std::cerr << "No CPU sensors in system\n";
return true;
@@ -184,9 +182,9 @@
sensor : sensorConfigurations)
{
sensorData = &(sensor.second);
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
- sensorType = CONFIG_PREFIX + std::string(type);
+ sensorType = configPrefix + std::string(type);
auto sensorBase = sensorData->find(sensorType);
if (sensorBase != sensorData->end())
{
@@ -239,8 +237,7 @@
auto directory = hwmonNamePath.parent_path();
std::vector<fs::path> inputPaths;
- if (!find_files(fs::path(directory), R"(temp\d+_input$)", inputPaths,
- 0))
+ if (!findFiles(fs::path(directory), R"(temp\d+_input$)", inputPaths, 0))
{
std::cerr << "No temperature sensors in system\n";
continue;
@@ -276,12 +273,12 @@
std::vector<thresholds::Threshold> sensorThresholds;
std::string labelHead = label.substr(0, label.find(" "));
- ParseThresholdsFromConfig(*sensorData, sensorThresholds,
+ parseThresholdsFromConfig(*sensorData, sensorThresholds,
&labelHead);
if (!sensorThresholds.size())
{
- if (!ParseThresholdsFromAttr(sensorThresholds, inputPathStr,
- CPUSensor::SENSOR_SCALE_FACTOR))
+ if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr,
+ CPUSensor::sensorScaleFactor))
{
std::cerr << "error populating thresholds for "
<< sensorName << "\n";
@@ -360,10 +357,10 @@
boost::container::flat_set<CPUConfig>& configs,
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
{
- auto file = open(PECI_DEV, O_RDWR);
+ auto file = open(peciDev, O_RDWR);
if (file < 0)
{
- std::cerr << "unable to open " << PECI_DEV << "\n";
+ std::cerr << "unable to open " << peciDev << "\n";
std::exit(EXIT_FAILURE);
}
@@ -377,7 +374,7 @@
if (!ioctl(file, PECI_IOC_PING, &msg))
{
bool dimmReady = false;
- for (unsigned int rank = 0; rank < RANK_NUM_MAX; rank++)
+ for (unsigned int rank = 0; rank < rankNumMax; rank++)
{
struct peci_rd_pkg_cfg_msg msg;
msg.addr = config.addr;
@@ -488,10 +485,10 @@
ManagedObjectType sensorConfigurations;
bool useCache = false;
// use new data the first time, then refresh
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
- if (!getSensorConfiguration(CONFIG_PREFIX + std::string(type),
- systemBus, sensorConfigurations, useCache))
+ if (!getSensorConfiguration(configPrefix + std::string(type), systemBus,
+ sensorConfigurations, useCache))
{
return false;
}
@@ -500,7 +497,7 @@
// check PECI client addresses and DT overlay names from CPU configuration
// before starting ping operation
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
for (const std::pair<sdbusplus::message::object_path, SensorData>&
sensor : sensorConfigurations)
@@ -510,7 +507,7 @@
boost::container::flat_map<std::string, BasicVariantType>>&
config : sensor.second)
{
- if ((CONFIG_PREFIX + std::string(type)) != config.first)
+ if ((configPrefix + std::string(type)) != config.first)
{
continue;
}
@@ -523,7 +520,7 @@
std::string nameRaw = variant_ns::visit(
VariantToStringVisitor(), findName->second);
std::string name =
- std::regex_replace(nameRaw, ILLEGAL_NAME_REGEX, "_");
+ std::regex_replace(nameRaw, illegalDbusRegex, "_");
auto findBus = config.second.find("Bus");
if (findBus == config.second.end())
@@ -634,13 +631,13 @@
});
};
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto match = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
"type='signal',member='PropertiesChanged',path_namespace='" +
- std::string(INVENTORY_PATH) + "',arg0namespace='" +
- CONFIG_PREFIX + type + "'",
+ std::string(inventoryPath) + "',arg0namespace='" +
+ configPrefix + type + "'",
eventHandler);
matches.emplace_back(std::move(match));
}
diff --git a/sensors/src/FanMain.cpp b/sensors/src/FanMain.cpp
index b562e05..4fa9ff2 100644
--- a/sensors/src/FanMain.cpp
+++ b/sensors/src/FanMain.cpp
@@ -32,9 +32,9 @@
namespace fs = std::experimental::filesystem;
namespace variant_ns = sdbusplus::message::variant_ns;
-static constexpr std::array<const char*, 1> SENSOR_TYPES = {
+static constexpr std::array<const char*, 1> sensorTypes = {
"xyz.openbmc_project.Configuration.AspeedFan"};
-static std::regex INPUT_REGEX(R"(fan(\d+)_input)");
+static std::regex inputRegex(R"(fan(\d+)_input)");
void createSensors(
boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
@@ -50,7 +50,7 @@
// use new data the first time, then refresh
ManagedObjectType sensorConfigurations;
bool useCache = false;
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
if (!getSensorConfiguration(type, dbusConnection, sensorConfigurations,
useCache))
@@ -61,7 +61,7 @@
useCache = true;
}
std::vector<fs::path> paths;
- if (!find_files(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", paths))
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", paths))
{
std::cerr << "No temperature sensors in system\n";
return;
@@ -74,7 +74,7 @@
std::smatch match;
std::string pathStr = path.string();
- std::regex_search(pathStr, match, INPUT_REGEX);
+ std::regex_search(pathStr, match, inputRegex);
std::string indexStr = *(match.begin() + 1);
auto directory = path.parent_path();
@@ -91,7 +91,7 @@
sensor : sensorConfigurations)
{
// find the base of the configuration to see if indexes match
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto sensorBaseFind = sensor.second.find(type);
if (sensorBaseFind != sensor.second.end())
@@ -124,7 +124,9 @@
std::to_string(pwmIndex);
if (DEBUG)
+ {
std::cout << "Checking path " << oemNamePath << "\n";
+ }
std::ifstream nameFile(oemNamePath);
if (!nameFile.good())
{
@@ -205,7 +207,7 @@
}
}
std::vector<thresholds::Threshold> sensorThresholds;
- if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds))
+ if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
{
std::cerr << "error populating thresholds for " << sensorName
<< "\n";
@@ -216,7 +218,7 @@
std::move(sensorThresholds), *interfacePath);
}
std::vector<fs::path> pwms;
- if (!find_files(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwms))
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwms))
{
std::cerr << "No pwm in system\n";
return;
@@ -277,12 +279,12 @@
});
};
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto match = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
"type='signal',member='PropertiesChanged',path_namespace='" +
- std::string(INVENTORY_PATH) + "',arg0namespace='" + type + "'",
+ std::string(inventoryPath) + "',arg0namespace='" + type + "'",
eventHandler);
matches.emplace_back(std::move(match));
}
diff --git a/sensors/src/HwmonTempMain.cpp b/sensors/src/HwmonTempMain.cpp
index d4b8099..70fbb75 100644
--- a/sensors/src/HwmonTempMain.cpp
+++ b/sensors/src/HwmonTempMain.cpp
@@ -28,7 +28,7 @@
static constexpr bool DEBUG = false;
namespace fs = std::experimental::filesystem;
-static constexpr std::array<const char*, 2> SENSOR_TYPES = {
+static constexpr std::array<const char*, 2> sensorTypes = {
"xyz.openbmc_project.Configuration.TMP75",
"xyz.openbmc_project.Configuration.TMP421"};
@@ -44,7 +44,7 @@
// use new data the first time, then refresh
ManagedObjectType sensorConfigurations;
bool useCache = false;
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
if (!getSensorConfiguration(type, dbusConnection, sensorConfigurations,
useCache))
@@ -55,7 +55,7 @@
useCache = true;
}
std::vector<fs::path> paths;
- if (!find_files(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths))
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths))
{
std::cerr << "No temperature sensors in system\n";
return;
@@ -110,7 +110,7 @@
sensor : sensorConfigurations)
{
sensorData = &(sensor.second);
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto sensorBase = sensorData->find(type);
if (sensorBase != sensorData->end())
@@ -186,7 +186,7 @@
}
}
std::vector<thresholds::Threshold> sensorThresholds;
- if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds))
+ if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
{
std::cerr << "error populating thresholds for " << sensorName
<< "\n";
@@ -255,12 +255,12 @@
});
};
- for (const char* type : SENSOR_TYPES)
+ for (const char* type : sensorTypes)
{
auto match = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
"type='signal',member='PropertiesChanged',path_namespace='" +
- std::string(INVENTORY_PATH) + "',arg0namespace='" + type + "'",
+ std::string(inventoryPath) + "',arg0namespace='" + type + "'",
eventHandler);
matches.emplace_back(std::move(match));
}
diff --git a/sensors/src/HwmonTempSensor.cpp b/sensors/src/HwmonTempSensor.cpp
index 5d3251a..1d58f07 100644
--- a/sensors/src/HwmonTempSensor.cpp
+++ b/sensors/src/HwmonTempSensor.cpp
@@ -26,140 +26,139 @@
#include <sdbusplus/asio/object_server.hpp>
#include <string>
-static constexpr unsigned int SENSOR_POLL_MS = 500;
-static constexpr unsigned int SENSOR_SCALE_FACTOR = 1000;
-static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+static constexpr unsigned int sensorPollMs = 500;
+static constexpr unsigned int sensorScaleFactor = 1000;
+static constexpr size_t warnAfterErrorCount = 10;
HwmonTempSensor::HwmonTempSensor(
const std::string &path, const std::string &objectType,
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 std::string &sensorConfiguration) :
Sensor(),
path(path), objectType(objectType), configuration(sensorConfiguration),
objServer(objectServer),
- name(boost::replace_all_copy(sensor_name, " ", "_")),
- input_dev(io, open(path.c_str(), O_RDONLY)), wait_timer(io), err_count(0),
+ name(boost::replace_all_copy(sensorName, " ", "_")),
+ 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);
- setup_read();
+ setInitialProperties(conn);
+ setupRead();
}
HwmonTempSensor::~HwmonTempSensor()
{
// 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 HwmonTempSensor::setup_read(void)
+void HwmonTempSensor::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 HwmonTempSensor::handle_response(const boost::system::error_code &err)
+void HwmonTempSensor::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);
try
{
float nvalue = std::stof(response);
- nvalue /= SENSOR_SCALE_FACTOR;
+ nvalue /= sensorScaleFactor;
if (nvalue != value)
{
- update_value(nvalue);
+ updateValue(nvalue);
}
- err_count = 0;
+ errCount = 0;
}
catch (const std::invalid_argument &)
{
- err_count++;
+ errCount++;
}
}
else
{
std::cerr << "Failure to read sensor " << name << " at " << path
<< "\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));
+ inputDev.assign(fd);
+ waitTimer.expires_from_now(boost::posix_time::milliseconds(sensorPollMs));
;
- wait_timer.async_wait([&](const boost::system::error_code &ec) {
+ 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 HwmonTempSensor::check_thresholds(void)
+void HwmonTempSensor::checkThresholds(void)
{
thresholds::checkThresholds(this);
}
-void HwmonTempSensor::update_value(const double &new_value)
+void HwmonTempSensor::updateValue(const double &newValue)
{
- sensorInterface->set_property("Value", new_value);
- value = new_value;
- check_thresholds();
+ sensorInterface->set_property("Value", newValue);
+ value = newValue;
+ checkThresholds();
}
-void HwmonTempSensor::set_initial_properties(
+void HwmonTempSensor::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)
diff --git a/sensors/src/PwmSensor.cpp b/sensors/src/PwmSensor.cpp
index 11d635f..dabc2f8 100644
--- a/sensors/src/PwmSensor.cpp
+++ b/sensors/src/PwmSensor.cpp
@@ -18,8 +18,8 @@
#include <iostream>
#include <sdbusplus/asio/object_server.hpp>
-constexpr size_t pwmMax = 255;
-constexpr size_t pwmMin = 0;
+static constexpr size_t pwmMax = 255;
+static constexpr size_t pwmMin = 0;
PwmSensor::PwmSensor(const std::string& sysPath,
sdbusplus::asio::object_server& objectServer) :
diff --git a/sensors/src/TachSensor.cpp b/sensors/src/TachSensor.cpp
index 10d94f2..e4ff3fd 100644
--- a/sensors/src/TachSensor.cpp
+++ b/sensors/src/TachSensor.cpp
@@ -27,8 +27,8 @@
#include <sdbusplus/asio/object_server.hpp>
#include <string>
-static constexpr unsigned int PWM_POLL_MS = 500;
-static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+static constexpr unsigned int pwmPollMs = 500;
+static constexpr size_t warnAfterErrorCount = 10;
TachSensor::TachSensor(const std::string &path,
sdbusplus::asio::object_server &objectServer,
@@ -40,134 +40,134 @@
path(path), objServer(objectServer), dbusConnection(conn),
name(boost::replace_all_copy(fanName, " ", "_")),
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(25000), min_value(0)
+ maxValue(25000), minValue(0)
{
thresholds = std::move(_thresholds);
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/fan_tach/" + name,
"xyz.openbmc_project.Sensor.Value");
- if (thresholds::HasWarningInterface(thresholds))
+ if (thresholds::hasWarningInterface(thresholds))
{
thresholdInterfaceWarning = objectServer.add_interface(
"/xyz/openbmc_project/sensors/fan_tach/" + name,
"xyz.openbmc_project.Sensor.Threshold.Warning");
}
- if (thresholds::HasCriticalInterface(thresholds))
+ if (thresholds::hasCriticalInterface(thresholds))
{
thresholdInterfaceCritical = objectServer.add_interface(
"/xyz/openbmc_project/sensors/fan_tach/" + name,
"xyz.openbmc_project.Sensor.Threshold.Critical");
}
- set_initial_properties(conn);
+ setInitialProperties(conn);
isPowerOn(dbusConnection); // first call initializes
- setup_read();
+ setupRead();
}
TachSensor::~TachSensor()
{
// 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 TachSensor::setup_read(void)
+void TachSensor::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 TachSensor::handle_response(const boost::system::error_code &err)
+void TachSensor::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();
+ responseStream.clear();
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);
+ updateValue(0);
}
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(PWM_POLL_MS));
- wait_timer.async_wait([&](const boost::system::error_code &ec) {
+ inputDev.assign(fd);
+ waitTimer.expires_from_now(boost::posix_time::milliseconds(pwmPollMs));
+ 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 TachSensor::check_thresholds(void)
+void TachSensor::checkThresholds(void)
{
thresholds::checkThresholds(this);
}
-void TachSensor::update_value(const double &new_value)
+void TachSensor::updateValue(const double &newValue)
{
- sensorInterface->set_property("Value", new_value);
- value = new_value;
- check_thresholds();
+ sensorInterface->set_property("Value", newValue);
+ value = newValue;
+ checkThresholds();
}
-void TachSensor::set_initial_properties(
+void TachSensor::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)
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;
}
diff --git a/sensors/src/Utils.cpp b/sensors/src/Utils.cpp
index 45670c5..768f708 100644
--- a/sensors/src/Utils.cpp
+++ b/sensors/src/Utils.cpp
@@ -23,9 +23,9 @@
#include <sdbusplus/bus/match.hpp>
namespace fs = std::experimental::filesystem;
-const static constexpr char* POWER_INTERFACE_NAME =
+const static constexpr char* powerInterfaceName =
"xyz.openbmc_project.Chassis.Control.Power";
-const static constexpr char* POWER_OBJECT_NAME =
+const static constexpr char* powerObjectName =
"/xyz/openbmc_project/Chassis/Control/Power0";
bool getSensorConfiguration(
@@ -40,7 +40,7 @@
managedObj.clear();
sdbusplus::message::message getManagedObjects =
dbusConnection->new_method_call(
- ENTITY_MANAGER_NAME, "/", "org.freedesktop.DBus.ObjectManager",
+ entityManagerName, "/", "org.freedesktop.DBus.ObjectManager",
"GetManagedObjects");
bool err = false;
try
@@ -81,26 +81,25 @@
return true;
}
-bool find_files(const fs::path dir_path, const std::string& match_string,
- std::vector<fs::path>& found_paths, unsigned int symlink_depth)
+bool findFiles(const fs::path dirPath, const std::string& matchString,
+ std::vector<fs::path>& foundPaths, unsigned int symlinkDepth)
{
- if (!fs::exists(dir_path))
+ if (!fs::exists(dirPath))
return false;
- fs::directory_iterator end_itr;
- std::regex search(match_string);
+ std::regex search(matchString);
std::smatch match;
- for (auto& p : fs::recursive_directory_iterator(dir_path))
+ for (auto& p : fs::recursive_directory_iterator(dirPath))
{
std::string path = p.path().string();
if (!is_directory(p))
{
if (std::regex_search(path, match, search))
- found_paths.emplace_back(p.path());
+ foundPaths.emplace_back(p.path());
}
- else if (is_symlink(p) && symlink_depth)
+ else if (is_symlink(p) && symlinkDepth)
{
- find_files(p.path(), match_string, found_paths, symlink_depth - 1);
+ findFiles(p.path(), matchString, foundPaths, symlinkDepth - 1);
}
}
return true;
@@ -152,8 +151,8 @@
}
powerStatusOn = sdbusplus::message::variant_ns::get<int32_t>(pgood);
},
- POWER_INTERFACE_NAME, POWER_OBJECT_NAME,
- "org.freedesktop.DBus.Properties", "Get", "pgood");
+ powerInterfaceName, powerObjectName, "org.freedesktop.DBus.Properties",
+ "Get", "pgood");
return powerStatusOn;
}
\ No newline at end of file