clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: Ib7af6345a7b9e858700bd81645fe87d9d7e9d0fb
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index d43e884..28e3328 100644
--- a/.clang-format
+++ b/.clang-format
@@ -87,7 +87,7 @@
IndentWrappedFunctionNames: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
-LambdaBodyIndentation: OuterScope
+LambdaBodyIndentation: Signature
LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
@@ -98,13 +98,14 @@
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 25
-PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakBeforeFirstCallParameter: 50
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
-PenaltyIndentedWhitespace: 0
+PenaltyIndentedWhitespace: 1
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Left
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index a025419..0b3fd28 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -48,15 +48,14 @@
static constexpr double maxVoltageReading = 1.8; // pre sensor scaling
static constexpr double minVoltageReading = 0;
-ADCSensor::ADCSensor(const std::string& path,
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_context& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& thresholdsIn,
- const double scaleFactor, const float pollRate,
- PowerState readState,
- const std::string& sensorConfiguration,
- std::optional<BridgeGpio>&& bridgeGpio) :
+ADCSensor::ADCSensor(
+ const std::string& path, sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& sensorName,
+ std::vector<thresholds::Threshold>&& thresholdsIn, const double scaleFactor,
+ const float pollRate, PowerState readState,
+ const std::string& sensorConfiguration,
+ std::optional<BridgeGpio>&& bridgeGpio) :
Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
"ADC", false, false, maxVoltageReading / scaleFactor,
minVoltageReading / scaleFactor, conn, readState),
@@ -121,27 +120,27 @@
std::chrono::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
{
@@ -149,13 +148,13 @@
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/ADCSensor.hpp b/src/ADCSensor.hpp
index 81f630d..f562405 100644
--- a/src/ADCSensor.hpp
+++ b/src/ADCSensor.hpp
@@ -29,11 +29,11 @@
{
try
{
- line.request({"adcsensor",
- gpiod::line_request::DIRECTION_OUTPUT,
- polarity == gpiod::line::ACTIVE_HIGH
- ? 0
- : gpiod::line_request::FLAG_ACTIVE_LOW});
+ line.request(
+ {"adcsensor", gpiod::line_request::DIRECTION_OUTPUT,
+ polarity == gpiod::line::ACTIVE_HIGH
+ ? 0
+ : gpiod::line_request::FLAG_ACTIVE_LOW});
}
catch (const std::system_error&)
{
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 723ff01..ec38908 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -98,217 +98,220 @@
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))
- {
- 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()))
+ bool firstScan = sensorsChanged == nullptr;
+ std::vector<fs::path> paths;
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)",
+ paths))
{
- continue;
+ std::cerr << "No adc sensors in system\n";
+ return;
}
- std::smatch match;
- std::string pathStr = path.string();
- std::regex_search(pathStr, match, inputRegex);
- std::string indexStr = *(match.begin() + 1);
-
- // 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, SensorBaseConfigMap>*
- baseConfiguration = nullptr;
- for (const auto& [path, cfgData] : sensorConfigurations)
+ // iterate through all found adc sensors, and try to match them with
+ // configuration
+ for (auto& path : paths)
{
- // clear it out each loop
- baseConfiguration = nullptr;
-
- // find base configuration
- for (const char* type : sensorTypes)
+ if (!isAdc(path.parent_path()))
{
- auto sensorBase = cfgData.find(configInterfaceName(type));
- if (sensorBase != cfgData.end())
+ continue;
+ }
+ std::smatch match;
+ std::string pathStr = path.string();
+
+ std::regex_search(pathStr, match, inputRegex);
+ std::string indexStr = *(match.begin() + 1);
+
+ // 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, SensorBaseConfigMap>*
+ baseConfiguration = nullptr;
+ for (const auto& [path, cfgData] : sensorConfigurations)
+ {
+ // clear it out each loop
+ baseConfiguration = nullptr;
+
+ // find base configuration
+ for (const char* type : sensorTypes)
{
- 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 = &cfgData;
- interfacePath = &path.str;
- break;
- }
- if (sensorData == nullptr)
- {
- if constexpr (debug)
- {
- 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 &&
- it->ends_with(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;
- }
- }
-
- float pollRate = getPollRate(baseConfiguration->second,
- pollRateDefault);
- PowerState readState = getPowerState(baseConfiguration->second);
-
- auto& sensor = sensors[sensorName];
- sensor = nullptr;
-
- std::optional<BridgeGpio> bridgeGpio;
- for (const auto& [key, cfgMap] : *sensorData)
- {
- if (key.find("BridgeGpio") != std::string::npos)
- {
- auto findName = cfgMap.find("Name");
- if (findName != cfgMap.end())
- {
- std::string gpioName = std::visit(
- VariantToStringVisitor(), findName->second);
-
- int polarity = gpiod::line::ACTIVE_HIGH;
- auto findPolarity = cfgMap.find("Polarity");
- if (findPolarity != cfgMap.end())
+ auto sensorBase =
+ cfgData.find(configInterfaceName(type));
+ if (sensorBase != cfgData.end())
{
- if (std::string("Low") ==
- std::visit(VariantToStringVisitor(),
- findPolarity->second))
- {
- polarity = gpiod::line::ACTIVE_LOW;
- }
+ baseConfiguration = &(*sensorBase);
+ break;
}
-
- float setupTime = gpioBridgeSetupTimeDefault;
- auto findSetupTime = cfgMap.find("SetupTime");
- if (findSetupTime != cfgMap.end())
- {
- setupTime = std::visit(VariantToFloatVisitor(),
- findSetupTime->second);
- }
-
- bridgeGpio = BridgeGpio(gpioName, polarity, setupTime);
+ }
+ 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 = &cfgData;
+ interfacePath = &path.str;
break;
}
- }
+ if (sensorData == nullptr)
+ {
+ if constexpr (debug)
+ {
+ std::cerr << "failed to find match for "
+ << path.string() << "\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();
- }
- });
+ 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 &&
+ it->ends_with(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;
+ }
+ }
+
+ float pollRate =
+ getPollRate(baseConfiguration->second, pollRateDefault);
+ PowerState readState = getPowerState(baseConfiguration->second);
+
+ auto& sensor = sensors[sensorName];
+ sensor = nullptr;
+
+ std::optional<BridgeGpio> bridgeGpio;
+ for (const auto& [key, cfgMap] : *sensorData)
+ {
+ if (key.find("BridgeGpio") != std::string::npos)
+ {
+ auto findName = cfgMap.find("Name");
+ if (findName != cfgMap.end())
+ {
+ std::string gpioName = std::visit(
+ VariantToStringVisitor(), findName->second);
+
+ int polarity = gpiod::line::ACTIVE_HIGH;
+ auto findPolarity = cfgMap.find("Polarity");
+ if (findPolarity != cfgMap.end())
+ {
+ if (std::string("Low") ==
+ std::visit(VariantToStringVisitor(),
+ findPolarity->second))
+ {
+ polarity = gpiod::line::ACTIVE_LOW;
+ }
+ }
+
+ float setupTime = gpioBridgeSetupTimeDefault;
+ auto findSetupTime = cfgMap.find("SetupTime");
+ if (findSetupTime != cfgMap.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(
std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()});
@@ -334,81 +337,81 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- sensorsChanged->insert(message.get_path());
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ sensorsChanged->insert(message.get_path());
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- /* we were canceled*/
- return;
- }
- if (ec)
- {
- std::cerr << "timer error\n";
- return;
- }
- createSensors(io, objectServer, sensors, systemBus, sensorsChanged,
- UpdateType::init);
- });
- };
+ 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);
+ });
+ };
boost::asio::steady_timer cpuFilterTimer(io);
std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
[&](sdbusplus::message_t& message) {
- std::string path = message.get_path();
- boost::to_lower(path);
+ std::string path = message.get_path();
+ boost::to_lower(path);
- sdbusplus::message::object_path cpuPath(path);
- std::string cpuName = cpuPath.filename();
- if (!cpuName.starts_with("cpu"))
- {
- 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
- cpuFilterTimer.expires_after(std::chrono::seconds(1));
-
- cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
+ sdbusplus::message::object_path cpuPath(path);
+ std::string cpuName = cpuPath.filename();
+ if (!cpuName.starts_with("cpu"))
{
- /* we were canceled*/
+ 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;
}
- if (ec)
+
+ 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())
{
- std::cerr << "timer error\n";
- return;
+ cpuPresence[index] = std::get<bool>(findPresence->second);
}
- createSensors(io, objectServer, sensors, systemBus, nullptr,
- UpdateType::cpuPresenceChange);
- });
- };
+
+ // this implicitly cancels the timer
+ cpuFilterTimer.expires_after(std::chrono::seconds(1));
+
+ cpuFilterTimer.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);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp
index 52c254a..2c1e391 100644
--- a/src/ChassisIntrusionSensor.cpp
+++ b/src/ChassisIntrusionSensor.cpp
@@ -199,28 +199,30 @@
void ChassisIntrusionGpioSensor::pollSensorStatus()
{
- 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
- {
- int value = readSensor();
- if (value >= 0)
+ 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)
{
- updateValue(value);
+ return; // we're being destroyed
}
- // trigger next polling
- pollSensorStatus();
- }
- });
+
+ if (ec)
+ {
+ std::cerr
+ << "Error on GPIO based intrusion sensor wait event\n";
+ }
+ else
+ {
+ int value = readSensor();
+ if (value >= 0)
+ {
+ updateValue(value);
+ }
+ // trigger next polling
+ pollSensorStatus();
+ }
+ });
}
int ChassisIntrusionHwmonSensor::readSensor()
@@ -349,8 +351,8 @@
mIface->register_property(
"Status", mValue,
[&](const std::string& req, std::string& propertyValue) {
- return setSensorValue(req, propertyValue);
- });
+ return setSensorValue(req, propertyValue);
+ });
std::string rearmStr = mAutoRearm ? autoRearmStr : manualRearmStr;
mIface->register_property("Rearm", rearmStr);
mIface->initialize();
@@ -359,8 +361,7 @@
ChassisIntrusionSensor::ChassisIntrusionSensor(
bool autoRearm, sdbusplus::asio::object_server& objServer) :
- mValue(normalValStr),
- mAutoRearm(autoRearm), mObjServer(objServer)
+ mValue(normalValStr), mAutoRearm(autoRearm), mObjServer(objServer)
{
mIface = mObjServer.add_interface("/xyz/openbmc_project/Chassis/Intrusion",
"xyz.openbmc_project.Chassis.Intrusion");
@@ -369,14 +370,13 @@
ChassisIntrusionPchSensor::ChassisIntrusionPchSensor(
bool autoRearm, boost::asio::io_context& io,
sdbusplus::asio::object_server& objServer, int busId, int slaveAddr) :
- ChassisIntrusionSensor(autoRearm, objServer),
- mPollTimer(io)
+ ChassisIntrusionSensor(autoRearm, objServer), mPollTimer(io)
{
if (busId < 0 || slaveAddr <= 0)
{
- throw std::invalid_argument("Invalid i2c bus " + std::to_string(busId) +
- " address " + std::to_string(slaveAddr) +
- "\n");
+ throw std::invalid_argument(
+ "Invalid i2c bus " + std::to_string(busId) + " address " +
+ std::to_string(slaveAddr) + "\n");
}
mSlaveAddr = slaveAddr;
@@ -413,14 +413,14 @@
ChassisIntrusionGpioSensor::ChassisIntrusionGpioSensor(
bool autoRearm, boost::asio::io_context& io,
sdbusplus::asio::object_server& objServer, bool gpioInverted) :
- ChassisIntrusionSensor(autoRearm, objServer),
- mGpioInverted(gpioInverted), mGpioFd(io)
+ ChassisIntrusionSensor(autoRearm, objServer), mGpioInverted(gpioInverted),
+ mGpioFd(io)
{
mGpioLine = gpiod::find_line(mPinName);
if (!mGpioLine)
{
- throw std::invalid_argument("Error finding gpio pin name: " + mPinName +
- "\n");
+ throw std::invalid_argument(
+ "Error finding gpio pin name: " + mPinName + "\n");
}
mGpioLine.request(
{"ChassisIntrusionSensor", gpiod::line_request::EVENT_BOTH_EDGES,
@@ -450,8 +450,8 @@
if (paths.empty())
{
- throw std::invalid_argument("Hwmon file " + mHwmonName +
- " can't be found in sysfs\n");
+ throw std::invalid_argument(
+ "Hwmon file " + mHwmonName + " can't be found in sysfs\n");
}
if (paths.size() > 1)
diff --git a/src/DeviceMgmt.cpp b/src/DeviceMgmt.cpp
index 1987c73..6d6c296 100644
--- a/src/DeviceMgmt.cpp
+++ b/src/DeviceMgmt.cpp
@@ -17,9 +17,8 @@
namespace fs = std::filesystem;
-std::optional<I2CDeviceParams>
- getI2CDeviceParams(const I2CDeviceTypeMap& dtmap,
- const SensorBaseConfigMap& cfg)
+std::optional<I2CDeviceParams> getI2CDeviceParams(
+ const I2CDeviceTypeMap& dtmap, const SensorBaseConfigMap& cfg)
{
auto findType = cfg.find("Type");
auto findBus = cfg.find("Bus");
diff --git a/src/DeviceMgmt.hpp b/src/DeviceMgmt.hpp
index 84ad8a0..4b4dea8 100644
--- a/src/DeviceMgmt.hpp
+++ b/src/DeviceMgmt.hpp
@@ -28,7 +28,7 @@
struct I2CDeviceParams
{
I2CDeviceParams(const I2CDeviceType& type, uint64_t bus, uint64_t address) :
- type(&type), bus(bus), address(address){};
+ type(&type), bus(bus), address(address) {};
const I2CDeviceType* type;
uint64_t bus;
@@ -38,9 +38,8 @@
bool deviceStatic() const;
};
-std::optional<I2CDeviceParams>
- getI2CDeviceParams(const I2CDeviceTypeMap& dtmap,
- const SensorBaseConfigMap& cfg);
+std::optional<I2CDeviceParams> getI2CDeviceParams(
+ const I2CDeviceTypeMap& dtmap, const SensorBaseConfigMap& cfg);
class I2CDevice
{
diff --git a/src/ExitAirTempSensor.cpp b/src/ExitAirTempSensor.cpp
index 533c94d..bd8960b 100644
--- a/src/ExitAirTempSensor.cpp
+++ b/src/ExitAirTempSensor.cpp
@@ -81,31 +81,33 @@
{
std::function<void(sdbusplus::message_t & message)> eventHandler =
[callback{std::move(callback)}](sdbusplus::message_t& 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);
- };
- matches.emplace_back(connection,
- "type='signal',"
- "member='PropertiesChanged',interface='org."
- "freedesktop.DBus.Properties',path_"
- "namespace='/xyz/openbmc_project/sensors/" +
- std::string(type) +
- "',arg0='xyz.openbmc_project.Sensor.Value'",
- std::move(eventHandler));
+ callback(value, message);
+ };
+ matches.emplace_back(
+ connection,
+ "type='signal',"
+ "member='PropertiesChanged',interface='org."
+ "freedesktop.DBus.Properties',path_"
+ "namespace='/xyz/openbmc_project/sensors/" +
+ std::string(type) + "',arg0='xyz.openbmc_project.Sensor.Value'",
+ std::move(eventHandler));
}
static void setMaxPWM(const std::shared_ptr<sdbusplus::asio::connection>& conn,
@@ -116,51 +118,52 @@
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
conn->async_method_call(
- [conn, value](const boost::system::error_code ec,
- const GetSubTreeType& ret) {
- if (ec)
- {
- std::cerr << "Error calling mapper\n";
- return;
- }
- for (const auto& [path, objDict] : ret)
- {
- if (objDict.empty())
+ [conn,
+ value](const boost::system::error_code ec, const GetSubTreeType& ret) {
+ if (ec)
{
+ std::cerr << "Error calling mapper\n";
return;
}
- const std::string& owner = objDict.begin()->first;
+ for (const auto& [path, objDict] : ret)
+ {
+ if (objDict.empty())
+ {
+ 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;
- }
- const 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));
- },
- owner, path, "org.freedesktop.DBus.Properties", "Get",
- pidConfigurationType, "Class");
- }
- },
+ [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;
+ }
+ const 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));
+ },
+ owner, path, "org.freedesktop.DBus.Properties", "Get",
+ pidConfigurationType, "Class");
+ }
+ },
mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/",
0, std::array<std::string, 1>{pidConfigurationType});
}
@@ -207,83 +210,86 @@
setupSensorMatch(
matches, *dbusConnection, "fan_tach",
[weakRef](const double& value, sdbusplus::message_t& 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;
- }
-
- uint64_t maxRpm = 100;
- if (!ec)
- {
- const auto* cfm = std::get_if<double>(&cfmVariant);
- if (cfm != nullptr && *cfm >= minSystemCfm)
+ auto self = weakRef.lock();
+ if (!self)
{
- maxRpm = self->getMaxRpm(*cfm);
+ return;
}
- }
- self->pwmLimitIface->register_property("Limit", maxRpm);
- self->pwmLimitIface->initialize();
- setMaxPWM(self->dbusConnection, maxRpm);
- },
+
+ uint64_t maxRpm = 100;
+ if (!ec)
+ {
+ const 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);
+ },
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_t& 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;
- }
- auto* const 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_t& 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;
+ }
+ auto* const 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()
@@ -311,21 +317,21 @@
dbusConnection->async_method_call(
[weakRef, path](const boost::system::error_code ec,
const SensorBaseConfigMap& 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");
}
@@ -544,101 +550,103 @@
std::weak_ptr<ExitAirTempSensor> weakRef = weak_from_this();
for (const std::string type : matchTypes)
{
- setupSensorMatch(matches, *dbusConnection, type,
- [weakRef, type](const double& value,
- sdbusplus::message_t& message) {
+ setupSensorMatch(
+ matches, *dbusConnection, type,
+ [weakRef,
+ type](const double& value, sdbusplus::message_t& message) {
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ if (type == "power")
+ {
+ std::string path = message.get_path();
+ if (path.find("PS") != std::string::npos &&
+ path.ends_with("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;
}
- if (type == "power")
- {
- std::string path = message.get_path();
- if (path.find("PS") != std::string::npos &&
- path.ends_with("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);
- },
+ 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)
- {
- std::cerr << "Error contacting mapper\n";
- return;
- }
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- for (const auto& [path, matches] : subtree)
- {
- size_t lastSlash = path.rfind('/');
- if (lastSlash == std::string::npos || lastSlash == path.size() ||
- matches.empty())
+ if (ec)
{
- continue;
+ std::cerr << "Error contacting mapper\n";
+ return;
}
- std::string sensorName = path.substr(lastSlash + 1);
- if (sensorName.starts_with("PS") &&
- sensorName.ends_with("Input_Power"))
+ auto self = weakRef.lock();
+ if (!self)
{
- // lambda capture requires a proper variable (not a structured
- // binding)
- const std::string& cbPath = path;
- self->dbusConnection->async_method_call(
- [weakRef, cbPath](boost::system::error_code ec,
- const std::variant<double>& value) {
- if (ec)
- {
- std::cerr << "Error getting value from " << cbPath
- << "\n";
- }
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- double reading = std::visit(VariantToDoubleVisitor(),
- value);
- if constexpr (debug)
- {
- std::cerr << cbPath << "Reading " << reading << "\n";
- }
- self->powerReadings[cbPath] = reading;
- },
- matches[0].first, cbPath, properties::interface,
- properties::get, sensorValueInterface, "Value");
+ return;
}
- }
- },
+ for (const auto& [path, matches] : subtree)
+ {
+ size_t lastSlash = path.rfind('/');
+ if (lastSlash == std::string::npos ||
+ lastSlash == path.size() || matches.empty())
+ {
+ continue;
+ }
+ std::string sensorName = path.substr(lastSlash + 1);
+ if (sensorName.starts_with("PS") &&
+ sensorName.ends_with("Input_Power"))
+ {
+ // lambda capture requires a proper variable (not a
+ // structured binding)
+ const std::string& cbPath = path;
+ self->dbusConnection->async_method_call(
+ [weakRef, cbPath](boost::system::error_code ec,
+ const std::variant<double>& value) {
+ if (ec)
+ {
+ std::cerr << "Error getting value from "
+ << cbPath << "\n";
+ }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ double reading =
+ std::visit(VariantToDoubleVisitor(), value);
+ if constexpr (debug)
+ {
+ std::cerr
+ << cbPath << "Reading " << reading << "\n";
+ }
+ self->powerReadings[cbPath] = reading;
+ },
+ matches[0].first, cbPath, properties::interface,
+ properties::get, sensorValueInterface, "Value");
+ }
+ }
+ },
mapper::busName, mapper::path, mapper::interface, mapper::subtree,
"/xyz/openbmc_project/sensors/power", 0,
std::array<const char*, 1>{sensorValueInterface});
@@ -873,63 +881,67 @@
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection, [&objectServer, &dbusConnection,
&exitAirSensor](const ManagedObjectType& resp) {
- cfmSensors.clear();
- for (const auto& [path, interfaces] : resp)
- {
- for (const auto& [intf, cfg] : interfaces)
+ cfmSensors.clear();
+ for (const auto& [path, interfaces] : resp)
{
- if (intf == configInterfaceName(exitAirType))
+ for (const auto& [intf, cfg] : interfaces)
{
- // thresholds should be under the same path
- std::vector<thresholds::Threshold> sensorThresholds;
- parseThresholdsFromConfig(interfaces, sensorThresholds);
+ if (intf == configInterfaceName(exitAirType))
+ {
+ // thresholds should be under the same path
+ std::vector<thresholds::Threshold> sensorThresholds;
+ parseThresholdsFromConfig(interfaces, sensorThresholds);
- std::string name = loadVariant<std::string>(cfg, "Name");
- exitAirSensor = nullptr;
- exitAirSensor = std::make_shared<ExitAirTempSensor>(
- dbusConnection, name, path.str, objectServer,
- std::move(sensorThresholds));
- exitAirSensor->powerFactorMin =
- loadVariant<double>(cfg, "PowerFactorMin");
- exitAirSensor->powerFactorMax =
- loadVariant<double>(cfg, "PowerFactorMax");
- exitAirSensor->qMin = loadVariant<double>(cfg, "QMin");
- exitAirSensor->qMax = loadVariant<double>(cfg, "QMax");
- exitAirSensor->alphaS = loadVariant<double>(cfg, "AlphaS");
- exitAirSensor->alphaF = loadVariant<double>(cfg, "AlphaF");
- }
- else if (intf == configInterfaceName(cfmType))
- {
- // thresholds should be under the same path
- std::vector<thresholds::Threshold> sensorThresholds;
- parseThresholdsFromConfig(interfaces, sensorThresholds);
- std::string name = loadVariant<std::string>(cfg, "Name");
- auto sensor = std::make_shared<CFMSensor>(
- dbusConnection, name, path.str, objectServer,
- std::move(sensorThresholds), exitAirSensor);
- loadVariantPathArray(cfg, "Tachs", sensor->tachs);
- sensor->maxCFM = loadVariant<double>(cfg, "MaxCFM");
+ std::string name =
+ loadVariant<std::string>(cfg, "Name");
+ exitAirSensor = nullptr;
+ exitAirSensor = std::make_shared<ExitAirTempSensor>(
+ dbusConnection, name, path.str, objectServer,
+ std::move(sensorThresholds));
+ exitAirSensor->powerFactorMin =
+ loadVariant<double>(cfg, "PowerFactorMin");
+ exitAirSensor->powerFactorMax =
+ loadVariant<double>(cfg, "PowerFactorMax");
+ exitAirSensor->qMin = loadVariant<double>(cfg, "QMin");
+ exitAirSensor->qMax = loadVariant<double>(cfg, "QMax");
+ exitAirSensor->alphaS =
+ loadVariant<double>(cfg, "AlphaS");
+ exitAirSensor->alphaF =
+ loadVariant<double>(cfg, "AlphaF");
+ }
+ else if (intf == configInterfaceName(cfmType))
+ {
+ // thresholds should be under the same path
+ std::vector<thresholds::Threshold> sensorThresholds;
+ parseThresholdsFromConfig(interfaces, sensorThresholds);
+ std::string name =
+ loadVariant<std::string>(cfg, "Name");
+ auto sensor = std::make_shared<CFMSensor>(
+ dbusConnection, name, path.str, objectServer,
+ std::move(sensorThresholds), exitAirSensor);
+ loadVariantPathArray(cfg, "Tachs", sensor->tachs);
+ sensor->maxCFM = loadVariant<double>(cfg, "MaxCFM");
- // change these into percent upon getting the data
- sensor->c1 = loadVariant<double>(cfg, "C1") / 100;
- sensor->c2 = loadVariant<double>(cfg, "C2") / 100;
- sensor->tachMinPercent =
- loadVariant<double>(cfg, "TachMinPercent");
- sensor->tachMaxPercent =
- loadVariant<double>(cfg, "TachMaxPercent");
- sensor->createMaxCFMIface();
- sensor->setupMatches();
+ // change these into percent upon getting the data
+ sensor->c1 = loadVariant<double>(cfg, "C1") / 100;
+ sensor->c2 = loadVariant<double>(cfg, "C2") / 100;
+ sensor->tachMinPercent =
+ loadVariant<double>(cfg, "TachMinPercent");
+ sensor->tachMaxPercent =
+ loadVariant<double>(cfg, "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>(monitorTypes.begin(), monitorTypes.end()));
}
@@ -951,20 +963,20 @@
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t&) {
- configTimer.expires_after(std::chrono::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_after(std::chrono::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";
+ }
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, monitorTypes, eventHandler);
diff --git a/src/ExternalSensor.cpp b/src/ExternalSensor.cpp
index bce0a31..506823a 100644
--- a/src/ExternalSensor.cpp
+++ b/src/ExternalSensor.cpp
@@ -59,8 +59,8 @@
objectServer.add_interface(objectPath, interface);
}
- association = objectServer.add_interface(objectPath,
- association::interface);
+ association =
+ objectServer.add_interface(objectPath, association::interface);
setInitialProperties(sensorUnits);
if constexpr (debug)
diff --git a/src/ExternalSensor.hpp b/src/ExternalSensor.hpp
index 6f5b3db..c3a7103 100644
--- a/src/ExternalSensor.hpp
+++ b/src/ExternalSensor.hpp
@@ -14,15 +14,14 @@
public std::enable_shared_from_this<ExternalSensor>
{
public:
- ExternalSensor(const std::string& objectType,
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- const std::string& sensorName,
- const std::string& sensorUnits,
- std::vector<thresholds::Threshold>&& thresholdsIn,
- const std::string& sensorConfiguration, double maxReading,
- double minReading, double timeoutSecs,
- const PowerState& powerState);
+ ExternalSensor(
+ const std::string& objectType,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::string& sensorName, const std::string& sensorUnits,
+ std::vector<thresholds::Threshold>&& thresholdsIn,
+ const std::string& sensorConfiguration, double maxReading,
+ double minReading, double timeoutSecs, const PowerState& powerState);
~ExternalSensor() override;
// Call this immediately after calling the constructor
diff --git a/src/ExternalSensorMain.cpp b/src/ExternalSensorMain.cpp
index 3beb5b9..9bd7a4d 100644
--- a/src/ExternalSensorMain.cpp
+++ b/src/ExternalSensorMain.cpp
@@ -59,10 +59,11 @@
static const char* sensorType = "ExternalSensor";
-void updateReaper(boost::container::flat_map<
- std::string, std::shared_ptr<ExternalSensor>>& sensors,
- boost::asio::steady_timer& timer,
- const std::chrono::steady_clock::time_point& now)
+void updateReaper(
+ boost::container::flat_map<std::string, std::shared_ptr<ExternalSensor>>&
+ sensors,
+ boost::asio::steady_timer& timer,
+ const std::chrono::steady_clock::time_point& now)
{
// First pass, reap all stale sensors
for (const auto& [name, sensor] : sensors)
@@ -169,169 +170,172 @@
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)
- {
- const std::string& interfacePath = sensor.first.str;
- const SensorData& sensorData = sensor.second;
+ 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(configInterfaceName(sensorType));
- if (sensorBase == sensorData.end())
- {
- std::cerr << "Base configuration not found for "
- << interfacePath << "\n";
- continue;
- }
-
- 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;
- }
-
- 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;
-
- // 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;
-
- // 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;
- }
-
- // 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++)
+ auto sensorBase =
+ sensorData.find(configInterfaceName(sensorType));
+ if (sensorBase == sensorData.end())
{
- std::string suffixIt = "/";
- suffixIt += *it;
- if (suffixIt.ends_with(suffixName))
- {
- sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- if constexpr (debug)
- {
- std::cerr << "ExternalSensor " << sensorName
- << " change found\n";
- }
- break;
- }
- }
- if (!found)
- {
+ std::cerr << "Base configuration not found for "
+ << interfacePath << "\n";
continue;
}
+
+ 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;
+ }
+
+ 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;
+
+ // 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;
+
+ // 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;
+ }
+
+ // 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 (suffixIt.ends_with(suffixName))
+ {
+ sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ if constexpr (debug)
+ {
+ std::cerr << "ExternalSensor " << sensorName
+ << " change found\n";
+ }
+ break;
+ }
+ }
+ if (!found)
+ {
+ continue;
+ }
+ }
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(sensorData, sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for "
+ << sensorName << "\n";
+ }
+
+ PowerState readState = getPowerState(baseConfigMap);
+
+ 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";
+ }
}
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(sensorData, sensorThresholds))
- {
- std::cerr << "error populating thresholds for " << sensorName
- << "\n";
- }
-
- PowerState readState = getPowerState(baseConfigMap);
-
- 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});
}
@@ -356,8 +360,8 @@
std::make_shared<boost::container::flat_set<std::string>>();
boost::asio::steady_timer reaperTimer(io);
- boost::asio::post(io,
- [&objectServer, &sensors, &systemBus, &reaperTimer]() {
+ boost::asio::post(io, [&objectServer, &sensors, &systemBus,
+ &reaperTimer]() {
createSensors(objectServer, sensors, systemBus, nullptr, reaperTimer);
});
@@ -365,39 +369,40 @@
std::function<void(sdbusplus::message_t&)> eventHandler =
[&objectServer, &sensors, &systemBus, &sensorsChanged, &filterTimer,
&reaperTimer](sdbusplus::message_t& message) mutable {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
-
- const 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_after(std::chrono::seconds(1));
-
- filterTimer.async_wait(
- [&objectServer, &sensors, &systemBus, &sensorsChanged,
- &reaperTimer](const boost::system::error_code& ec) mutable {
- if (ec != boost::system::errc::success)
+ if (message.is_method_error())
{
- if (ec != boost::asio::error::operation_aborted)
- {
- std::cerr << "callback error: " << ec.message() << "\n";
- }
+ std::cerr << "callback method error\n";
return;
}
- createSensors(objectServer, sensors, systemBus, sensorsChanged,
- reaperTimer);
- });
- };
+ const 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_after(std::chrono::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);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 8061d4c..4087472 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -228,42 +228,42 @@
conn->async_method_call(
[&objectServer, &sensors](boost::system::error_code& ec,
const ManagedObjectType& managedObj) {
- if (ec)
- {
- std::cerr << "Error calling entity manager \n";
- return;
- }
- for (const auto& [path, interfaces] : managedObj)
- {
- for (const auto& [intf, cfg] : interfaces)
+ if (ec)
{
- if (intf == redundancyConfiguration)
+ std::cerr << "Error calling entity manager \n";
+ return;
+ }
+ for (const auto& [path, interfaces] : managedObj)
+ {
+ for (const auto& [intf, cfg] : interfaces)
{
- // currently only support one
- auto findCount = cfg.find("AllowedFailures");
- if (findCount == cfg.end())
+ if (intf == redundancyConfiguration)
{
- std::cerr << "Malformed redundancy record \n";
+ // currently only support one
+ auto findCount = cfg.find("AllowedFailures");
+ if (findCount == cfg.end())
+ {
+ std::cerr << "Malformed redundancy record \n";
+ return;
+ }
+ std::vector<std::string> sensorList;
+
+ for (const auto& [name, sensor] : sensors)
+ {
+ sensorList.push_back(
+ "/xyz/openbmc_project/sensors/fan_tach/" +
+ sensor->name);
+ }
+ systemRedundancy.reset();
+ systemRedundancy.emplace(RedundancySensor(
+ std::get<uint64_t>(findCount->second), sensorList,
+ objectServer, path));
+
return;
}
- std::vector<std::string> sensorList;
-
- for (const auto& [name, sensor] : sensors)
- {
- sensorList.push_back(
- "/xyz/openbmc_project/sensors/fan_tach/" +
- sensor->name);
- }
- systemRedundancy.reset();
- systemRedundancy.emplace(
- RedundancySensor(std::get<uint64_t>(findCount->second),
- sensorList, objectServer, path));
-
- return;
}
}
- }
- },
+ },
"xyz.openbmc_project.EntityManager", "/xyz/openbmc_project/inventory",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
}
@@ -282,314 +282,322 @@
size_t retries = 0)
{
auto getter = std::make_shared<GetSensorConfiguration>(
- dbusConnection, [&io, &objectServer, &tachSensors, &pwmSensors,
- &presenceSensors, &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))
- {
- 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);
- std::string cfgIntf = configInterfaceName(sensorTypes[fanType]);
-
- // 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 auto& [path, cfgData] : sensorConfigurations)
+ dbusConnection,
+ [&io, &objectServer, &tachSensors, &pwmSensors, &presenceSensors,
+ &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))
{
- // find the base of the configuration to see if indexes
- // match
- auto sensorBaseFind = cfgData.find(cfgIntf);
- if (sensorBaseFind == cfgData.end())
- {
- continue;
- }
+ std::cerr << "No fan sensors in system\n";
+ return;
+ }
- baseConfiguration = &(*sensorBaseFind);
- interfacePath = &path.str;
- baseType = sensorTypes[fanType];
+ // 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();
- 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 || fanType == FanTypes::hpe)
- {
- // there will be only 1 aspeed or nuvoton or hpe sensor
- // object in sysfs, we found the fan
- sensorData = &cfgData;
- break;
- }
- if (fanType == FanTypes::i2c)
- {
- std::string deviceName =
- fs::read_symlink(directory / "device").filename();
+ std::regex_search(pathStr, match, inputRegex);
+ std::string indexStr = *(match.begin() + 1);
- size_t bus = 0;
- size_t addr = 0;
- if (!getDeviceBusAddr(deviceName, bus, addr))
+ fs::path directory = path.parent_path();
+ FanTypes fanType = getFanType(directory);
+ std::string cfgIntf = configInterfaceName(sensorTypes[fanType]);
+
+ // 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 auto& [path, cfgData] : sensorConfigurations)
+ {
+ // find the base of the configuration to see if indexes
+ // match
+ auto sensorBaseFind = cfgData.find(cfgIntf);
+ if (sensorBaseFind == cfgData.end())
{
continue;
}
- auto findBus = baseConfiguration->second.find("Bus");
- auto findAddress =
- baseConfiguration->second.find("Address");
- if (findBus == baseConfiguration->second.end() ||
- findAddress == baseConfiguration->second.end())
+ baseConfiguration = &(*sensorBaseFind);
+ interfacePath = &path.str;
+ baseType = sensorTypes[fanType];
+
+ auto findIndex = baseConfiguration->second.find("Index");
+ if (findIndex == baseConfiguration->second.end())
{
- std::cerr << baseConfiguration->first
- << " missing bus or address\n";
+ std::cerr
+ << baseConfiguration->first << " missing index\n";
continue;
}
- unsigned int configBus = std::visit(
- VariantToUnsignedIntVisitor(), findBus->second);
- unsigned int configAddress = std::visit(
- VariantToUnsignedIntVisitor(), findAddress->second);
-
- if (configBus == bus && configAddress == addr)
+ unsigned int configIndex = std::visit(
+ VariantToUnsignedIntVisitor(), findIndex->second);
+ if (configIndex != index)
{
+ continue;
+ }
+ if (fanType == FanTypes::aspeed ||
+ fanType == FanTypes::nuvoton ||
+ fanType == FanTypes::hpe)
+ {
+ // there will be only 1 aspeed or nuvoton or hpe sensor
+ // object in sysfs, we found the fan
sensorData = &cfgData;
break;
}
- }
- }
- 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 (it->ends_with(findSensor->second->name))
+ if (fanType == FanTypes::i2c)
{
- sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- break;
+ std::string deviceName =
+ fs::read_symlink(directory / "device").filename();
+
+ size_t bus = 0;
+ size_t addr = 0;
+ if (!getDeviceBusAddr(deviceName, bus, addr))
+ {
+ continue;
+ }
+
+ 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 == addr)
+ {
+ sensorData = &cfgData;
+ break;
+ }
}
}
- if (!found)
+ if (sensorData == nullptr)
{
+ 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 presenceConfig =
- sensorData->find(cfgIntf + std::string(".Presence"));
+ auto findSensorName = baseConfiguration->second.find("Name");
- std::shared_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())
+ if (findSensorName == baseConfiguration->second.end())
{
- std::cerr << "Malformed Presence Configuration\n";
+ std::cerr << "could not determine configuration name for "
+ << path.string() << "\n";
+ continue;
}
- else
- {
- bool inverted =
- std::get<std::string>(findPolarity->second) == "Low";
- const auto* pinName =
- std::get_if<std::string>(&findPinName->second);
+ std::string sensorName =
+ std::get<std::string>(findSensorName->second);
- if (pinName != nullptr)
+ // 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++)
{
- auto findPresenceSensor =
- presenceSensors.find(*pinName);
- if (findPresenceSensor != presenceSensors.end())
+ if (it->ends_with(findSensor->second->name))
{
- auto p = findPresenceSensor->second.lock();
- if (p)
- {
- presenceSensor = p;
- }
- }
- if (!presenceSensor)
- {
- presenceSensor = std::make_shared<PresenceSensor>(
- *pinName, inverted, io, sensorName);
- presenceSensors[*pinName] = presenceSensor;
+ sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ break;
}
}
- else
+ if (!found)
{
- std::cerr << "Malformed Presence pinName for sensor "
- << sensorName << " \n";
- }
- }
- }
- std::optional<RedundancySensor>* redundancy = nullptr;
- if (fanType == FanTypes::aspeed)
- {
- redundancy = &systemRedundancy;
- }
-
- PowerState powerState = getPowerState(baseConfiguration->second);
-
- constexpr double defaultMaxReading = 25000;
- constexpr double defaultMinReading = 0;
- std::pair<double, double> limits =
- std::make_pair(defaultMinReading, defaultMaxReading);
-
- auto connector =
- sensorData->find(cfgIntf + 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;
}
+ }
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for "
+ << sensorName << "\n";
+ }
- fs::path pwmEnableFile = "pwm" + std::to_string(pwm + 1) +
- "_enable";
- fs::path enablePath = pwmPath.parent_path() / pwmEnableFile;
- enablePwm(enablePath);
+ auto presenceConfig =
+ sensorData->find(cfgIntf + std::string(".Presence"));
- /* use pwm name override if found in configuration else
- * use default */
- auto findOverride = connector->second.find("PwmName");
- if (findOverride != connector->second.end())
+ std::shared_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())
{
- pwmName = std::visit(VariantToStringVisitor(),
- findOverride->second);
+ std::cerr << "Malformed Presence Configuration\n";
}
else
{
- pwmName = "Pwm_" + std::to_string(pwm + 1);
- }
+ bool inverted = std::get<std::string>(
+ findPolarity->second) == "Low";
+ const auto* pinName =
+ std::get_if<std::string>(&findPinName->second);
- // Check PWM sensor mutability
- auto findMutable = connector->second.find("Mutable");
- if (findMutable != connector->second.end())
- {
- const auto* ptrMutable =
- std::get_if<bool>(&(findMutable->second));
- if (ptrMutable != nullptr)
+ if (pinName != nullptr)
{
- isValueMutable = *ptrMutable;
+ auto findPresenceSensor =
+ presenceSensors.find(*pinName);
+ if (findPresenceSensor != presenceSensors.end())
+ {
+ auto p = findPresenceSensor->second.lock();
+ if (p)
+ {
+ presenceSensor = p;
+ }
+ }
+ if (!presenceSensor)
+ {
+ presenceSensor =
+ std::make_shared<PresenceSensor>(
+ *pinName, inverted, io, sensorName);
+ presenceSensors[*pinName] = presenceSensor;
+ }
+ }
+ else
+ {
+ std::cerr
+ << "Malformed Presence pinName for sensor "
+ << sensorName << " \n";
}
}
}
- else
+ std::optional<RedundancySensor>* redundancy = nullptr;
+ if (fanType == FanTypes::aspeed)
{
- std::cerr << "Connector for " << sensorName
- << " missing pwm!\n";
+ redundancy = &systemRedundancy;
}
- auto findLED = connector->second.find("LED");
- if (findLED != connector->second.end())
+ PowerState powerState =
+ getPowerState(baseConfiguration->second);
+
+ constexpr double defaultMaxReading = 25000;
+ constexpr double defaultMinReading = 0;
+ std::pair<double, double> limits =
+ std::make_pair(defaultMinReading, defaultMaxReading);
+
+ auto connector =
+ sensorData->find(cfgIntf + 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())
{
- const auto* ledName =
- std::get_if<std::string>(&(findLED->second));
- if (ledName == nullptr)
+ auto findPwm = connector->second.find("Pwm");
+ if (findPwm != connector->second.end())
{
- std::cerr << "Wrong format for LED of " << sensorName
- << "\n";
+ 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())
+ {
+ const auto* ptrMutable =
+ std::get_if<bool>(&(findMutable->second));
+ if (ptrMutable != nullptr)
+ {
+ isValueMutable = *ptrMutable;
+ }
+ }
}
else
{
- led = *ledName;
+ std::cerr << "Connector for " << sensorName
+ << " missing pwm!\n";
}
+
+ auto findLED = connector->second.find("LED");
+ if (findLED != connector->second.end())
+ {
+ const 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);
+
+ enableFanInput(path);
+
+ auto& tachSensor = tachSensors[sensorName];
+ tachSensor = nullptr;
+ tachSensor = std::make_shared<TachSensor>(
+ path.string(), baseType, objectServer, dbusConnection,
+ presenceSensor, redundancy, io, sensorName,
+ std::move(sensorThresholds), *interfacePath, limits,
+ powerState, led);
+ tachSensor->setupRead();
+
+ if (!pwmPath.empty() && fs::exists(pwmPath) &&
+ (pwmSensors.count(pwmPath) == 0U))
+ {
+ pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
+ pwmName, pwmPath, dbusConnection, objectServer,
+ *interfacePath, "Fan", isValueMutable);
}
}
- findLimits(limits, baseConfiguration);
-
- enableFanInput(path);
-
- auto& tachSensor = tachSensors[sensorName];
- tachSensor = nullptr;
- tachSensor = std::make_shared<TachSensor>(
- path.string(), baseType, objectServer, dbusConnection,
- presenceSensor, redundancy, io, sensorName,
- std::move(sensorThresholds), *interfacePath, limits, powerState,
- led);
- tachSensor->setupRead();
-
- if (!pwmPath.empty() && fs::exists(pwmPath) &&
- (pwmSensors.count(pwmPath) == 0U))
- {
- pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
- pwmName, pwmPath, dbusConnection, objectServer,
- *interfacePath, "Fan", isValueMutable);
- }
- }
-
- createRedundancySensor(tachSensors, dbusConnection, objectServer);
- });
+ createRedundancySensor(tachSensors, dbusConnection, objectServer);
+ });
getter->getConfiguration(
std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()},
retries);
@@ -622,30 +630,30 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- sensorsChanged->insert(message.get_path());
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ sensorsChanged->insert(message.get_path());
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- /* we were canceled*/
- return;
- }
- if (ec)
- {
- std::cerr << "timer error\n";
- return;
- }
- createSensors(io, objectServer, tachSensors, pwmSensors,
- presenceSensors, systemBus, sensorsChanged, 5);
- });
- };
+ 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,
+ presenceSensors, systemBus, sensorsChanged, 5);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
@@ -653,8 +661,8 @@
// redundancy sensor
std::function<void(sdbusplus::message_t&)> redundancyHandler =
[&tachSensors, &systemBus, &objectServer](sdbusplus::message_t&) {
- createRedundancySensor(tachSensors, systemBus, objectServer);
- };
+ createRedundancySensor(tachSensors, systemBus, objectServer);
+ };
auto match = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(*systemBus),
"type='signal',member='PropertiesChanged',path_namespace='" +
diff --git a/src/FileHandle.cpp b/src/FileHandle.cpp
index cb33e90..90bf64b 100644
--- a/src/FileHandle.cpp
+++ b/src/FileHandle.cpp
@@ -19,7 +19,7 @@
}
}
-FileHandle::FileHandle(int fdIn) : fd(fdIn){};
+FileHandle::FileHandle(int fdIn) : fd(fdIn) {};
FileHandle::FileHandle(FileHandle&& in) noexcept : fd(in.fd)
{
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index ec64c43..956e9e5 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -120,8 +120,8 @@
const std::string pathStr = path.string();
if (pathStr.ends_with("_raw"))
{
- std::string pathOffsetStr = pathStr.substr(0, pathStr.size() - 4) +
- "_offset";
+ std::string pathOffsetStr =
+ pathStr.substr(0, pathStr.size() - 4) + "_offset";
std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
// In case there is nothing to read skip this device
// This is not an error condition see lore
@@ -131,8 +131,8 @@
tmpSensorParameters.offsetValue = *tmpOffsetValue;
}
- std::string pathScaleStr = pathStr.substr(0, pathStr.size() - 4) +
- "_scale";
+ std::string pathScaleStr =
+ pathStr.substr(0, pathStr.size() - 4) + "_scale";
std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
// In case there is nothing to read skip this device
// This is not an error condition see lore
@@ -276,229 +276,173 @@
dbusConnection,
[&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
activateOnly](const ManagedObjectType& sensorConfigurations) {
- bool firstScan = sensorsChanged == nullptr;
+ bool firstScan = sensorsChanged == nullptr;
- SensorConfigMap configMap = buildSensorConfigMap(sensorConfigurations);
+ SensorConfigMap configMap =
+ buildSensorConfigMap(sensorConfigurations);
- auto devices = instantiateDevices(sensorConfigurations, sensors,
- sensorTypes);
+ auto devices =
+ instantiateDevices(sensorConfigurations, sensors, sensorTypes);
- // IIO _raw devices look like this on sysfs:
- // /sys/bus/iio/devices/iio:device0/in_temp_raw
- // /sys/bus/iio/devices/iio:device0/in_temp_offset
- // /sys/bus/iio/devices/iio:device0/in_temp_scale
- //
- // Other IIO devices look like this on sysfs:
- // /sys/bus/iio/devices/iio:device1/in_temp_input
- // /sys/bus/iio/devices/iio:device1/in_pressure_input
- std::vector<fs::path> paths;
- fs::path root("/sys/bus/iio/devices");
- findFiles(root, R"(in_temp\d*_(input|raw))", paths);
- findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
- findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
- findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
+ // IIO _raw devices look like this on sysfs:
+ // /sys/bus/iio/devices/iio:device0/in_temp_raw
+ // /sys/bus/iio/devices/iio:device0/in_temp_offset
+ // /sys/bus/iio/devices/iio:device0/in_temp_scale
+ //
+ // Other IIO devices look like this on sysfs:
+ // /sys/bus/iio/devices/iio:device1/in_temp_input
+ // /sys/bus/iio/devices/iio:device1/in_pressure_input
+ std::vector<fs::path> paths;
+ fs::path root("/sys/bus/iio/devices");
+ findFiles(root, R"(in_temp\d*_(input|raw))", paths);
+ findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
+ findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
+ findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
- // iterate through all found temp and pressure sensors,
- // and try to match them with configuration
- for (auto& path : paths)
- {
- std::smatch match;
- const std::string pathStr = path.string();
- auto directory = path.parent_path();
- fs::path device;
-
- std::string deviceName;
- std::error_code ec;
- if (pathStr.starts_with("/sys/bus/iio/devices"))
+ // iterate through all found temp and pressure sensors,
+ // and try to match them with configuration
+ for (auto& path : paths)
{
- device = fs::canonical(directory, ec);
- if (ec)
+ std::smatch match;
+ const std::string pathStr = path.string();
+ auto directory = path.parent_path();
+ fs::path device;
+
+ std::string deviceName;
+ std::error_code ec;
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
{
- std::cerr << "Fail to find device in path [" << pathStr
- << "]\n";
- continue;
- }
- deviceName = device.parent_path().stem();
- }
- else
- {
- device = fs::canonical(directory / "device", ec);
- if (ec)
- {
- std::cerr << "Fail to find device in path [" << pathStr
- << "]\n";
- continue;
- }
- deviceName = device.stem();
- }
-
- uint64_t bus = 0;
- uint64_t addr = 0;
- if (!getDeviceBusAddr(deviceName, bus, addr))
- {
- continue;
- }
-
- auto thisSensorParameters = getSensorParameters(path);
- auto findSensorCfg = configMap.find({bus, addr});
- if (findSensorCfg == configMap.end())
- {
- continue;
- }
-
- const std::string& interfacePath = findSensorCfg->second.sensorPath;
- auto findI2CDev = devices.find(interfacePath);
-
- std::shared_ptr<I2CDevice> i2cDev;
- if (findI2CDev != devices.end())
- {
- // If we're only looking to activate newly-instantiated i2c
- // devices and this sensor's underlying device was already there
- // before this call, there's nothing more to do here.
- if (activateOnly && !findI2CDev->second.second)
- {
- continue;
- }
- i2cDev = findI2CDev->second.first;
- }
-
- const SensorData& sensorData = findSensorCfg->second.sensorData;
- std::string sensorType = findSensorCfg->second.interface;
- auto pos = sensorType.find_last_of('.');
- if (pos != std::string::npos)
- {
- sensorType = sensorType.substr(pos + 1);
- }
- const SensorBaseConfigMap& baseConfigMap =
- findSensorCfg->second.config;
- std::vector<std::string>& hwmonName = findSensorCfg->second.name;
-
- // Temperature has "Name", pressure has "Name1"
- auto findSensorName = baseConfigMap.find("Name");
- int index = 1;
- if (thisSensorParameters.typeName == "pressure" ||
- thisSensorParameters.typeName == "humidity")
- {
- findSensorName = baseConfigMap.find("Name1");
- index = 2;
- }
-
- if (findSensorName == baseConfigMap.end())
- {
- std::cerr << "could not determine configuration name for "
- << deviceName << "\n";
- continue;
- }
- std::string sensorName =
- std::get<std::string>(findSensorName->second);
- // on rescans, only update sensors we were signaled by
- auto findSensor = sensors.find(sensorName);
- if (!firstScan && findSensor != sensors.end())
- {
- bool found = false;
- auto it = sensorsChanged->begin();
- while (it != sensorsChanged->end())
- {
- if (it->ends_with(findSensor->second->name))
+ device = fs::canonical(directory, ec);
+ if (ec)
{
- it = sensorsChanged->erase(it);
- findSensor->second = nullptr;
- found = true;
- break;
+ std::cerr << "Fail to find device in path [" << pathStr
+ << "]\n";
+ continue;
}
- ++it;
- }
- if (!found)
- {
- continue;
- }
- }
-
- std::vector<thresholds::Threshold> sensorThresholds;
-
- if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
- nullptr, &index))
- {
- std::cerr << "error populating thresholds for " << sensorName
- << " index " << index << "\n";
- }
-
- float pollRate = getPollRate(baseConfigMap, pollRateDefault);
- PowerState readState = getPowerState(baseConfigMap);
-
- auto permitSet = getPermitSet(baseConfigMap);
- auto& sensor = sensors[sensorName];
- if (!activateOnly)
- {
- sensor = nullptr;
- }
- auto hwmonFile = getFullHwmonFilePath(directory.string(), "temp1",
- permitSet);
- if (pathStr.starts_with("/sys/bus/iio/devices"))
- {
- hwmonFile = pathStr;
- }
- if (hwmonFile)
- {
- if (sensor != nullptr)
- {
- sensor->activate(*hwmonFile, i2cDev);
+ deviceName = device.parent_path().stem();
}
else
{
- sensor = std::make_shared<HwmonTempSensor>(
- *hwmonFile, sensorType, objectServer, dbusConnection,
- io, sensorName, std::move(sensorThresholds),
- thisSensorParameters, pollRate, interfacePath,
- readState, i2cDev);
- sensor->setupRead();
+ device = fs::canonical(directory / "device", ec);
+ if (ec)
+ {
+ std::cerr << "Fail to find device in path [" << pathStr
+ << "]\n";
+ continue;
+ }
+ deviceName = device.stem();
}
- }
- hwmonName.erase(
- remove(hwmonName.begin(), hwmonName.end(), sensorName),
- hwmonName.end());
- // Looking for keys like "Name1" for temp2_input,
- // "Name2" for temp3_input, etc.
- int i = 0;
- while (true)
- {
- ++i;
- auto findKey = baseConfigMap.find("Name" + std::to_string(i));
- if (findKey == baseConfigMap.end())
- {
- break;
- }
- std::string sensorName = std::get<std::string>(findKey->second);
- hwmonFile = getFullHwmonFilePath(directory.string(),
- "temp" + std::to_string(i + 1),
- permitSet);
- if (pathStr.starts_with("/sys/bus/iio/devices"))
+ uint64_t bus = 0;
+ uint64_t addr = 0;
+ if (!getDeviceBusAddr(deviceName, bus, addr))
{
continue;
}
+
+ auto thisSensorParameters = getSensorParameters(path);
+ auto findSensorCfg = configMap.find({bus, addr});
+ if (findSensorCfg == configMap.end())
+ {
+ continue;
+ }
+
+ const std::string& interfacePath =
+ findSensorCfg->second.sensorPath;
+ auto findI2CDev = devices.find(interfacePath);
+
+ std::shared_ptr<I2CDevice> i2cDev;
+ if (findI2CDev != devices.end())
+ {
+ // If we're only looking to activate newly-instantiated i2c
+ // devices and this sensor's underlying device was already
+ // there before this call, there's nothing more to do here.
+ if (activateOnly && !findI2CDev->second.second)
+ {
+ continue;
+ }
+ i2cDev = findI2CDev->second.first;
+ }
+
+ const SensorData& sensorData = findSensorCfg->second.sensorData;
+ std::string sensorType = findSensorCfg->second.interface;
+ auto pos = sensorType.find_last_of('.');
+ if (pos != std::string::npos)
+ {
+ sensorType = sensorType.substr(pos + 1);
+ }
+ const SensorBaseConfigMap& baseConfigMap =
+ findSensorCfg->second.config;
+ std::vector<std::string>& hwmonName =
+ findSensorCfg->second.name;
+
+ // Temperature has "Name", pressure has "Name1"
+ auto findSensorName = baseConfigMap.find("Name");
+ int index = 1;
+ if (thisSensorParameters.typeName == "pressure" ||
+ thisSensorParameters.typeName == "humidity")
+ {
+ findSensorName = baseConfigMap.find("Name1");
+ index = 2;
+ }
+
+ if (findSensorName == baseConfigMap.end())
+ {
+ std::cerr << "could not determine configuration name for "
+ << deviceName << "\n";
+ continue;
+ }
+ std::string sensorName =
+ std::get<std::string>(findSensorName->second);
+ // on rescans, only update sensors we were signaled by
+ auto findSensor = sensors.find(sensorName);
+ if (!firstScan && findSensor != sensors.end())
+ {
+ bool found = false;
+ auto it = sensorsChanged->begin();
+ while (it != sensorsChanged->end())
+ {
+ if (it->ends_with(findSensor->second->name))
+ {
+ it = sensorsChanged->erase(it);
+ findSensor->second = nullptr;
+ found = true;
+ break;
+ }
+ ++it;
+ }
+ if (!found)
+ {
+ continue;
+ }
+ }
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+
+ if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
+ nullptr, &index))
+ {
+ std::cerr << "error populating thresholds for "
+ << sensorName << " index " << index << "\n";
+ }
+
+ float pollRate = getPollRate(baseConfigMap, pollRateDefault);
+ PowerState readState = getPowerState(baseConfigMap);
+
+ auto permitSet = getPermitSet(baseConfigMap);
+ auto& sensor = sensors[sensorName];
+ if (!activateOnly)
+ {
+ sensor = nullptr;
+ }
+ auto hwmonFile = getFullHwmonFilePath(directory.string(),
+ "temp1", permitSet);
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
+ {
+ hwmonFile = pathStr;
+ }
if (hwmonFile)
{
- // To look up thresholds for these additional sensors,
- // match on the Index property in the threshold data
- // where the index comes from the sysfs file we're on,
- // i.e. index = 2 for temp2_input.
- int index = i + 1;
- std::vector<thresholds::Threshold> thresholds;
-
- if (!parseThresholdsFromConfig(sensorData, thresholds,
- nullptr, &index))
- {
- std::cerr << "error populating thresholds for "
- << sensorName << " index " << index << "\n";
- }
-
- auto& sensor = sensors[sensorName];
- if (!activateOnly)
- {
- sensor = nullptr;
- }
-
if (sensor != nullptr)
{
sensor->activate(*hwmonFile, i2cDev);
@@ -508,22 +452,84 @@
sensor = std::make_shared<HwmonTempSensor>(
*hwmonFile, sensorType, objectServer,
dbusConnection, io, sensorName,
- std::move(thresholds), thisSensorParameters,
+ std::move(sensorThresholds), thisSensorParameters,
pollRate, interfacePath, readState, i2cDev);
sensor->setupRead();
}
}
-
hwmonName.erase(
remove(hwmonName.begin(), hwmonName.end(), sensorName),
hwmonName.end());
+
+ // Looking for keys like "Name1" for temp2_input,
+ // "Name2" for temp3_input, etc.
+ int i = 0;
+ while (true)
+ {
+ ++i;
+ auto findKey =
+ baseConfigMap.find("Name" + std::to_string(i));
+ if (findKey == baseConfigMap.end())
+ {
+ break;
+ }
+ std::string sensorName =
+ std::get<std::string>(findKey->second);
+ hwmonFile = getFullHwmonFilePath(
+ directory.string(), "temp" + std::to_string(i + 1),
+ permitSet);
+ if (pathStr.starts_with("/sys/bus/iio/devices"))
+ {
+ continue;
+ }
+ if (hwmonFile)
+ {
+ // To look up thresholds for these additional sensors,
+ // match on the Index property in the threshold data
+ // where the index comes from the sysfs file we're on,
+ // i.e. index = 2 for temp2_input.
+ int index = i + 1;
+ std::vector<thresholds::Threshold> thresholds;
+
+ if (!parseThresholdsFromConfig(sensorData, thresholds,
+ nullptr, &index))
+ {
+ std::cerr
+ << "error populating thresholds for "
+ << sensorName << " index " << index << "\n";
+ }
+
+ auto& sensor = sensors[sensorName];
+ if (!activateOnly)
+ {
+ sensor = nullptr;
+ }
+
+ if (sensor != nullptr)
+ {
+ sensor->activate(*hwmonFile, i2cDev);
+ }
+ else
+ {
+ sensor = std::make_shared<HwmonTempSensor>(
+ *hwmonFile, sensorType, objectServer,
+ dbusConnection, io, sensorName,
+ std::move(thresholds), thisSensorParameters,
+ pollRate, interfacePath, readState, i2cDev);
+ sensor->setupRead();
+ }
+ }
+
+ hwmonName.erase(
+ remove(hwmonName.begin(), hwmonName.end(), sensorName),
+ hwmonName.end());
+ }
+ if (hwmonName.empty())
+ {
+ configMap.erase(findSensorCfg);
+ }
}
- if (hwmonName.empty())
- {
- configMap.erase(findSensorCfg);
- }
- }
- });
+ });
std::vector<std::string> types(sensorTypes.size());
for (const auto& [type, dt] : sensorTypes)
{
@@ -615,30 +621,30 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- sensorsChanged->insert(message.get_path());
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
+ if (message.is_method_error())
+ {
+ std::cerr << "callback method error\n";
+ return;
+ }
+ sensorsChanged->insert(message.get_path());
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- /* we were canceled*/
- return;
- }
- if (ec)
- {
- std::cerr << "timer error\n";
- return;
- }
- createSensors(io, objectServer, sensors, systemBus, sensorsChanged,
- false);
- });
- };
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ /* we were canceled*/
+ return;
+ }
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, sensors, systemBus,
+ sensorsChanged, false);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
@@ -651,8 +657,8 @@
"type='signal',member='InterfacesRemoved',arg0path='" +
std::string(inventoryPath) + "/'",
[&sensors](sdbusplus::message_t& msg) {
- interfaceRemoved(msg, sensors);
- });
+ interfaceRemoved(msg, sensors);
+ });
matches.emplace_back(std::move(ifaceRemovedMatch));
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index 0afacf8..eab7349 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -77,15 +77,15 @@
{
std::string interface = thresholds::getInterface(threshold.level);
thresholdInterfaces[static_cast<size_t>(threshold.level)] =
- objectServer.add_interface("/xyz/openbmc_project/sensors/" +
- thisSensorParameters.typeName + "/" +
- name,
- interface);
+ objectServer.add_interface(
+ "/xyz/openbmc_project/sensors/" +
+ thisSensorParameters.typeName + "/" + name,
+ interface);
}
- association = objectServer.add_interface("/xyz/openbmc_project/sensors/" +
- thisSensorParameters.typeName +
- "/" + name,
- association::interface);
+ association = objectServer.add_interface(
+ "/xyz/openbmc_project/sensors/" + thisSensorParameters.typeName + "/" +
+ name,
+ association::interface);
setInitialProperties(thisSensorParameters.units);
}
@@ -140,12 +140,12 @@
inputDev.async_read_some_at(
0, boost::asio::buffer(readBuf),
[weakRef](const boost::system::error_code& ec, std::size_t bytesRead) {
- std::shared_ptr<HwmonTempSensor> self = weakRef.lock();
- if (self)
- {
- self->handleResponse(ec, bytesRead);
- }
- });
+ std::shared_ptr<HwmonTempSensor> self = weakRef.lock();
+ if (self)
+ {
+ self->handleResponse(ec, bytesRead);
+ }
+ });
}
void HwmonTempSensor::restartRead()
@@ -181,8 +181,8 @@
{
const char* bufEnd = readBuf.data() + bytesRead;
int nvalue = 0;
- std::from_chars_result ret = std::from_chars(readBuf.data(), bufEnd,
- nvalue);
+ std::from_chars_result ret =
+ std::from_chars(readBuf.data(), bufEnd, nvalue);
if (ret.ec != std::errc())
{
incrementError();
diff --git a/src/IntelCPUSensor.cpp b/src/IntelCPUSensor.cpp
index e21f4b0..dfe09fd 100644
--- a/src/IntelCPUSensor.cpp
+++ b/src/IntelCPUSensor.cpp
@@ -169,13 +169,14 @@
std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this();
inputDev.async_wait(boost::asio::posix::descriptor_base::wait_read,
[weakRef](const boost::system::error_code& ec) {
- std::shared_ptr<IntelCPUSensor> self = weakRef.lock();
+ std::shared_ptr<IntelCPUSensor> self =
+ weakRef.lock();
- if (self)
- {
- self->handleResponse(ec);
- }
- });
+ if (self)
+ {
+ self->handleResponse(ec);
+ }
+ });
}
void IntelCPUSensor::updateMinMaxValues()
@@ -204,8 +205,8 @@
{
const auto& [suffix, oldValue, dbusName] = vectorItem;
auto attrPath = boost::replace_all_copy(path, fileItem, suffix);
- if (auto newVal = readFile(attrPath,
- IntelCPUSensor::sensorScaleFactor))
+ if (auto newVal =
+ readFile(attrPath, IntelCPUSensor::sensorScaleFactor))
{
updateProperty(sensorInterface, oldValue, *newVal,
dbusName);
diff --git a/src/IntelCPUSensor.hpp b/src/IntelCPUSensor.hpp
index 88e6040..0c55c6c 100644
--- a/src/IntelCPUSensor.hpp
+++ b/src/IntelCPUSensor.hpp
@@ -70,8 +70,8 @@
{
return false;
}
- std::string gpioName = std::visit(VariantToStringVisitor(),
- findName->second);
+ std::string gpioName =
+ std::visit(VariantToStringVisitor(), findName->second);
auto findIndex = cpuPresence.find(gpioName);
if (findIndex != cpuPresence.end())
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index 7d14915..4ad0853 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -82,8 +82,7 @@
{
CPUConfig(const uint64_t& bus, const uint64_t& addr,
const std::string& name, const State& state) :
- bus(bus),
- addr(addr), name(name), state(state)
+ bus(bus), addr(addr), name(name), state(state)
{}
int bus;
int addr;
@@ -140,20 +139,20 @@
bool isWordEnd = true;
std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(),
[&isWordEnd](int c) {
- if (std::isspace(c) != 0)
- {
- isWordEnd = true;
- }
- else
- {
- if (isWordEnd)
- {
- isWordEnd = false;
- return std::toupper(c);
- }
- }
- return c;
- });
+ if (std::isspace(c) != 0)
+ {
+ isWordEnd = true;
+ }
+ else
+ {
+ if (isWordEnd)
+ {
+ isWordEnd = false;
+ return std::toupper(c);
+ }
+ }
+ return c;
+ });
return sensorName;
}
@@ -304,8 +303,8 @@
std::cerr << "could not determine CPU ID for " << hwmonName << "\n";
continue;
}
- int cpuId = std::visit(VariantToUnsignedIntVisitor(),
- findCpuId->second);
+ int cpuId =
+ std::visit(VariantToUnsignedIntVisitor(), findCpuId->second);
auto directory = hwmonNamePath.parent_path();
std::vector<fs::path> inputPaths;
@@ -326,8 +325,8 @@
}
auto& [type, nr, item] = *fileParts;
auto inputPathStr = inputPath.string();
- auto labelPath = boost::replace_all_copy(inputPathStr, item,
- "label");
+ auto labelPath =
+ boost::replace_all_copy(inputPathStr, item, "label");
std::ifstream labelFile(labelPath);
if (!labelFile.good())
{
@@ -569,8 +568,8 @@
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_DDR_DIMM_TEMP,
- rank, 4, pkgConfig.data(),
- &cc) == PECI_CC_SUCCESS)
+ rank, 4, pkgConfig.data(), &cc) ==
+ PECI_CC_SUCCESS)
{
// Depending on CPU generation, both 0 and 0xFF can be used
// to indicate no DIMM presence
@@ -607,8 +606,8 @@
uint8_t cc = 0;
if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_CPU_ID, 0,
- 4, pkgConfig.data(),
- &cc) == PECI_CC_SUCCESS)
+ 4, pkgConfig.data(), &cc) ==
+ PECI_CC_SUCCESS)
{
std::cout << config.name << " is detected\n";
if (!exportDevice(config))
@@ -629,8 +628,8 @@
else if (newState == State::READY)
{
rescanDelaySeconds = 5;
- std::cout << "DIMM(s) on " << config.name
- << " is/are detected\n";
+ std::cout
+ << "DIMM(s) on " << config.name << " is/are detected\n";
}
}
@@ -729,10 +728,10 @@
{
continue;
}
- std::string nameRaw = std::visit(VariantToStringVisitor(),
- findName->second);
- std::string name = std::regex_replace(nameRaw, illegalDbusRegex,
- "_");
+ std::string nameRaw =
+ std::visit(VariantToStringVisitor(), findName->second);
+ std::string name =
+ std::regex_replace(nameRaw, illegalDbusRegex, "_");
auto present = std::optional<bool>();
// if we can't detect it via gpio, we set presence later
@@ -763,14 +762,14 @@
std::cerr << "Can't find 'Bus' setting in " << name << "\n";
continue;
}
- uint64_t bus = std::visit(VariantToUnsignedIntVisitor(),
- findBus->second);
+ uint64_t bus =
+ std::visit(VariantToUnsignedIntVisitor(), findBus->second);
auto findAddress = cfg.find("Address");
if (findAddress == cfg.end())
{
- std::cerr << "Can't find 'Address' setting in " << name
- << "\n";
+ std::cerr
+ << "Can't find 'Address' setting in " << name << "\n";
continue;
}
uint64_t addr = std::visit(VariantToUnsignedIntVisitor(),
@@ -828,33 +827,33 @@
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- 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_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
+ if (message.is_method_error())
{
- return; // we're being canceled
+ std::cerr << "callback method error\n";
+ return;
}
- if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
- objectServer))
+ if (debug)
{
- detectCpuAsync(pingTimer, creationTimer, io, objectServer,
- systemBus, cpuConfigs, sensorConfigs);
+ std::cout << message.get_path() << " is changed\n";
}
- });
- };
+
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+
+ if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
+ objectServer))
+ {
+ detectCpuAsync(pingTimer, creationTimer, io, objectServer,
+ systemBus, cpuConfigs, sensorConfigs);
+ }
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index a0cf1b7..c94727a 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -201,9 +201,9 @@
pSensor->start();
if (debug)
{
- std::cout << "find matched bus " << busId
- << ", matched slave addr " << slaveAddr
- << "\n";
+ std::cout
+ << "find matched bus " << busId
+ << ", matched slave addr " << slaveAddr << "\n";
}
return;
}
@@ -243,47 +243,48 @@
{
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection, [](const ManagedObjectType& sensorConfigurations) {
- // Get NIC name and save to map
- lanInfoMap.clear();
- for (const auto& [path, cfgData] : sensorConfigurations)
- {
- const std::pair<std::string, SensorBaseConfigMap>*
- baseConfiguration = nullptr;
-
- // find base configuration
- auto sensorBase = cfgData.find(configInterfaceName(nicType));
- if (sensorBase == cfgData.end())
+ // Get NIC name and save to map
+ lanInfoMap.clear();
+ for (const auto& [path, cfgData] : sensorConfigurations)
{
- continue;
- }
- baseConfiguration = &(*sensorBase);
+ const std::pair<std::string, SensorBaseConfigMap>*
+ baseConfiguration = nullptr;
- auto findEthIndex = baseConfiguration->second.find("EthIndex");
- auto findName = baseConfiguration->second.find("Name");
-
- if (findEthIndex != baseConfiguration->second.end() &&
- findName != baseConfiguration->second.end())
- {
- const auto* pEthIndex =
- std::get_if<uint64_t>(&findEthIndex->second);
- const auto* pName = std::get_if<std::string>(&findName->second);
- if (pEthIndex != nullptr && pName != nullptr)
+ // find base configuration
+ auto sensorBase = cfgData.find(configInterfaceName(nicType));
+ if (sensorBase == cfgData.end())
{
- lanInfoMap[*pEthIndex] = *pName;
- if (debugLanLeash)
+ continue;
+ }
+ baseConfiguration = &(*sensorBase);
+
+ auto findEthIndex = baseConfiguration->second.find("EthIndex");
+ auto findName = baseConfiguration->second.find("Name");
+
+ if (findEthIndex != baseConfiguration->second.end() &&
+ findName != baseConfiguration->second.end())
+ {
+ const auto* pEthIndex =
+ std::get_if<uint64_t>(&findEthIndex->second);
+ const auto* pName =
+ std::get_if<std::string>(&findName->second);
+ if (pEthIndex != nullptr && pName != nullptr)
{
- std::cout << "find name of eth" << *pEthIndex << " is "
- << *pName << "\n";
+ lanInfoMap[*pEthIndex] = *pName;
+ if (debugLanLeash)
+ {
+ std::cout << "find name of eth" << *pEthIndex
+ << " is " << *pName << "\n";
+ }
}
}
}
- }
- if (lanInfoMap.empty())
- {
- std::cerr << "can't find matched NIC name. \n";
- }
- });
+ if (lanInfoMap.empty())
+ {
+ std::cerr << "can't find matched NIC name. \n";
+ }
+ });
getter->getConfiguration(
std::vector<std::string>{nicTypes.begin(), nicTypes.end()});
@@ -366,8 +367,8 @@
{
std::string strEthNum = "eth" + std::to_string(ethNum) + lanInfo;
const auto* strState = newLanConnected ? "connected" : "lost";
- const auto* strMsgId = newLanConnected ? "OpenBMC.0.1.LanRegained"
- : "OpenBMC.0.1.LanLost";
+ const auto* strMsgId =
+ newLanConnected ? "OpenBMC.0.1.LanRegained" : "OpenBMC.0.1.LanLost";
lg2::info("{ETHDEV} LAN leash {STATE}", "ETHDEV", strEthNum, "STATE",
strState, "REDFISH_MESSAGE_ID", strMsgId,
@@ -431,39 +432,38 @@
pathSuffixMap[pathSuffix] = ethNum;
if (debugLanLeash)
{
- std::cout << "ethNum = " << std::to_string(ethNum)
- << ", ifindex = " << line
- << ", pathSuffix = " << pathSuffix << "\n";
+ std::cout << "ethNum = " << std::to_string(ethNum) << ", ifindex = "
+ << line << ", pathSuffix = " << pathSuffix << "\n";
}
// init lan connected status from networkd
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,
"org.freedesktop.DBus.Properties", "Get",
@@ -493,23 +493,24 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
+ if (message.is_method_error())
{
- // timer was cancelled
+ std::cerr << "callback method error\n";
return;
}
- std::cout << "rescan due to configuration change \n";
- createSensorsFromConfig(io, objServer, systemBus, intrusionSensor);
- });
- };
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ // timer was cancelled
+ return;
+ }
+ std::cout << "rescan due to configuration change \n";
+ createSensorsFromConfig(io, objServer, systemBus,
+ intrusionSensor);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(
@@ -532,13 +533,13 @@
std::string(inventoryPath) + "',arg0namespace='" +
configInterfaceName(nicType) + "'",
[&systemBus](sdbusplus::message_t& 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);
+ });
}
io.run();
diff --git a/src/IpmbSDRSensor.cpp b/src/IpmbSDRSensor.cpp
index 299ff80..c23ddea 100644
--- a/src/IpmbSDRSensor.cpp
+++ b/src/IpmbSDRSensor.cpp
@@ -21,8 +21,7 @@
IpmbSDRDevice::IpmbSDRDevice(
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
uint8_t cmdAddr) :
- commandAddress(cmdAddr << 2),
- hostIndex(cmdAddr + 1), conn(dbusConnection)
+ commandAddress(cmdAddr << 2), hostIndex(cmdAddr + 1), conn(dbusConnection)
{}
bool validateStatus(boost::system::error_code ec,
@@ -52,36 +51,37 @@
conn->async_method_call(
[weakRef](boost::system::error_code ec,
const IpmbMethodType& response) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
- auto status = std::bind_front(validateStatus, ec, response);
- if (!status(self->hostIndex))
- {
- return;
- }
+ auto status = std::bind_front(validateStatus, ec, response);
+ if (!status(self->hostIndex))
+ {
+ return;
+ }
- const std::vector<uint8_t>& data = std::get<5>(response);
- const size_t sdrInfoDataSize = 14;
+ const std::vector<uint8_t>& data = std::get<5>(response);
+ const size_t sdrInfoDataSize = 14;
- if (data.size() < sdrInfoDataSize)
- {
- std::cerr << " IPMB Get SDR Repository Info data is empty for host "
- << self->hostIndex << "\n";
- return;
- }
+ if (data.size() < sdrInfoDataSize)
+ {
+ std::cerr
+ << " IPMB Get SDR Repository Info data is empty for host "
+ << self->hostIndex << "\n";
+ return;
+ }
- constexpr uint8_t recordCountLSB = 1;
- constexpr uint8_t recordCountMSB = 2;
+ constexpr uint8_t recordCountLSB = 1;
+ constexpr uint8_t recordCountMSB = 2;
- uint16_t recordCount = (data[recordCountMSB] << 8) |
- data[recordCountLSB];
+ uint16_t recordCount = (data[recordCountMSB] << 8) |
+ data[recordCountLSB];
- self->reserveSDRRepository(recordCount);
- },
+ self->reserveSDRRepository(recordCount);
+ },
ipmbService, ipmbDbusPath, ipmbInterface, ipmbMethod, commandAddress,
sdr::netfnStorageReq, lun, sdr::cmdStorageGetSdrInfo, sdrCommandData);
}
@@ -94,32 +94,33 @@
conn->async_method_call(
[weakRef, recordCount](boost::system::error_code ec,
const IpmbMethodType& response) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
- auto status = std::bind_front(validateStatus, ec, response);
- if (!status(self->hostIndex))
- {
- return;
- }
+ auto status = std::bind_front(validateStatus, ec, response);
+ if (!status(self->hostIndex))
+ {
+ return;
+ }
- const std::vector<uint8_t>& data = std::get<5>(response);
- const size_t sdrReserveDataSize = 2;
+ const std::vector<uint8_t>& data = std::get<5>(response);
+ const size_t sdrReserveDataSize = 2;
- if (data.size() < sdrReserveDataSize)
- {
- std::cerr << " IPMB SDR Reserve Repository data is empty for host "
- << self->hostIndex << "\n";
- return;
- }
- uint8_t resrvIDLSB = data[0];
- uint8_t resrvIDMSB = data[1];
+ if (data.size() < sdrReserveDataSize)
+ {
+ std::cerr
+ << " IPMB SDR Reserve Repository data is empty for host "
+ << self->hostIndex << "\n";
+ return;
+ }
+ uint8_t resrvIDLSB = data[0];
+ uint8_t resrvIDMSB = data[1];
- self->getSDRSensorData(recordCount, resrvIDLSB, resrvIDMSB);
- },
+ self->getSDRSensorData(recordCount, resrvIDLSB, resrvIDMSB);
+ },
ipmbService, ipmbDbusPath, ipmbInterface, ipmbMethod, commandAddress,
sdr::netfnStorageReq, lun, sdr::cmdStorageReserveSdr, sdrCommandData);
}
@@ -139,30 +140,30 @@
conn->async_method_call(
[weakRef, recordCount, resrvIDLSB, resrvIDMSB](
boost::system::error_code ec, const IpmbMethodType& response) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
- auto status = std::bind_front(validateStatus, ec, response);
- if (!status(self->hostIndex))
- {
- return;
- }
+ auto status = std::bind_front(validateStatus, ec, response);
+ if (!status(self->hostIndex))
+ {
+ return;
+ }
- const std::vector<uint8_t>& data = std::get<5>(response);
- const size_t sdrSensorDataSize = 18;
+ const std::vector<uint8_t>& data = std::get<5>(response);
+ const size_t sdrSensorDataSize = 18;
- if (data.size() < sdrSensorDataSize)
- {
- std::cerr << "IPMB SDR sensor data is empty for host "
- << self->hostIndex << "\n";
- return;
- }
+ if (data.size() < sdrSensorDataSize)
+ {
+ std::cerr << "IPMB SDR sensor data is empty for host "
+ << self->hostIndex << "\n";
+ return;
+ }
- self->handleSDRData(data, recordCount, resrvIDLSB, resrvIDMSB);
- },
+ self->handleSDRData(data, recordCount, resrvIDLSB, resrvIDMSB);
+ },
ipmbService, ipmbDbusPath, ipmbInterface, ipmbMethod, commandAddress,
sdr::netfnStorageReq, lun, sdr::cmdStorageGetSdr, commandData);
}
@@ -271,17 +272,17 @@
* mDataByte - Byte 28 - 8 bits LSB
* mTolDataByte - Byte 29 - 2 bits MSB [7-6]
*/
- uint16_t mData = ((sdrDataBytes[sdrtype01::mTolDataByte] & 0xC0)
- << bitShiftMsb) |
- sdrDataBytes[sdrtype01::mDataByte];
+ uint16_t mData =
+ ((sdrDataBytes[sdrtype01::mTolDataByte] & 0xC0) << bitShiftMsb) |
+ sdrDataBytes[sdrtype01::mDataByte];
/* bData - 10 bits
* bDataByte - Byte 30 - 8 bits LSB
* bAcuDataByte - Byte 31 - 2 bits MSB [7-6]
*/
- uint16_t bData = ((sdrDataBytes[sdrtype01::bAcuDataByte] & 0xC0)
- << bitShiftMsb) |
- sdrDataBytes[sdrtype01::bDataByte];
+ uint16_t bData =
+ ((sdrDataBytes[sdrtype01::bAcuDataByte] & 0xC0) << bitShiftMsb) |
+ sdrDataBytes[sdrtype01::bDataByte];
/* rbExpDataByte (Byte 33) represents the exponent value
* Bit [3-0] - B Exponent 2's complement signed bit.
diff --git a/src/IpmbSensor.cpp b/src/IpmbSensor.cpp
index fbc4b7d..fc6cc7a 100644
--- a/src/IpmbSensor.cpp
+++ b/src/IpmbSensor.cpp
@@ -60,14 +60,13 @@
static constexpr const char* sensorPathPrefix = "/xyz/openbmc_project/sensors/";
-IpmbSensor::IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_context& io,
- const std::string& sensorName,
- const std::string& sensorConfiguration,
- sdbusplus::asio::object_server& objectServer,
- std::vector<thresholds::Threshold>&& thresholdData,
- uint8_t deviceAddress, uint8_t hostSMbusIndex,
- const float pollRate, std::string& sensorTypeName) :
+IpmbSensor::IpmbSensor(
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& sensorName,
+ const std::string& sensorConfiguration,
+ sdbusplus::asio::object_server& objectServer,
+ std::vector<thresholds::Threshold>&& thresholdData, uint8_t deviceAddress,
+ uint8_t hostSMbusIndex, const float pollRate, std::string& sensorTypeName) :
Sensor(escapeName(sensorName), std::move(thresholdData),
sensorConfiguration, "IpmbSensor", false, false, ipmbMaxReading,
ipmbMinReading, conn, PowerState::on),
@@ -156,8 +155,8 @@
dbusConnection->async_method_call(
[weakRef{weak_from_this()}](const boost::system::error_code& ec,
const IpmbMethodType& response) {
- initCmdCb(weakRef, ec, response);
- },
+ initCmdCb(weakRef, ec, response);
+ },
"xyz.openbmc_project.Ipmi.Channel.Ipmb",
"/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb",
"sendRequest", commandAddress, netfn, lun, *initCommand, initData);
@@ -478,17 +477,17 @@
waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs));
waitTimer.async_wait(
[weakRef{weak_from_this()}](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
- std::shared_ptr<IpmbSensor> self = weakRef.lock();
- if (!self)
- {
- return;
- }
- self->sendIpmbRequest();
- });
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ std::shared_ptr<IpmbSensor> self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->sendIpmbRequest();
+ });
}
void IpmbSensor::sendIpmbRequest()
@@ -502,13 +501,13 @@
dbusConnection->async_method_call(
[weakRef{weak_from_this()}](boost::system::error_code ec,
const IpmbMethodType& response) {
- std::shared_ptr<IpmbSensor> self = weakRef.lock();
- if (!self)
- {
- return;
- }
- self->ipmbRequestCompletionCb(ec, response);
- },
+ std::shared_ptr<IpmbSensor> self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->ipmbRequestCompletionCb(ec, response);
+ },
"xyz.openbmc_project.Ipmi.Channel.Ipmb",
"/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb",
"sendRequest", commandAddress, netfn, lun, command, commandData);
@@ -602,77 +601,80 @@
}
dbusConnection->async_method_call(
[&](boost::system::error_code ec, const ManagedObjectType& resp) {
- if (ec)
- {
- std::cerr << "Error contacting entity manager\n";
- return;
- }
- for (const auto& [path, interfaces] : resp)
- {
- for (const auto& [intf, cfg] : interfaces)
+ if (ec)
{
- if (intf != configInterfaceName(sensorType))
- {
- continue;
- }
- std::string name = loadVariant<std::string>(cfg, "Name");
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(interfaces, sensorThresholds))
- {
- std::cerr << "error populating thresholds " << name << "\n";
- }
- uint8_t deviceAddress = loadVariant<uint8_t>(cfg, "Address");
-
- std::string sensorClass = loadVariant<std::string>(cfg,
- "Class");
-
- uint8_t hostSMbusIndex = hostSMbusIndexDefault;
- auto findSmType = cfg.find("HostSMbusIndex");
- if (findSmType != cfg.end())
- {
- hostSMbusIndex = std::visit(VariantToUnsignedIntVisitor(),
- findSmType->second);
- }
-
- float pollRate = getPollRate(cfg, pollRateDefault);
-
- uint8_t ipmbBusIndex = ipmbBusIndexDefault;
- auto findBusType = cfg.find("Bus");
- if (findBusType != cfg.end())
- {
- ipmbBusIndex = std::visit(VariantToUnsignedIntVisitor(),
- findBusType->second);
- std::cerr << "Ipmb Bus Index for " << name << " is "
- << static_cast<int>(ipmbBusIndex) << "\n";
- }
-
- /* Default sensor type is "temperature" */
- std::string sensorTypeName = "temperature";
- auto findType = cfg.find("SensorType");
- if (findType != cfg.end())
- {
- sensorTypeName = std::visit(VariantToStringVisitor(),
- findType->second);
- }
-
- auto& sensor = sensors[name];
- sensor = nullptr;
- sensor = std::make_shared<IpmbSensor>(
- dbusConnection, io, name, path, objectServer,
- std::move(sensorThresholds), deviceAddress, hostSMbusIndex,
- pollRate, sensorTypeName);
-
- sensor->parseConfigValues(cfg);
- if (!(sensor->sensorClassType(sensorClass)))
- {
- continue;
- }
- sensor->sensorSubType(sensorTypeName);
- sensor->init();
+ std::cerr << "Error contacting entity manager\n";
+ return;
}
- }
- },
+ for (const auto& [path, interfaces] : resp)
+ {
+ for (const auto& [intf, cfg] : interfaces)
+ {
+ if (intf != configInterfaceName(sensorType))
+ {
+ continue;
+ }
+ std::string name = loadVariant<std::string>(cfg, "Name");
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(interfaces,
+ sensorThresholds))
+ {
+ std::cerr
+ << "error populating thresholds " << name << "\n";
+ }
+ uint8_t deviceAddress =
+ loadVariant<uint8_t>(cfg, "Address");
+
+ std::string sensorClass =
+ loadVariant<std::string>(cfg, "Class");
+
+ uint8_t hostSMbusIndex = hostSMbusIndexDefault;
+ auto findSmType = cfg.find("HostSMbusIndex");
+ if (findSmType != cfg.end())
+ {
+ hostSMbusIndex = std::visit(
+ VariantToUnsignedIntVisitor(), findSmType->second);
+ }
+
+ float pollRate = getPollRate(cfg, pollRateDefault);
+
+ uint8_t ipmbBusIndex = ipmbBusIndexDefault;
+ auto findBusType = cfg.find("Bus");
+ if (findBusType != cfg.end())
+ {
+ ipmbBusIndex = std::visit(VariantToUnsignedIntVisitor(),
+ findBusType->second);
+ std::cerr << "Ipmb Bus Index for " << name << " is "
+ << static_cast<int>(ipmbBusIndex) << "\n";
+ }
+
+ /* Default sensor type is "temperature" */
+ std::string sensorTypeName = "temperature";
+ auto findType = cfg.find("SensorType");
+ if (findType != cfg.end())
+ {
+ sensorTypeName = std::visit(VariantToStringVisitor(),
+ findType->second);
+ }
+
+ auto& sensor = sensors[name];
+ sensor = nullptr;
+ sensor = std::make_shared<IpmbSensor>(
+ dbusConnection, io, name, path, objectServer,
+ std::move(sensorThresholds), deviceAddress,
+ hostSMbusIndex, pollRate, sensorTypeName);
+
+ sensor->parseConfigValues(cfg);
+ if (!(sensor->sensorClassType(sensorClass)))
+ {
+ continue;
+ }
+ sensor->sensorSubType(sensorTypeName);
+ sensor->init();
+ }
+ }
+ },
entityManagerName, "/xyz/openbmc_project/inventory",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
}
diff --git a/src/IpmbSensorMain.cpp b/src/IpmbSensorMain.cpp
index 9223264..5e38dd2 100644
--- a/src/IpmbSensorMain.cpp
+++ b/src/IpmbSensorMain.cpp
@@ -104,27 +104,28 @@
initCmdTimer = std::make_unique<boost::asio::steady_timer>(io);
- boost::asio::post(
- io, [&]() { createSensors(io, objectServer, sensors, systemBus); });
+ boost::asio::post(io, [&]() {
+ createSensors(io, objectServer, sensors, systemBus);
+ });
boost::asio::steady_timer configTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t&) {
- configTimer.expires_after(std::chrono::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_after(std::chrono::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";
+ }
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(
@@ -143,8 +144,8 @@
std::string(inventoryPath) + "',arg0namespace='" +
configInterfaceName(sdrInterface) + "'",
[&systemBus](sdbusplus::message_t& msg) {
- sdrHandler(sdrsensor, msg, systemBus);
- });
+ sdrHandler(sdrsensor, msg, systemBus);
+ });
// Watch for entity-manager to remove configuration interfaces
// so the corresponding sensors can be removed.
diff --git a/src/MCUTempSensor.cpp b/src/MCUTempSensor.cpp
index 48d2300..205521e 100644
--- a/src/MCUTempSensor.cpp
+++ b/src/MCUTempSensor.cpp
@@ -61,14 +61,13 @@
boost::container::flat_map<std::string, std::unique_ptr<MCUTempSensor>> sensors;
-MCUTempSensor::MCUTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_context& io,
- const std::string& sensorName,
- const std::string& sensorConfiguration,
- sdbusplus::asio::object_server& objectServer,
- std::vector<thresholds::Threshold>&& thresholdData,
- uint8_t busId, uint8_t mcuAddress,
- uint8_t tempReg) :
+MCUTempSensor::MCUTempSensor(
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& sensorName,
+ const std::string& sensorConfiguration,
+ sdbusplus::asio::object_server& objectServer,
+ std::vector<thresholds::Threshold>&& thresholdData, uint8_t busId,
+ uint8_t mcuAddress, uint8_t tempReg) :
Sensor(escapeName(sensorName), std::move(thresholdData),
sensorConfiguration, "MCUTempSensor", false, false,
mcuTempMaxReading, mcuTempMinReading, conn),
@@ -215,57 +214,60 @@
dbusConnection->async_method_call(
[&io, &objectServer, &dbusConnection, &sensors](
boost::system::error_code ec, const ManagedObjectType& resp) {
- if (ec)
- {
- std::cerr << "Error contacting entity manager\n";
- return;
- }
- for (const auto& [path, interfaces] : resp)
- {
- for (const auto& [intf, cfg] : interfaces)
+ if (ec)
{
- if (intf != configInterfaceName(sensorType))
- {
- continue;
- }
- std::string name = loadVariant<std::string>(cfg, "Name");
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(interfaces, sensorThresholds))
- {
- std::cerr << "error populating thresholds for " << name
- << "\n";
- }
-
- uint8_t busId = loadVariant<uint8_t>(cfg, "Bus");
- uint8_t mcuAddress = loadVariant<uint8_t>(cfg, "Address");
- uint8_t tempReg = loadVariant<uint8_t>(cfg, "Reg");
-
- std::string sensorClass = loadVariant<std::string>(cfg,
- "Class");
-
- if constexpr (debug)
- {
- std::cerr << "Configuration parsed for \n\t" << intf << "\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, path, objectServer,
- std::move(sensorThresholds), busId, mcuAddress, tempReg);
-
- sensor->init();
+ std::cerr << "Error contacting entity manager\n";
+ return;
}
- }
- },
+ for (const auto& [path, interfaces] : resp)
+ {
+ for (const auto& [intf, cfg] : interfaces)
+ {
+ if (intf != configInterfaceName(sensorType))
+ {
+ continue;
+ }
+ std::string name = loadVariant<std::string>(cfg, "Name");
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(interfaces,
+ sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << name
+ << "\n";
+ }
+
+ uint8_t busId = loadVariant<uint8_t>(cfg, "Bus");
+ uint8_t mcuAddress = loadVariant<uint8_t>(cfg, "Address");
+ uint8_t tempReg = loadVariant<uint8_t>(cfg, "Reg");
+
+ std::string sensorClass =
+ loadVariant<std::string>(cfg, "Class");
+
+ if constexpr (debug)
+ {
+ std::cerr
+ << "Configuration parsed for \n\t" << intf << "\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, path, objectServer,
+ std::move(sensorThresholds), busId, mcuAddress,
+ tempReg);
+
+ sensor->init();
+ }
+ }
+ },
entityManagerName, "/xyz/openbmc_project/inventory",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
}
@@ -279,33 +281,34 @@
systemBus->request_name("xyz.openbmc_project.MCUTempSensor");
- boost::asio::post(
- io, [&]() { createSensors(io, objectServer, sensors, systemBus); });
+ boost::asio::post(io, [&]() {
+ createSensors(io, objectServer, sensors, systemBus);
+ });
boost::asio::steady_timer configTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t&) {
- configTimer.expires_after(std::chrono::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_after(std::chrono::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";
+ }
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(
diff --git a/src/NVMeBasicContext.cpp b/src/NVMeBasicContext.cpp
index eb5ecd9..64549a4 100644
--- a/src/NVMeBasicContext.cpp
+++ b/src/NVMeBasicContext.cpp
@@ -288,11 +288,11 @@
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>();
response->prepare(1);
@@ -301,70 +301,70 @@
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;
+ },
[weakSelf{weak_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;
+ }
- if (auto self = weakSelf.lock())
- {
- /* 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());
+ if (auto self = weakSelf.lock())
+ {
+ /* 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()
diff --git a/src/NVMeSensorMain.cpp b/src/NVMeSensorMain.cpp
index 5f0222d..2fe295d 100644
--- a/src/NVMeSensorMain.cpp
+++ b/src/NVMeSensorMain.cpp
@@ -57,9 +57,8 @@
return nvmeDeviceMap;
}
-static std::optional<int>
- extractBusNumber(const std::string& path,
- const SensorBaseConfigMap& properties)
+static std::optional<int> extractBusNumber(
+ const std::string& path, const SensorBaseConfigMap& properties)
{
auto findBus = properties.find("Bus");
if (findBus == properties.end())
@@ -86,9 +85,8 @@
return std::visit(VariantToUnsignedIntVisitor(), findSlaveAddr->second);
}
-static std::optional<std::string>
- extractSensorName(const std::string& path,
- const SensorBaseConfigMap& properties)
+static std::optional<std::string> extractSensorName(
+ const std::string& path, const SensorBaseConfigMap& properties)
{
auto findSensorName = properties.find("Name");
if (findSensorName == properties.end())
@@ -132,9 +130,8 @@
return std::stoi(rootName.substr(0, dash));
}
-static std::shared_ptr<NVMeContext>
- provideRootBusContext(boost::asio::io_context& io, NVMEMap& map,
- int rootBus)
+static std::shared_ptr<NVMeContext> provideRootBusContext(
+ boost::asio::io_context& io, NVMEMap& map, int rootBus)
{
auto findRoot = map.find(rootBus);
if (findRoot != map.end())
@@ -176,10 +173,10 @@
}
const SensorBaseConfigMap& sensorConfig = sensorBase->second;
- std::optional<int> busNumber = extractBusNumber(interfacePath,
- sensorConfig);
- std::optional<std::string> sensorName = extractSensorName(interfacePath,
- sensorConfig);
+ std::optional<int> busNumber =
+ extractBusNumber(interfacePath, sensorConfig);
+ std::optional<std::string> sensorName =
+ extractSensorName(interfacePath, sensorConfig);
uint8_t slaveAddr = extractSlaveAddr(interfacePath, sensorConfig);
std::optional<int> rootBus = deriveRootBus(busNumber);
@@ -231,9 +228,9 @@
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection, [&io, &objectServer, &dbusConnection](
const ManagedObjectType& sensorConfigurations) {
- handleSensorConfigurations(io, objectServer, dbusConnection,
- sensorConfigurations);
- });
+ handleSensorConfigurations(io, objectServer, dbusConnection,
+ sensorConfigurations);
+ });
getter->getConfiguration(std::vector<std::string>{NVMeSensor::sensorType});
}
@@ -284,24 +281,24 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&filterTimer, &io, &objectServer, &systemBus](sdbusplus::message_t&) {
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
+ // this implicitly cancels the timer
+ filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- 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);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(
@@ -315,8 +312,8 @@
"type='signal',member='InterfacesRemoved',arg0path='" +
std::string(inventoryPath) + "/'",
[](sdbusplus::message_t& msg) {
- interfaceRemoved(msg, nvmeDeviceMap);
- });
+ interfaceRemoved(msg, nvmeDeviceMap);
+ });
setupManufacturingModeMatch(*systemBus);
io.run();
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index 8a83f37..438faa2 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -45,8 +45,7 @@
boost::asio::io_context& io, const std::string& psuName,
const PowerState& powerState, EventPathList& eventPathList,
GroupEventPathList& groupEventPathList, const std::string& combineEventName,
- double pollRate) :
- objServer(objectServer)
+ double pollRate) : objServer(objectServer)
{
std::string psuNameEscaped = sensor_paths::escapePathForDbus(psuName);
eventInterface = objServer.add_interface(
@@ -146,10 +145,9 @@
std::shared_ptr<std::set<std::string>> asserts,
std::shared_ptr<std::set<std::string>> combineEvent,
std::shared_ptr<bool> state, const std::string& psuName, double pollRate) :
- eventInterface(std::move(eventInterface)),
- asserts(std::move(asserts)), combineEvent(std::move(combineEvent)),
- assertState(std::move(state)), path(path), eventName(eventName),
- readState(powerState), waitTimer(io),
+ eventInterface(std::move(eventInterface)), asserts(std::move(asserts)),
+ combineEvent(std::move(combineEvent)), assertState(std::move(state)),
+ path(path), eventName(eventName), readState(powerState), waitTimer(io),
inputDev(io, path, boost::asio::random_access_file::read_only),
psuName(psuName), groupEventName(groupEventName), systemBus(conn)
@@ -210,12 +208,12 @@
0, boost::asio::buffer(buffer->data(), buffer->size() - 1),
[weakRef, buffer{buffer}](const boost::system::error_code& ec,
std::size_t bytesTransferred) {
- std::shared_ptr<PSUSubEvent> self = weakRef.lock();
- if (self)
- {
- self->handleResponse(ec, bytesTransferred);
- }
- });
+ std::shared_ptr<PSUSubEvent> self = weakRef.lock();
+ if (self)
+ {
+ self->handleResponse(ec, bytesTransferred);
+ }
+ });
}
void PSUSubEvent::restartRead()
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index db632b6..3c02b93 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -44,17 +44,16 @@
static constexpr bool debug = false;
-PSUSensor::PSUSensor(const std::string& path, const std::string& objectType,
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_context& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& thresholdsIn,
- const std::string& sensorConfiguration,
- const PowerState& powerState,
- const std::string& sensorUnits, unsigned int factor,
- double max, double min, double offset,
- const std::string& label, size_t tSize, double pollRate,
- const std::shared_ptr<I2CDevice>& i2cDevice) :
+PSUSensor::PSUSensor(
+ const std::string& path, const std::string& objectType,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& sensorName,
+ std::vector<thresholds::Threshold>&& thresholdsIn,
+ const std::string& sensorConfiguration, const PowerState& powerState,
+ const std::string& sensorUnits, unsigned int factor, double max, double min,
+ double offset, const std::string& label, size_t tSize, double pollRate,
+ const std::shared_ptr<I2CDevice>& i2cDevice) :
Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
objectType, false, false, max, min, conn, powerState),
i2cDevice(i2cDevice), objServer(objectServer),
@@ -168,14 +167,14 @@
0, boost::asio::buffer(buffer->data(), buffer->size() - 1),
[weak, buffer{buffer}](const boost::system::error_code& ec,
size_t bytesRead) {
- std::shared_ptr<PSUSensor> self = weak.lock();
- if (!self)
- {
- return;
- }
+ std::shared_ptr<PSUSensor> self = weak.lock();
+ if (!self)
+ {
+ return;
+ }
- self->handleResponse(ec, bytesRead);
- });
+ self->handleResponse(ec, bytesRead);
+ });
}
void PSUSensor::restartRead()
diff --git a/src/PSUSensor.hpp b/src/PSUSensor.hpp
index f9b738f..09601f8 100644
--- a/src/PSUSensor.hpp
+++ b/src/PSUSensor.hpp
@@ -69,9 +69,8 @@
public:
PSUProperty(std::string name, double max, double min, unsigned int factor,
double offset) :
- labelTypeName(std::move(name)),
- maxReading(max), minReading(min), sensorScaleFactor(factor),
- sensorOffset(offset)
+ labelTypeName(std::move(name)), maxReading(max), minReading(min),
+ sensorScaleFactor(factor), sensorOffset(offset)
{}
~PSUProperty() = default;
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index 2b159c3..ad37956 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -251,12 +251,11 @@
}
}
-static void
- checkPWMSensor(const fs::path& sensorPath, std::string& labelHead,
- const std::string& interfacePath,
- std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
- sdbusplus::asio::object_server& objectServer,
- const std::string& psuName)
+static void checkPWMSensor(
+ const fs::path& sensorPath, std::string& labelHead,
+ const std::string& interfacePath,
+ std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+ sdbusplus::asio::object_server& objectServer, const std::string& psuName)
{
if (!labelHead.starts_with("fan"))
{
@@ -265,8 +264,8 @@
std::string labelHeadIndex = labelHead.substr(3);
const std::string& sensorPathStr = sensorPath.string();
- const std::string& pwmPathStr = boost::replace_all_copy(sensorPathStr,
- "input", "target");
+ const std::string& pwmPathStr =
+ boost::replace_all_copy(sensorPathStr, "input", "target");
std::ifstream pwmFile(pwmPathStr);
if (!pwmFile.good())
{
@@ -486,11 +485,11 @@
if (!firstScan)
{
std::string psuNameStr = "/" + escapeName(*psuName);
- auto it = std::find_if(sensorsChanged->begin(),
- sensorsChanged->end(),
- [psuNameStr](std::string& s) {
- return s.ends_with(psuNameStr);
- });
+ auto it =
+ std::find_if(sensorsChanged->begin(), sensorsChanged->end(),
+ [psuNameStr](std::string& s) {
+ return s.ends_with(psuNameStr);
+ });
if (it == sensorsChanged->end())
{
@@ -604,8 +603,8 @@
}
// hwmon *_input filename with number:
// temp1, temp2, temp3, ...
- labelHead = sensorNameStr.substr(0,
- sensorNameStr.find('_'));
+ labelHead =
+ sensorNameStr.substr(0, sensorNameStr.find('_'));
}
else
{
@@ -954,8 +953,8 @@
++numCreated;
if constexpr (debug)
{
- std::cerr << "Created " << numCreated
- << " sensors so far\n";
+ std::cerr
+ << "Created " << numCreated << " sensors so far\n";
}
}
}
@@ -1057,9 +1056,9 @@
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
activateOnly](const ManagedObjectType& sensorConfigs) {
- createSensorsCallback(io, objectServer, dbusConnection, sensorConfigs,
- sensorsChanged, activateOnly);
- });
+ createSensorsCallback(io, objectServer, dbusConnection,
+ sensorConfigs, sensorsChanged, activateOnly);
+ });
std::vector<std::string> types(sensorTypes.size());
for (const auto& [type, dt] : sensorTypes)
{
@@ -1148,8 +1147,8 @@
propertyInitialize();
- auto powerCallBack = [&io, &objectServer, &systemBus](PowerState type,
- bool state) {
+ auto powerCallBack = [&io, &objectServer,
+ &systemBus](PowerState type, bool state) {
powerStateChanged(type, state, sensors, io, objectServer, systemBus);
};
@@ -1161,80 +1160,81 @@
boost::asio::steady_timer filterTimer(io);
std::function<void(sdbusplus::message_t&)> eventHandler =
[&](sdbusplus::message_t& message) {
- if (message.is_method_error())
- {
- std::cerr << "callback method error\n";
- return;
- }
- sensorsChanged->insert(message.get_path());
- filterTimer.expires_after(std::chrono::seconds(3));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
+ if (message.is_method_error())
{
+ std::cerr << "callback method error\n";
return;
}
- if (ec)
- {
- std::cerr << "timer error\n";
- }
- createSensors(io, objectServer, systemBus, sensorsChanged, false);
- });
- };
+ sensorsChanged->insert(message.get_path());
+ filterTimer.expires_after(std::chrono::seconds(3));
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ }
+ createSensors(io, objectServer, systemBus, sensorsChanged,
+ false);
+ });
+ };
boost::asio::steady_timer cpuFilterTimer(io);
std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
[&](sdbusplus::message_t& message) {
- std::string path = message.get_path();
- boost::to_lower(path);
+ std::string path = message.get_path();
+ boost::to_lower(path);
- sdbusplus::message::object_path cpuPath(path);
- std::string cpuName = cpuPath.filename();
- if (!cpuName.starts_with("cpu"))
- {
- return;
- }
- 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");
- try
- {
- cpuPresence[index] = std::get<bool>(findPresence->second);
- }
- catch (const std::bad_variant_access& err)
- {
- return;
- }
-
- if (!cpuPresence[index])
- {
- return;
- }
- cpuFilterTimer.expires_after(std::chrono::seconds(1));
- cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
+ sdbusplus::message::object_path cpuPath(path);
+ std::string cpuName = cpuPath.filename();
+ if (!cpuName.starts_with("cpu"))
{
return;
}
- if (ec)
+ size_t index = 0;
+ try
{
- std::cerr << "timer error\n";
+ index = std::stoi(path.substr(path.size() - 1));
+ }
+ catch (const std::invalid_argument&)
+ {
+ std::cerr << "Found invalid path " << path << "\n";
return;
}
- createSensors(io, objectServer, systemBus, nullptr, false);
- });
- };
+
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<bool>> values;
+ message.read(objectName, values);
+ auto findPresence = values.find("Present");
+ try
+ {
+ cpuPresence[index] = std::get<bool>(findPresence->second);
+ }
+ catch (const std::bad_variant_access& err)
+ {
+ return;
+ }
+
+ if (!cpuPresence[index])
+ {
+ return;
+ }
+ cpuFilterTimer.expires_after(std::chrono::seconds(1));
+ cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, systemBus, nullptr, false);
+ });
+ };
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
diff --git a/src/PwmSensor.cpp b/src/PwmSensor.cpp
index 2a431eb..a06d7c4 100644
--- a/src/PwmSensor.cpp
+++ b/src/PwmSensor.cpp
@@ -41,8 +41,8 @@
sdbusplus::asio::object_server& objectServer,
const std::string& sensorConfiguration,
const std::string& sensorType, bool isValueMutable) :
- sysPath(sysPath),
- objectServer(objectServer), name(sensor_paths::escapePathForDbus(pwmname))
+ sysPath(sysPath), objectServer(objectServer),
+ name(sensor_paths::escapePathForDbus(pwmname))
{
// add interface under sensor and Control.FanPwm as Control is used
// in obmc project, also add sensor so it can be viewed as a sensor
@@ -69,49 +69,50 @@
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;
+ 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;
- });
+
+ 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;
+ });
// pwm sensor interface is in percent
sensorInterface->register_property("MaxValue", static_cast<double>(100));
sensorInterface->register_property("MinValue", static_cast<double>(0));
@@ -123,37 +124,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;
+ 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;
- });
+
+ 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;
+ });
sensorInterface->initialize();
controlInterface->initialize();
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index b31c1b7..7a57f5a 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -44,17 +44,17 @@
static constexpr unsigned int pwmPollMs = 500;
-TachSensor::TachSensor(const std::string& path, const std::string& objectType,
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- std::shared_ptr<PresenceSensor>& presenceSensor,
- std::optional<RedundancySensor>* redundancy,
- boost::asio::io_context& io, const std::string& fanName,
- std::vector<thresholds::Threshold>&& thresholdsIn,
- const std::string& sensorConfiguration,
- const std::pair<double, double>& limits,
- const PowerState& powerState,
- const std::optional<std::string>& ledIn) :
+TachSensor::TachSensor(
+ const std::string& path, const std::string& objectType,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ std::shared_ptr<PresenceSensor>& presenceSensor,
+ std::optional<RedundancySensor>* redundancy, boost::asio::io_context& io,
+ const std::string& fanName,
+ std::vector<thresholds::Threshold>&& thresholdsIn,
+ const std::string& sensorConfiguration,
+ const std::pair<double, double>& limits, const PowerState& powerState,
+ const std::optional<std::string>& ledIn) :
Sensor(escapeName(fanName), std::move(thresholdsIn), sensorConfiguration,
objectType, false, false, limits.second, limits.first, conn,
powerState),
@@ -119,12 +119,12 @@
inputDev.async_read_some_at(
0, boost::asio::buffer(readBuf),
[weakRef](const boost::system::error_code& ec, std::size_t bytesRead) {
- std::shared_ptr<TachSensor> self = weakRef.lock();
- if (self)
- {
- self->handleResponse(ec, bytesRead);
- }
- });
+ std::shared_ptr<TachSensor> self = weakRef.lock();
+ if (self)
+ {
+ self->handleResponse(ec, bytesRead);
+ }
+ });
}
void TachSensor::restartRead(size_t pollTime)
@@ -173,8 +173,8 @@
{
const char* bufEnd = readBuf.data() + bytesRead;
int nvalue = 0;
- std::from_chars_result ret = std::from_chars(readBuf.data(), bufEnd,
- nvalue);
+ std::from_chars_result ret =
+ std::from_chars(readBuf.data(), bufEnd, nvalue);
if (ret.ec != std::errc())
{
incrementError();
@@ -216,8 +216,7 @@
PresenceSensor::PresenceSensor(const std::string& gpioName, bool inverted,
boost::asio::io_context& io,
const std::string& name) :
- gpioLine(gpiod::find_line(gpioName)),
- gpioFd(io), name(name)
+ gpioLine(gpiod::find_line(gpioName)), gpioFd(io), name(name)
{
if (!gpioLine)
{
@@ -261,21 +260,22 @@
{
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()
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index 42c634f..fc252ac 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -101,8 +101,8 @@
auto hysteresisFind = cfg.find("Hysteresis");
if (hysteresisFind != cfg.end())
{
- hysteresis = std::visit(VariantToDoubleVisitor(),
- hysteresisFind->second);
+ hysteresis =
+ std::visit(VariantToDoubleVisitor(), hysteresisFind->second);
}
auto directionFind = cfg.find("Direction");
@@ -115,11 +115,11 @@
<< intf << "\n";
return false;
}
- unsigned int severity = std::visit(VariantToUnsignedIntVisitor(),
- severityFind->second);
+ unsigned int severity =
+ std::visit(VariantToUnsignedIntVisitor(), severityFind->second);
- std::string directions = std::visit(VariantToStringVisitor(),
- directionFind->second);
+ std::string directions =
+ std::visit(VariantToStringVisitor(), directionFind->second);
Level level = findThresholdLevel(severity);
Direction direction = findThresholdDirection(directions);
@@ -142,64 +142,65 @@
{
for (size_t ii = 0; ii < thresholdCount; ii++)
{
- std::string thresholdInterface = baseInterface + ".Thresholds" +
- std::to_string(ii);
+ std::string thresholdInterface =
+ baseInterface + ".Thresholds" + std::to_string(ii);
conn->async_method_call(
[&, path, threshold, thresholdInterface,
labelMatch](const boost::system::error_code& ec,
const SensorBaseConfigMap& result) {
- if (ec)
- {
- return; // threshold not supported
- }
-
- if (!labelMatch.empty())
- {
- 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";
- 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";
+ return; // threshold not supported
}
+
+ if (!labelMatch.empty())
+ {
+ 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";
+ 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",
- "Set", thresholdInterface, "Value", value);
- },
entityManagerName, path, "org.freedesktop.DBus.Properties",
"GetAll", thresholdInterface);
}
@@ -217,8 +218,8 @@
continue;
}
- std::string property = Sensor::propertyLevel(threshold.level,
- threshold.direction);
+ std::string property =
+ Sensor::propertyLevel(threshold.level, threshold.direction);
if (property.empty())
{
continue;
@@ -292,10 +293,10 @@
thresholdChanges.emplace_back(threshold, true, value);
if (++cLoTrue < assertLogCount)
{
- std::cerr << "Sensor " << sensor->name << " low threshold "
- << threshold.value << " assert: value "
- << sensor->value << " raw data "
- << sensor->rawValue << "\n";
+ std::cerr
+ << "Sensor " << sensor->name << " low threshold "
+ << threshold.value << " assert: value " << sensor->value
+ << " raw data " << sensor->rawValue << "\n";
}
}
else if (value > (threshold.value + threshold.hysteresis))
@@ -514,8 +515,8 @@
for (const auto& t : map.at(item))
{
const auto& [suffix, level, direction, offset] = t;
- auto attrPath = boost::replace_all_copy(inputPath, item,
- suffix);
+ auto attrPath =
+ boost::replace_all_copy(inputPath, item, suffix);
if (auto val = readFile(attrPath, scaleFactor))
{
*val += offset;
diff --git a/src/Thresholds.hpp b/src/Thresholds.hpp
index 352c55c..6338290 100644
--- a/src/Thresholds.hpp
+++ b/src/Thresholds.hpp
@@ -36,8 +36,8 @@
const Level& lev, const Direction& dir, const double& val,
const double hysteresis = std::numeric_limits<double>::quiet_NaN(),
bool write = true) :
- level(lev),
- direction(dir), value(val), hysteresis(hysteresis), writeable(write)
+ level(lev), direction(dir), value(val), hysteresis(hysteresis),
+ writeable(write)
{}
Level level;
Direction direction;
diff --git a/src/Utils.cpp b/src/Utils.cpp
index e3cbfeb..ac0778d 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -95,10 +95,9 @@
* @return a string to the full path of the file to create a temp sensor with or
* nullopt to indicate that no sensor should be created for this basename.
*/
-std::optional<std::string>
- getFullHwmonFilePath(const std::string& directory,
- const std::string& hwmonBaseName,
- const std::set<std::string>& permitSet)
+std::optional<std::string> getFullHwmonFilePath(
+ const std::string& directory, const std::string& hwmonBaseName,
+ const std::set<std::string>& permitSet)
{
std::optional<std::string> result;
std::string filename;
@@ -354,27 +353,28 @@
conn->async_method_call(
[conn, retries](boost::system::error_code ec,
const std::variant<std::string>& state) {
- if (ec)
- {
- if (retries != 0U)
+ if (ec)
{
- 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);
- });
+ if (retries != 0U)
+ {
+ 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";
return;
}
-
- // 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 = std::get<std::string>(state).ends_with(".Running");
- },
+ powerStatusOn = std::get<std::string>(state).ends_with(".Running");
+ },
power::busname, power::path, properties::interface, properties::get,
power::interface, power::property);
}
@@ -386,29 +386,30 @@
conn->async_method_call(
[conn, retries](boost::system::error_code ec,
const std::variant<std::string>& state) {
- if (ec)
- {
- if (retries != 0U)
+ if (ec)
{
- 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);
- });
+ if (retries != 0U)
+ {
+ 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";
return;
}
- // we commonly come up before power control, we'll capture the
- // property change later
- std::cerr << "error getting post status " << ec.message() << "\n";
- return;
- }
- const auto& value = std::get<std::string>(state);
- biosHasPost = (value != "Inactive") &&
- (value != "xyz.openbmc_project.State.OperatingSystem."
- "Status.OSStatus.Inactive");
- },
+ const 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);
}
@@ -420,28 +421,29 @@
conn->async_method_call(
[conn, retries](boost::system::error_code ec,
const std::variant<std::string>& state) {
- if (ec)
- {
- if (retries != 0U)
+ if (ec)
{
- 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) {
- getChassisStatus(conn, retries - 1);
- });
+ if (retries != 0U)
+ {
+ 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) {
+ getChassisStatus(conn, retries - 1);
+ });
+ return;
+ }
+
+ // we commonly come up before power control, we'll capture the
+ // property change later
+ std::cerr << "error getting chassis power status "
+ << ec.message() << "\n";
return;
}
-
- // we commonly come up before power control, we'll capture the
- // property change later
- std::cerr << "error getting chassis power status " << ec.message()
- << "\n";
- return;
- }
- chassisStatusOn = std::get<std::string>(state).ends_with(chassis::sOn);
- },
+ chassisStatusOn =
+ std::get<std::string>(state).ends_with(chassis::sOn);
+ },
chassis::busname, chassis::path, properties::interface, properties::get,
chassis::interface, chassis::property);
}
@@ -465,40 +467,40 @@
"',path='" + std::string(power::path) + "',arg0='" +
std::string(power::interface) + "'",
[hostStatusCallback](sdbusplus::message_t& 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())
- {
- bool on =
- std::get<std::string>(findState->second).ends_with(".Running");
- if (!on)
+ 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())
{
- timer.cancel();
- powerStatusOn = false;
- hostStatusCallback(PowerState::on, powerStatusOn);
- return;
+ bool on = std::get<std::string>(findState->second)
+ .ends_with(".Running");
+ if (!on)
+ {
+ timer.cancel();
+ powerStatusOn = false;
+ hostStatusCallback(PowerState::on, powerStatusOn);
+ return;
+ }
+ // on comes too quickly
+ timer.expires_after(std::chrono::seconds(10));
+ timer.async_wait(
+ [hostStatusCallback](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;
+ hostStatusCallback(PowerState::on, powerStatusOn);
+ });
}
- // on comes too quickly
- timer.expires_after(std::chrono::seconds(10));
- timer.async_wait(
- [hostStatusCallback](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;
- hostStatusCallback(PowerState::on, powerStatusOn);
- });
- }
- });
+ });
postMatch = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(*conn),
@@ -506,20 +508,21 @@
"',path='" + std::string(post::path) + "',arg0='" +
std::string(post::interface) + "'",
[hostStatusCallback](sdbusplus::message_t& 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");
- hostStatusCallback(PowerState::biosPost, biosHasPost);
- }
- });
+ 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");
+ hostStatusCallback(PowerState::biosPost, biosHasPost);
+ }
+ });
chassisMatch = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(*conn),
@@ -528,40 +531,40 @@
std::string(chassis::interface) + "'",
[hostStatusCallback = std::move(hostStatusCallback)](
sdbusplus::message_t& message) {
- std::string objectName;
- boost::container::flat_map<std::string, std::variant<std::string>>
- values;
- message.read(objectName, values);
- auto findState = values.find(chassis::property);
- if (findState != values.end())
- {
- bool on = std::get<std::string>(findState->second)
- .ends_with(chassis::sOn);
- if (!on)
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<std::string>>
+ values;
+ message.read(objectName, values);
+ auto findState = values.find(chassis::property);
+ if (findState != values.end())
{
- timerChassisOn.cancel();
- chassisStatusOn = false;
- hostStatusCallback(PowerState::chassisOn, chassisStatusOn);
- return;
+ bool on = std::get<std::string>(findState->second)
+ .ends_with(chassis::sOn);
+ if (!on)
+ {
+ timerChassisOn.cancel();
+ chassisStatusOn = false;
+ hostStatusCallback(PowerState::chassisOn, chassisStatusOn);
+ return;
+ }
+ // on comes too quickly
+ timerChassisOn.expires_after(std::chrono::seconds(10));
+ timerChassisOn.async_wait([hostStatusCallback](
+ boost::system::error_code ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
+ if (ec)
+ {
+ std::cerr << "Timer error " << ec.message() << "\n";
+ return;
+ }
+ chassisStatusOn = true;
+ hostStatusCallback(PowerState::chassisOn, chassisStatusOn);
+ });
}
- // on comes too quickly
- timerChassisOn.expires_after(std::chrono::seconds(10));
- timerChassisOn.async_wait(
- [hostStatusCallback](boost::system::error_code ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return;
- }
- if (ec)
- {
- std::cerr << "Timer error " << ec.message() << "\n";
- return;
- }
- chassisStatusOn = true;
- hostStatusCallback(PowerState::chassisOn, chassisStatusOn);
- });
- }
- });
+ });
getPowerStatus(conn);
getPostStatus(conn);
getChassisStatus(conn);
@@ -672,21 +675,21 @@
conn->async_method_call(
[association, path](const boost::system::error_code ec,
const GetSubTreeType& subtree) {
- // The parent of the config is always the inventory object, and may be
- // the associated chassis. If the parent is not itself a chassis or
- // board, the sensor is associated with the system chassis.
- std::string parent = fs::path(path).parent_path().string();
- if (ec)
- {
- // In case of error, set the default associations and
- // initialize the association Interface.
- setInventoryAssociation(association, parent, parent);
- return;
- }
- setInventoryAssociation(
- association, parent,
- findContainingChassis(parent, subtree).value_or(parent));
- },
+ // The parent of the config is always the inventory object, and may
+ // be the associated chassis. If the parent is not itself a chassis
+ // or board, the sensor is associated with the system chassis.
+ std::string parent = fs::path(path).parent_path().string();
+ if (ec)
+ {
+ // In case of error, set the default associations and
+ // initialize the association Interface.
+ setInventoryAssociation(association, parent, parent);
+ return;
+ }
+ setInventoryAssociation(
+ association, parent,
+ findContainingChassis(parent, subtree).value_or(parent));
+ },
mapper::busName, mapper::path, mapper::interface, "GetSubTree",
"/xyz/openbmc_project/inventory/system", 2, allInterfaces);
}
@@ -764,62 +767,67 @@
static std::unique_ptr<sdbusplus::bus::match_t> specialModeIntfMatch =
std::make_unique<sdbusplus::bus::match_t>(
conn, filterSpecialModeIntfAdd, [](sdbusplus::message_t& 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);
- });
+ 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 =
rules::type::signal() + rules::member("PropertiesChanged") +
rules::interface("org.freedesktop.DBus.Properties") +
rules::argN(0, specialModeInterface);
static std::unique_ptr<sdbusplus::bus::match_t> specialModeChangeMatch =
- std::make_unique<sdbusplus::bus::match_t>(conn, filterSpecialModeChange,
- [](sdbusplus::message_t& m) {
- std::string interfaceName;
- boost::container::flat_map<std::string, std::variant<std::string>>
- propertiesChanged;
+ std::make_unique<sdbusplus::bus::match_t>(
+ conn, filterSpecialModeChange, [](sdbusplus::message_t& 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;
- }
- const auto* manufacturingModeStatus =
- std::get_if<std::string>(&getManufactMode);
- handleSpecialModeChange(*manufacturingModeStatus);
- },
+ if (ec)
+ {
+ std::cerr << "error getting SpecialMode status "
+ << ec.message() << "\n";
+ return;
+ }
+ const auto* manufacturingModeStatus =
+ std::get_if<std::string>(&getManufactMode);
+ handleSpecialModeChange(*manufacturingModeStatus);
+ },
"xyz.openbmc_project.SpecialMode",
"/xyz/openbmc_project/security/special_mode",
"org.freedesktop.DBus.Properties", "Get", specialModeInterface,
diff --git a/src/Utils.hpp b/src/Utils.hpp
index d76f954..78a6ecd 100644
--- a/src/Utils.hpp
+++ b/src/Utils.hpp
@@ -59,10 +59,9 @@
};
std::optional<std::string> openAndRead(const std::string& hwmonFile);
-std::optional<std::string>
- getFullHwmonFilePath(const std::string& directory,
- const std::string& hwmonBaseName,
- const std::set<std::string>& permitSet);
+std::optional<std::string> getFullHwmonFilePath(
+ const std::string& directory, const std::string& hwmonBaseName,
+ const std::set<std::string>& permitSet);
std::set<std::string> getPermitSet(const SensorBaseConfigMap& config);
bool findFiles(const std::filesystem::path& dirPath,
std::string_view matchString,
@@ -198,8 +197,8 @@
auto findPowerState = cfg.find("PowerState");
if (findPowerState != cfg.end())
{
- std::string powerState = std::visit(VariantToStringVisitor(),
- findPowerState->second);
+ std::string powerState =
+ std::visit(VariantToStringVisitor(), findPowerState->second);
setReadState(powerState, state);
}
return state;
@@ -225,11 +224,11 @@
{
conn->async_method_call(
[name](const boost::system::error_code ec) {
- if (ec)
- {
- std::cerr << "Failed to set LED " << name << "\n";
- }
- },
+ if (ec)
+ {
+ std::cerr << "Failed to set LED " << name << "\n";
+ }
+ },
"xyz.openbmc_project.LED.GroupManager",
"/xyz/openbmc_project/led/groups/" + name, properties::interface,
properties::set, "xyz.openbmc_project.Led.Group", "Asserted",
@@ -247,8 +246,7 @@
GetSensorConfiguration(
std::shared_ptr<sdbusplus::asio::connection> connection,
std::function<void(ManagedObjectType& resp)>&& callbackFunc) :
- dbusConnection(std::move(connection)),
- callback(std::move(callbackFunc))
+ dbusConnection(std::move(connection)), callback(std::move(callbackFunc))
{}
void getPath(const std::string& path, const std::string& interface,
@@ -263,31 +261,31 @@
self->dbusConnection->async_method_call(
[self, path, interface, owner, retries](
const boost::system::error_code ec, SensorBaseConfigMap& data) {
- if (ec)
- {
- std::cerr << "Error getting " << path << ": retries left"
- << retries - 1 << "\n";
- if (retries == 0U)
+ if (ec)
{
- return;
- }
- auto timer = std::make_shared<boost::asio::steady_timer>(
- self->dbusConnection->get_io_context());
- timer->expires_after(std::chrono::seconds(10));
- timer->async_wait([self, timer, path, interface, owner,
- retries](boost::system::error_code ec) {
- if (ec)
+ std::cerr << "Error getting " << path << ": retries left"
+ << retries - 1 << "\n";
+ if (retries == 0U)
{
- std::cerr << "Timer error!\n";
return;
}
- self->getPath(path, interface, owner, retries - 1);
- });
- return;
- }
+ auto timer = std::make_shared<boost::asio::steady_timer>(
+ self->dbusConnection->get_io_context());
+ timer->expires_after(std::chrono::seconds(10));
+ timer->async_wait([self, timer, path, interface, owner,
+ retries](boost::system::error_code ec) {
+ if (ec)
+ {
+ std::cerr << "Timer error!\n";
+ return;
+ }
+ self->getPath(path, interface, owner, retries - 1);
+ });
+ return;
+ }
- self->respData[path][interface] = std::move(data);
- },
+ self->respData[path][interface] = std::move(data);
+ },
owner, path, "org.freedesktop.DBus.Properties", "GetAll",
interface);
}
@@ -310,51 +308,52 @@
dbusConnection->async_method_call(
[self, interfaces, retries](const boost::system::error_code ec,
const GetSubTreeType& ret) {
- if (ec)
- {
- std::cerr << "Error calling mapper\n";
- if (retries == 0U)
+ if (ec)
{
- return;
- }
- auto timer = std::make_shared<boost::asio::steady_timer>(
- self->dbusConnection->get_io_context());
- timer->expires_after(std::chrono::seconds(10));
- timer->async_wait([self, timer, interfaces,
- retries](boost::system::error_code ec) {
- if (ec)
+ std::cerr << "Error calling mapper\n";
+ if (retries == 0U)
{
- std::cerr << "Timer error!\n";
return;
}
- self->getConfiguration(interfaces, retries - 1);
- });
+ auto timer = std::make_shared<boost::asio::steady_timer>(
+ self->dbusConnection->get_io_context());
+ timer->expires_after(std::chrono::seconds(10));
+ timer->async_wait([self, timer, interfaces,
+ retries](boost::system::error_code ec) {
+ if (ec)
+ {
+ std::cerr << "Timer error!\n";
+ return;
+ }
+ self->getConfiguration(interfaces, retries - 1);
+ });
- return;
- }
- for (const auto& [path, objDict] : ret)
- {
- if (objDict.empty())
- {
return;
}
- const std::string& owner = objDict.begin()->first;
-
- for (const std::string& interface : objDict.begin()->second)
+ for (const auto& [path, objDict] : ret)
{
- // anything that starts with a requested configuration
- // is good
- if (std::find_if(interfaces.begin(), interfaces.end(),
- [interface](const std::string& possible) {
- return interface.starts_with(possible);
- }) == interfaces.end())
+ if (objDict.empty())
{
- continue;
+ return;
}
- self->getPath(path, interface, owner);
+ const std::string& owner = objDict.begin()->first;
+
+ for (const std::string& interface : objDict.begin()->second)
+ {
+ // anything that starts with a requested configuration
+ // is good
+ if (std::find_if(
+ interfaces.begin(), interfaces.end(),
+ [interface](const std::string& possible) {
+ return interface.starts_with(possible);
+ }) == interfaces.end())
+ {
+ continue;
+ }
+ self->getPath(path, interface, owner);
+ }
}
- }
- },
+ },
mapper::busName, mapper::path, mapper::interface, mapper::subtree,
"/", 0, interfaces);
}
diff --git a/src/sensor.hpp b/src/sensor.hpp
index 7d22160..82798dc 100644
--- a/src/sensor.hpp
+++ b/src/sensor.hpp
@@ -267,8 +267,8 @@
sensorInterface->register_property("MinValue", minValue);
sensorInterface->register_property(
"Value", value, [this](const double& newValue, double& oldValue) {
- return setSensorValue(newValue, oldValue);
- });
+ return setSensorValue(newValue, oldValue);
+ });
fillMissingThresholds();
@@ -288,36 +288,36 @@
continue;
}
- std::string level = propertyLevel(threshold.level,
- threshold.direction);
- std::string alarm = propertyAlarm(threshold.level,
- threshold.direction);
+ std::string level =
+ propertyLevel(threshold.level, threshold.direction);
+ std::string alarm =
+ propertyAlarm(threshold.level, threshold.direction);
if ((level.empty()) || (alarm.empty()))
{
continue;
}
- size_t thresSize = label.empty() ? thresholds.size()
- : thresholdSize;
+ size_t thresSize =
+ label.empty() ? thresholds.size() : thresholdSize;
iface->register_property(
level, threshold.value,
[&, label, thresSize](const double& request, double& oldValue) {
- oldValue = request; // todo, just let the config do this?
- threshold.value = request;
- thresholds::persistThreshold(configurationPath, configInterface,
- threshold, dbusConnection,
- thresSize, label);
- // Invalidate previously remembered value,
- // so new thresholds will be checked during next update,
- // even if sensor reading remains unchanged.
- value = std::numeric_limits<double>::quiet_NaN();
+ oldValue = request; // todo, just let the config do this?
+ threshold.value = request;
+ thresholds::persistThreshold(
+ configurationPath, configInterface, threshold,
+ dbusConnection, thresSize, label);
+ // Invalidate previously remembered value,
+ // so new thresholds will be checked during next update,
+ // even if sensor reading remains unchanged.
+ value = std::numeric_limits<double>::quiet_NaN();
- // Although tempting, don't call checkThresholds() from here
- // directly. Let the regular sensor monitor call the same
- // using updateValue(), which can check conditions like
- // poweron, etc., before raising any event.
- return 1;
- });
+ // Although tempting, don't call checkThresholds() from here
+ // directly. Let the regular sensor monitor call the same
+ // using updateValue(), which can check conditions like
+ // poweron, etc., before raising any event.
+ return 1;
+ });
iface->register_property(alarm, false);
}
if (!sensorInterface->initialize())
@@ -359,17 +359,17 @@
availableInterfaceName);
availableInterface->register_property(
"Available", true, [this](const bool propIn, bool& old) {
- if (propIn == old)
- {
+ if (propIn == old)
+ {
+ return 1;
+ }
+ old = propIn;
+ if (!propIn)
+ {
+ updateValue(std::numeric_limits<double>::quiet_NaN());
+ }
return 1;
- }
- old = propIn;
- if (!propIn)
- {
- updateValue(std::numeric_limits<double>::quiet_NaN());
- }
- return 1;
- });
+ });
availableInterface->initialize();
}
if (!operationalInterface)
diff --git a/tests/test_Utils.cpp b/tests/test_Utils.cpp
index b46db7b..8192475 100644
--- a/tests/test_Utils.cpp
+++ b/tests/test_Utils.cpp
@@ -115,9 +115,9 @@
TEST_F(TestUtils, findFiles_in_peci_no_match)
{
std::vector<fs::path> foundPaths;
- auto ret = findFiles(peciDir,
- R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/aaa$)",
- foundPaths, 6);
+ auto ret =
+ findFiles(peciDir, R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/aaa$)",
+ foundPaths, 6);
EXPECT_TRUE(ret);
EXPECT_TRUE(foundPaths.empty());
@@ -126,9 +126,9 @@
TEST_F(TestUtils, findFiles_in_peci_match)
{
std::vector<fs::path> foundPaths;
- auto ret = findFiles(peciDir,
- R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
- foundPaths, 6);
+ auto ret =
+ findFiles(peciDir, R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
+ foundPaths, 6);
EXPECT_TRUE(ret);
EXPECT_EQ(foundPaths.size(), 1U);
@@ -166,9 +166,9 @@
TEST_F(TestUtils, findFiles_in_sub_peci_match)
{
std::vector<fs::path> foundPaths;
- auto ret = findFiles(peciDir / "peci-0",
- R"(\d+-.+/peci-.+/hwmon/hwmon\d+/name$)", foundPaths,
- 5);
+ auto ret =
+ findFiles(peciDir / "peci-0", R"(\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
+ foundPaths, 5);
EXPECT_TRUE(ret);
EXPECT_EQ(foundPaths.size(), 1U);