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/ADCSensor.cpp b/src/ADCSensor.cpp
index a8287b4..d9456cd 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -114,27 +114,27 @@
boost::posix_time::milliseconds(bridgeGpio->setupTimeMs));
waitTimer.async_wait(
[weakRef, buffer](const boost::system::error_code& ec) {
- std::shared_ptr<ADCSensor> self = weakRef.lock();
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
+ std::shared_ptr<ADCSensor> self = weakRef.lock();
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
- if (self)
- {
- boost::asio::async_read_until(
- self->inputDev, *buffer, '\n',
- [weakRef, buffer](const boost::system::error_code& ec,
- std::size_t /*bytes_transfered*/) {
- std::shared_ptr<ADCSensor> self = weakRef.lock();
- if (self)
- {
- self->readBuf = buffer;
- self->handleResponse(ec);
- }
- });
- }
- });
+ if (self)
+ {
+ boost::asio::async_read_until(
+ self->inputDev, *buffer, '\n',
+ [weakRef, buffer](const boost::system::error_code& ec,
+ std::size_t /*bytes_transfered*/) {
+ std::shared_ptr<ADCSensor> self = weakRef.lock();
+ if (self)
+ {
+ self->readBuf = buffer;
+ self->handleResponse(ec);
+ }
+ });
+ }
+ });
}
else
{
@@ -142,12 +142,12 @@
inputDev, *buffer, '\n',
[weakRef, buffer](const boost::system::error_code& ec,
std::size_t /*bytes_transfered*/) {
- std::shared_ptr<ADCSensor> self = weakRef.lock();
- if (self)
- {
- self->readBuf = buffer;
- self->handleResponse(ec);
- }
+ std::shared_ptr<ADCSensor> self = weakRef.lock();
+ if (self)
+ {
+ self->readBuf = buffer;
+ self->handleResponse(ec);
+ }
});
}
}
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 401da12..8e973e7 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -83,239 +83,234 @@
dbusConnection,
[&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
updateType](const ManagedObjectType& sensorConfigurations) {
- bool firstScan = sensorsChanged == nullptr;
- std::vector<fs::path> paths;
- if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)",
- paths))
+ bool firstScan = sensorsChanged == nullptr;
+ std::vector<fs::path> paths;
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)", paths))
+ {
+ std::cerr << "No adc sensors in system\n";
+ return;
+ }
+
+ // iterate through all found adc sensors, and try to match them with
+ // configuration
+ for (auto& path : paths)
+ {
+ if (!isAdc(path.parent_path()))
{
- std::cerr << "No adc sensors in system\n";
- return;
+ continue;
}
+ std::smatch match;
+ std::string pathStr = path.string();
- // iterate through all found adc sensors, and try to match them with
- // configuration
- for (auto& path : paths)
+ 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;
+
+ const SensorData* sensorData = nullptr;
+ const std::string* interfacePath = nullptr;
+ const std::pair<std::string, boost::container::flat_map<
+ std::string, BasicVariantType>>*
+ baseConfiguration = nullptr;
+ for (const std::pair<sdbusplus::message::object_path, SensorData>&
+ sensor : sensorConfigurations)
{
- if (!isAdc(path.parent_path()))
+ // clear it out each loop
+ baseConfiguration = nullptr;
+
+ // find base configuration
+ for (const char* type : sensorTypes)
{
- continue;
- }
- std::smatch match;
- std::string pathStr = path.string();
-
- 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;
-
- const SensorData* sensorData = nullptr;
- const std::string* interfacePath = nullptr;
- const std::pair<
- std::string,
- boost::container::flat_map<std::string, BasicVariantType>>*
- baseConfiguration = nullptr;
- for (const std::pair<sdbusplus::message::object_path,
- SensorData>& sensor : sensorConfigurations)
- {
- // clear it out each loop
- baseConfiguration = nullptr;
-
- // find base configuration
- for (const char* type : sensorTypes)
+ auto sensorBase = sensor.second.find(type);
+ if (sensorBase != sensor.second.end())
{
- auto sensorBase = sensor.second.find(type);
- if (sensorBase != sensor.second.end())
- {
- baseConfiguration = &(*sensorBase);
- break;
- }
- }
- if (baseConfiguration == nullptr)
- {
- continue;
- }
- auto findIndex = baseConfiguration->second.find("Index");
- if (findIndex == baseConfiguration->second.end())
- {
- std::cerr << "Base configuration missing Index"
- << baseConfiguration->first << "\n";
- continue;
- }
-
- unsigned int number = std::visit(
- VariantToUnsignedIntVisitor(), findIndex->second);
-
- if (number != index)
- {
- continue;
- }
-
- sensorData = &(sensor.second);
- interfacePath = &(sensor.first.str);
- break;
- }
- if (sensorData == nullptr)
- {
- std::cerr << "failed to find match for " << path.string()
- << "\n";
- continue;
- }
-
- if (baseConfiguration == nullptr)
- {
- std::cerr << "error finding base configuration 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 = sensors.find(sensorName);
- if (!firstScan && findSensor != sensors.end())
- {
- bool found = false;
- for (auto it = sensorsChanged->begin();
- it != sensorsChanged->end(); it++)
- {
- if (findSensor->second &&
- boost::ends_with(*it, findSensor->second->name))
- {
- sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- break;
- }
- }
- if (!found)
- {
- continue;
- }
- }
-
- auto findCPU = baseConfiguration->second.find("CPURequired");
- if (findCPU != baseConfiguration->second.end())
- {
- size_t index =
- std::visit(VariantToIntVisitor(), findCPU->second);
- auto presenceFind = cpuPresence.find(index);
- if (presenceFind == cpuPresence.end())
- {
- continue; // no such cpu
- }
- if (!presenceFind->second)
- {
- continue; // cpu not installed
- }
- }
- else if (updateType == UpdateType::cpuPresenceChange)
- {
- continue;
- }
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
- {
- std::cerr << "error populating thresholds for "
- << sensorName << "\n";
- }
-
- auto findScaleFactor =
- baseConfiguration->second.find("ScaleFactor");
- float scaleFactor = 1.0;
- if (findScaleFactor != baseConfiguration->second.end())
- {
- scaleFactor = std::visit(VariantToFloatVisitor(),
- findScaleFactor->second);
- // scaleFactor is used in division
- if (scaleFactor == 0.0f)
- {
- scaleFactor = 1.0;
- }
- }
-
- auto findPollRate = baseConfiguration->second.find("PollRate");
- float pollRate = pollRateDefault;
- if (findPollRate != baseConfiguration->second.end())
- {
- pollRate = std::visit(VariantToFloatVisitor(),
- findPollRate->second);
- if (pollRate <= 0.0f)
- {
- pollRate = pollRateDefault; // polling time too short
- }
- }
-
- auto findPowerOn = baseConfiguration->second.find("PowerState");
- PowerState readState = PowerState::always;
- if (findPowerOn != baseConfiguration->second.end())
- {
- std::string powerState = std::visit(
- VariantToStringVisitor(), findPowerOn->second);
- setReadState(powerState, readState);
- }
-
- auto& sensor = sensors[sensorName];
- sensor = nullptr;
-
- std::optional<BridgeGpio> bridgeGpio;
- for (const SensorBaseConfiguration& suppConfig : *sensorData)
- {
- if (suppConfig.first.find("BridgeGpio") !=
- std::string::npos)
- {
- auto findName = suppConfig.second.find("Name");
- if (findName != suppConfig.second.end())
- {
- std::string gpioName = std::visit(
- VariantToStringVisitor(), findName->second);
-
- int polarity = gpiod::line::ACTIVE_HIGH;
- auto findPolarity =
- suppConfig.second.find("Polarity");
- if (findPolarity != suppConfig.second.end())
- {
- if (std::string("Low") ==
- std::visit(VariantToStringVisitor(),
- findPolarity->second))
- {
- polarity = gpiod::line::ACTIVE_LOW;
- }
- }
-
- float setupTime = gpioBridgeSetupTimeDefault;
- auto findSetupTime =
- suppConfig.second.find("SetupTime");
- if (findSetupTime != suppConfig.second.end())
- {
- setupTime = std::visit(VariantToFloatVisitor(),
- findSetupTime->second);
- }
-
- bridgeGpio =
- BridgeGpio(gpioName, polarity, setupTime);
- }
-
+ baseConfiguration = &(*sensorBase);
break;
}
}
+ if (baseConfiguration == nullptr)
+ {
+ continue;
+ }
+ auto findIndex = baseConfiguration->second.find("Index");
+ if (findIndex == baseConfiguration->second.end())
+ {
+ std::cerr << "Base configuration missing Index"
+ << baseConfiguration->first << "\n";
+ continue;
+ }
- sensor = std::make_shared<ADCSensor>(
- path.string(), objectServer, dbusConnection, io, sensorName,
- std::move(sensorThresholds), scaleFactor, pollRate,
- readState, *interfacePath, std::move(bridgeGpio));
- sensor->setupRead();
+ unsigned int number = std::visit(VariantToUnsignedIntVisitor(),
+ findIndex->second);
+
+ if (number != index)
+ {
+ continue;
+ }
+
+ sensorData = &(sensor.second);
+ interfacePath = &(sensor.first.str);
+ break;
}
+ if (sensorData == nullptr)
+ {
+ std::cerr << "failed to find match for " << path.string()
+ << "\n";
+ continue;
+ }
+
+ if (baseConfiguration == nullptr)
+ {
+ std::cerr << "error finding base configuration 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 = sensors.find(sensorName);
+ if (!firstScan && findSensor != sensors.end())
+ {
+ bool found = false;
+ for (auto it = sensorsChanged->begin();
+ it != sensorsChanged->end(); it++)
+ {
+ if (findSensor->second &&
+ boost::ends_with(*it, findSensor->second->name))
+ {
+ sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ continue;
+ }
+ }
+
+ auto findCPU = baseConfiguration->second.find("CPURequired");
+ if (findCPU != baseConfiguration->second.end())
+ {
+ size_t index =
+ std::visit(VariantToIntVisitor(), findCPU->second);
+ auto presenceFind = cpuPresence.find(index);
+ if (presenceFind == cpuPresence.end())
+ {
+ continue; // no such cpu
+ }
+ if (!presenceFind->second)
+ {
+ continue; // cpu not installed
+ }
+ }
+ else if (updateType == UpdateType::cpuPresenceChange)
+ {
+ continue;
+ }
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << sensorName
+ << "\n";
+ }
+
+ auto findScaleFactor =
+ baseConfiguration->second.find("ScaleFactor");
+ float scaleFactor = 1.0;
+ if (findScaleFactor != baseConfiguration->second.end())
+ {
+ scaleFactor = std::visit(VariantToFloatVisitor(),
+ findScaleFactor->second);
+ // scaleFactor is used in division
+ if (scaleFactor == 0.0f)
+ {
+ scaleFactor = 1.0;
+ }
+ }
+
+ auto findPollRate = baseConfiguration->second.find("PollRate");
+ float pollRate = pollRateDefault;
+ if (findPollRate != baseConfiguration->second.end())
+ {
+ pollRate =
+ std::visit(VariantToFloatVisitor(), findPollRate->second);
+ if (pollRate <= 0.0f)
+ {
+ pollRate = pollRateDefault; // polling time too short
+ }
+ }
+
+ auto findPowerOn = baseConfiguration->second.find("PowerState");
+ PowerState readState = PowerState::always;
+ if (findPowerOn != baseConfiguration->second.end())
+ {
+ std::string powerState =
+ std::visit(VariantToStringVisitor(), findPowerOn->second);
+ setReadState(powerState, readState);
+ }
+
+ auto& sensor = sensors[sensorName];
+ sensor = nullptr;
+
+ std::optional<BridgeGpio> bridgeGpio;
+ for (const SensorBaseConfiguration& suppConfig : *sensorData)
+ {
+ if (suppConfig.first.find("BridgeGpio") != std::string::npos)
+ {
+ auto findName = suppConfig.second.find("Name");
+ if (findName != suppConfig.second.end())
+ {
+ std::string gpioName = std::visit(
+ VariantToStringVisitor(), findName->second);
+
+ int polarity = gpiod::line::ACTIVE_HIGH;
+ auto findPolarity = suppConfig.second.find("Polarity");
+ if (findPolarity != suppConfig.second.end())
+ {
+ if (std::string("Low") ==
+ std::visit(VariantToStringVisitor(),
+ findPolarity->second))
+ {
+ polarity = gpiod::line::ACTIVE_LOW;
+ }
+ }
+
+ float setupTime = gpioBridgeSetupTimeDefault;
+ auto findSetupTime =
+ suppConfig.second.find("SetupTime");
+ if (findSetupTime != suppConfig.second.end())
+ {
+ setupTime = std::visit(VariantToFloatVisitor(),
+ findSetupTime->second);
+ }
+
+ bridgeGpio = BridgeGpio(gpioName, polarity, setupTime);
+ }
+
+ break;
+ }
+ }
+
+ sensor = std::make_shared<ADCSensor>(
+ path.string(), objectServer, dbusConnection, io, sensorName,
+ std::move(sensorThresholds), scaleFactor, pollRate, readState,
+ *interfacePath, std::move(bridgeGpio));
+ sensor->setupRead();
+ }
});
getter->getConfiguration(
@@ -341,78 +336,78 @@
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, sensors, systemBus,
- sensorsChanged, UpdateType::init);
- });
- };
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, sensors, systemBus, sensorsChanged,
+ UpdateType::init);
+ });
+ };
std::function<void(sdbusplus::message::message&)> cpuPresenceHandler =
[&](sdbusplus::message::message& message) {
- std::string path = message.get_path();
- boost::to_lower(path);
+ std::string path = message.get_path();
+ boost::to_lower(path);
- if (path.rfind("cpu") == std::string::npos)
+ if (path.rfind("cpu") == std::string::npos)
+ {
+ return; // not interested
+ }
+ size_t index = 0;
+ try
+ {
+ index = std::stoi(path.substr(path.size() - 1));
+ }
+ catch (const std::invalid_argument&)
+ {
+ std::cerr << "Found invalid path " << path << "\n";
+ return;
+ }
+
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<bool>> values;
+ message.read(objectName, values);
+ auto findPresence = values.find("Present");
+ if (findPresence != values.end())
+ {
+ cpuPresence[index] = std::get<bool>(findPresence->second);
+ }
+
+ // 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)
{
- return; // not interested
- }
- size_t index = 0;
- try
- {
- index = std::stoi(path.substr(path.size() - 1));
- }
- catch (const std::invalid_argument&)
- {
- std::cerr << "Found invalid path " << path << "\n";
+ /* we were canceled*/
return;
}
-
- std::string objectName;
- boost::container::flat_map<std::string, std::variant<bool>> values;
- message.read(objectName, values);
- auto findPresence = values.find("Present");
- if (findPresence != values.end())
+ if (ec)
{
- cpuPresence[index] = std::get<bool>(findPresence->second);
+ std::cerr << "timer error\n";
+ return;
}
-
- // 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, sensors, systemBus, nullptr,
- UpdateType::cpuPresenceChange);
- });
- };
+ createSensors(io, objectServer, sensors, systemBus, nullptr,
+ UpdateType::cpuPresenceChange);
+ });
+ };
for (const char* type : sensorTypes)
{
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index b95c76a..06d0a69 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -156,13 +156,13 @@
std::weak_ptr<CPUSensor> weakRef = weak_from_this();
inputDev.async_wait(boost::asio::posix::descriptor_base::wait_read,
[weakRef](const boost::system::error_code& ec) {
- std::shared_ptr<CPUSensor> self = weakRef.lock();
+ std::shared_ptr<CPUSensor> self = weakRef.lock();
- if (self)
- {
- self->handleResponse(ec);
- }
- });
+ if (self)
+ {
+ self->handleResponse(ec);
+ }
+ });
}
void CPUSensor::updateMinMaxValues(void)
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index 4f377aa..9d5bda4 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -116,20 +116,20 @@
bool isWordEnd = true;
std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(),
[&isWordEnd](int c) {
- if (std::isspace(c))
- {
- isWordEnd = true;
- }
- else
- {
- if (isWordEnd)
- {
- isWordEnd = false;
- return std::toupper(c);
- }
- }
- return c;
- });
+ if (std::isspace(c))
+ {
+ isWordEnd = true;
+ }
+ else
+ {
+ if (isWordEnd)
+ {
+ isWordEnd = false;
+ return std::toupper(c);
+ }
+ }
+ return c;
+ });
return sensorName;
}
@@ -737,33 +737,33 @@
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;
+ }
+
+ if (debug)
+ {
+ std::cout << message.get_path() << " is changed\n";
+ }
+
+ // 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";
- return;
+ return; // we're being canceled
}
- if (debug)
+ if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
+ objectServer))
{
- std::cout << message.get_path() << " is changed\n";
+ detectCpuAsync(pingTimer, creationTimer, io, objectServer,
+ systemBus, cpuConfigs, sensorConfigs);
}
-
- // 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)
- {
- return; // we're being canceled
- }
-
- if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
- objectServer))
- {
- detectCpuAsync(pingTimer, creationTimer, io, objectServer,
- systemBus, cpuConfigs, sensorConfigs);
- }
- });
- };
+ });
+ };
for (const char* type : sensorTypes)
{
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp
index 9b35da2..d480055 100644
--- a/src/ChassisIntrusionSensor.cpp
+++ b/src/ChassisIntrusionSensor.cpp
@@ -199,24 +199,22 @@
void ChassisIntrusionSensor::pollSensorStatusByGpio(void)
{
- mGpioFd.async_wait(
- boost::asio::posix::stream_descriptor::wait_read,
- [this](const boost::system::error_code& ec) {
- if (ec == boost::system::errc::bad_file_descriptor)
- {
- return; // we're being destroyed
- }
- if (ec)
- {
- std::cerr
- << "Error on GPIO based intrusion sensor wait event\n";
- }
- else
- {
- readGpio();
- }
- pollSensorStatusByGpio();
- });
+ mGpioFd.async_wait(boost::asio::posix::stream_descriptor::wait_read,
+ [this](const boost::system::error_code& ec) {
+ if (ec == boost::system::errc::bad_file_descriptor)
+ {
+ return; // we're being destroyed
+ }
+ if (ec)
+ {
+ std::cerr << "Error on GPIO based intrusion sensor wait event\n";
+ }
+ else
+ {
+ readGpio();
+ }
+ pollSensorStatusByGpio();
+ });
}
void ChassisIntrusionSensor::initGpioDeviceFile()
@@ -315,7 +313,7 @@
mIface->register_property(
"Status", mValue,
[&](const std::string& req, std::string& propertyValue) {
- return setSensorValue(req, propertyValue);
+ return setSensorValue(req, propertyValue);
});
mIface->initialize();
diff --git a/src/ExitAirTempSensor.cpp b/src/ExitAirTempSensor.cpp
index 58f7468..4d77ef4 100644
--- a/src/ExitAirTempSensor.cpp
+++ b/src/ExitAirTempSensor.cpp
@@ -70,25 +70,23 @@
std::function<void(sdbusplus::message::message & message)> eventHandler =
[callback{std::move(callback)}](sdbusplus::message::message& message) {
- std::string objectName;
- boost::container::flat_map<std::string,
- std::variant<double, int64_t>>
- values;
- message.read(objectName, values);
- auto findValue = values.find("Value");
- if (findValue == values.end())
- {
- return;
- }
- double value =
- std::visit(VariantToDoubleVisitor(), findValue->second);
- if (std::isnan(value))
- {
- return;
- }
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<double, int64_t>>
+ values;
+ message.read(objectName, values);
+ auto findValue = values.find("Value");
+ if (findValue == values.end())
+ {
+ return;
+ }
+ double value = std::visit(VariantToDoubleVisitor(), findValue->second);
+ if (std::isnan(value))
+ {
+ return;
+ }
- callback(value, message);
- };
+ callback(value, message);
+ };
matches.emplace_back(connection,
"type='signal',"
"member='PropertiesChanged',interface='org."
@@ -109,48 +107,48 @@
conn->async_method_call(
[conn, value](const boost::system::error_code ec,
const GetSubTreeType& ret) {
- if (ec)
+ if (ec)
+ {
+ std::cerr << "Error calling mapper\n";
+ return;
+ }
+ for (const auto& [path, objDict] : ret)
+ {
+ if (objDict.empty())
{
- std::cerr << "Error calling mapper\n";
return;
}
- for (const auto& [path, objDict] : ret)
- {
- if (objDict.empty())
+ const std::string& owner = objDict.begin()->first;
+
+ conn->async_method_call(
+ [conn, value, owner,
+ path{path}](const boost::system::error_code ec,
+ const std::variant<std::string>& classType) {
+ if (ec)
+ {
+ std::cerr << "Error getting pid class\n";
+ return;
+ }
+ auto classStr = std::get_if<std::string>(&classType);
+ if (classStr == nullptr || *classStr != "fan")
{
return;
}
- const std::string& owner = objDict.begin()->first;
-
conn->async_method_call(
- [conn, value, owner,
- path{path}](const boost::system::error_code ec,
- const std::variant<std::string>& classType) {
- if (ec)
- {
- std::cerr << "Error getting pid class\n";
- return;
- }
- auto classStr = std::get_if<std::string>(&classType);
- if (classStr == nullptr || *classStr != "fan")
- {
- return;
- }
- conn->async_method_call(
- [](boost::system::error_code& ec) {
- if (ec)
- {
- std::cerr << "Error setting pid class\n";
- return;
- }
- },
- owner, path, "org.freedesktop.DBus.Properties",
- "Set", pidConfigurationType, "OutLimitMax",
- std::variant<double>(value));
+ [](boost::system::error_code& ec) {
+ if (ec)
+ {
+ std::cerr << "Error setting pid class\n";
+ return;
+ }
},
- owner, path, "org.freedesktop.DBus.Properties", "Get",
- pidConfigurationType, "Class");
- }
+ owner, path, "org.freedesktop.DBus.Properties", "Set",
+ pidConfigurationType, "OutLimitMax",
+ std::variant<double>(value));
+ },
+ owner, path, "org.freedesktop.DBus.Properties", "Get",
+ pidConfigurationType, "Class");
+ }
},
mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/",
0, std::array<std::string, 1>{pidConfigurationType});
@@ -200,87 +198,84 @@
setupSensorMatch(
matches, *dbusConnection, "fan_tach",
[weakRef](const double& value, sdbusplus::message::message& message) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- self->tachReadings[message.get_path()] = value;
- if (self->tachRanges.find(message.get_path()) ==
- self->tachRanges.end())
- {
- // calls update reading after updating ranges
- self->addTachRanges(message.get_sender(), message.get_path());
- }
- else
- {
- self->updateReading();
- }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->tachReadings[message.get_path()] = value;
+ if (self->tachRanges.find(message.get_path()) == self->tachRanges.end())
+ {
+ // calls update reading after updating ranges
+ self->addTachRanges(message.get_sender(), message.get_path());
+ }
+ else
+ {
+ self->updateReading();
+ }
});
dbusConnection->async_method_call(
[weakRef](const boost::system::error_code ec,
const std::variant<double> cfmVariant) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
- uint64_t maxRpm = 100;
- if (!ec)
- {
+ uint64_t maxRpm = 100;
+ if (!ec)
+ {
- auto cfm = std::get_if<double>(&cfmVariant);
- if (cfm != nullptr && *cfm >= minSystemCfm)
- {
- maxRpm = self->getMaxRpm(*cfm);
- }
+ auto cfm = std::get_if<double>(&cfmVariant);
+ if (cfm != nullptr && *cfm >= minSystemCfm)
+ {
+ maxRpm = self->getMaxRpm(*cfm);
}
- self->pwmLimitIface->register_property("Limit", maxRpm);
- self->pwmLimitIface->initialize();
- setMaxPWM(self->dbusConnection, maxRpm);
+ }
+ self->pwmLimitIface->register_property("Limit", maxRpm);
+ self->pwmLimitIface->initialize();
+ setMaxPWM(self->dbusConnection, maxRpm);
},
settingsDaemon, cfmSettingPath, "org.freedesktop.DBus.Properties",
"Get", cfmSettingIface, "Limit");
- matches.emplace_back(
- *dbusConnection,
- "type='signal',"
- "member='PropertiesChanged',interface='org."
- "freedesktop.DBus.Properties',path='" +
- std::string(cfmSettingPath) + "',arg0='" +
- std::string(cfmSettingIface) + "'",
- [weakRef](sdbusplus::message::message& message) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- boost::container::flat_map<std::string, std::variant<double>>
- values;
- std::string objectName;
- message.read(objectName, values);
- const auto findValue = values.find("Limit");
- if (findValue == values.end())
- {
- return;
- }
- const auto reading = std::get_if<double>(&(findValue->second));
- if (reading == nullptr)
- {
- std::cerr << "Got CFM Limit of wrong type\n";
- return;
- }
- if (*reading < minSystemCfm && *reading != 0)
- {
- std::cerr << "Illegal CFM setting detected\n";
- return;
- }
- uint64_t maxRpm = self->getMaxRpm(*reading);
- self->pwmLimitIface->set_property("Limit", maxRpm);
- setMaxPWM(self->dbusConnection, maxRpm);
- });
+ matches.emplace_back(*dbusConnection,
+ "type='signal',"
+ "member='PropertiesChanged',interface='org."
+ "freedesktop.DBus.Properties',path='" +
+ std::string(cfmSettingPath) + "',arg0='" +
+ std::string(cfmSettingIface) + "'",
+ [weakRef](sdbusplus::message::message& message) {
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ boost::container::flat_map<std::string, std::variant<double>> values;
+ std::string objectName;
+ message.read(objectName, values);
+ const auto findValue = values.find("Limit");
+ if (findValue == values.end())
+ {
+ return;
+ }
+ const auto reading = std::get_if<double>(&(findValue->second));
+ if (reading == nullptr)
+ {
+ std::cerr << "Got CFM Limit of wrong type\n";
+ return;
+ }
+ if (*reading < minSystemCfm && *reading != 0)
+ {
+ std::cerr << "Illegal CFM setting detected\n";
+ return;
+ }
+ uint64_t maxRpm = self->getMaxRpm(*reading);
+ self->pwmLimitIface->set_property("Limit", maxRpm);
+ setMaxPWM(self->dbusConnection, maxRpm);
+ });
}
CFMSensor::~CFMSensor()
@@ -310,20 +305,20 @@
path](const boost::system::error_code ec,
const boost::container::flat_map<std::string, BasicVariantType>&
data) {
- if (ec)
- {
- std::cerr << "Error getting properties from " << path << "\n";
- return;
- }
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- double max = loadVariant<double>(data, "MaxValue");
- double min = loadVariant<double>(data, "MinValue");
- self->tachRanges[path] = std::make_pair(min, max);
- self->updateReading();
+ if (ec)
+ {
+ std::cerr << "Error getting properties from " << path << "\n";
+ return;
+ }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ double max = loadVariant<double>(data, "MaxValue");
+ double min = loadVariant<double>(data, "MinValue");
+ self->tachRanges[path] = std::make_pair(min, max);
+ self->updateReading();
},
serviceName, path, "org.freedesktop.DBus.Properties", "GetAll",
"xyz.openbmc_project.Sensor.Value");
@@ -417,10 +412,10 @@
tachReadings.begin(), tachReadings.end(), [&](const auto& item) {
return boost::ends_with(item.first, tachName);
});
- auto findRange = std::find_if(
- tachRanges.begin(), tachRanges.end(), [&](const auto& item) {
- return boost::ends_with(item.first, tachName);
- });
+ auto findRange = std::find_if(tachRanges.begin(), tachRanges.end(),
+ [&](const auto& item) {
+ return boost::ends_with(item.first, tachName);
+ });
if (findReading == tachReadings.end())
{
if constexpr (debug)
@@ -550,97 +545,95 @@
setupSensorMatch(matches, *dbusConnection, type,
[weakRef, type](const double& value,
sdbusplus::message::message& message) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- if (type == "power")
- {
- std::string path = message.get_path();
- if (path.find("PS") != std::string::npos &&
- boost::ends_with(path, "Input_Power"))
- {
- self->powerReadings[message.get_path()] =
- value;
- }
- }
- else if (type == inletTemperatureSensor)
- {
- self->inletTemp = value;
- }
- self->updateReading();
- });
- }
- dbusConnection->async_method_call(
- [weakRef](boost::system::error_code ec,
- const std::variant<double>& value) {
- if (ec)
- {
- // sensor not ready yet
- return;
- }
auto self = weakRef.lock();
if (!self)
{
return;
}
- self->inletTemp = std::visit(VariantToDoubleVisitor(), value);
+ if (type == "power")
+ {
+ std::string path = message.get_path();
+ if (path.find("PS") != std::string::npos &&
+ boost::ends_with(path, "Input_Power"))
+ {
+ self->powerReadings[message.get_path()] = value;
+ }
+ }
+ else if (type == inletTemperatureSensor)
+ {
+ self->inletTemp = value;
+ }
+ self->updateReading();
+ });
+ }
+ dbusConnection->async_method_call(
+ [weakRef](boost::system::error_code ec,
+ const std::variant<double>& value) {
+ if (ec)
+ {
+ // sensor not ready yet
+ return;
+ }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->inletTemp = std::visit(VariantToDoubleVisitor(), value);
},
"xyz.openbmc_project.HwmonTempSensor",
std::string("/xyz/openbmc_project/sensors/") + inletTemperatureSensor,
properties::interface, properties::get, sensorValueInterface, "Value");
dbusConnection->async_method_call(
[weakRef](boost::system::error_code ec, const GetSubTreeType& subtree) {
- if (ec)
+ if (ec)
+ {
+ std::cerr << "Error contacting mapper\n";
+ return;
+ }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ for (const auto& item : subtree)
+ {
+ size_t lastSlash = item.first.rfind("/");
+ if (lastSlash == std::string::npos ||
+ lastSlash == item.first.size() || !item.second.size())
{
- std::cerr << "Error contacting mapper\n";
- return;
+ continue;
}
- auto self = weakRef.lock();
- if (!self)
+ std::string sensorName = item.first.substr(lastSlash + 1);
+ if (boost::starts_with(sensorName, "PS") &&
+ boost::ends_with(sensorName, "Input_Power"))
{
- return;
+ const std::string& path = item.first;
+ self->dbusConnection->async_method_call(
+ [weakRef, path](boost::system::error_code ec,
+ const std::variant<double>& value) {
+ if (ec)
+ {
+ std::cerr << "Error getting value from " << path
+ << "\n";
+ }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ double reading =
+ std::visit(VariantToDoubleVisitor(), value);
+ if constexpr (debug)
+ {
+ std::cerr << path << "Reading " << reading << "\n";
+ }
+ self->powerReadings[path] = reading;
+ },
+ item.second[0].first, item.first, properties::interface,
+ properties::get, sensorValueInterface, "Value");
}
- for (const auto& item : subtree)
- {
- size_t lastSlash = item.first.rfind("/");
- if (lastSlash == std::string::npos ||
- lastSlash == item.first.size() || !item.second.size())
- {
- continue;
- }
- std::string sensorName = item.first.substr(lastSlash + 1);
- if (boost::starts_with(sensorName, "PS") &&
- boost::ends_with(sensorName, "Input_Power"))
- {
- const std::string& path = item.first;
- self->dbusConnection->async_method_call(
- [weakRef, path](boost::system::error_code ec,
- const std::variant<double>& value) {
- if (ec)
- {
- std::cerr << "Error getting value from " << path
- << "\n";
- }
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- double reading =
- std::visit(VariantToDoubleVisitor(), value);
- if constexpr (debug)
- {
- std::cerr << path << "Reading " << reading
- << "\n";
- }
- self->powerReadings[path] = reading;
- },
- item.second[0].first, item.first, properties::interface,
- properties::get, sensorValueInterface, "Value");
- }
- }
+ }
},
mapper::busName, mapper::path, mapper::interface, mapper::subtree,
"/xyz/openbmc_project/sensors/power", 0,
@@ -875,77 +868,74 @@
return;
}
auto getter = std::make_shared<GetSensorConfiguration>(
- dbusConnection, [&objectServer, &dbusConnection,
- &exitAirSensor](const ManagedObjectType& resp) {
- cfmSensors.clear();
- for (const auto& pathPair : resp)
+ dbusConnection,
+ [&objectServer, &dbusConnection,
+ &exitAirSensor](const ManagedObjectType& resp) {
+ cfmSensors.clear();
+ for (const auto& pathPair : resp)
+ {
+ for (const auto& entry : pathPair.second)
{
- for (const auto& entry : pathPair.second)
+ if (entry.first == exitAirIface)
{
- if (entry.first == exitAirIface)
- {
- // thresholds should be under the same path
- std::vector<thresholds::Threshold> sensorThresholds;
- parseThresholdsFromConfig(pathPair.second,
- sensorThresholds);
+ // thresholds should be under the same path
+ std::vector<thresholds::Threshold> sensorThresholds;
+ parseThresholdsFromConfig(pathPair.second,
+ sensorThresholds);
- std::string name =
- loadVariant<std::string>(entry.second, "Name");
- exitAirSensor = std::make_shared<ExitAirTempSensor>(
- dbusConnection, name, pathPair.first.str,
- objectServer, std::move(sensorThresholds));
- exitAirSensor->powerFactorMin =
- loadVariant<double>(entry.second, "PowerFactorMin");
- exitAirSensor->powerFactorMax =
- loadVariant<double>(entry.second, "PowerFactorMax");
- exitAirSensor->qMin =
- loadVariant<double>(entry.second, "QMin");
- exitAirSensor->qMax =
- loadVariant<double>(entry.second, "QMax");
- exitAirSensor->alphaS =
- loadVariant<double>(entry.second, "AlphaS");
- exitAirSensor->alphaF =
- loadVariant<double>(entry.second, "AlphaF");
- }
- else if (entry.first == cfmIface)
+ std::string name =
+ loadVariant<std::string>(entry.second, "Name");
+ exitAirSensor = std::make_shared<ExitAirTempSensor>(
+ dbusConnection, name, pathPair.first.str, objectServer,
+ std::move(sensorThresholds));
+ exitAirSensor->powerFactorMin =
+ loadVariant<double>(entry.second, "PowerFactorMin");
+ exitAirSensor->powerFactorMax =
+ loadVariant<double>(entry.second, "PowerFactorMax");
+ exitAirSensor->qMin =
+ loadVariant<double>(entry.second, "QMin");
+ exitAirSensor->qMax =
+ loadVariant<double>(entry.second, "QMax");
+ exitAirSensor->alphaS =
+ loadVariant<double>(entry.second, "AlphaS");
+ exitAirSensor->alphaF =
+ loadVariant<double>(entry.second, "AlphaF");
+ }
+ else if (entry.first == cfmIface)
- {
- // thresholds should be under the same path
- std::vector<thresholds::Threshold> sensorThresholds;
- parseThresholdsFromConfig(pathPair.second,
- sensorThresholds);
- std::string name =
- loadVariant<std::string>(entry.second, "Name");
- auto sensor = std::make_shared<CFMSensor>(
- dbusConnection, name, pathPair.first.str,
- objectServer, std::move(sensorThresholds),
- exitAirSensor);
- loadVariantPathArray(entry.second, "Tachs",
- sensor->tachs);
- sensor->maxCFM =
- loadVariant<double>(entry.second, "MaxCFM");
+ {
+ // thresholds should be under the same path
+ std::vector<thresholds::Threshold> sensorThresholds;
+ parseThresholdsFromConfig(pathPair.second,
+ sensorThresholds);
+ std::string name =
+ loadVariant<std::string>(entry.second, "Name");
+ auto sensor = std::make_shared<CFMSensor>(
+ dbusConnection, name, pathPair.first.str, objectServer,
+ std::move(sensorThresholds), exitAirSensor);
+ loadVariantPathArray(entry.second, "Tachs", sensor->tachs);
+ sensor->maxCFM =
+ loadVariant<double>(entry.second, "MaxCFM");
- // change these into percent upon getting the data
- sensor->c1 =
- loadVariant<double>(entry.second, "C1") / 100;
- sensor->c2 =
- loadVariant<double>(entry.second, "C2") / 100;
- sensor->tachMinPercent =
- loadVariant<double>(entry.second, "TachMinPercent");
- sensor->tachMaxPercent =
- loadVariant<double>(entry.second, "TachMaxPercent");
- sensor->createMaxCFMIface();
- sensor->setupMatches();
+ // change these into percent upon getting the data
+ sensor->c1 = loadVariant<double>(entry.second, "C1") / 100;
+ sensor->c2 = loadVariant<double>(entry.second, "C2") / 100;
+ sensor->tachMinPercent =
+ loadVariant<double>(entry.second, "TachMinPercent");
+ sensor->tachMaxPercent =
+ loadVariant<double>(entry.second, "TachMaxPercent");
+ sensor->createMaxCFMIface();
+ sensor->setupMatches();
- cfmSensors.emplace_back(std::move(sensor));
- }
+ cfmSensors.emplace_back(std::move(sensor));
}
}
- if (exitAirSensor)
- {
- exitAirSensor->setupMatches();
- exitAirSensor->updateReading();
- }
+ }
+ if (exitAirSensor)
+ {
+ exitAirSensor->setupMatches();
+ exitAirSensor->updateReading();
+ }
});
getter->getConfiguration(
std::vector<std::string>(monitorIfaces.begin(), monitorIfaces.end()));
@@ -968,20 +958,20 @@
std::function<void(sdbusplus::message::message&)> eventHandler =
[&](sdbusplus::message::message&) {
- configTimer.expires_from_now(boost::posix_time::seconds(1));
- // create a timer because normally multiple properties change
- configTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
- createSensor(objectServer, sensor, systemBus);
- if (!sensor)
- {
- std::cout << "Configuration not detected\n";
- }
- });
- };
+ configTimer.expires_from_now(boost::posix_time::seconds(1));
+ // create a timer because normally multiple properties change
+ configTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ createSensor(objectServer, sensor, systemBus);
+ if (!sensor)
+ {
+ std::cout << "Configuration not detected\n";
+ }
+ });
+ };
for (const char* type : monitorIfaces)
{
auto match = std::make_unique<sdbusplus::bus::match::match>(
diff --git a/src/ExternalSensorMain.cpp b/src/ExternalSensorMain.cpp
index 477a4c6..a096175 100644
--- a/src/ExternalSensorMain.cpp
+++ b/src/ExternalSensorMain.cpp
@@ -165,177 +165,175 @@
dbusConnection,
[&objectServer, &sensors, &dbusConnection, sensorsChanged,
&reaperTimer](const ManagedObjectType& sensorConfigurations) {
- bool firstScan = (sensorsChanged == nullptr);
+ bool firstScan = (sensorsChanged == nullptr);
- for (const std::pair<sdbusplus::message::object_path, SensorData>&
- sensor : sensorConfigurations)
+ for (const std::pair<sdbusplus::message::object_path, SensorData>&
+ sensor : sensorConfigurations)
+ {
+ const std::string& interfacePath = sensor.first.str;
+ const SensorData& sensorData = sensor.second;
+
+ auto sensorBase = sensorData.find(sensorType);
+ if (sensorBase == sensorData.end())
{
- const std::string& interfacePath = sensor.first.str;
- const SensorData& sensorData = sensor.second;
+ std::cerr << "Base configuration not found for "
+ << interfacePath << "\n";
+ continue;
+ }
- auto sensorBase = sensorData.find(sensorType);
- if (sensorBase == sensorData.end())
- {
- std::cerr << "Base configuration not found for "
- << interfacePath << "\n";
- continue;
- }
+ const SensorBaseConfiguration& baseConfiguration = *sensorBase;
+ const SensorBaseConfigMap& baseConfigMap = baseConfiguration.second;
- const SensorBaseConfiguration& baseConfiguration = *sensorBase;
- const SensorBaseConfigMap& baseConfigMap =
- baseConfiguration.second;
+ // MinValue and MinValue are mandatory numeric parameters
+ auto minFound = baseConfigMap.find("MinValue");
+ if (minFound == baseConfigMap.end())
+ {
+ std::cerr << "MinValue parameter not found for "
+ << interfacePath << "\n";
+ continue;
+ }
+ double minValue =
+ std::visit(VariantToDoubleVisitor(), minFound->second);
+ if (!std::isfinite(minValue))
+ {
+ std::cerr << "MinValue parameter not parsed for "
+ << interfacePath << "\n";
+ continue;
+ }
- // MinValue and MinValue are mandatory numeric parameters
- auto minFound = baseConfigMap.find("MinValue");
- if (minFound == baseConfigMap.end())
- {
- std::cerr << "MinValue parameter not found for "
- << interfacePath << "\n";
- continue;
- }
- double minValue =
- std::visit(VariantToDoubleVisitor(), minFound->second);
- if (!std::isfinite(minValue))
- {
- std::cerr << "MinValue parameter not parsed for "
- << interfacePath << "\n";
- continue;
- }
+ auto maxFound = baseConfigMap.find("MaxValue");
+ if (maxFound == baseConfigMap.end())
+ {
+ std::cerr << "MaxValue parameter not found for "
+ << interfacePath << "\n";
+ continue;
+ }
+ double maxValue =
+ std::visit(VariantToDoubleVisitor(), maxFound->second);
+ if (!std::isfinite(maxValue))
+ {
+ std::cerr << "MaxValue parameter not parsed for "
+ << interfacePath << "\n";
+ continue;
+ }
- auto maxFound = baseConfigMap.find("MaxValue");
- if (maxFound == baseConfigMap.end())
- {
- std::cerr << "MaxValue parameter not found for "
- << interfacePath << "\n";
- continue;
- }
- double maxValue =
- std::visit(VariantToDoubleVisitor(), maxFound->second);
- if (!std::isfinite(maxValue))
- {
- std::cerr << "MaxValue parameter not parsed for "
- << interfacePath << "\n";
- continue;
- }
+ double timeoutSecs = 0.0;
- double timeoutSecs = 0.0;
+ // Timeout is an optional numeric parameter
+ auto timeoutFound = baseConfigMap.find("Timeout");
+ if (timeoutFound != baseConfigMap.end())
+ {
+ timeoutSecs =
+ std::visit(VariantToDoubleVisitor(), timeoutFound->second);
+ }
+ if (!(std::isfinite(timeoutSecs) && (timeoutSecs >= 0.0)))
+ {
+ std::cerr << "Timeout parameter not parsed for "
+ << interfacePath << "\n";
+ continue;
+ }
- // Timeout is an optional numeric parameter
- auto timeoutFound = baseConfigMap.find("Timeout");
- if (timeoutFound != baseConfigMap.end())
- {
- timeoutSecs = std::visit(VariantToDoubleVisitor(),
- timeoutFound->second);
- }
- if (!(std::isfinite(timeoutSecs) && (timeoutSecs >= 0.0)))
- {
- std::cerr << "Timeout parameter not parsed for "
- << interfacePath << "\n";
- continue;
- }
+ std::string sensorName;
+ std::string sensorUnits;
- std::string sensorName;
- std::string sensorUnits;
+ // Name and Units are mandatory string parameters
+ auto nameFound = baseConfigMap.find("Name");
+ if (nameFound == baseConfigMap.end())
+ {
+ std::cerr << "Name parameter not found for " << interfacePath
+ << "\n";
+ continue;
+ }
+ sensorName =
+ std::visit(VariantToStringVisitor(), nameFound->second);
+ if (sensorName.empty())
+ {
+ std::cerr << "Name parameter not parsed for " << interfacePath
+ << "\n";
+ continue;
+ }
- // Name and Units are mandatory string parameters
- auto nameFound = baseConfigMap.find("Name");
- if (nameFound == baseConfigMap.end())
- {
- std::cerr << "Name parameter not found for "
- << interfacePath << "\n";
- continue;
- }
- sensorName =
- std::visit(VariantToStringVisitor(), nameFound->second);
- if (sensorName.empty())
- {
- std::cerr << "Name parameter not parsed for "
- << interfacePath << "\n";
- continue;
- }
+ auto unitsFound = baseConfigMap.find("Units");
+ if (unitsFound == baseConfigMap.end())
+ {
+ std::cerr << "Units parameter not found for " << interfacePath
+ << "\n";
+ continue;
+ }
+ sensorUnits =
+ std::visit(VariantToStringVisitor(), unitsFound->second);
+ if (sensorUnits.empty())
+ {
+ std::cerr << "Units parameter not parsed for " << interfacePath
+ << "\n";
+ continue;
+ }
- auto unitsFound = baseConfigMap.find("Units");
- if (unitsFound == baseConfigMap.end())
+ // on rescans, only update sensors we were signaled by
+ auto findSensor = sensors.find(sensorName);
+ if (!firstScan && (findSensor != sensors.end()))
+ {
+ std::string suffixName = "/";
+ suffixName += findSensor->second->name;
+ bool found = false;
+ for (auto it = sensorsChanged->begin();
+ it != sensorsChanged->end(); it++)
{
- std::cerr << "Units parameter not found for "
- << interfacePath << "\n";
- continue;
- }
- sensorUnits =
- std::visit(VariantToStringVisitor(), unitsFound->second);
- if (sensorUnits.empty())
- {
- std::cerr << "Units parameter not parsed for "
- << interfacePath << "\n";
- continue;
- }
-
- // on rescans, only update sensors we were signaled by
- auto findSensor = sensors.find(sensorName);
- if (!firstScan && (findSensor != sensors.end()))
- {
- std::string suffixName = "/";
- suffixName += findSensor->second->name;
- bool found = false;
- for (auto it = sensorsChanged->begin();
- it != sensorsChanged->end(); it++)
+ std::string suffixIt = "/";
+ suffixIt += *it;
+ if (boost::ends_with(suffixIt, suffixName))
{
- std::string suffixIt = "/";
- suffixIt += *it;
- if (boost::ends_with(suffixIt, suffixName))
+ sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ if constexpr (debug)
{
- sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- if constexpr (debug)
- {
- std::cerr << "ExternalSensor " << sensorName
- << " change found\n";
- }
- break;
+ std::cerr << "ExternalSensor " << sensorName
+ << " change found\n";
}
- }
- if (!found)
- {
- continue;
+ break;
}
}
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(sensorData, sensorThresholds))
+ if (!found)
{
- std::cerr << "error populating thresholds for "
- << sensorName << "\n";
- }
-
- auto findPowerOn = baseConfiguration.second.find("PowerState");
- PowerState readState = PowerState::always;
- if (findPowerOn != baseConfiguration.second.end())
- {
- std::string powerState = std::visit(
- VariantToStringVisitor(), findPowerOn->second);
- setReadState(powerState, readState);
- }
-
- auto& sensorEntry = sensors[sensorName];
- sensorEntry = nullptr;
-
- sensorEntry = std::make_shared<ExternalSensor>(
- sensorType, objectServer, dbusConnection, sensorName,
- sensorUnits, std::move(sensorThresholds), interfacePath,
- maxValue, minValue, timeoutSecs, readState);
- sensorEntry->initWriteHook(
- [&sensors, &reaperTimer](
- const std::chrono::steady_clock::time_point& now) {
- updateReaper(sensors, reaperTimer, now);
- });
-
- if constexpr (debug)
- {
- std::cerr << "ExternalSensor " << sensorName
- << " created\n";
+ continue;
}
}
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(sensorData, sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << sensorName
+ << "\n";
+ }
+
+ auto findPowerOn = baseConfiguration.second.find("PowerState");
+ PowerState readState = PowerState::always;
+ if (findPowerOn != baseConfiguration.second.end())
+ {
+ std::string powerState =
+ std::visit(VariantToStringVisitor(), findPowerOn->second);
+ setReadState(powerState, readState);
+ }
+
+ auto& sensorEntry = sensors[sensorName];
+ sensorEntry = nullptr;
+
+ sensorEntry = std::make_shared<ExternalSensor>(
+ sensorType, objectServer, dbusConnection, sensorName,
+ sensorUnits, std::move(sensorThresholds), interfacePath,
+ maxValue, minValue, timeoutSecs, readState);
+ sensorEntry->initWriteHook(
+ [&sensors, &reaperTimer](
+ const std::chrono::steady_clock::time_point& now) {
+ updateReaper(sensors, reaperTimer, now);
+ });
+
+ if constexpr (debug)
+ {
+ std::cerr << "ExternalSensor " << sensorName << " created\n";
+ }
+ }
});
getter->getConfiguration(std::vector<std::string>{sensorType});
@@ -367,40 +365,39 @@
std::function<void(sdbusplus::message::message&)> eventHandler =
[&objectServer, &sensors, &systemBus, &sensorsChanged, &filterTimer,
&reaperTimer](sdbusplus::message::message& message) mutable {
- if (message.is_method_error())
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+
+ auto messagePath = message.get_path();
+ sensorsChanged->insert(messagePath);
+ if constexpr (debug)
+ {
+ std::cerr << "ExternalSensor change event received: " << messagePath
+ << "\n";
+ }
+
+ // this implicitly cancels the timer
+ filterTimer.expires_from_now(boost::posix_time::seconds(1));
+
+ filterTimer.async_wait(
+ [&objectServer, &sensors, &systemBus, &sensorsChanged,
+ &reaperTimer](const boost::system::error_code& ec) mutable {
+ if (ec != boost::system::errc::success)
{
- std::cerr << "callback method error\n";
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ std::cerr << "callback error: " << ec.message() << "\n";
+ }
return;
}
- auto messagePath = message.get_path();
- sensorsChanged->insert(messagePath);
- if constexpr (debug)
- {
- std::cerr << "ExternalSensor change event received: "
- << messagePath << "\n";
- }
-
- // this implicitly cancels the timer
- filterTimer.expires_from_now(boost::posix_time::seconds(1));
-
- filterTimer.async_wait(
- [&objectServer, &sensors, &systemBus, &sensorsChanged,
- &reaperTimer](const boost::system::error_code& ec) mutable {
- if (ec != boost::system::errc::success)
- {
- if (ec != boost::asio::error::operation_aborted)
- {
- std::cerr << "callback error: " << ec.message()
- << "\n";
- }
- return;
- }
-
- createSensors(objectServer, sensors, systemBus,
- sensorsChanged, reaperTimer);
- });
- };
+ createSensors(objectServer, sensors, systemBus, sensorsChanged,
+ reaperTimer);
+ });
+ };
auto match = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
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='" +
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index 1d2fb5c..a9d4748 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -255,242 +255,235 @@
dbusConnection,
[&io, &objectServer, &sensors, &dbusConnection,
sensorsChanged](const ManagedObjectType& sensorConfigurations) {
- bool firstScan = sensorsChanged == nullptr;
+ bool firstScan = sensorsChanged == nullptr;
- SensorConfigMap configMap =
- buildSensorConfigMap(sensorConfigurations);
+ SensorConfigMap configMap = buildSensorConfigMap(sensorConfigurations);
- // 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);
- if (paths.empty())
+ if (paths.empty())
+ {
+ return;
+ }
+
+ // 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;
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
{
- return;
+ device = fs::canonical(directory);
+ deviceName = device.parent_path().stem();
+ }
+ else
+ {
+ device = directory / "device";
+ deviceName = fs::canonical(device).stem();
+ }
+ auto findHyphen = deviceName.find('-');
+ if (findHyphen == std::string::npos)
+ {
+ std::cerr << "found bad device " << deviceName << "\n";
+ continue;
+ }
+ std::string busStr = deviceName.substr(0, findHyphen);
+ std::string addrStr = deviceName.substr(findHyphen + 1);
+
+ uint64_t bus = 0;
+ uint64_t addr = 0;
+ std::from_chars_result res;
+ res = std::from_chars(busStr.data(), busStr.data() + busStr.size(),
+ bus);
+ if (res.ec != std::errc{})
+ {
+ continue;
+ }
+ res = std::from_chars(addrStr.data(),
+ addrStr.data() + addrStr.size(), addr, 16);
+ if (res.ec != std::errc{})
+ {
+ continue;
}
- // iterate through all found temp and pressure sensors,
- // and try to match them with configuration
- for (auto& path : paths)
+ auto thisSensorParameters = getSensorParameters(path);
+ auto findSensorCfg = configMap.find({bus, addr});
+ if (findSensorCfg == configMap.end())
{
- std::smatch match;
- const std::string pathStr = path.string();
- auto directory = path.parent_path();
- fs::path device;
+ continue;
+ }
- std::string deviceName;
+ const std::string& interfacePath = findSensorCfg->second.sensorPath;
+ const SensorData& sensorData = findSensorCfg->second.sensorData;
+ const std::string& sensorType = findSensorCfg->second.interface;
+ 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 (boost::ends_with(*it, 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";
+ }
+
+ auto findPollRate = baseConfigMap.find("PollRate");
+ float pollRate = pollRateDefault;
+ if (findPollRate != baseConfigMap.end())
+ {
+ pollRate =
+ std::visit(VariantToFloatVisitor(), findPollRate->second);
+ if (pollRate <= 0.0f)
+ {
+ pollRate = pollRateDefault; // polling time too short
+ }
+ }
+
+ auto findPowerOn = baseConfigMap.find("PowerState");
+ PowerState readState = PowerState::always;
+ if (findPowerOn != baseConfigMap.end())
+ {
+ std::string powerState =
+ std::visit(VariantToStringVisitor(), findPowerOn->second);
+ setReadState(powerState, readState);
+ }
+
+ auto permitSet = getPermitSet(baseConfigMap);
+ auto& sensor = sensors[sensorName];
+ sensor = nullptr;
+ auto hwmonFile =
+ getFullHwmonFilePath(directory.string(), "temp1", permitSet);
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
+ {
+ hwmonFile = pathStr;
+ }
+ if (hwmonFile)
+ {
+ sensor = std::make_shared<HwmonTempSensor>(
+ *hwmonFile, sensorType, objectServer, dbusConnection, io,
+ sensorName, std::move(sensorThresholds),
+ thisSensorParameters, pollRate, interfacePath, readState);
+ 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"))
{
- device = fs::canonical(directory);
- deviceName = device.parent_path().stem();
- }
- else
- {
- device = directory / "device";
- deviceName = fs::canonical(device).stem();
- }
- auto findHyphen = deviceName.find('-');
- if (findHyphen == std::string::npos)
- {
- std::cerr << "found bad device " << deviceName << "\n";
continue;
}
- std::string busStr = deviceName.substr(0, findHyphen);
- std::string addrStr = deviceName.substr(findHyphen + 1);
-
- uint64_t bus = 0;
- uint64_t addr = 0;
- std::from_chars_result res;
- res = std::from_chars(busStr.data(),
- busStr.data() + busStr.size(), bus);
- if (res.ec != std::errc{})
- {
- continue;
- }
- res = std::from_chars(
- addrStr.data(), addrStr.data() + addrStr.size(), addr, 16);
- if (res.ec != std::errc{})
- {
- continue;
- }
-
- auto thisSensorParameters = getSensorParameters(path);
- auto findSensorCfg = configMap.find({bus, addr});
- if (findSensorCfg == configMap.end())
- {
- continue;
- }
-
- const std::string& interfacePath =
- findSensorCfg->second.sensorPath;
- const SensorData& sensorData = findSensorCfg->second.sensorData;
- const std::string& sensorType = findSensorCfg->second.interface;
- 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 (boost::ends_with(*it, 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";
- }
-
- auto findPollRate = baseConfigMap.find("PollRate");
- float pollRate = pollRateDefault;
- if (findPollRate != baseConfigMap.end())
- {
- pollRate = std::visit(VariantToFloatVisitor(),
- findPollRate->second);
- if (pollRate <= 0.0f)
- {
- pollRate = pollRateDefault; // polling time too short
- }
- }
-
- auto findPowerOn = baseConfigMap.find("PowerState");
- PowerState readState = PowerState::always;
- if (findPowerOn != baseConfigMap.end())
- {
- std::string powerState = std::visit(
- VariantToStringVisitor(), findPowerOn->second);
- setReadState(powerState, readState);
- }
-
- auto permitSet = getPermitSet(baseConfigMap);
- auto& sensor = sensors[sensorName];
- 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];
+ sensor = nullptr;
sensor = std::make_shared<HwmonTempSensor>(
*hwmonFile, sensorType, objectServer, dbusConnection,
- io, sensorName, std::move(sensorThresholds),
+ io, sensorName, std::move(thresholds),
thisSensorParameters, pollRate, interfacePath,
readState);
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];
- sensor = nullptr;
- sensor = std::make_shared<HwmonTempSensor>(
- *hwmonFile, sensorType, objectServer,
- dbusConnection, io, sensorName,
- std::move(thresholds), thisSensorParameters,
- pollRate, interfacePath, readState);
- sensor->setupRead();
- }
-
- hwmonName.erase(
- remove(hwmonName.begin(), hwmonName.end(), sensorName),
- hwmonName.end());
- }
- if (hwmonName.empty())
- {
- configMap.erase(findSensorCfg);
- }
}
+ if (hwmonName.empty())
+ {
+ configMap.erase(findSensorCfg);
+ }
+ }
});
getter->getConfiguration(
std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
@@ -549,30 +542,29 @@
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, sensors, systemBus,
- sensorsChanged);
- });
- };
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, sensors, systemBus, sensorsChanged);
+ });
+ };
for (const char* type : sensorTypes)
{
@@ -593,7 +585,7 @@
"type='signal',member='InterfacesRemoved',arg0path='" +
std::string(inventoryPath) + "/'",
[&sensors](sdbusplus::message::message& msg) {
- interfaceRemoved(msg, sensors);
+ interfaceRemoved(msg, sensors);
});
matches.emplace_back(std::move(ifaceRemovedMatch));
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index 6577739..22824e0 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -114,13 +114,12 @@
boost::asio::async_read_until(inputDev, readBuf, '\n',
[weakRef](const boost::system::error_code& ec,
std::size_t /*bytes_transfered*/) {
- std::shared_ptr<HwmonTempSensor> self =
- weakRef.lock();
- if (self)
- {
- self->handleResponse(ec);
- }
- });
+ std::shared_ptr<HwmonTempSensor> self = weakRef.lock();
+ if (self)
+ {
+ self->handleResponse(ec);
+ }
+ });
}
void HwmonTempSensor::restartRead()
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index bed6675..2f737af 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -182,50 +182,49 @@
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
{
auto getter = std::make_shared<GetSensorConfiguration>(
- dbusConnection, [](const ManagedObjectType& sensorConfigurations) {
- // Get NIC name and save to map
- lanInfoMap.clear();
- for (const std::pair<sdbusplus::message::object_path, SensorData>&
- sensor : sensorConfigurations)
+ dbusConnection,
+ [](const ManagedObjectType& sensorConfigurations) {
+ // Get NIC name and save to map
+ lanInfoMap.clear();
+ for (const std::pair<sdbusplus::message::object_path, SensorData>&
+ sensor : sensorConfigurations)
+ {
+ const std::pair<std::string, boost::container::flat_map<
+ std::string, BasicVariantType>>*
+ baseConfiguration = nullptr;
+
+ // find base configuration
+ auto sensorBase = sensor.second.find(nicType);
+ if (sensorBase == sensor.second.end())
{
- const std::pair<
- std::string,
- boost::container::flat_map<std::string, BasicVariantType>>*
- baseConfiguration = nullptr;
+ continue;
+ }
+ baseConfiguration = &(*sensorBase);
- // find base configuration
- auto sensorBase = sensor.second.find(nicType);
- if (sensorBase == sensor.second.end())
+ auto findEthIndex = baseConfiguration->second.find("EthIndex");
+ auto findName = baseConfiguration->second.find("Name");
+
+ if (findEthIndex != baseConfiguration->second.end() &&
+ findName != baseConfiguration->second.end())
+ {
+ auto* pEthIndex = std::get_if<uint64_t>(&findEthIndex->second);
+ auto* pName = std::get_if<std::string>(&findName->second);
+ if (pEthIndex != nullptr && pName != nullptr)
{
- continue;
- }
- baseConfiguration = &(*sensorBase);
-
- auto findEthIndex = baseConfiguration->second.find("EthIndex");
- auto findName = baseConfiguration->second.find("Name");
-
- if (findEthIndex != baseConfiguration->second.end() &&
- findName != baseConfiguration->second.end())
- {
- auto* pEthIndex =
- std::get_if<uint64_t>(&findEthIndex->second);
- auto* pName = std::get_if<std::string>(&findName->second);
- if (pEthIndex != nullptr && pName != nullptr)
+ lanInfoMap[*pEthIndex] = *pName;
+ if (debugLanLeash)
{
- lanInfoMap[*pEthIndex] = *pName;
- if (debugLanLeash)
- {
- std::cout << "find name of eth" << *pEthIndex
- << " is " << *pName << "\n";
- }
+ std::cout << "find name of eth" << *pEthIndex << " is "
+ << *pName << "\n";
}
}
}
+ }
- if (lanInfoMap.size() == 0)
- {
- std::cerr << "can't find matched NIC name. \n";
- }
+ if (lanInfoMap.size() == 0)
+ {
+ std::cerr << "can't find matched NIC name. \n";
+ }
});
getter->getConfiguration(
@@ -383,29 +382,29 @@
conn->async_method_call(
[ethNum](boost::system::error_code ec,
const std::variant<std::string>& property) {
- lanStatusMap[ethNum] = false;
- if (ec)
- {
- std::cerr << "Error reading init status of eth" << ethNum
- << "\n";
- return;
- }
- const std::string* pState = std::get_if<std::string>(&property);
- if (pState == nullptr)
- {
- std::cerr << "Unable to read lan status value\n";
- return;
- }
- bool isLanConnected =
- (*pState == "routable" || *pState == "carrier" ||
- *pState == "degraded");
- if (debugLanLeash)
- {
- std::cout << "ethNum = " << std::to_string(ethNum)
- << ", init LAN status = "
- << (isLanConnected ? "true" : "false") << "\n";
- }
- lanStatusMap[ethNum] = isLanConnected;
+ lanStatusMap[ethNum] = false;
+ if (ec)
+ {
+ std::cerr << "Error reading init status of eth" << ethNum
+ << "\n";
+ return;
+ }
+ const std::string* pState = std::get_if<std::string>(&property);
+ if (pState == nullptr)
+ {
+ std::cerr << "Unable to read lan status value\n";
+ return;
+ }
+ bool isLanConnected =
+ (*pState == "routable" || *pState == "carrier" ||
+ *pState == "degraded");
+ if (debugLanLeash)
+ {
+ std::cout << "ethNum = " << std::to_string(ethNum)
+ << ", init LAN status = "
+ << (isLanConnected ? "true" : "false") << "\n";
+ }
+ lanStatusMap[ethNum] = isLanConnected;
},
"org.freedesktop.network1",
"/org/freedesktop/network1/link/_" + pathSuffix,
@@ -446,20 +445,19 @@
// callback to handle configuration change
std::function<void(sdbusplus::message::message&)> eventHandler =
[&](sdbusplus::message::message& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
- std::cout << "rescan due to configuration change \n";
- if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
- &gpioInverted))
- {
- chassisIntrusionSensor.start(type, busId, slaveAddr,
- gpioInverted);
- }
- };
+ std::cout << "rescan due to configuration change \n";
+ if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
+ &gpioInverted))
+ {
+ chassisIntrusionSensor.start(type, busId, slaveAddr, gpioInverted);
+ }
+ };
auto eventMatch = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
@@ -475,7 +473,7 @@
"type='signal', member='PropertiesChanged',"
"arg0namespace='org.freedesktop.network1.Link'",
[](sdbusplus::message::message& msg) {
- processLanStatusChange(msg);
+ processLanStatusChange(msg);
});
// add match to monitor entity manager signal about nic name config
@@ -486,12 +484,12 @@
std::string(inventoryPath) + "',arg0namespace='" + nicType +
"'",
[&systemBus](sdbusplus::message::message& msg) {
- if (msg.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- getNicNameInfo(systemBus);
+ if (msg.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ getNicNameInfo(systemBus);
});
}
diff --git a/src/IpmbSensor.cpp b/src/IpmbSensor.cpp
index c569997..a8cd25a 100644
--- a/src/IpmbSensor.cpp
+++ b/src/IpmbSensor.cpp
@@ -133,14 +133,13 @@
dbusConnection->async_method_call(
[this](boost::system::error_code ec,
const IpmbMethodType& response) {
- const int& status = std::get<0>(response);
+ const int& status = std::get<0>(response);
- if (ec || status)
- {
- std::cerr
- << "Error setting init command for device: " << name
- << "\n";
- }
+ if (ec || status)
+ {
+ std::cerr << "Error setting init command for device: " << name
+ << "\n";
+ }
},
"xyz.openbmc_project.Ipmi.Channel.Ipmb",
"/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb",
@@ -353,53 +352,53 @@
dbusConnection->async_method_call(
[this](boost::system::error_code ec,
const IpmbMethodType& response) {
- const int& status = std::get<0>(response);
- if (ec || status)
- {
- incrementError();
- read();
- return;
- }
- const std::vector<uint8_t>& data = std::get<5>(response);
- if constexpr (debug)
- {
- std::cout << name << ": ";
- for (size_t d : data)
- {
- std::cout << d << " ";
- }
- std::cout << "\n";
- }
- if (data.empty())
- {
- incrementError();
- read();
- return;
- }
-
- double value = 0;
-
- if (!processReading(data, value))
- {
- incrementError();
- read();
- return;
- }
-
- // rawValue only used in debug logging
- // up to 5th byte in data are used to derive value
- size_t end = std::min(sizeof(uint64_t), data.size());
- uint64_t rawData = 0;
- for (size_t i = 0; i < end; i++)
- {
- reinterpret_cast<uint8_t*>(&rawData)[i] = data[i];
- }
- rawValue = static_cast<double>(rawData);
-
- /* Adjust value as per scale and offset */
- value = (value * scaleVal) + offsetVal;
- updateValue(value);
+ const int& status = std::get<0>(response);
+ if (ec || status)
+ {
+ incrementError();
read();
+ return;
+ }
+ const std::vector<uint8_t>& data = std::get<5>(response);
+ if constexpr (debug)
+ {
+ std::cout << name << ": ";
+ for (size_t d : data)
+ {
+ std::cout << d << " ";
+ }
+ std::cout << "\n";
+ }
+ if (data.empty())
+ {
+ incrementError();
+ read();
+ return;
+ }
+
+ double value = 0;
+
+ if (!processReading(data, value))
+ {
+ incrementError();
+ read();
+ return;
+ }
+
+ // rawValue only used in debug logging
+ // up to 5th byte in data are used to derive value
+ size_t end = std::min(sizeof(uint64_t), data.size());
+ uint64_t rawData = 0;
+ for (size_t i = 0; i < end; i++)
+ {
+ reinterpret_cast<uint8_t*>(&rawData)[i] = data[i];
+ }
+ rawValue = static_cast<double>(rawData);
+
+ /* Adjust value as per scale and offset */
+ value = (value * scaleVal) + offsetVal;
+ updateValue(value);
+ read();
},
"xyz.openbmc_project.Ipmi.Channel.Ipmb",
"/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb",
@@ -499,79 +498,79 @@
}
dbusConnection->async_method_call(
[&](boost::system::error_code ec, const ManagedObjectType& resp) {
- if (ec)
+ if (ec)
+ {
+ std::cerr << "Error contacting entity manager\n";
+ return;
+ }
+ for (const auto& pathPair : resp)
+ {
+ for (const auto& entry : pathPair.second)
{
- std::cerr << "Error contacting entity manager\n";
- return;
- }
- for (const auto& pathPair : resp)
- {
- for (const auto& entry : pathPair.second)
+ if (entry.first != configInterface)
{
- if (entry.first != configInterface)
- {
- continue;
- }
- std::string name =
- loadVariant<std::string>(entry.second, "Name");
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(pathPair.second,
- sensorThresholds))
- {
- std::cerr << "error populating thresholds for " << name
- << "\n";
- }
- uint8_t deviceAddress =
- loadVariant<uint8_t>(entry.second, "Address");
-
- std::string sensorClass =
- loadVariant<std::string>(entry.second, "Class");
-
- uint8_t hostSMbusIndex = hostSMbusIndexDefault;
- auto findSmType = entry.second.find("HostSMbusIndex");
- if (findSmType != entry.second.end())
- {
- hostSMbusIndex = std::visit(
- VariantToUnsignedIntVisitor(), findSmType->second);
- }
-
- float pollRate = pollRateDefault;
- auto findPollRate = entry.second.find("PollRate");
- if (findPollRate != entry.second.end())
- {
- pollRate = std::visit(VariantToFloatVisitor(),
- findPollRate->second);
- if (pollRate <= 0.0f)
- {
- pollRate = pollRateDefault;
- }
- }
-
- /* Default sensor type is "temperature" */
- std::string sensorTypeName = "temperature";
- auto findType = entry.second.find("SensorType");
- if (findType != entry.second.end())
- {
- sensorTypeName = std::visit(VariantToStringVisitor(),
- findType->second);
- }
-
- auto& sensor = sensors[name];
- sensor = std::make_unique<IpmbSensor>(
- dbusConnection, io, name, pathPair.first, objectServer,
- std::move(sensorThresholds), deviceAddress,
- hostSMbusIndex, pollRate, sensorTypeName);
-
- sensor->parseConfigValues(entry.second);
- if (!(sensor->sensorClassType(sensorClass)))
- {
- continue;
- }
- sensor->sensorSubType(sensorTypeName);
- sensor->init();
+ continue;
}
+ std::string name =
+ loadVariant<std::string>(entry.second, "Name");
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(pathPair.second,
+ sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << name
+ << "\n";
+ }
+ uint8_t deviceAddress =
+ loadVariant<uint8_t>(entry.second, "Address");
+
+ std::string sensorClass =
+ loadVariant<std::string>(entry.second, "Class");
+
+ uint8_t hostSMbusIndex = hostSMbusIndexDefault;
+ auto findSmType = entry.second.find("HostSMbusIndex");
+ if (findSmType != entry.second.end())
+ {
+ hostSMbusIndex = std::visit(VariantToUnsignedIntVisitor(),
+ findSmType->second);
+ }
+
+ float pollRate = pollRateDefault;
+ auto findPollRate = entry.second.find("PollRate");
+ if (findPollRate != entry.second.end())
+ {
+ pollRate = std::visit(VariantToFloatVisitor(),
+ findPollRate->second);
+ if (pollRate <= 0.0f)
+ {
+ pollRate = pollRateDefault;
+ }
+ }
+
+ /* Default sensor type is "temperature" */
+ std::string sensorTypeName = "temperature";
+ auto findType = entry.second.find("SensorType");
+ if (findType != entry.second.end())
+ {
+ sensorTypeName =
+ std::visit(VariantToStringVisitor(), findType->second);
+ }
+
+ auto& sensor = sensors[name];
+ sensor = std::make_unique<IpmbSensor>(
+ dbusConnection, io, name, pathPair.first, objectServer,
+ std::move(sensorThresholds), deviceAddress, hostSMbusIndex,
+ pollRate, sensorTypeName);
+
+ sensor->parseConfigValues(entry.second);
+ if (!(sensor->sensorClassType(sensorClass)))
+ {
+ continue;
+ }
+ sensor->sensorSubType(sensorTypeName);
+ sensor->init();
}
+ }
},
entityManagerName, "/", "org.freedesktop.DBus.ObjectManager",
"GetManagedObjects");
@@ -635,20 +634,20 @@
std::function<void(sdbusplus::message::message&)> eventHandler =
[&](sdbusplus::message::message&) {
- configTimer.expires_from_now(boost::posix_time::seconds(1));
- // create a timer because normally multiple properties change
- configTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
- createSensors(io, objectServer, sensors, systemBus);
- if (sensors.empty())
- {
- std::cout << "Configuration not detected\n";
- }
- });
- };
+ configTimer.expires_from_now(boost::posix_time::seconds(1));
+ // create a timer because normally multiple properties change
+ configTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ createSensors(io, objectServer, sensors, systemBus);
+ if (sensors.empty())
+ {
+ std::cout << "Configuration not detected\n";
+ }
+ });
+ };
sdbusplus::bus::match::match configMatch(
static_cast<sdbusplus::bus::bus&>(*systemBus),
diff --git a/src/MCUTempSensor.cpp b/src/MCUTempSensor.cpp
index 4653bc8..c8aef67 100644
--- a/src/MCUTempSensor.cpp
+++ b/src/MCUTempSensor.cpp
@@ -201,64 +201,62 @@
dbusConnection->async_method_call(
[&io, &objectServer, &dbusConnection, &sensors](
boost::system::error_code ec, const ManagedObjectType& resp) {
- if (ec)
+ if (ec)
+ {
+ std::cerr << "Error contacting entity manager\n";
+ return;
+ }
+ for (const auto& pathPair : resp)
+ {
+ for (const auto& entry : pathPair.second)
{
- std::cerr << "Error contacting entity manager\n";
- return;
- }
- for (const auto& pathPair : resp)
- {
- for (const auto& entry : pathPair.second)
+ if (entry.first != configInterface)
{
- if (entry.first != configInterface)
- {
- continue;
- }
- std::string name =
- loadVariant<std::string>(entry.second, "Name");
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(pathPair.second,
- sensorThresholds))
- {
- std::cerr << "error populating thresholds for " << name
- << "\n";
- }
-
- uint8_t busId = loadVariant<uint8_t>(entry.second, "Bus");
-
- uint8_t mcuAddress =
- loadVariant<uint8_t>(entry.second, "Address");
-
- uint8_t tempReg = loadVariant<uint8_t>(entry.second, "Reg");
-
- std::string sensorClass =
- loadVariant<std::string>(entry.second, "Class");
-
- if constexpr (debug)
- {
- std::cerr
- << "Configuration parsed for \n\t" << entry.first
- << "\n"
- << "with\n"
- << "\tName: " << name << "\n"
- << "\tBus: " << static_cast<int>(busId) << "\n"
- << "\tAddress: " << static_cast<int>(mcuAddress)
- << "\n"
- << "\tReg: " << static_cast<int>(tempReg) << "\n"
- << "\tClass: " << sensorClass << "\n";
- }
-
- auto& sensor = sensors[name];
-
- sensor = std::make_unique<MCUTempSensor>(
- dbusConnection, io, name, pathPair.first, objectServer,
- std::move(sensorThresholds), busId, mcuAddress,
- tempReg);
-
- sensor->init();
+ continue;
}
+ std::string name =
+ loadVariant<std::string>(entry.second, "Name");
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(pathPair.second,
+ sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << name
+ << "\n";
+ }
+
+ uint8_t busId = loadVariant<uint8_t>(entry.second, "Bus");
+
+ uint8_t mcuAddress =
+ loadVariant<uint8_t>(entry.second, "Address");
+
+ uint8_t tempReg = loadVariant<uint8_t>(entry.second, "Reg");
+
+ std::string sensorClass =
+ loadVariant<std::string>(entry.second, "Class");
+
+ if constexpr (debug)
+ {
+ std::cerr << "Configuration parsed for \n\t" << entry.first
+ << "\n"
+ << "with\n"
+ << "\tName: " << name << "\n"
+ << "\tBus: " << static_cast<int>(busId) << "\n"
+ << "\tAddress: " << static_cast<int>(mcuAddress)
+ << "\n"
+ << "\tReg: " << static_cast<int>(tempReg) << "\n"
+ << "\tClass: " << sensorClass << "\n";
+ }
+
+ auto& sensor = sensors[name];
+
+ sensor = std::make_unique<MCUTempSensor>(
+ dbusConnection, io, name, pathPair.first, objectServer,
+ std::move(sensorThresholds), busId, mcuAddress, tempReg);
+
+ sensor->init();
}
+ }
},
entityManagerName, "/", "org.freedesktop.DBus.ObjectManager",
"GetManagedObjects");
@@ -277,26 +275,26 @@
std::function<void(sdbusplus::message::message&)> eventHandler =
[&](sdbusplus::message::message&) {
- configTimer.expires_from_now(boost::posix_time::seconds(1));
- // create a timer because normally multiple properties change
- configTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
- // config timer error
- if (ec)
- {
- std::cerr << "timer error\n";
- return;
- }
- createSensors(io, objectServer, sensors, systemBus);
- if (sensors.empty())
- {
- std::cout << "Configuration not detected\n";
- }
- });
- };
+ configTimer.expires_from_now(boost::posix_time::seconds(1));
+ // create a timer because normally multiple properties change
+ configTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ // config timer error
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, sensors, systemBus);
+ if (sensors.empty())
+ {
+ std::cout << "Configuration not detected\n";
+ }
+ });
+ };
sdbusplus::bus::match::match configMatch(
static_cast<sdbusplus::bus::bus&>(*systemBus),
diff --git a/src/NVMeBasicContext.cpp b/src/NVMeBasicContext.cpp
index d0ece2c..760167e 100644
--- a/src/NVMeBasicContext.cpp
+++ b/src/NVMeBasicContext.cpp
@@ -277,10 +277,10 @@
boost::asio::async_write(
reqStream, boost::asio::buffer(command->data(), command->size()),
[command](boost::system::error_code ec, std::size_t) {
- if (ec)
- {
- std::cerr << "Got error writing basic query: " << ec << "\n";
- }
+ if (ec)
+ {
+ std::cerr << "Got error writing basic query: " << ec << "\n";
+ }
});
auto response = std::make_shared<boost::asio::streambuf>();
@@ -290,67 +290,67 @@
boost::asio::async_read(
respStream, *response,
[response](const boost::system::error_code& ec, std::size_t n) {
- if (ec)
- {
- std::cerr << "Got error completing basic query: " << ec << "\n";
- return static_cast<std::size_t>(0);
- }
+ if (ec)
+ {
+ std::cerr << "Got error completing basic query: " << ec << "\n";
+ return static_cast<std::size_t>(0);
+ }
- if (n == 0)
- {
- return static_cast<std::size_t>(1);
- }
+ if (n == 0)
+ {
+ return static_cast<std::size_t>(1);
+ }
- std::istream is(response.get());
- size_t len = static_cast<std::size_t>(is.peek());
+ std::istream is(response.get());
+ size_t len = static_cast<std::size_t>(is.peek());
- if (n > len + 1)
- {
- std::cerr << "Query stream has become unsynchronised: "
- << "n: " << n << ", "
- << "len: " << len << "\n";
- return static_cast<std::size_t>(0);
- }
+ if (n > len + 1)
+ {
+ std::cerr << "Query stream has become unsynchronised: "
+ << "n: " << n << ", "
+ << "len: " << len << "\n";
+ return static_cast<std::size_t>(0);
+ }
- if (n == len + 1)
- {
- return static_cast<std::size_t>(0);
- }
+ if (n == len + 1)
+ {
+ return static_cast<std::size_t>(0);
+ }
- if (n > 1)
- {
- return len + 1 - n;
- }
+ if (n > 1)
+ {
+ return len + 1 - n;
+ }
- response->prepare(len);
- return len;
+ response->prepare(len);
+ return len;
},
[self{shared_from_this()}, sensor, response](
const boost::system::error_code& ec, std::size_t length) mutable {
- if (ec)
- {
- std::cerr << "Got error reading basic query: " << ec << "\n";
- return;
- }
+ if (ec)
+ {
+ std::cerr << "Got error reading basic query: " << ec << "\n";
+ return;
+ }
- if (length == 0)
- {
- std::cerr << "Invalid message length: " << length << "\n";
- return;
- }
+ if (length == 0)
+ {
+ std::cerr << "Invalid message length: " << length << "\n";
+ return;
+ }
- /* Deserialise the response */
- response->consume(1); /* Drop the length byte */
- std::istream is(response.get());
- std::vector<char> data(response->size());
- is.read(data.data(), response->size());
+ /* Deserialise the response */
+ response->consume(1); /* Drop the length byte */
+ std::istream is(response.get());
+ std::vector<char> data(response->size());
+ is.read(data.data(), response->size());
- /* Update the sensor */
- self->processResponse(sensor, data.data(), data.size());
+ /* Update the sensor */
+ self->processResponse(sensor, data.data(), data.size());
- /* Enqueue processing of the next sensor */
- self->readAndProcessNVMeSensor();
- });
+ /* Enqueue processing of the next sensor */
+ self->readAndProcessNVMeSensor();
+ });
}
void NVMeBasicContext::pollNVMeDevices()
@@ -360,19 +360,19 @@
scanTimer.expires_from_now(boost::posix_time::seconds(1));
scanTimer.async_wait(
[self{shared_from_this()}](const boost::system::error_code errorCode) {
- if (errorCode == boost::asio::error::operation_aborted)
- {
- return;
- }
+ if (errorCode == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
- if (errorCode)
- {
- std::cerr << errorCode.message() << "\n";
- return;
- }
+ if (errorCode)
+ {
+ std::cerr << errorCode.message() << "\n";
+ return;
+ }
- self->readAndProcessNVMeSensor();
- });
+ self->readAndProcessNVMeSensor();
+ });
}
static double getTemperatureReading(int8_t reading)
diff --git a/src/NVMeSensorMain.cpp b/src/NVMeSensorMain.cpp
index d5e3026..ed46923 100644
--- a/src/NVMeSensorMain.cpp
+++ b/src/NVMeSensorMain.cpp
@@ -237,24 +237,24 @@
std::function<void(sdbusplus::message::message&)> eventHandler =
[&filterTimer, &io, &objectServer,
&systemBus](sdbusplus::message::message&) {
- // this implicitly cancels the timer
- filterTimer.expires_from_now(boost::posix_time::seconds(1));
+ // 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)
- {
- return; // we're being canceled
- }
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
- if (ec)
- {
- std::cerr << "Error: " << ec.message() << "\n";
- return;
- }
+ if (ec)
+ {
+ std::cerr << "Error: " << ec.message() << "\n";
+ return;
+ }
- createSensors(io, objectServer, systemBus);
- });
- };
+ createSensors(io, objectServer, systemBus);
+ });
+ };
sdbusplus::bus::match::match configMatch(
static_cast<sdbusplus::bus::bus&>(*systemBus),
@@ -270,7 +270,7 @@
"type='signal',member='InterfacesRemoved',arg0path='" +
std::string(inventoryPath) + "/'",
[](sdbusplus::message::message& msg) {
- interfaceRemoved(msg, nvmeDeviceMap);
+ interfaceRemoved(msg, nvmeDeviceMap);
});
setupManufacturingModeMatch(*systemBus);
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index 7813741..c2ed486 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -214,12 +214,12 @@
inputDev, *buffer, '\n',
[weakRef, buffer](const boost::system::error_code& ec,
std::size_t /*bytes_transfered*/) {
- std::shared_ptr<PSUSubEvent> self = weakRef.lock();
- if (self)
- {
- self->readBuf = buffer;
- self->handleResponse(ec);
- }
+ std::shared_ptr<PSUSubEvent> self = weakRef.lock();
+ if (self)
+ {
+ self->readBuf = buffer;
+ self->handleResponse(ec);
+ }
});
}
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index bbc0d2f..eedbfcc 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -128,12 +128,12 @@
std::weak_ptr<PSUSensor> weakRef = weak_from_this();
inputDev.async_wait(boost::asio::posix::descriptor_base::wait_read,
[weakRef](const boost::system::error_code& ec) {
- std::shared_ptr<PSUSensor> self = weakRef.lock();
- if (self)
- {
- self->handleResponse(ec);
- }
- });
+ std::shared_ptr<PSUSensor> self = weakRef.lock();
+ if (self)
+ {
+ self->handleResponse(ec);
+ }
+ });
}
void PSUSensor::restartRead(void)
diff --git a/src/PwmSensor.cpp b/src/PwmSensor.cpp
index c1f0674..2ed24a6 100644
--- a/src/PwmSensor.cpp
+++ b/src/PwmSensor.cpp
@@ -60,50 +60,49 @@
sensorInterface->register_property(
"Value", fValue,
[this](const double& req, double& resp) {
- if (!std::isfinite(req))
- {
- // Reject attempted change, if to NaN or other non-numeric
- return -1;
- }
- if (req > 100.0 || req < 0.0)
- {
- // TODO(): It does not seem desirable to halt daemon here,
- // probably should just reject the change, continue running?
- throw std::runtime_error("Value out of range");
- return -1;
- }
+ if (!std::isfinite(req))
+ {
+ // Reject attempted change, if to NaN or other non-numeric
+ return -1;
+ }
+ if (req > 100.0 || req < 0.0)
+ {
+ // TODO(): It does not seem desirable to halt daemon here,
+ // probably should just reject the change, continue running?
+ throw std::runtime_error("Value out of range");
+ return -1;
+ }
- double reqValue = (req / 100.0) * pwmMax;
- double respValue = (resp / 100.0) * pwmMax;
- auto reqInt = static_cast<uint32_t>(std::round(reqValue));
- auto respInt = static_cast<uint32_t>(std::round(respValue));
- // Avoid floating-point equality, compare as integers
- if (reqInt == respInt)
- {
- return 1;
- }
- setValue(reqInt);
- resp = req;
-
- controlInterface->signal_property("Target");
-
+ double reqValue = (req / 100.0) * pwmMax;
+ double respValue = (resp / 100.0) * pwmMax;
+ auto reqInt = static_cast<uint32_t>(std::round(reqValue));
+ auto respInt = static_cast<uint32_t>(std::round(respValue));
+ // Avoid floating-point equality, compare as integers
+ if (reqInt == respInt)
+ {
return 1;
+ }
+ setValue(reqInt);
+ resp = req;
+
+ controlInterface->signal_property("Target");
+
+ return 1;
},
[this](double& curVal) {
- double currScaled = (curVal / 100.0) * pwmMax;
- auto currInt = static_cast<uint32_t>(std::round(currScaled));
- auto getInt = getValue();
- // Avoid floating-point equality, compare as integers
- if (currInt != getInt)
- {
- double getScaled =
- 100.0 * (static_cast<double>(getInt) / pwmMax);
- curVal = getScaled;
- controlInterface->signal_property("Target");
- sensorInterface->signal_property("Value");
- }
- return curVal;
- });
+ double currScaled = (curVal / 100.0) * pwmMax;
+ auto currInt = static_cast<uint32_t>(std::round(currScaled));
+ auto getInt = getValue();
+ // Avoid floating-point equality, compare as integers
+ if (currInt != getInt)
+ {
+ double getScaled = 100.0 * (static_cast<double>(getInt) / pwmMax);
+ curVal = getScaled;
+ controlInterface->signal_property("Target");
+ sensorInterface->signal_property("Value");
+ }
+ return curVal;
+ });
// pwm sensor interface is in percent
sensorInterface->register_property("MaxValue", static_cast<int64_t>(100));
sensorInterface->register_property("MinValue", static_cast<int64_t>(0));
@@ -115,37 +114,37 @@
controlInterface->register_property(
"Target", static_cast<uint64_t>(pwmValue),
[this](const uint64_t& req, uint64_t& resp) {
- if (req > static_cast<uint64_t>(targetIfaceMax))
- {
- throw std::runtime_error("Value out of range");
- return -1;
- }
- if (req == resp)
- {
- return 1;
- }
- auto scaledValue = static_cast<double>(req) / targetIfaceMax;
- auto roundValue = std::round(scaledValue * pwmMax);
- setValue(static_cast<uint32_t>(roundValue));
- resp = req;
-
- sensorInterface->signal_property("Value");
-
+ if (req > static_cast<uint64_t>(targetIfaceMax))
+ {
+ throw std::runtime_error("Value out of range");
+ return -1;
+ }
+ if (req == resp)
+ {
return 1;
+ }
+ auto scaledValue = static_cast<double>(req) / targetIfaceMax;
+ auto roundValue = std::round(scaledValue * pwmMax);
+ setValue(static_cast<uint32_t>(roundValue));
+ resp = req;
+
+ sensorInterface->signal_property("Value");
+
+ return 1;
},
[this](uint64_t& curVal) {
- auto getInt = getValue();
- auto scaledValue = static_cast<double>(getInt) / pwmMax;
- auto roundValue = std::round(scaledValue * targetIfaceMax);
- auto value = static_cast<uint64_t>(roundValue);
- if (curVal != value)
- {
- curVal = value;
- controlInterface->signal_property("Target");
- sensorInterface->signal_property("Value");
- }
- return curVal;
- });
+ auto getInt = getValue();
+ auto scaledValue = static_cast<double>(getInt) / pwmMax;
+ auto roundValue = std::round(scaledValue * targetIfaceMax);
+ auto value = static_cast<uint64_t>(roundValue);
+ if (curVal != value)
+ {
+ curVal = value;
+ controlInterface->signal_property("Target");
+ sensorInterface->signal_property("Value");
+ }
+ return curVal;
+ });
sensorInterface->initialize();
controlInterface->initialize();
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index f609410..f5d420d 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -118,10 +118,11 @@
void TachSensor::setupRead(void)
{
- boost::asio::async_read_until(
- inputDev, readBuf, '\n',
- [&](const boost::system::error_code& ec,
- std::size_t /*bytes_transfered*/) { handleResponse(ec); });
+ boost::asio::async_read_until(inputDev, readBuf, '\n',
+ [&](const boost::system::error_code& ec,
+ std::size_t /*bytes_transfered*/) {
+ handleResponse(ec);
+ });
}
void TachSensor::handleResponse(const boost::system::error_code& err)
@@ -253,22 +254,21 @@
{
gpioFd.async_wait(boost::asio::posix::stream_descriptor::wait_read,
[this](const boost::system::error_code& ec) {
- if (ec == boost::system::errc::bad_file_descriptor)
- {
- return; // we're being destroyed
- }
- if (ec)
- {
- std::cerr << "Error on presence sensor " << name
- << " \n";
- ;
- }
- else
- {
- read();
- }
- monitorPresence();
- });
+ if (ec == boost::system::errc::bad_file_descriptor)
+ {
+ return; // we're being destroyed
+ }
+ if (ec)
+ {
+ std::cerr << "Error on presence sensor " << name << " \n";
+ ;
+ }
+ else
+ {
+ read();
+ }
+ monitorPresence();
+ });
}
void PresenceSensor::read(void)
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index 5fa82aa..1690c25 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -140,58 +140,57 @@
const boost::system::error_code& ec,
const boost::container::flat_map<std::string, BasicVariantType>&
result) {
- if (ec)
- {
- return; // threshold not supported
- }
+ if (ec)
+ {
+ return; // threshold not supported
+ }
- if (!labelMatch.empty())
+ if (!labelMatch.empty())
+ {
+ auto labelFind = result.find("Label");
+ if (labelFind == result.end())
{
- auto labelFind = result.find("Label");
- if (labelFind == result.end())
- {
- std::cerr << "No label in threshold configuration\n";
- return;
- }
- std::string label =
- std::visit(VariantToStringVisitor(), labelFind->second);
- if (label != labelMatch)
- {
- return;
- }
- }
-
- auto directionFind = result.find("Direction");
- auto severityFind = result.find("Severity");
- auto valueFind = result.find("Value");
- if (valueFind == result.end() || severityFind == result.end() ||
- directionFind == result.end())
- {
- std::cerr << "Malformed threshold in configuration\n";
+ std::cerr << "No label in threshold configuration\n";
return;
}
- unsigned int severity = std::visit(
- VariantToUnsignedIntVisitor(), severityFind->second);
-
- std::string dir =
- std::visit(VariantToStringVisitor(), directionFind->second);
- if ((findThresholdLevel(severity) != threshold.level) ||
- (findThresholdDirection(dir) != threshold.direction))
+ std::string label =
+ std::visit(VariantToStringVisitor(), labelFind->second);
+ if (label != labelMatch)
{
- return; // not the droid we're looking for
+ return;
}
+ }
- std::variant<double> value(threshold.value);
- conn->async_method_call(
- [](const boost::system::error_code& ec) {
- if (ec)
- {
- std::cerr << "Error setting threshold " << ec
- << "\n";
- }
- },
- entityManagerName, path, "org.freedesktop.DBus.Properties",
- "Set", thresholdInterface, "Value", value);
+ auto directionFind = result.find("Direction");
+ auto severityFind = result.find("Severity");
+ auto valueFind = result.find("Value");
+ if (valueFind == result.end() || severityFind == result.end() ||
+ directionFind == result.end())
+ {
+ std::cerr << "Malformed threshold in configuration\n";
+ return;
+ }
+ unsigned int severity =
+ std::visit(VariantToUnsignedIntVisitor(), severityFind->second);
+
+ std::string dir =
+ std::visit(VariantToStringVisitor(), directionFind->second);
+ if ((findThresholdLevel(severity) != threshold.level) ||
+ (findThresholdDirection(dir) != threshold.direction))
+ {
+ return; // not the droid we're looking for
+ }
+
+ std::variant<double> value(threshold.value);
+ conn->async_method_call(
+ [](const boost::system::error_code& ec) {
+ if (ec)
+ {
+ std::cerr << "Error setting threshold " << ec << "\n";
+ }
+ },
+ entityManagerName, path, "org.freedesktop.DBus.Properties",
+ "Set", thresholdInterface, "Value", value);
},
entityManagerName, path, "org.freedesktop.DBus.Properties",
"GetAll", thresholdInterface);
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 8df9a48..ad43caa 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -335,28 +335,27 @@
conn->async_method_call(
[conn, retries](boost::system::error_code ec,
const std::variant<std::string>& state) {
- if (ec)
+ if (ec)
+ {
+ if (retries)
{
- if (retries)
- {
- auto timer = std::make_shared<boost::asio::steady_timer>(
- conn->get_io_context());
- timer->expires_after(std::chrono::seconds(15));
- timer->async_wait(
- [timer, conn, retries](boost::system::error_code) {
- getPowerStatus(conn, retries - 1);
- });
- return;
- }
-
- // we commonly come up before power control, we'll capture the
- // property change later
- std::cerr << "error getting power status " << ec.message()
- << "\n";
+ auto timer = std::make_shared<boost::asio::steady_timer>(
+ conn->get_io_context());
+ timer->expires_after(std::chrono::seconds(15));
+ timer->async_wait(
+ [timer, conn, retries](boost::system::error_code) {
+ getPowerStatus(conn, retries - 1);
+ });
return;
}
- powerStatusOn =
- boost::ends_with(std::get<std::string>(state), ".Running");
+
+ // we commonly come up before power control, we'll capture the
+ // property change later
+ std::cerr << "error getting power status " << ec.message() << "\n";
+ return;
+ }
+ powerStatusOn =
+ boost::ends_with(std::get<std::string>(state), ".Running");
},
power::busname, power::path, properties::interface, properties::get,
power::interface, power::property);
@@ -369,29 +368,28 @@
conn->async_method_call(
[conn, retries](boost::system::error_code ec,
const std::variant<std::string>& state) {
- if (ec)
+ if (ec)
+ {
+ if (retries)
{
- if (retries)
- {
- auto timer = std::make_shared<boost::asio::steady_timer>(
- conn->get_io_context());
- timer->expires_after(std::chrono::seconds(15));
- timer->async_wait(
- [timer, conn, retries](boost::system::error_code) {
- getPostStatus(conn, retries - 1);
- });
- return;
- }
- // we commonly come up before power control, we'll capture the
- // property change later
- std::cerr << "error getting post status " << ec.message()
- << "\n";
+ auto timer = std::make_shared<boost::asio::steady_timer>(
+ conn->get_io_context());
+ timer->expires_after(std::chrono::seconds(15));
+ timer->async_wait(
+ [timer, conn, retries](boost::system::error_code) {
+ getPostStatus(conn, retries - 1);
+ });
return;
}
- auto& value = std::get<std::string>(state);
- biosHasPost = (value != "Inactive") &&
- (value != "xyz.openbmc_project.State.OperatingSystem."
- "Status.OSStatus.Inactive");
+ // we commonly come up before power control, we'll capture the
+ // property change later
+ std::cerr << "error getting post status " << ec.message() << "\n";
+ return;
+ }
+ auto& value = std::get<std::string>(state);
+ biosHasPost = (value != "Inactive") &&
+ (value != "xyz.openbmc_project.State.OperatingSystem."
+ "Status.OSStatus.Inactive");
},
post::busname, post::path, properties::interface, properties::get,
post::interface, post::property);
@@ -413,36 +411,36 @@
"',path='" + std::string(power::path) + "',arg0='" +
std::string(power::interface) + "'",
[](sdbusplus::message::message& message) {
- std::string objectName;
- boost::container::flat_map<std::string, std::variant<std::string>>
- values;
- message.read(objectName, values);
- auto findState = values.find(power::property);
- if (findState != values.end())
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<std::string>>
+ values;
+ message.read(objectName, values);
+ auto findState = values.find(power::property);
+ if (findState != values.end())
+ {
+ bool on = boost::ends_with(std::get<std::string>(findState->second),
+ ".Running");
+ if (!on)
{
- bool on = boost::ends_with(
- std::get<std::string>(findState->second), ".Running");
- if (!on)
+ timer.cancel();
+ powerStatusOn = false;
+ return;
+ }
+ // on comes too quickly
+ timer.expires_after(std::chrono::seconds(10));
+ timer.async_wait([](boost::system::error_code ec) {
+ if (ec == boost::asio::error::operation_aborted)
{
- timer.cancel();
- powerStatusOn = false;
return;
}
- // on comes too quickly
- timer.expires_after(std::chrono::seconds(10));
- timer.async_wait([](boost::system::error_code ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return;
- }
- if (ec)
- {
- std::cerr << "Timer error " << ec.message() << "\n";
- return;
- }
- powerStatusOn = true;
- });
- }
+ if (ec)
+ {
+ std::cerr << "Timer error " << ec.message() << "\n";
+ return;
+ }
+ powerStatusOn = true;
+ });
+ }
});
postMatch = std::make_unique<sdbusplus::bus::match::match>(
@@ -451,19 +449,18 @@
"',path='" + std::string(post::path) + "',arg0='" +
std::string(post::interface) + "'",
[](sdbusplus::message::message& message) {
- std::string objectName;
- boost::container::flat_map<std::string, std::variant<std::string>>
- values;
- message.read(objectName, values);
- auto findState = values.find(post::property);
- if (findState != values.end())
- {
- auto& value = std::get<std::string>(findState->second);
- biosHasPost =
- (value != "Inactive") &&
- (value != "xyz.openbmc_project.State.OperatingSystem."
- "Status.OSStatus.Inactive");
- }
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<std::string>>
+ values;
+ message.read(objectName, values);
+ auto findState = values.find(post::property);
+ if (findState != values.end())
+ {
+ auto& value = std::get<std::string>(findState->second);
+ biosHasPost = (value != "Inactive") &&
+ (value != "xyz.openbmc_project.State.OperatingSystem."
+ "Status.OSStatus.Inactive");
+ }
});
getPowerStatus(conn);
@@ -544,14 +541,14 @@
conn->async_method_call(
[association, path](const boost::system::error_code ec,
const std::vector<std::string>& invSysObjPaths) {
- if (ec)
- {
- // In case of error, set the default associations and
- // initialize the association Interface.
- setInventoryAssociation(association, path);
- return;
- }
- setInventoryAssociation(association, path, invSysObjPaths);
+ if (ec)
+ {
+ // In case of error, set the default associations and
+ // initialize the association Interface.
+ setInventoryAssociation(association, path);
+ return;
+ }
+ setInventoryAssociation(association, path, invSysObjPaths);
},
mapper::busName, mapper::path, mapper::interface, "GetSubTreePaths",
"/xyz/openbmc_project/inventory/system", 2,
@@ -631,30 +628,28 @@
rules::argNpath(0, "/xyz/openbmc_project/security/special_mode");
static std::unique_ptr<sdbusplus::bus::match::match> specialModeIntfMatch =
std::make_unique<sdbusplus::bus::match::match>(
- conn, filterSpecialModeIntfAdd, [](sdbusplus::message::message& m) {
- sdbusplus::message::object_path path;
- using PropertyMap =
- boost::container::flat_map<std::string,
- std::variant<std::string>>;
- boost::container::flat_map<std::string, PropertyMap>
- interfaceAdded;
- m.read(path, interfaceAdded);
- auto intfItr = interfaceAdded.find(specialModeInterface);
- if (intfItr == interfaceAdded.end())
- {
- return;
- }
- PropertyMap& propertyList = intfItr->second;
- auto itr = propertyList.find("SpecialMode");
- if (itr == propertyList.end())
- {
- std::cerr << "error getting SpecialMode property "
- << "\n";
- return;
- }
- auto manufacturingModeStatus =
- std::get_if<std::string>(&itr->second);
- handleSpecialModeChange(*manufacturingModeStatus);
+ conn, filterSpecialModeIntfAdd,
+ [](sdbusplus::message::message& m) {
+ sdbusplus::message::object_path path;
+ using PropertyMap =
+ boost::container::flat_map<std::string, std::variant<std::string>>;
+ boost::container::flat_map<std::string, PropertyMap> interfaceAdded;
+ m.read(path, interfaceAdded);
+ auto intfItr = interfaceAdded.find(specialModeInterface);
+ if (intfItr == interfaceAdded.end())
+ {
+ return;
+ }
+ PropertyMap& propertyList = intfItr->second;
+ auto itr = propertyList.find("SpecialMode");
+ if (itr == propertyList.end())
+ {
+ std::cerr << "error getting SpecialMode property "
+ << "\n";
+ return;
+ }
+ auto manufacturingModeStatus = std::get_if<std::string>(&itr->second);
+ handleSpecialModeChange(*manufacturingModeStatus);
});
const std::string filterSpecialModeChange =
@@ -663,35 +658,34 @@
rules::argN(0, specialModeInterface);
static std::unique_ptr<sdbusplus::bus::match::match>
specialModeChangeMatch = std::make_unique<sdbusplus::bus::match::match>(
- conn, filterSpecialModeChange, [](sdbusplus::message::message& m) {
- std::string interfaceName;
- boost::container::flat_map<std::string,
- std::variant<std::string>>
- propertiesChanged;
+ conn, filterSpecialModeChange,
+ [](sdbusplus::message::message& m) {
+ std::string interfaceName;
+ boost::container::flat_map<std::string, std::variant<std::string>>
+ propertiesChanged;
- m.read(interfaceName, propertiesChanged);
- auto itr = propertiesChanged.find("SpecialMode");
- if (itr == propertiesChanged.end())
- {
- return;
- }
- auto manufacturingModeStatus =
- std::get_if<std::string>(&itr->second);
- handleSpecialModeChange(*manufacturingModeStatus);
+ m.read(interfaceName, propertiesChanged);
+ auto itr = propertiesChanged.find("SpecialMode");
+ if (itr == propertiesChanged.end())
+ {
+ return;
+ }
+ auto manufacturingModeStatus = std::get_if<std::string>(&itr->second);
+ handleSpecialModeChange(*manufacturingModeStatus);
});
conn.async_method_call(
[](const boost::system::error_code ec,
const std::variant<std::string>& getManufactMode) {
- if (ec)
- {
- std::cerr << "error getting SpecialMode status "
- << ec.message() << "\n";
- return;
- }
- auto manufacturingModeStatus =
- std::get_if<std::string>(&getManufactMode);
- handleSpecialModeChange(*manufacturingModeStatus);
+ if (ec)
+ {
+ std::cerr << "error getting SpecialMode status " << ec.message()
+ << "\n";
+ return;
+ }
+ auto manufacturingModeStatus =
+ std::get_if<std::string>(&getManufactMode);
+ handleSpecialModeChange(*manufacturingModeStatus);
},
"xyz.openbmc_project.SpecialMode",
"/xyz/openbmc_project/security/special_mode",