clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: Ib7af6345a7b9e858700bd81645fe87d9d7e9d0fb
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index ec64c43..956e9e5 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -120,8 +120,8 @@
const std::string pathStr = path.string();
if (pathStr.ends_with("_raw"))
{
- std::string pathOffsetStr = pathStr.substr(0, pathStr.size() - 4) +
- "_offset";
+ std::string pathOffsetStr =
+ pathStr.substr(0, pathStr.size() - 4) + "_offset";
std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
// In case there is nothing to read skip this device
// This is not an error condition see lore
@@ -131,8 +131,8 @@
tmpSensorParameters.offsetValue = *tmpOffsetValue;
}
- std::string pathScaleStr = pathStr.substr(0, pathStr.size() - 4) +
- "_scale";
+ std::string pathScaleStr =
+ pathStr.substr(0, pathStr.size() - 4) + "_scale";
std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
// In case there is nothing to read skip this device
// This is not an error condition see lore
@@ -276,229 +276,173 @@
dbusConnection,
[&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
activateOnly](const ManagedObjectType& sensorConfigurations) {
- bool firstScan = sensorsChanged == nullptr;
+ bool firstScan = sensorsChanged == nullptr;
- SensorConfigMap configMap = buildSensorConfigMap(sensorConfigurations);
+ SensorConfigMap configMap =
+ buildSensorConfigMap(sensorConfigurations);
- auto devices = instantiateDevices(sensorConfigurations, sensors,
- sensorTypes);
+ auto devices =
+ instantiateDevices(sensorConfigurations, sensors, sensorTypes);
- // IIO _raw devices look like this on sysfs:
- // /sys/bus/iio/devices/iio:device0/in_temp_raw
- // /sys/bus/iio/devices/iio:device0/in_temp_offset
- // /sys/bus/iio/devices/iio:device0/in_temp_scale
- //
- // Other IIO devices look like this on sysfs:
- // /sys/bus/iio/devices/iio:device1/in_temp_input
- // /sys/bus/iio/devices/iio:device1/in_pressure_input
- std::vector<fs::path> paths;
- fs::path root("/sys/bus/iio/devices");
- findFiles(root, R"(in_temp\d*_(input|raw))", paths);
- findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
- findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
- findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
+ // IIO _raw devices look like this on sysfs:
+ // /sys/bus/iio/devices/iio:device0/in_temp_raw
+ // /sys/bus/iio/devices/iio:device0/in_temp_offset
+ // /sys/bus/iio/devices/iio:device0/in_temp_scale
+ //
+ // Other IIO devices look like this on sysfs:
+ // /sys/bus/iio/devices/iio:device1/in_temp_input
+ // /sys/bus/iio/devices/iio:device1/in_pressure_input
+ std::vector<fs::path> paths;
+ fs::path root("/sys/bus/iio/devices");
+ findFiles(root, R"(in_temp\d*_(input|raw))", paths);
+ findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
+ findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
+ findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
- // iterate through all found temp and pressure sensors,
- // and try to match them with configuration
- for (auto& path : paths)
- {
- std::smatch match;
- const std::string pathStr = path.string();
- auto directory = path.parent_path();
- fs::path device;
-
- std::string deviceName;
- std::error_code ec;
- if (pathStr.starts_with("/sys/bus/iio/devices"))
+ // iterate through all found temp and pressure sensors,
+ // and try to match them with configuration
+ for (auto& path : paths)
{
- device = fs::canonical(directory, ec);
- if (ec)
+ std::smatch match;
+ const std::string pathStr = path.string();
+ auto directory = path.parent_path();
+ fs::path device;
+
+ std::string deviceName;
+ std::error_code ec;
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
{
- std::cerr << "Fail to find device in path [" << pathStr
- << "]\n";
- continue;
- }
- deviceName = device.parent_path().stem();
- }
- else
- {
- device = fs::canonical(directory / "device", ec);
- if (ec)
- {
- std::cerr << "Fail to find device in path [" << pathStr
- << "]\n";
- continue;
- }
- deviceName = device.stem();
- }
-
- uint64_t bus = 0;
- uint64_t addr = 0;
- if (!getDeviceBusAddr(deviceName, bus, addr))
- {
- continue;
- }
-
- auto thisSensorParameters = getSensorParameters(path);
- auto findSensorCfg = configMap.find({bus, addr});
- if (findSensorCfg == configMap.end())
- {
- continue;
- }
-
- const std::string& interfacePath = findSensorCfg->second.sensorPath;
- auto findI2CDev = devices.find(interfacePath);
-
- std::shared_ptr<I2CDevice> i2cDev;
- if (findI2CDev != devices.end())
- {
- // If we're only looking to activate newly-instantiated i2c
- // devices and this sensor's underlying device was already there
- // before this call, there's nothing more to do here.
- if (activateOnly && !findI2CDev->second.second)
- {
- continue;
- }
- i2cDev = findI2CDev->second.first;
- }
-
- const SensorData& sensorData = findSensorCfg->second.sensorData;
- std::string sensorType = findSensorCfg->second.interface;
- auto pos = sensorType.find_last_of('.');
- if (pos != std::string::npos)
- {
- sensorType = sensorType.substr(pos + 1);
- }
- const SensorBaseConfigMap& baseConfigMap =
- findSensorCfg->second.config;
- std::vector<std::string>& hwmonName = findSensorCfg->second.name;
-
- // Temperature has "Name", pressure has "Name1"
- auto findSensorName = baseConfigMap.find("Name");
- int index = 1;
- if (thisSensorParameters.typeName == "pressure" ||
- thisSensorParameters.typeName == "humidity")
- {
- findSensorName = baseConfigMap.find("Name1");
- index = 2;
- }
-
- if (findSensorName == baseConfigMap.end())
- {
- std::cerr << "could not determine configuration name for "
- << deviceName << "\n";
- continue;
- }
- std::string sensorName =
- std::get<std::string>(findSensorName->second);
- // on rescans, only update sensors we were signaled by
- auto findSensor = sensors.find(sensorName);
- if (!firstScan && findSensor != sensors.end())
- {
- bool found = false;
- auto it = sensorsChanged->begin();
- while (it != sensorsChanged->end())
- {
- if (it->ends_with(findSensor->second->name))
+ device = fs::canonical(directory, ec);
+ if (ec)
{
- it = sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- break;
+ std::cerr << "Fail to find device in path [" << pathStr
+ << "]\n";
+ continue;
}
- ++it;
- }
- if (!found)
- {
- continue;
- }
- }
-
- std::vector<thresholds::Threshold> sensorThresholds;
-
- if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
- nullptr, &index))
- {
- std::cerr << "error populating thresholds for " << sensorName
- << " index " << index << "\n";
- }
-
- float pollRate = getPollRate(baseConfigMap, pollRateDefault);
- PowerState readState = getPowerState(baseConfigMap);
-
- auto permitSet = getPermitSet(baseConfigMap);
- auto& sensor = sensors[sensorName];
- if (!activateOnly)
- {
- sensor = nullptr;
- }
- auto hwmonFile = getFullHwmonFilePath(directory.string(), "temp1",
- permitSet);
- if (pathStr.starts_with("/sys/bus/iio/devices"))
- {
- hwmonFile = pathStr;
- }
- if (hwmonFile)
- {
- if (sensor != nullptr)
- {
- sensor->activate(*hwmonFile, i2cDev);
+ deviceName = device.parent_path().stem();
}
else
{
- sensor = std::make_shared<HwmonTempSensor>(
- *hwmonFile, sensorType, objectServer, dbusConnection,
- io, sensorName, std::move(sensorThresholds),
- thisSensorParameters, pollRate, interfacePath,
- readState, i2cDev);
- sensor->setupRead();
+ device = fs::canonical(directory / "device", ec);
+ if (ec)
+ {
+ std::cerr << "Fail to find device in path [" << pathStr
+ << "]\n";
+ continue;
+ }
+ deviceName = device.stem();
}
- }
- hwmonName.erase(
- remove(hwmonName.begin(), hwmonName.end(), sensorName),
- hwmonName.end());
- // Looking for keys like "Name1" for temp2_input,
- // "Name2" for temp3_input, etc.
- int i = 0;
- while (true)
- {
- ++i;
- auto findKey = baseConfigMap.find("Name" + std::to_string(i));
- if (findKey == baseConfigMap.end())
- {
- break;
- }
- std::string sensorName = std::get<std::string>(findKey->second);
- hwmonFile = getFullHwmonFilePath(directory.string(),
- "temp" + std::to_string(i + 1),
- permitSet);
- if (pathStr.starts_with("/sys/bus/iio/devices"))
+ uint64_t bus = 0;
+ uint64_t addr = 0;
+ if (!getDeviceBusAddr(deviceName, bus, addr))
{
continue;
}
+
+ auto thisSensorParameters = getSensorParameters(path);
+ auto findSensorCfg = configMap.find({bus, addr});
+ if (findSensorCfg == configMap.end())
+ {
+ continue;
+ }
+
+ const std::string& interfacePath =
+ findSensorCfg->second.sensorPath;
+ auto findI2CDev = devices.find(interfacePath);
+
+ std::shared_ptr<I2CDevice> i2cDev;
+ if (findI2CDev != devices.end())
+ {
+ // If we're only looking to activate newly-instantiated i2c
+ // devices and this sensor's underlying device was already
+ // there before this call, there's nothing more to do here.
+ if (activateOnly && !findI2CDev->second.second)
+ {
+ continue;
+ }
+ i2cDev = findI2CDev->second.first;
+ }
+
+ const SensorData& sensorData = findSensorCfg->second.sensorData;
+ std::string sensorType = findSensorCfg->second.interface;
+ auto pos = sensorType.find_last_of('.');
+ if (pos != std::string::npos)
+ {
+ sensorType = sensorType.substr(pos + 1);
+ }
+ const SensorBaseConfigMap& baseConfigMap =
+ findSensorCfg->second.config;
+ std::vector<std::string>& hwmonName =
+ findSensorCfg->second.name;
+
+ // Temperature has "Name", pressure has "Name1"
+ auto findSensorName = baseConfigMap.find("Name");
+ int index = 1;
+ if (thisSensorParameters.typeName == "pressure" ||
+ thisSensorParameters.typeName == "humidity")
+ {
+ findSensorName = baseConfigMap.find("Name1");
+ index = 2;
+ }
+
+ if (findSensorName == baseConfigMap.end())
+ {
+ std::cerr << "could not determine configuration name for "
+ << deviceName << "\n";
+ continue;
+ }
+ std::string sensorName =
+ std::get<std::string>(findSensorName->second);
+ // on rescans, only update sensors we were signaled by
+ auto findSensor = sensors.find(sensorName);
+ if (!firstScan && findSensor != sensors.end())
+ {
+ bool found = false;
+ auto it = sensorsChanged->begin();
+ while (it != sensorsChanged->end())
+ {
+ if (it->ends_with(findSensor->second->name))
+ {
+ it = sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ break;
+ }
+ ++it;
+ }
+ if (!found)
+ {
+ continue;
+ }
+ }
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+
+ if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
+ nullptr, &index))
+ {
+ std::cerr << "error populating thresholds for "
+ << sensorName << " index " << index << "\n";
+ }
+
+ float pollRate = getPollRate(baseConfigMap, pollRateDefault);
+ PowerState readState = getPowerState(baseConfigMap);
+
+ auto permitSet = getPermitSet(baseConfigMap);
+ auto& sensor = sensors[sensorName];
+ if (!activateOnly)
+ {
+ sensor = nullptr;
+ }
+ auto hwmonFile = getFullHwmonFilePath(directory.string(),
+ "temp1", permitSet);
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
+ {
+ hwmonFile = pathStr;
+ }
if (hwmonFile)
{
- // To look up thresholds for these additional sensors,
- // match on the Index property in the threshold data
- // where the index comes from the sysfs file we're on,
- // i.e. index = 2 for temp2_input.
- int index = i + 1;
- std::vector<thresholds::Threshold> thresholds;
-
- if (!parseThresholdsFromConfig(sensorData, thresholds,
- nullptr, &index))
- {
- std::cerr << "error populating thresholds for "
- << sensorName << " index " << index << "\n";
- }
-
- auto& sensor = sensors[sensorName];
- if (!activateOnly)
- {
- sensor = nullptr;
- }
-
if (sensor != nullptr)
{
sensor->activate(*hwmonFile, i2cDev);
@@ -508,22 +452,84 @@
sensor = std::make_shared<HwmonTempSensor>(
*hwmonFile, sensorType, objectServer,
dbusConnection, io, sensorName,
- std::move(thresholds), thisSensorParameters,
+ std::move(sensorThresholds), thisSensorParameters,
pollRate, interfacePath, readState, i2cDev);
sensor->setupRead();
}
}
-
hwmonName.erase(
remove(hwmonName.begin(), hwmonName.end(), sensorName),
hwmonName.end());
+
+ // Looking for keys like "Name1" for temp2_input,
+ // "Name2" for temp3_input, etc.
+ int i = 0;
+ while (true)
+ {
+ ++i;
+ auto findKey =
+ baseConfigMap.find("Name" + std::to_string(i));
+ if (findKey == baseConfigMap.end())
+ {
+ break;
+ }
+ std::string sensorName =
+ std::get<std::string>(findKey->second);
+ hwmonFile = getFullHwmonFilePath(
+ directory.string(), "temp" + std::to_string(i + 1),
+ permitSet);
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
+ {
+ continue;
+ }
+ if (hwmonFile)
+ {
+ // To look up thresholds for these additional sensors,
+ // match on the Index property in the threshold data
+ // where the index comes from the sysfs file we're on,
+ // i.e. index = 2 for temp2_input.
+ int index = i + 1;
+ std::vector<thresholds::Threshold> thresholds;
+
+ if (!parseThresholdsFromConfig(sensorData, thresholds,
+ nullptr, &index))
+ {
+ std::cerr
+ << "error populating thresholds for "
+ << sensorName << " index " << index << "\n";
+ }
+
+ auto& sensor = sensors[sensorName];
+ if (!activateOnly)
+ {
+ sensor = nullptr;
+ }
+
+ if (sensor != nullptr)
+ {
+ sensor->activate(*hwmonFile, i2cDev);
+ }
+ else
+ {
+ sensor = std::make_shared<HwmonTempSensor>(
+ *hwmonFile, sensorType, objectServer,
+ dbusConnection, io, sensorName,
+ std::move(thresholds), thisSensorParameters,
+ pollRate, interfacePath, readState, i2cDev);
+ sensor->setupRead();
+ }
+ }
+
+ hwmonName.erase(
+ remove(hwmonName.begin(), hwmonName.end(), sensorName),
+ hwmonName.end());
+ }
+ if (hwmonName.empty())
+ {
+ configMap.erase(findSensorCfg);
+ }
}
- if (hwmonName.empty())
- {
- configMap.erase(findSensorCfg);
- }
- }
- });
+ });
std::vector<std::string> types(sensorTypes.size());
for (const auto& [type, dt] : sensorTypes)
{
@@ -615,30 +621,30 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- sensorsChanged->insert(message.get_path());
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ sensorsChanged->insert(message.get_path());
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- /* we were canceled*/
- return;
- }
- if (ec)
- {
- std::cerr << "timer error\n";
- return;
- }
- createSensors(io, objectServer, sensors, systemBus, sensorsChanged,
- false);
- });
- };
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ /* we were canceled*/
+ return;
+ }
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, sensors, systemBus,
+ sensorsChanged, false);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
@@ -651,8 +657,8 @@
"type='signal',member='InterfacesRemoved',arg0path='" +
std::string(inventoryPath) + "/'",
[&sensors](sdbusplus::message_t& msg) {
- interfaceRemoved(msg, sensors);
- });
+ interfaceRemoved(msg, sensors);
+ });
matches.emplace_back(std::move(ifaceRemovedMatch));