Apply LambdaBodyIndentation to dbus-sensors
Per the transform being done in bmcweb, do the same for dbus-sensors.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: If21489607759f3cdf20fad17eede50fb4e228e5e
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 50838a5..83bb9b6 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -164,42 +164,42 @@
conn->async_method_call(
[&objectServer, &sensors](boost::system::error_code& ec,
const ManagedObjectType& managedObj) {
- if (ec)
+ if (ec)
+ {
+ std::cerr << "Error calling entity manager \n";
+ return;
+ }
+ for (const auto& pathPair : managedObj)
+ {
+ for (const auto& interfacePair : pathPair.second)
{
- std::cerr << "Error calling entity manager \n";
- return;
- }
- for (const auto& pathPair : managedObj)
- {
- for (const auto& interfacePair : pathPair.second)
+ if (interfacePair.first == redundancyConfiguration)
{
- if (interfacePair.first == redundancyConfiguration)
+ // currently only support one
+ auto findCount =
+ interfacePair.second.find("AllowedFailures");
+ if (findCount == interfacePair.second.end())
{
- // currently only support one
- auto findCount =
- interfacePair.second.find("AllowedFailures");
- if (findCount == interfacePair.second.end())
- {
- std::cerr << "Malformed redundancy record \n";
- return;
- }
- std::vector<std::string> sensorList;
-
- for (const auto& sensor : sensors)
- {
- sensorList.push_back(
- "/xyz/openbmc_project/sensors/fan_tach/" +
- sensor.second->name);
- }
- systemRedundancy.reset();
- systemRedundancy.emplace(RedundancySensor(
- std::get<uint64_t>(findCount->second), sensorList,
- objectServer, pathPair.first));
-
+ std::cerr << "Malformed redundancy record \n";
return;
}
+ std::vector<std::string> sensorList;
+
+ for (const auto& sensor : sensors)
+ {
+ sensorList.push_back(
+ "/xyz/openbmc_project/sensors/fan_tach/" +
+ sensor.second->name);
+ }
+ systemRedundancy.reset();
+ systemRedundancy.emplace(RedundancySensor(
+ std::get<uint64_t>(findCount->second), sensorList,
+ objectServer, pathPair.first));
+
+ return;
}
}
+ }
},
"xyz.openbmc_project.EntityManager", "/",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
@@ -220,309 +220,300 @@
dbusConnection,
[&io, &objectServer, &tachSensors, &pwmSensors, &dbusConnection,
sensorsChanged](const ManagedObjectType& sensorConfigurations) {
- bool firstScan = sensorsChanged == nullptr;
- std::vector<fs::path> paths;
- if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)",
- paths))
+ bool firstScan = sensorsChanged == nullptr;
+ std::vector<fs::path> paths;
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", paths))
+ {
+ std::cerr << "No fan sensors in system\n";
+ return;
+ }
+
+ // iterate through all found fan sensors, and try to match them with
+ // configuration
+ for (const auto& path : paths)
+ {
+ std::smatch match;
+ std::string pathStr = path.string();
+
+ std::regex_search(pathStr, match, inputRegex);
+ std::string indexStr = *(match.begin() + 1);
+
+ fs::path directory = path.parent_path();
+ FanTypes fanType = getFanType(directory);
+
+ // convert to 0 based
+ size_t index = std::stoul(indexStr) - 1;
+
+ const char* baseType = nullptr;
+ const SensorData* sensorData = nullptr;
+ const std::string* interfacePath = nullptr;
+ const SensorBaseConfiguration* baseConfiguration = nullptr;
+ for (const std::pair<sdbusplus::message::object_path, SensorData>&
+ sensor : sensorConfigurations)
{
- std::cerr << "No fan sensors in system\n";
- return;
- }
-
- // iterate through all found fan sensors, and try to match them with
- // configuration
- for (const auto& path : paths)
- {
- std::smatch match;
- std::string pathStr = path.string();
-
- std::regex_search(pathStr, match, inputRegex);
- std::string indexStr = *(match.begin() + 1);
-
- fs::path directory = path.parent_path();
- FanTypes fanType = getFanType(directory);
-
- // convert to 0 based
- size_t index = std::stoul(indexStr) - 1;
-
- const char* baseType = nullptr;
- const SensorData* sensorData = nullptr;
- const std::string* interfacePath = nullptr;
- const SensorBaseConfiguration* baseConfiguration = nullptr;
- for (const std::pair<sdbusplus::message::object_path,
- SensorData>& sensor : sensorConfigurations)
+ // find the base of the configuration to see if indexes
+ // match
+ auto sensorBaseFind = sensor.second.find(sensorTypes[fanType]);
+ if (sensorBaseFind == sensor.second.end())
{
- // find the base of the configuration to see if indexes
- // match
- auto sensorBaseFind =
- sensor.second.find(sensorTypes[fanType]);
- if (sensorBaseFind == sensor.second.end())
+ continue;
+ }
+
+ baseConfiguration = &(*sensorBaseFind);
+ interfacePath = &(sensor.first.str);
+ baseType = sensorTypes[fanType];
+
+ auto findIndex = baseConfiguration->second.find("Index");
+ if (findIndex == baseConfiguration->second.end())
+ {
+ std::cerr << baseConfiguration->first << " missing index\n";
+ continue;
+ }
+ unsigned int configIndex = std::visit(
+ VariantToUnsignedIntVisitor(), findIndex->second);
+ if (configIndex != index)
+ {
+ continue;
+ }
+ if (fanType == FanTypes::aspeed || fanType == FanTypes::nuvoton)
+ {
+ // there will be only 1 aspeed or nuvoton sensor object
+ // in sysfs, we found the fan
+ sensorData = &(sensor.second);
+ break;
+ }
+ if (fanType == FanTypes::i2c)
+ {
+ size_t bus = 0;
+ size_t address = 0;
+
+ std::string link =
+ fs::read_symlink(directory / "device").filename();
+
+ size_t findDash = link.find('-');
+ if (findDash == std::string::npos ||
+ link.size() <= findDash + 1)
{
- continue;
+ std::cerr << "Error finding device from symlink";
}
+ bus = std::stoi(link.substr(0, findDash));
+ address = std::stoi(link.substr(findDash + 1), nullptr, 16);
- baseConfiguration = &(*sensorBaseFind);
- interfacePath = &(sensor.first.str);
- baseType = sensorTypes[fanType];
-
- auto findIndex = baseConfiguration->second.find("Index");
- if (findIndex == baseConfiguration->second.end())
+ auto findBus = baseConfiguration->second.find("Bus");
+ auto findAddress =
+ baseConfiguration->second.find("Address");
+ if (findBus == baseConfiguration->second.end() ||
+ findAddress == baseConfiguration->second.end())
{
std::cerr << baseConfiguration->first
- << " missing index\n";
+ << " missing bus or address\n";
continue;
}
- unsigned int configIndex = std::visit(
- VariantToUnsignedIntVisitor(), findIndex->second);
- if (configIndex != index)
+ unsigned int configBus = std::visit(
+ VariantToUnsignedIntVisitor(), findBus->second);
+ unsigned int configAddress = std::visit(
+ VariantToUnsignedIntVisitor(), findAddress->second);
+
+ if (configBus == bus && configAddress == address)
{
- continue;
- }
- if (fanType == FanTypes::aspeed ||
- fanType == FanTypes::nuvoton)
- {
- // there will be only 1 aspeed or nuvoton sensor object
- // in sysfs, we found the fan
sensorData = &(sensor.second);
break;
}
- if (fanType == FanTypes::i2c)
+ }
+ }
+ if (sensorData == nullptr)
+ {
+ std::cerr << "failed to find match for " << path.string()
+ << "\n";
+ continue;
+ }
+
+ auto findSensorName = baseConfiguration->second.find("Name");
+
+ if (findSensorName == baseConfiguration->second.end())
+ {
+ std::cerr << "could not determine configuration name for "
+ << path.string() << "\n";
+ continue;
+ }
+ std::string sensorName =
+ std::get<std::string>(findSensorName->second);
+
+ // on rescans, only update sensors we were signaled by
+ auto findSensor = tachSensors.find(sensorName);
+ if (!firstScan && findSensor != tachSensors.end())
+ {
+ bool found = false;
+ for (auto it = sensorsChanged->begin();
+ it != sensorsChanged->end(); it++)
+ {
+ if (boost::ends_with(*it, findSensor->second->name))
{
- size_t bus = 0;
- size_t address = 0;
-
- std::string link =
- fs::read_symlink(directory / "device").filename();
-
- size_t findDash = link.find('-');
- if (findDash == std::string::npos ||
- link.size() <= findDash + 1)
- {
- std::cerr << "Error finding device from symlink";
- }
- bus = std::stoi(link.substr(0, findDash));
- address =
- std::stoi(link.substr(findDash + 1), nullptr, 16);
-
- auto findBus = baseConfiguration->second.find("Bus");
- auto findAddress =
- baseConfiguration->second.find("Address");
- if (findBus == baseConfiguration->second.end() ||
- findAddress == baseConfiguration->second.end())
- {
- std::cerr << baseConfiguration->first
- << " missing bus or address\n";
- continue;
- }
- unsigned int configBus = std::visit(
- VariantToUnsignedIntVisitor(), findBus->second);
- unsigned int configAddress = std::visit(
- VariantToUnsignedIntVisitor(), findAddress->second);
-
- if (configBus == bus && configAddress == address)
- {
- sensorData = &(sensor.second);
- break;
- }
+ sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ break;
}
}
- if (sensorData == nullptr)
+ if (!found)
{
- std::cerr << "failed to find match for " << path.string()
- << "\n";
continue;
}
+ }
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << sensorName
+ << "\n";
+ }
- auto findSensorName = baseConfiguration->second.find("Name");
+ auto presenceConfig =
+ sensorData->find(baseType + std::string(".Presence"));
- if (findSensorName == baseConfiguration->second.end())
+ std::unique_ptr<PresenceSensor> presenceSensor(nullptr);
+
+ // presence sensors are optional
+ if (presenceConfig != sensorData->end())
+ {
+ auto findPolarity = presenceConfig->second.find("Polarity");
+ auto findPinName = presenceConfig->second.find("PinName");
+
+ if (findPinName == presenceConfig->second.end() ||
+ findPolarity == presenceConfig->second.end())
{
- std::cerr << "could not determine configuration name for "
- << path.string() << "\n";
- continue;
+ std::cerr << "Malformed Presence Configuration\n";
}
- std::string sensorName =
- std::get<std::string>(findSensorName->second);
-
- // on rescans, only update sensors we were signaled by
- auto findSensor = tachSensors.find(sensorName);
- if (!firstScan && findSensor != tachSensors.end())
+ else
{
- bool found = false;
- for (auto it = sensorsChanged->begin();
- it != sensorsChanged->end(); it++)
+ bool inverted =
+ std::get<std::string>(findPolarity->second) == "Low";
+ if (auto pinName =
+ std::get_if<std::string>(&findPinName->second))
{
- if (boost::ends_with(*it, findSensor->second->name))
- {
- sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- break;
- }
- }
- if (!found)
- {
- continue;
- }
- }
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
- {
- std::cerr << "error populating thresholds for "
- << sensorName << "\n";
- }
-
- auto presenceConfig =
- sensorData->find(baseType + std::string(".Presence"));
-
- std::unique_ptr<PresenceSensor> presenceSensor(nullptr);
-
- // presence sensors are optional
- if (presenceConfig != sensorData->end())
- {
- auto findPolarity = presenceConfig->second.find("Polarity");
- auto findPinName = presenceConfig->second.find("PinName");
-
- if (findPinName == presenceConfig->second.end() ||
- findPolarity == presenceConfig->second.end())
- {
- std::cerr << "Malformed Presence Configuration\n";
+ presenceSensor = std::make_unique<PresenceSensor>(
+ *pinName, inverted, io, sensorName);
}
else
{
- bool inverted = std::get<std::string>(
- findPolarity->second) == "Low";
- if (auto pinName =
- std::get_if<std::string>(&findPinName->second))
- {
- presenceSensor = std::make_unique<PresenceSensor>(
- *pinName, inverted, io, sensorName);
- }
- else
- {
- std::cerr
- << "Malformed Presence pinName for sensor "
- << sensorName << " \n";
- }
+ std::cerr << "Malformed Presence pinName for sensor "
+ << sensorName << " \n";
}
}
- std::optional<RedundancySensor>* redundancy = nullptr;
- if (fanType == FanTypes::aspeed)
+ }
+ std::optional<RedundancySensor>* redundancy = nullptr;
+ if (fanType == FanTypes::aspeed)
+ {
+ redundancy = &systemRedundancy;
+ }
+
+ PowerState powerState = PowerState::on;
+ auto findPower = baseConfiguration->second.find("PowerState");
+ if (findPower != baseConfiguration->second.end())
+ {
+ auto ptrPower = std::get_if<std::string>(&(findPower->second));
+ if (ptrPower)
{
- redundancy = &systemRedundancy;
- }
-
- PowerState powerState = PowerState::on;
- auto findPower = baseConfiguration->second.find("PowerState");
- if (findPower != baseConfiguration->second.end())
- {
- auto ptrPower =
- std::get_if<std::string>(&(findPower->second));
- if (ptrPower)
- {
- setReadState(*ptrPower, powerState);
- }
- }
-
- constexpr double defaultMaxReading = 25000;
- constexpr double defaultMinReading = 0;
- std::pair<double, double> limits =
- std::make_pair(defaultMinReading, defaultMaxReading);
-
- auto connector =
- sensorData->find(baseType + std::string(".Connector"));
-
- std::optional<std::string> led;
- std::string pwmName;
- fs::path pwmPath;
-
- // The Mutable parameter is optional, defaulting to false
- bool isValueMutable = false;
- if (connector != sensorData->end())
- {
- auto findPwm = connector->second.find("Pwm");
- if (findPwm != connector->second.end())
- {
- size_t pwm = std::visit(VariantToUnsignedIntVisitor(),
- findPwm->second);
- if (!findPwmPath(directory, pwm, pwmPath))
- {
- std::cerr << "Connector for " << sensorName
- << " no pwm channel found!\n";
- continue;
- }
-
- fs::path pwmEnableFile =
- "pwm" + std::to_string(pwm + 1) + "_enable";
- fs::path enablePath =
- pwmPath.parent_path() / pwmEnableFile;
- enablePwm(enablePath);
-
- /* use pwm name override if found in configuration else
- * use default */
- auto findOverride = connector->second.find("PwmName");
- if (findOverride != connector->second.end())
- {
- pwmName = std::visit(VariantToStringVisitor(),
- findOverride->second);
- }
- else
- {
- pwmName = "Pwm_" + std::to_string(pwm + 1);
- }
-
- // Check PWM sensor mutability
- auto findMutable = connector->second.find("Mutable");
- if (findMutable != connector->second.end())
- {
- auto ptrMutable =
- std::get_if<bool>(&(findMutable->second));
- if (ptrMutable)
- {
- isValueMutable = *ptrMutable;
- }
- }
- }
- else
- {
- std::cerr << "Connector for " << sensorName
- << " missing pwm!\n";
- }
-
- auto findLED = connector->second.find("LED");
- if (findLED != connector->second.end())
- {
- auto ledName =
- std::get_if<std::string>(&(findLED->second));
- if (ledName == nullptr)
- {
- std::cerr << "Wrong format for LED of "
- << sensorName << "\n";
- }
- else
- {
- led = *ledName;
- }
- }
- }
-
- findLimits(limits, baseConfiguration);
- tachSensors[sensorName] = std::make_unique<TachSensor>(
- path.string(), baseType, objectServer, dbusConnection,
- std::move(presenceSensor), redundancy, io, sensorName,
- std::move(sensorThresholds), *interfacePath, limits,
- powerState, led);
-
- if (!pwmPath.empty() && fs::exists(pwmPath) &&
- !pwmSensors.count(pwmPath))
- {
- pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
- pwmName, pwmPath, dbusConnection, objectServer,
- *interfacePath, "Fan", isValueMutable);
+ setReadState(*ptrPower, powerState);
}
}
- createRedundancySensor(tachSensors, dbusConnection, objectServer);
+ constexpr double defaultMaxReading = 25000;
+ constexpr double defaultMinReading = 0;
+ std::pair<double, double> limits =
+ std::make_pair(defaultMinReading, defaultMaxReading);
+
+ auto connector =
+ sensorData->find(baseType + std::string(".Connector"));
+
+ std::optional<std::string> led;
+ std::string pwmName;
+ fs::path pwmPath;
+
+ // The Mutable parameter is optional, defaulting to false
+ bool isValueMutable = false;
+ if (connector != sensorData->end())
+ {
+ auto findPwm = connector->second.find("Pwm");
+ if (findPwm != connector->second.end())
+ {
+ size_t pwm = std::visit(VariantToUnsignedIntVisitor(),
+ findPwm->second);
+ if (!findPwmPath(directory, pwm, pwmPath))
+ {
+ std::cerr << "Connector for " << sensorName
+ << " no pwm channel found!\n";
+ continue;
+ }
+
+ fs::path pwmEnableFile =
+ "pwm" + std::to_string(pwm + 1) + "_enable";
+ fs::path enablePath = pwmPath.parent_path() / pwmEnableFile;
+ enablePwm(enablePath);
+
+ /* use pwm name override if found in configuration else
+ * use default */
+ auto findOverride = connector->second.find("PwmName");
+ if (findOverride != connector->second.end())
+ {
+ pwmName = std::visit(VariantToStringVisitor(),
+ findOverride->second);
+ }
+ else
+ {
+ pwmName = "Pwm_" + std::to_string(pwm + 1);
+ }
+
+ // Check PWM sensor mutability
+ auto findMutable = connector->second.find("Mutable");
+ if (findMutable != connector->second.end())
+ {
+ auto ptrMutable =
+ std::get_if<bool>(&(findMutable->second));
+ if (ptrMutable)
+ {
+ isValueMutable = *ptrMutable;
+ }
+ }
+ }
+ else
+ {
+ std::cerr << "Connector for " << sensorName
+ << " missing pwm!\n";
+ }
+
+ auto findLED = connector->second.find("LED");
+ if (findLED != connector->second.end())
+ {
+ auto ledName = std::get_if<std::string>(&(findLED->second));
+ if (ledName == nullptr)
+ {
+ std::cerr << "Wrong format for LED of " << sensorName
+ << "\n";
+ }
+ else
+ {
+ led = *ledName;
+ }
+ }
+ }
+
+ findLimits(limits, baseConfiguration);
+ tachSensors[sensorName] = std::make_unique<TachSensor>(
+ path.string(), baseType, objectServer, dbusConnection,
+ std::move(presenceSensor), redundancy, io, sensorName,
+ std::move(sensorThresholds), *interfacePath, limits, powerState,
+ led);
+
+ if (!pwmPath.empty() && fs::exists(pwmPath) &&
+ !pwmSensors.count(pwmPath))
+ {
+ pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
+ pwmName, pwmPath, dbusConnection, objectServer,
+ *interfacePath, "Fan", isValueMutable);
+ }
+ }
+
+ createRedundancySensor(tachSensors, dbusConnection, objectServer);
});
getter->getConfiguration(
std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()},
@@ -551,30 +542,30 @@
boost::asio::deadline_timer filterTimer(io);
std::function<void(sdbusplus::message::message&)> eventHandler =
[&](sdbusplus::message::message& message) {
- if (message.is_method_error())
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ sensorsChanged->insert(message.get_path());
+ // this implicitly cancels the timer
+ filterTimer.expires_from_now(boost::posix_time::seconds(1));
+
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
{
- std::cerr << "callback method error\n";
+ /* we were canceled*/
return;
}
- sensorsChanged->insert(message.get_path());
- // this implicitly cancels the timer
- filterTimer.expires_from_now(boost::posix_time::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, tachSensors, pwmSensors,
- systemBus, sensorsChanged, 5);
- });
- };
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, tachSensors, pwmSensors, systemBus,
+ sensorsChanged, 5);
+ });
+ };
for (const char* type : sensorTypes)
{
@@ -590,8 +581,8 @@
std::function<void(sdbusplus::message::message&)> redundancyHandler =
[&tachSensors, &systemBus,
&objectServer](sdbusplus::message::message&) {
- createRedundancySensor(tachSensors, systemBus, objectServer);
- };
+ createRedundancySensor(tachSensors, systemBus, objectServer);
+ };
auto match = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
"type='signal',member='PropertiesChanged',path_namespace='" +