add clang-tidy
This commit implements a clang-tidy file, and makes some changes to get
it to pass. Most changes are naming or mechanical in nature.
Tested:
Clang-tidy now passes.
Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: Ia441e4801b6c8725421d160c531c5df141f255d4
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..f90f316
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,262 @@
+Checks: '
+-*,
+readability-identifier-naming,
+clang-analyzer-apiModeling.StdCLibraryFunctions,
+clang-analyzer-apiModeling.TrustNonnull,
+clang-analyzer-apiModeling.google.GTest,
+clang-analyzer-apiModeling.llvm.CastValue,
+clang-analyzer-apiModeling.llvm.ReturnValue,
+clang-analyzer-core.CallAndMessageModeling,
+clang-analyzer-core.DivideZero,
+clang-analyzer-core.DynamicTypePropagation,
+clang-analyzer-core.NonNullParamChecker,
+clang-analyzer-core.NonnilStringConstants,
+clang-analyzer-core.NullDereference,
+clang-analyzer-core.StackAddrEscapeBase,
+clang-analyzer-core.StackAddressEscape,
+clang-analyzer-core.UndefinedBinaryOperatorResult,
+clang-analyzer-core.VLASize,
+clang-analyzer-core.builtin.BuiltinFunctions,
+clang-analyzer-core.builtin.NoReturnFunctions,
+clang-analyzer-core.uninitialized.ArraySubscript,
+clang-analyzer-core.uninitialized.Assign,
+clang-analyzer-core.uninitialized.Branch,
+clang-analyzer-core.uninitialized.CapturedBlockVariable,
+clang-analyzer-core.uninitialized.UndefReturn,
+clang-analyzer-cplusplus.InnerPointer,
+clang-analyzer-cplusplus.Move,
+clang-analyzer-cplusplus.NewDelete,
+clang-analyzer-cplusplus.NewDeleteLeaks,
+clang-analyzer-cplusplus.PlacementNew,
+clang-analyzer-cplusplus.PureVirtualCall,
+clang-analyzer-cplusplus.SelfAssignment,
+clang-analyzer-cplusplus.SmartPtrModeling,
+clang-analyzer-cplusplus.VirtualCallModeling,
+clang-analyzer-deadcode.DeadStores,
+clang-analyzer-fuchsia.HandleChecker,
+clang-analyzer-nullability.NullPassedToNonnull,
+clang-analyzer-nullability.NullReturnedFromNonnull,
+clang-analyzer-nullability.NullabilityBase,
+clang-analyzer-nullability.NullableDereferenced,
+clang-analyzer-nullability.NullablePassedToNonnull,
+clang-analyzer-nullability.NullableReturnedFromNonnull,
+clang-analyzer-optin.cplusplus.UninitializedObject,
+clang-analyzer-optin.cplusplus.VirtualCall,
+clang-analyzer-optin.mpi.MPI-Checker,
+clang-analyzer-optin.osx.OSObjectCStyleCast,
+clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
+clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
+clang-analyzer-optin.performance.GCDAntipattern,
+clang-analyzer-optin.performance.Padding,
+clang-analyzer-optin.portability.UnixAPI,
+clang-analyzer-osx.API,
+clang-analyzer-osx.MIG,
+clang-analyzer-osx.NSOrCFErrorDerefChecker,
+clang-analyzer-osx.NumberObjectConversion,
+clang-analyzer-osx.OSObjectRetainCount,
+clang-analyzer-osx.ObjCProperty,
+clang-analyzer-osx.SecKeychainAPI,
+clang-analyzer-osx.cocoa.AtSync,
+clang-analyzer-osx.cocoa.AutoreleaseWrite,
+clang-analyzer-osx.cocoa.ClassRelease,
+clang-analyzer-osx.cocoa.Dealloc,
+clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
+clang-analyzer-osx.cocoa.Loops,
+clang-analyzer-osx.cocoa.MissingSuperCall,
+clang-analyzer-osx.cocoa.NSAutoreleasePool,
+clang-analyzer-osx.cocoa.NSError,
+clang-analyzer-osx.cocoa.NilArg,
+clang-analyzer-osx.cocoa.NonNilReturnValue,
+clang-analyzer-osx.cocoa.ObjCGenerics,
+clang-analyzer-osx.cocoa.RetainCount,
+clang-analyzer-osx.cocoa.RetainCountBase,
+clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
+clang-analyzer-osx.cocoa.SelfInit,
+clang-analyzer-osx.cocoa.SuperDealloc,
+clang-analyzer-osx.cocoa.UnusedIvars,
+clang-analyzer-osx.cocoa.VariadicMethodTypes,
+clang-analyzer-osx.coreFoundation.CFError,
+clang-analyzer-osx.coreFoundation.CFNumber,
+clang-analyzer-osx.coreFoundation.CFRetainRelease,
+clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
+clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
+clang-analyzer-security.FloatLoopCounter,
+clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
+clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
+clang-analyzer-security.insecureAPI.UncheckedReturn,
+clang-analyzer-security.insecureAPI.bcmp,
+clang-analyzer-security.insecureAPI.bcopy,
+clang-analyzer-security.insecureAPI.bzero,
+clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
+clang-analyzer-security.insecureAPI.getpw,
+clang-analyzer-security.insecureAPI.gets,
+clang-analyzer-security.insecureAPI.mkstemp,
+clang-analyzer-security.insecureAPI.mktemp,
+clang-analyzer-security.insecureAPI.rand,
+clang-analyzer-security.insecureAPI.strcpy,
+clang-analyzer-security.insecureAPI.vfork,
+clang-analyzer-unix.API,
+clang-analyzer-unix.DynamicMemoryModeling,
+clang-analyzer-unix.Malloc,
+clang-analyzer-unix.MallocSizeof,
+clang-analyzer-unix.MismatchedDeallocator,
+clang-analyzer-unix.Vfork,
+clang-analyzer-unix.cstring.BadSizeArg,
+clang-analyzer-unix.cstring.CStringModeling,
+clang-analyzer-unix.cstring.NullArg,
+clang-analyzer-valist.CopyToSelf,
+clang-analyzer-valist.Uninitialized,
+clang-analyzer-valist.Unterminated,
+clang-analyzer-valist.ValistBase,
+clang-analyzer-webkit.NoUncountedMemberChecker,
+clang-analyzer-webkit.RefCntblBaseVirtualDtor,
+cert-con36-c,
+cert-con54-cpp,
+cert-dcl03-c,
+cert-dcl16-c,
+cert-dcl21-cpp,
+cert-dcl37-c,
+cert-dcl50-cpp,
+cert-dcl51-cpp,
+cert-dcl54-cpp,
+cert-dcl58-cpp,
+cert-dcl59-cpp,
+cert-env33-c,
+cert-err09-cpp,
+cert-err34-c,
+cert-err52-cpp,
+cert-err60-cpp,
+cert-err61-cpp,
+cert-fio38-c,
+cert-flp30-c,
+cert-mem57-cpp,
+cert-msc30-c,
+cert-msc32-c,
+cert-msc50-cpp,
+cert-msc51-cpp,
+cert-oop11-cpp,
+cert-oop54-cpp,
+cert-oop57-cpp,
+modernize-avoid-bind,
+modernize-deprecated-headers,
+modernize-deprecated-ios-base-aliases,
+modernize-loop-convert,
+modernize-make-shared,
+modernize-make-unique,
+modernize-raw-string-literal,
+modernize-replace-auto-ptr,
+modernize-replace-random-shuffle,
+modernize-return-braced-init-list,
+modernize-shrink-to-fit,
+modernize-unary-static-assert,
+modernize-use-bool-literals,
+modernize-use-default-member-init,
+modernize-use-emplace,
+modernize-use-equals-default,
+modernize-use-equals-delete,
+modernize-use-noexcept,
+modernize-use-nullptr,
+modernize-use-override,
+modernize-use-transparent-functors,
+modernize-use-uncaught-exceptions,
+modernize-use-using,
+bugprone-argument-comment,
+bugprone-assert-side-effect,
+bugprone-bad-signal-to-kill-thread,
+bugprone-bool-pointer-implicit-conversion,
+bugprone-branch-clone,
+bugprone-copy-constructor-init,
+bugprone-dangling-handle,
+bugprone-dynamic-static-initializers,
+bugprone-fold-init-type,
+bugprone-forward-declaration-namespace,
+bugprone-forwarding-reference-overload,
+bugprone-inaccurate-erase,
+bugprone-incorrect-roundings,
+bugprone-infinite-loop,
+bugprone-integer-division,
+bugprone-lambda-function-name,
+bugprone-macro-parentheses,
+bugprone-macro-repeated-side-effects,
+bugprone-misplaced-operator-in-strlen-in-alloc,
+bugprone-misplaced-pointer-arithmetic-in-alloc,
+bugprone-misplaced-widening-cast,
+bugprone-multiple-statement-macro,
+bugprone-narrowing-conversions,
+bugprone-no-escape,
+bugprone-not-null-terminated-result,
+bugprone-parent-virtual-call,
+bugprone-posix-return,
+bugprone-reserved-identifier,
+bugprone-signed-char-misuse,
+bugprone-sizeof-container,
+bugprone-sizeof-expression,
+bugprone-spuriously-wake-up-functions,
+bugprone-string-constructor,
+bugprone-string-integer-assignment,
+bugprone-string-literal-with-embedded-nul,
+bugprone-suspicious-enum-usage,
+bugprone-suspicious-include,
+bugprone-suspicious-memset-usage,
+bugprone-suspicious-missing-comma,
+bugprone-suspicious-semicolon,
+bugprone-suspicious-string-compare,
+bugprone-swapped-arguments,
+bugprone-terminating-continue,
+bugprone-throw-keyword-missing,
+bugprone-too-small-loop-variable,
+bugprone-undefined-memory-manipulation,
+bugprone-undelegated-constructor,
+bugprone-unhandled-self-assignment,
+bugprone-unused-raii,
+bugprone-unused-return-value,
+bugprone-use-after-move,
+bugprone-virtual-near-miss,
+misc-misplaced-const,
+misc-no-recursion,
+misc-redundant-expression,
+misc-static-assert,
+misc-throw-by-value-catch-by-reference,
+misc-unconventional-assign-operator,
+misc-uniqueptr-reset-release,
+misc-unused-using-decls,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-vector-operation,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+performance-faster-string-find,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-string-concatenation,
+performance-inefficient-vector-operation,
+performance-move-const-arg,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-noexcept-move-constructor,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+performance-unnecessary-value-param,
+readability-identifier-naming,
+readability-braces-around-statements,
+readability-const-return-type,
+readability-delete-null-pointer,
+readability-deleted-default,
+readability-else-after-return'
+
+WarningsAsErrors: '*'
+HeaderFilterRegex: '^((?!linux).)*$'
+CheckOptions:
+ - { key: readability-identifier-naming.ClassCase, value: CamelCase }
+ - { key: readability-identifier-naming.VariableCase, value: camelBack }
+ - { key: readability-identifier-naming.FunctionCase, value: camelBack }
+ - { key: readability-identifier-naming.ParameterCase, value: camelBack }
+ - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
+ - { key: readability-identifier-naming.StructCase, value: CamelCase }
+
diff --git a/include/ADCSensor.hpp b/include/ADCSensor.hpp
index 800e1fc..d1edf6d 100644
--- a/include/ADCSensor.hpp
+++ b/include/ADCSensor.hpp
@@ -1,11 +1,10 @@
#pragma once
-#include "Thresholds.hpp"
-#include "sensor.hpp"
-
+#include <Thresholds.hpp>
#include <boost/asio/streambuf.hpp>
#include <gpiod.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sensor.hpp>
#include <memory>
#include <optional>
@@ -70,7 +69,7 @@
const double scaleFactor, PowerState readState,
const std::string& sensorConfiguration,
std::optional<BridgeGpio>&& bridgeGpio);
- ~ADCSensor();
+ ~ADCSensor() override;
void setupRead(void);
private:
diff --git a/include/CPUSensor.hpp b/include/CPUSensor.hpp
index 9dd8b23..29b8209 100644
--- a/include/CPUSensor.hpp
+++ b/include/CPUSensor.hpp
@@ -1,13 +1,12 @@
#pragma once
-#include "Thresholds.hpp"
-#include "Utils.hpp"
-#include "sensor.hpp"
-
+#include <Thresholds.hpp>
+#include <Utils.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/container/flat_map.hpp>
#include <gpiod.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sensor.hpp>
#include <filesystem>
#include <fstream>
@@ -27,7 +26,7 @@
std::vector<thresholds::Threshold>&& thresholds,
const std::string& configuration, int cpuId, bool show,
double dtsOffset);
- ~CPUSensor();
+ ~CPUSensor() override;
static constexpr unsigned int sensorScaleFactor = 1000;
static constexpr unsigned int sensorPollMs = 1000;
static constexpr size_t warnAfterErrorCount = 10;
diff --git a/include/ChassisIntrusionSensor.hpp b/include/ChassisIntrusionSensor.hpp
index a86dabc..142ced3 100644
--- a/include/ChassisIntrusionSensor.hpp
+++ b/include/ChassisIntrusionSensor.hpp
@@ -53,7 +53,7 @@
bool mInitialized = false;
- void updateValue(const std::string newValue);
+ void updateValue(const std::string& newValue);
int i2cReadFromPch(int busId, int slaveAddr);
void pollSensorStatusByPch();
void readGpio();
diff --git a/include/ExitAirTempSensor.hpp b/include/ExitAirTempSensor.hpp
index 2d69cec..191f95f 100644
--- a/include/ExitAirTempSensor.hpp
+++ b/include/ExitAirTempSensor.hpp
@@ -1,8 +1,7 @@
#pragma once
-#include "sensor.hpp"
-
#include <boost/container/flat_map.hpp>
#include <sdbusplus/bus/match.hpp>
+#include <sensor.hpp>
#include <chrono>
#include <limits>
@@ -27,7 +26,7 @@
sdbusplus::asio::object_server& objectServer,
std::vector<thresholds::Threshold>&& thresholds,
std::shared_ptr<ExitAirTempSensor>& parent);
- ~CFMSensor();
+ ~CFMSensor() override;
bool calculate(double&);
void updateReading(void);
@@ -68,7 +67,7 @@
const std::string& sensorConfiguration,
sdbusplus::asio::object_server& objectServer,
std::vector<thresholds::Threshold>&& thresholds);
- ~ExitAirTempSensor();
+ ~ExitAirTempSensor() override;
void checkThresholds(void) override;
void updateReading(void);
diff --git a/include/ExternalSensor.hpp b/include/ExternalSensor.hpp
index bf3e885..fd36bb0 100644
--- a/include/ExternalSensor.hpp
+++ b/include/ExternalSensor.hpp
@@ -18,7 +18,7 @@
std::shared_ptr<sdbusplus::asio::connection>& conn,
const std::string& sensorName,
const std::string& sensorMeasure,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration,
const double& maxReading, const double& minReading,
const PowerState& powerState);
diff --git a/include/HwmonTempSensor.hpp b/include/HwmonTempSensor.hpp
index 5cf0da5..11e46f3 100644
--- a/include/HwmonTempSensor.hpp
+++ b/include/HwmonTempSensor.hpp
@@ -1,10 +1,9 @@
#pragma once
-#include "Thresholds.hpp"
-#include "sensor.hpp"
-
+#include <Thresholds.hpp>
#include <boost/asio/streambuf.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sensor.hpp>
#include <string>
#include <vector>
@@ -22,7 +21,7 @@
const float pollRate,
const std::string& sensorConfiguration,
const PowerState powerState);
- ~HwmonTempSensor();
+ ~HwmonTempSensor() override;
void setupRead(void);
private:
diff --git a/include/IpmbSensor.hpp b/include/IpmbSensor.hpp
index 4207d1c..1d124b1 100644
--- a/include/IpmbSensor.hpp
+++ b/include/IpmbSensor.hpp
@@ -1,8 +1,7 @@
#pragma once
-#include "sensor.hpp"
-
#include <boost/asio/deadline_timer.hpp>
#include <boost/container/flat_map.hpp>
+#include <sensor.hpp>
#include <chrono>
#include <limits>
@@ -46,7 +45,7 @@
static bool isValid(const std::vector<uint8_t>& data)
{
- constexpr auto ReadingUnavailableBit = 5;
+ constexpr auto readingUnavailableBit = 5;
// Proper 'Get Sensor Reading' response has at least 4 bytes, including
// Completion Code. Our IPMB stack strips Completion Code from payload so we
@@ -57,7 +56,7 @@
}
// Per IPMI 'Get Sensor Reading' specification
- if (data[1] & (1 << ReadingUnavailableBit))
+ if (data[1] & (1 << readingUnavailableBit))
{
return false;
}
@@ -82,7 +81,7 @@
std::vector<thresholds::Threshold>&& thresholds,
uint8_t deviceAddress, uint8_t hostSMbusIndex,
std::string& sensorTypeName);
- ~IpmbSensor();
+ ~IpmbSensor() override;
void checkThresholds(void) override;
void read(void);
diff --git a/include/MCUTempSensor.hpp b/include/MCUTempSensor.hpp
index 2f3aef4..deb7102 100644
--- a/include/MCUTempSensor.hpp
+++ b/include/MCUTempSensor.hpp
@@ -1,8 +1,7 @@
#pragma once
-#include "sensor.hpp"
-
#include <boost/asio/deadline_timer.hpp>
#include <boost/container/flat_map.hpp>
+#include <sensor.hpp>
#include <chrono>
#include <limits>
@@ -18,7 +17,7 @@
sdbusplus::asio::object_server& objectServer,
std::vector<thresholds::Threshold>&& thresholds,
uint8_t busId, uint8_t mcuAddress, uint8_t tempReg);
- ~MCUTempSensor();
+ ~MCUTempSensor() override;
void checkThresholds(void) override;
void read(void);
diff --git a/include/NVMeSensor.hpp b/include/NVMeSensor.hpp
index d6d9b13..02510d4 100644
--- a/include/NVMeSensor.hpp
+++ b/include/NVMeSensor.hpp
@@ -15,7 +15,7 @@
boost::asio::io_service& io,
std::shared_ptr<sdbusplus::asio::connection>& conn,
const std::string& sensorName,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration, const int busNumber);
virtual ~NVMeSensor();
diff --git a/include/PSUSensor.hpp b/include/PSUSensor.hpp
index 7b4bfdb..0559073 100644
--- a/include/PSUSensor.hpp
+++ b/include/PSUSensor.hpp
@@ -1,14 +1,14 @@
#pragma once
-#include "PwmSensor.hpp"
-#include "Thresholds.hpp"
-#include "sensor.hpp"
-
+#include <PwmSensor.hpp>
+#include <Thresholds.hpp>
#include <boost/asio/streambuf.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sensor.hpp>
#include <memory>
#include <string>
+#include <utility>
class PSUSensor : public Sensor, public std::enable_shared_from_this<PSUSensor>
{
@@ -21,7 +21,7 @@
const std::string& sensorConfiguration,
std::string& sensorTypeName, unsigned int factor, double max,
double min, const std::string& label, size_t tSize);
- ~PSUSensor();
+ ~PSUSensor() override;
void setupRead(void);
private:
@@ -48,7 +48,7 @@
{
public:
PSUProperty(std::string name, double max, double min, unsigned int factor) :
- labelTypeName(name), maxReading(max), minReading(min),
+ labelTypeName(std::move(name)), maxReading(max), minReading(min),
sensorScaleFactor(factor)
{}
~PSUProperty() = default;
diff --git a/include/TachSensor.hpp b/include/TachSensor.hpp
index 1e5347f..1b80404 100644
--- a/include/TachSensor.hpp
+++ b/include/TachSensor.hpp
@@ -1,14 +1,13 @@
#pragma once
-#include "Thresholds.hpp"
-#include "sensor.hpp"
-
#include <systemd/sd-journal.h>
+#include <Thresholds.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <gpiod.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sensor.hpp>
#include <memory>
#include <optional>
@@ -75,7 +74,7 @@
const std::pair<size_t, size_t>& limits,
const PowerState& powerState,
const std::optional<std::string>& led);
- ~TachSensor();
+ ~TachSensor() override;
private:
sdbusplus::asio::object_server& objServer;
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index ca2b0a0..559f4df 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "Utils.hpp"
-
+#include <Utils.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <nlohmann/json.hpp>
@@ -132,9 +131,11 @@
{
return; // we're being canceled
}
- else if (ec)
+ if (ec)
{
+
std::cerr << "timer error: " << ec.message() << "\n";
+
return;
}
if (isPowerOn())
diff --git a/include/Utils.hpp b/include/Utils.hpp
index c164187..d2ab5ca 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "VariantVisitors.hpp"
-
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
@@ -48,17 +47,22 @@
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,
+bool findFiles(const std::filesystem::path& dirPath,
const std::string& matchString,
std::vector<std::filesystem::path>& foundPaths,
- unsigned int symlinkDepth = 1);
+ int symlinkDepth = 1);
bool isPowerOn(void);
bool hasBiosPost(void);
void setupPowerMatch(const std::shared_ptr<sdbusplus::asio::connection>& conn);
bool getSensorConfiguration(
const std::string& type,
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
- ManagedObjectType& resp, bool useCache = false);
+ ManagedObjectType& resp, bool useCache);
+
+bool getSensorConfiguration(
+ const std::string& type,
+ const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+ ManagedObjectType& resp);
void createAssociation(
std::shared_ptr<sdbusplus::asio::dbus_interface>& association,
@@ -159,7 +163,7 @@
}
}
-inline void setLed(std::shared_ptr<sdbusplus::asio::connection> conn,
+inline void setLed(const std::shared_ptr<sdbusplus::asio::connection>& conn,
const std::string& name, bool on)
{
conn->async_method_call(
@@ -176,8 +180,8 @@
}
void createInventoryAssoc(
- std::shared_ptr<sdbusplus::asio::connection> conn,
- std::shared_ptr<sdbusplus::asio::dbus_interface> association,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::shared_ptr<sdbusplus::asio::dbus_interface>& association,
const std::string& path);
struct GetSensorConfiguration :
@@ -186,7 +190,7 @@
GetSensorConfiguration(
std::shared_ptr<sdbusplus::asio::connection> connection,
std::function<void(ManagedObjectType& resp)>&& callbackFunc) :
- dbusConnection(connection),
+ dbusConnection(std::move(connection)),
callback(std::move(callbackFunc))
{}
diff --git a/include/sensor.hpp b/include/sensor.hpp
index 0ef87d5..115b8fa 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -1,8 +1,7 @@
#pragma once
-#include "Thresholds.hpp"
-#include "Utils.hpp"
-
+#include <Thresholds.hpp>
+#include <Utils.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <limits>
@@ -182,7 +181,7 @@
void
setInitialProperties(std::shared_ptr<sdbusplus::asio::connection>& conn,
- const std::string label = std::string(),
+ const std::string& label = std::string(),
size_t thresholdSize = 0)
{
if (readState == PowerState::on || readState == PowerState::biosPost)
diff --git a/meson.build b/meson.build
index a1b79be..3932a14 100644
--- a/meson.build
+++ b/meson.build
@@ -22,7 +22,6 @@
)
build_tests = get_option('tests')
-cppfs = meson.get_compiler('cpp').find_library('stdc++fs')
gpiodcxx = dependency('libgpiodcxx')
i2c = meson.get_compiler('cpp').find_library('i2c')
sdbusplus = dependency('sdbusplus')
@@ -43,9 +42,6 @@
utils_a = static_library(
'utils_a',
'src/Utils.cpp',
- dependencies: [
- cppfs,
- ],
implicit_include_directories: false,
include_directories: 'include',
)
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index fe600d7..646c269 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -14,10 +14,9 @@
// limitations under the License.
*/
-#include "ADCSensor.hpp"
-
#include <unistd.h>
+#include <ADCSensor.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/read_until.hpp>
@@ -49,13 +48,12 @@
sdbusplus::asio::object_server& objectServer,
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const double scaleFactor, PowerState readState,
const std::string& sensorConfiguration,
std::optional<BridgeGpio>&& bridgeGpio) :
- Sensor(boost::replace_all_copy(sensorName, " ", "_"),
- std::move(_thresholds), sensorConfiguration,
- "xyz.openbmc_project.Configuration.ADC",
+ Sensor(boost::replace_all_copy(sensorName, " ", "_"), std::move(thresholds),
+ sensorConfiguration, "xyz.openbmc_project.Configuration.ADC",
maxVoltageReading / scaleFactor, minVoltageReading / scaleFactor,
conn, readState),
std::enable_shared_from_this<ADCSensor>(), objServer(objectServer),
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 473d8a1..5265321 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -14,10 +14,9 @@
// limitations under the License.
*/
-#include "ADCSensor.hpp"
-#include "Utils.hpp"
-#include "VariantVisitors.hpp"
-
+#include <ADCSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
@@ -36,7 +35,7 @@
#include <variant>
#include <vector>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
namespace fs = std::filesystem;
@@ -321,7 +320,7 @@
/* we were canceled*/
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
return;
@@ -369,7 +368,7 @@
/* we were canceled*/
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
return;
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index ea56d03..c28b230 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -14,12 +14,10 @@
// limitations under the License.
*/
-#include "CPUSensor.hpp"
-
-#include "Utils.hpp"
-
#include <unistd.h>
+#include <CPUSensor.hpp>
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/read_until.hpp>
@@ -39,12 +37,11 @@
sdbusplus::asio::object_server& objectServer,
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration, int cpuId,
bool show, double dtsOffset) :
- Sensor(boost::replace_all_copy(sensorName, " ", "_"),
- std::move(_thresholds), sensorConfiguration, objectType, 0, 0, conn,
- PowerState::on),
+ Sensor(boost::replace_all_copy(sensorName, " ", "_"), std::move(thresholds),
+ sensorConfiguration, objectType, 0, 0, conn, PowerState::on),
objServer(objectServer), inputDev(io), waitTimer(io), path(path),
privTcontrol(std::numeric_limits<double>::quiet_NaN()),
dtsOffset(dtsOffset), show(show), pollTime(CPUSensor::sensorPollMs),
@@ -205,7 +202,7 @@
{
return; // we're being destroyed
}
- else if (err == boost::system::errc::operation_canceled)
+ if (err == boost::system::errc::operation_canceled)
{
if (readingStateGood())
{
@@ -214,7 +211,7 @@
std::cerr << name << " interface down!\n";
loggedInterfaceDown = true;
}
- pollTime = 10000 + rand() % 10000;
+ pollTime = CPUSensor::sensorPollMs * 10u;
markFunctional(false);
}
return;
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index dfc942f..07be8f6 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -14,18 +14,16 @@
// limitations under the License.
*/
-#include "CPUSensor.hpp"
-#include "Utils.hpp"
-#include "VariantVisitors.hpp"
-
#include <fcntl.h>
+#include <CPUSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/process/child.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/bus/match.hpp>
@@ -51,7 +49,7 @@
#endif
// clang-format on
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>> gCpuSensors;
boost::container::flat_map<std::string,
@@ -194,7 +192,7 @@
fs::path::iterator it = hwmonNamePath.begin();
std::advance(it, 6); // pick the 6th part for a PECI client device name
std::string deviceName = *it;
- auto findHyphen = deviceName.find("-");
+ auto findHyphen = deviceName.find('-');
if (findHyphen == std::string::npos)
{
std::cerr << "found bad device " << deviceName << "\n";
@@ -208,7 +206,7 @@
try
{
bus = std::stoi(busStr);
- addr = std::stoi(addrStr, 0, 16);
+ addr = std::stoi(addrStr, nullptr, 16);
}
catch (std::invalid_argument&)
{
@@ -229,7 +227,7 @@
// shouldn't have an empty name file
continue;
}
- if (DEBUG)
+ if (debug)
{
std::cout << "Checking: " << hwmonNamePath << ": " << hwmonName
<< "\n";
@@ -331,7 +329,7 @@
auto findSensor = gCpuSensors.find(sensorName);
if (findSensor != gCpuSensors.end())
{
- if (DEBUG)
+ if (debug)
{
std::cout << "Skipped: " << inputPath << ": " << sensorName
<< " is already created\n";
@@ -367,7 +365,7 @@
}
std::vector<thresholds::Threshold> sensorThresholds;
- std::string labelHead = label.substr(0, label.find(" "));
+ std::string labelHead = label.substr(0, label.find(' '));
parseThresholdsFromConfig(*sensorData, sensorThresholds,
&labelHead);
if (sensorThresholds.empty())
@@ -388,7 +386,7 @@
sensorName, std::move(sensorThresholds), *interfacePath, cpuId,
show, dtsOffset);
createdSensors.insert(sensorName);
- if (DEBUG)
+ if (debug)
{
std::cout << "Mapped: " << inputPath << " to " << sensorName
<< "\n";
@@ -428,7 +426,7 @@
if (boost::starts_with(directoryName, busStr) &&
boost::ends_with(directoryName, addrHexStr))
{
- if (DEBUG)
+ if (debug)
{
std::cout << parameters << " on bus " << busStr
<< " is already exported\n";
@@ -544,7 +542,7 @@
keepPinging = true;
}
- if (DEBUG)
+ if (debug)
{
std::cout << config.name << ", state: " << config.state << "\n";
}
@@ -681,7 +679,7 @@
uint64_t addr = std::visit(VariantToUnsignedIntVisitor(),
findAddress->second);
- if (DEBUG)
+ if (debug)
{
std::cout << "bus: " << bus << "\n";
std::cout << "addr: " << addr << "\n";
@@ -739,7 +737,7 @@
return;
}
- if (DEBUG)
+ if (debug)
{
std::cout << message.get_path() << " is changed\n";
}
diff --git a/src/ChassisIntrusionSensor.cpp b/src/ChassisIntrusionSensor.cpp
index 8293bab..af5ced3 100644
--- a/src/ChassisIntrusionSensor.cpp
+++ b/src/ChassisIntrusionSensor.cpp
@@ -14,22 +14,21 @@
// limitations under the License.
*/
-#include "ChassisIntrusionSensor.hpp"
-
-#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
-#include <boost/asio.hpp>
-#include <boost/bind.hpp>
+#include <ChassisIntrusionSensor.hpp>
+#include <boost/asio/io_service.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <cerrno>
#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
+#include <utility>
extern "C"
{
@@ -37,7 +36,7 @@
#include <linux/i2c-dev.h>
}
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
static constexpr unsigned int intrusionSensorPollSec = 1;
@@ -47,7 +46,7 @@
// Status bit field masks
const static constexpr size_t pchRegMaskIntrusion = 0x01;
-void ChassisIntrusionSensor::updateValue(const std::string newValue)
+void ChassisIntrusionSensor::updateValue(const std::string& newValue)
{
// Take no action if value already equal
// Same semantics as Sensor::updateValue(const double&)
@@ -109,12 +108,11 @@
return -1;
}
- int statusValue;
- unsigned int statusMask = pchRegMaskIntrusion;
- unsigned int statusReg = pchStatusRegIntrusion;
+ int32_t statusMask = pchRegMaskIntrusion;
+ int32_t statusReg = pchStatusRegIntrusion;
- statusValue = i2c_smbus_read_byte_data(fd, statusReg);
- if (DEBUG)
+ int32_t statusValue = i2c_smbus_read_byte_data(fd, statusReg);
+ if (debug)
{
std::cout << "\nRead bus " << busId << " addr " << slaveAddr
<< ", value = " << statusValue << "\n";
@@ -131,7 +129,7 @@
// Get status value with mask
int newValue = statusValue & statusMask;
- if (DEBUG)
+ if (debug)
{
std::cout << "statusValue is " << statusValue << "\n";
std::cout << "Intrusion sensor value is " << newValue << "\n";
@@ -180,7 +178,7 @@
// set string defined in chassis redfish schema
std::string newValue = value ? "HardwareIntrusion" : "Normal";
- if (DEBUG)
+ if (debug)
{
std::cout << "\nGPIO value is " << value << "\n";
std::cout << "Intrusion sensor value is " << newValue << "\n";
@@ -203,7 +201,7 @@
{
return; // we're being destroyed
}
- else if (ec)
+ if (ec)
{
std::cerr
<< "Error on GPIO based intrusion sensor wait event\n";
@@ -274,7 +272,7 @@
void ChassisIntrusionSensor::start(IntrusionSensorType type, int busId,
int slaveAddr, bool gpioInverted)
{
- if (DEBUG)
+ if (debug)
{
std::cerr << "enter ChassisIntrusionSensor::start, type = " << type
<< "\n";
@@ -361,7 +359,7 @@
ChassisIntrusionSensor::ChassisIntrusionSensor(
boost::asio::io_service& io,
std::shared_ptr<sdbusplus::asio::dbus_interface> iface) :
- mIface(iface),
+ mIface(std::move(iface)),
mType(IntrusionSensorType::gpio), mValue("unknown"), mOldValue("unknown"),
mBusId(-1), mSlaveAddr(-1), mPollTimer(io), mGpioInverted(false),
mGpioFd(io)
diff --git a/src/ExitAirTempSensor.cpp b/src/ExitAirTempSensor.cpp
index c667457..725cb12 100644
--- a/src/ExitAirTempSensor.cpp
+++ b/src/ExitAirTempSensor.cpp
@@ -14,13 +14,9 @@
// limitations under the License.
*/
-#include "ExitAirTempSensor.hpp"
-
-#include "Utils.hpp"
-#include "VariantVisitors.hpp"
-
-#include <math.h>
-
+#include <ExitAirTempSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
@@ -41,7 +37,7 @@
#include <variant>
#include <vector>
-constexpr const float altitudeFactor = 1.14;
+constexpr const double altitudeFactor = 1.14;
constexpr const char* exitAirIface =
"xyz.openbmc_project.Configuration.ExitAirTempSensor";
constexpr const char* cfmIface = "xyz.openbmc_project.Configuration.CFMSensor";
@@ -54,7 +50,7 @@
constexpr const char* cfmSettingPath = "/xyz/openbmc_project/control/cfm_limit";
constexpr const char* cfmSettingIface = "xyz.openbmc_project.Control.CFMLimit";
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
static constexpr double cfmMaxReading = 255;
static constexpr double cfmMinReading = 0;
@@ -128,8 +124,8 @@
conn->async_method_call(
[conn, value, owner,
- path](const boost::system::error_code ec,
- const std::variant<std::string>& classType) {
+ path{path}](const boost::system::error_code ec,
+ const std::variant<std::string>& classType) {
if (ec)
{
std::cerr << "Error getting pid class\n";
@@ -411,7 +407,7 @@
});
if (findReading == tachReadings.end())
{
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Can't find " << tachName << "in readings\n";
}
@@ -438,7 +434,7 @@
rpm /= findRange->second.second;
rpm *= 100;
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cout << "Tach " << tachName << "at " << rpm << "\n";
}
@@ -468,7 +464,7 @@
// Now calculate the CFM for this tach
// CFMi = Ci * Qmaxi * TACHi
totalCFM += ci * maxCFM * rpm;
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "totalCFM = " << totalCFM << "\n";
std::cerr << "Ci " << ci << " MaxCFM " << maxCFM << " rpm " << rpm
@@ -480,7 +476,7 @@
// divide by 100 since rpm is in percent
value = totalCFM / 100;
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "cfm value = " << value << "\n";
}
@@ -603,7 +599,7 @@
double reading =
std::visit(VariantToDoubleVisitor(), value);
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << path << "Reading " << reading
<< "\n";
@@ -695,7 +691,7 @@
// Calculate power correction factor
// Ci = CL + (CH - CL)/(QMax - QMin) * (CFM - QMin)
- float powerFactor = 0.0;
+ double powerFactor = 0.0;
if (cfm <= qMin)
{
powerFactor = powerFactorMin;
@@ -710,7 +706,7 @@
(qMax - qMin) * (cfm - qMin));
}
- totalPower *= static_cast<double>(powerFactor);
+ totalPower *= powerFactor;
totalPower += pOffset;
if (totalPower == 0)
@@ -724,7 +720,7 @@
return false;
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cout << "Power Factor " << powerFactor << "\n";
std::cout << "Inlet Temp " << inletTemp << "\n";
@@ -733,11 +729,11 @@
// Calculate the exit air temp
// Texit = Tfp + (1.76 * TotalPower / CFM * Faltitude)
- double reading = 1.76 * totalPower * static_cast<double>(altitudeFactor);
+ double reading = 1.76 * totalPower * altitudeFactor;
reading /= cfm;
reading += inletTemp;
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cout << "Reading 1: " << reading << "\n";
}
@@ -778,14 +774,14 @@
alphaDT = 1.0;
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cout << "AlphaDT: " << alphaDT << "\n";
}
reading = ((reading * alphaDT) + (lastReading * (1.0 - alphaDT)));
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cout << "Reading 2: " << reading << "\n";
}
diff --git a/src/ExternalSensor.cpp b/src/ExternalSensor.cpp
index 13e9415..f867151 100644
--- a/src/ExternalSensor.cpp
+++ b/src/ExternalSensor.cpp
@@ -21,16 +21,16 @@
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>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration, const double& maxReading,
const double& minReading, const PowerState& powerState) :
// TODO(): When the Mutable feature is integrated,
// make sure all ExternalSensor instances are mutable,
// because that is the entire point of ExternalSensor,
// to accept sensor values written by an external source.
- Sensor(boost::replace_all_copy(sensorName, " ", "_"),
- std::move(_thresholds), sensorConfiguration, objectType, maxReading,
- minReading, conn, powerState),
+ Sensor(boost::replace_all_copy(sensorName, " ", "_"), std::move(thresholds),
+ sensorConfiguration, objectType, maxReading, minReading, conn,
+ powerState),
std::enable_shared_from_this<ExternalSensor>(), objServer(objectServer)
{
// The caller must specify what physical characteristic
diff --git a/src/ExternalSensorMain.cpp b/src/ExternalSensorMain.cpp
index 9067d7e..19b8f60 100644
--- a/src/ExternalSensorMain.cpp
+++ b/src/ExternalSensorMain.cpp
@@ -43,7 +43,7 @@
// there is no other way to tell, and it will be used for the object path
// here: /xyz/openbmc_project/sensors/<Measure>/<Name>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
static const char* sensorType =
"xyz.openbmc_project.Configuration.ExternalSensor";
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 2e7442d..25e5739 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -14,11 +14,10 @@
// limitations under the License.
*/
-#include "PwmSensor.hpp"
-#include "TachSensor.hpp"
-#include "Utils.hpp"
-#include "VariantVisitors.hpp"
-
+#include <PwmSensor.hpp>
+#include <TachSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
@@ -40,7 +39,7 @@
#include <variant>
#include <vector>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
namespace fs = std::filesystem;
@@ -77,7 +76,7 @@
{
return FanTypes::aspeed;
}
- else if (boost::ends_with(canonical, "f0103000.pwm-fan-controller"))
+ if (boost::ends_with(canonical, "f0103000.pwm-fan-controller"))
{
return FanTypes::nuvoton;
}
@@ -88,13 +87,13 @@
void createRedundancySensor(
const boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
sensors,
- std::shared_ptr<sdbusplus::asio::connection> conn,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
sdbusplus::asio::object_server& objectServer)
{
conn->async_method_call(
[&objectServer, &sensors](boost::system::error_code& ec,
- const ManagedObjectType managedObj) {
+ const ManagedObjectType& managedObj) {
if (ec)
{
std::cerr << "Error calling entity manager \n";
@@ -182,7 +181,7 @@
std::string link =
fs::read_symlink(directory / "device").filename();
- size_t findDash = link.find("-");
+ size_t findDash = link.find('-');
if (findDash == std::string::npos ||
link.size() <= findDash + 1)
{
@@ -235,7 +234,7 @@
sensorData = &(sensor.second);
break;
}
- else if (fanType == FanTypes::i2c)
+ if (fanType == FanTypes::i2c)
{
auto findBus = baseConfiguration->second.find("Bus");
auto findAddress =
@@ -471,7 +470,7 @@
/* we were canceled*/
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
return;
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index 8a583b9..79eab20 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -14,9 +14,8 @@
// limitations under the License.
*/
-#include "HwmonTempSensor.hpp"
-#include "Utils.hpp"
-
+#include <HwmonTempSensor.hpp>
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
@@ -37,7 +36,7 @@
#include <variant>
#include <vector>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
static constexpr float pollRateDefault = 0.5;
namespace fs = std::filesystem;
@@ -97,7 +96,7 @@
fs::path device = directory / "device";
std::string deviceName = fs::canonical(device).stem();
- auto findHyphen = deviceName.find("-");
+ auto findHyphen = deviceName.find('-');
if (findHyphen == std::string::npos)
{
std::cerr << "found bad device " << deviceName << "\n";
@@ -111,7 +110,7 @@
try
{
bus = std::stoi(busStr);
- addr = std::stoi(addrStr, 0, 16);
+ addr = std::stoi(addrStr, nullptr, 16);
}
catch (std::invalid_argument&)
{
@@ -312,7 +311,7 @@
/* we were canceled*/
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
return;
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index e1e8f6c..b804b25 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -14,10 +14,9 @@
// limitations under the License.
*/
-#include "HwmonTempSensor.hpp"
-
#include <unistd.h>
+#include <HwmonTempSensor.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/read_until.hpp>
@@ -43,14 +42,14 @@
sdbusplus::asio::object_server& objectServer,
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& _thresholds, const float pollRate,
+ std::vector<thresholds::Threshold>&& thresholds, const float pollRate,
const std::string& sensorConfiguration, const PowerState powerState) :
- Sensor(boost::replace_all_copy(sensorName, " ", "_"),
- std::move(_thresholds), sensorConfiguration, objectType, maxReading,
- minReading, conn, powerState),
+ Sensor(boost::replace_all_copy(sensorName, " ", "_"), std::move(thresholds),
+ sensorConfiguration, objectType, maxReading, minReading, conn,
+ powerState),
std::enable_shared_from_this<HwmonTempSensor>(), objServer(objectServer),
inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path),
- sensorPollMs(pollRate * 1000)
+ sensorPollMs(static_cast<unsigned int>(pollRate * 1000))
{
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/temperature/" + name,
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index f3d95fb..e40c240 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -14,13 +14,12 @@
// limitations under the License.
*/
-#include "ChassisIntrusionSensor.hpp"
-#include "Utils.hpp"
-
#include <systemd/sd-journal.h>
+#include <ChassisIntrusionSensor.hpp>
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
-#include <boost/asio.hpp>
+#include <boost/asio/io_service.hpp>
#include <boost/container/flat_map.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
@@ -32,6 +31,7 @@
#include <sdbusplus/timer.hpp>
#include <array>
+#include <charconv>
#include <chrono>
#include <ctime>
#include <fstream>
@@ -43,7 +43,7 @@
#include <utility>
#include <vector>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
static constexpr const char* sensorType =
"xyz.openbmc_project.Configuration.ChassisIntrusionSensor";
@@ -125,7 +125,7 @@
continue;
}
- if (DEBUG)
+ if (debug)
{
std::cout << "find chassis intrusion sensor polarity inverted "
"flag is "
@@ -136,7 +136,7 @@
}
// case to find I2C info
- else if (*pType == IntrusionSensorType::pch)
+ if (*pType == IntrusionSensorType::pch)
{
auto findBus = baseConfiguration->second.find("Bus");
auto findAddress = baseConfiguration->second.find("Address");
@@ -158,7 +158,7 @@
continue;
}
- if (DEBUG)
+ if (debug)
{
std::cout << "find matched bus " << *pBusId
<< ", matched slave addr " << *pSlaveAddr << "\n";
@@ -340,7 +340,7 @@
}
// iterate through all found eth files, and save ifindex
- for (auto& fileName : files)
+ for (const fs::path& fileName : files)
{
if (debugLanLeash)
{
@@ -363,11 +363,9 @@
const int pos = fileStr.find("eth");
const std::string& ethNumStr = fileStr.substr(pos + 3);
int ethNum = 0;
- try
- {
- ethNum = std::stoul(ethNumStr);
- }
- catch (const std::invalid_argument& err)
+ std::from_chars_result r = std::from_chars(
+ ethNumStr.data(), ethNumStr.data() + ethNumStr.size(), ethNum);
+ if (r.ec != std::errc())
{
std::cerr << "invalid ethNum string: " << ethNumStr << "\n";
continue;
diff --git a/src/IpmbSensor.cpp b/src/IpmbSensor.cpp
index 29fd7f4..0f35353 100644
--- a/src/IpmbSensor.cpp
+++ b/src/IpmbSensor.cpp
@@ -14,14 +14,9 @@
// limitations under the License.
*/
-#include "IpmbSensor.hpp"
-
-#include "Utils.hpp"
-#include "VariantVisitors.hpp"
-
-#include <math.h>
-
-#include <boost/algorithm/string.hpp>
+#include <IpmbSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
@@ -30,6 +25,7 @@
#include <sdbusplus/bus/match.hpp>
#include <chrono>
+#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
@@ -181,9 +177,13 @@
case IpmbSubType::curr:
uint8_t snsNum;
if (subType == IpmbSubType::temp)
+ {
snsNum = 0x8d;
+ }
else
+ {
snsNum = 0x8c;
+ }
netfn = ipmi::me_bridge::netFn;
command = ipmi::me_bridge::sendRawPmbus;
commandData = {0x57, 0x01, 0x00, 0x86, deviceAddress,
@@ -354,18 +354,16 @@
read();
return;
}
- else
+
+ // rawValue only used in debug logging
+ // up to 5th byte in data are used to derive value
+ size_t end = std::min(sizeof(uint64_t), data.size());
+ uint64_t rawData = 0;
+ for (size_t i = 0; i < end; i++)
{
- // rawValue only used in debug logging
- // up to 5th byte in data are used to derive value
- size_t end = std::min(sizeof(uint64_t), data.size());
- uint64_t rawData = 0;
- for (size_t i = 0; i < end; i++)
- {
- reinterpret_cast<uint8_t*>(&rawData)[i] = data[i];
- }
- rawValue = static_cast<double>(rawData);
+ reinterpret_cast<uint8_t*>(&rawData)[i] = data[i];
}
+ rawValue = static_cast<double>(rawData);
/* Adjust value as per scale and offset */
value = (value * scaleVal) + offsetVal;
diff --git a/src/MCUTempSensor.cpp b/src/MCUTempSensor.cpp
index 6d94bd2..f637932 100644
--- a/src/MCUTempSensor.cpp
+++ b/src/MCUTempSensor.cpp
@@ -13,14 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
*/
-#include "MCUTempSensor.hpp"
-
-#include "Utils.hpp"
-#include "VariantVisitors.hpp"
-
-#include <math.h>
-
-#include <boost/algorithm/string.hpp>
+#include <MCUTempSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
@@ -29,6 +24,7 @@
#include <sdbusplus/bus/match.hpp>
#include <chrono>
+#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
@@ -166,7 +162,7 @@
return; // we're being cancelled
}
// read timer error
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
return;
@@ -291,7 +287,7 @@
return; // we're being canceled
}
// config timer error
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
return;
diff --git a/src/NVMeSensor.cpp b/src/NVMeSensor.cpp
index cfa7d20..db6a05b 100644
--- a/src/NVMeSensor.cpp
+++ b/src/NVMeSensor.cpp
@@ -14,13 +14,11 @@
// limitations under the License.
*/
-#include "NVMeSensor.hpp"
-
-#include "NVMeDevice.hpp"
-
#include <crc32c.h>
#include <libmctp-smbus.h>
+#include <NVMeDevice.hpp>
+#include <NVMeSensor.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/ip/tcp.hpp>
@@ -29,7 +27,7 @@
static constexpr double maxReading = 127;
static constexpr double minReading = 0;
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
void rxMessage(uint8_t eid, void* data, void* msg, size_t len);
@@ -241,7 +239,7 @@
readResponse(nvmeDevice);
- if (DEBUG)
+ if (debug)
{
std::cout << "Sending message to read data from Drive on bus: "
<< sensor->bus << " , rootBus: " << nvmeDevice->rootBus
@@ -300,7 +298,7 @@
return;
}
- if (DEBUG)
+ if (debug)
{
std::cout << "Eid from the received messaged: " << eid << "\n";
}
@@ -358,7 +356,7 @@
}
std::shared_ptr<NVMeSensor> sensorInfo = self->sensors.front();
- if (DEBUG)
+ if (debug)
{
std::cout << "Temperature Reading: "
<< getTemperatureReading(messageData[5])
@@ -376,7 +374,7 @@
sensorInfo->updateValue(value);
}
- if (DEBUG)
+ if (debug)
{
std::cout << "Cancelling the timer now\n";
}
@@ -435,13 +433,12 @@
boost::asio::io_service&,
std::shared_ptr<sdbusplus::asio::connection>& conn,
const std::string& sensorName,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration,
const int busNumber) :
- Sensor(boost::replace_all_copy(sensorName, " ", "_"),
- std::move(_thresholds), sensorConfiguration,
- "xyz.openbmc_project.Configuration.NVMe", maxReading, minReading,
- conn, PowerState::on),
+ Sensor(boost::replace_all_copy(sensorName, " ", "_"), std::move(thresholds),
+ sensorConfiguration, "xyz.openbmc_project.Configuration.NVMe",
+ maxReading, minReading, conn, PowerState::on),
objServer(objectServer), bus(busNumber)
{
sensorInterface = objectServer.add_interface(
diff --git a/src/NVMeSensorMain.cpp b/src/NVMeSensorMain.cpp
index 0552fad..21e722f 100644
--- a/src/NVMeSensorMain.cpp
+++ b/src/NVMeSensorMain.cpp
@@ -14,8 +14,7 @@
// limitations under the License.
*/
-#include "NVMeSensor.hpp"
-
+#include <NVMeSensor.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <regex>
@@ -25,7 +24,7 @@
static NVMEMap nvmeDeviceMap;
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
NVMEMap& getNVMEMap()
{
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index 4266918..375c24d 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -14,10 +14,9 @@
// limitations under the License.
*/
-#include "PSUEvent.hpp"
-
#include <systemd/sd-journal.h>
+#include <PSUEvent.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/container/flat_map.hpp>
@@ -145,10 +144,10 @@
std::shared_ptr<std::set<std::string>> combineEvent,
std::shared_ptr<bool> state, const std::string& psuName) :
std::enable_shared_from_this<PSUSubEvent>(),
- eventInterface(eventInterface), asserts(asserts),
- combineEvent(combineEvent), assertState(state), errCount(0), path(path),
- eventName(eventName), waitTimer(io), inputDev(io), psuName(psuName),
- groupEventName(groupEventName), systemBus(conn)
+ eventInterface(std::move(eventInterface)), asserts(std::move(asserts)),
+ combineEvent(std::move(combineEvent)), assertState(std::move(state)),
+ errCount(0), path(path), eventName(eventName), waitTimer(io), inputDev(io),
+ psuName(psuName), groupEventName(groupEventName), systemBus(conn)
{
fd = open(path.c_str(), O_RDONLY);
if (fd < 0)
@@ -174,7 +173,7 @@
if (fanPos != std::string::npos)
{
fanName = path.substr(fanPos);
- auto fanNamePos = fanName.find("_");
+ auto fanNamePos = fanName.find('_');
if (fanNamePos != std::string::npos)
{
fanName = fanName.substr(0, fanNamePos);
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 25cc5ad..e292863 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -14,10 +14,9 @@
// limitations under the License.
*/
-#include "PSUSensor.hpp"
-
#include <unistd.h>
+#include <PSUSensor.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/read_until.hpp>
@@ -34,25 +33,25 @@
static constexpr const char* sensorPathPrefix = "/xyz/openbmc_project/sensors/";
-static constexpr bool DEBUG = false;
+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_service& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholdsIn,
const std::string& sensorConfiguration,
std::string& sensorTypeName, unsigned int factor,
double max, double min, const std::string& label,
size_t tSize) :
Sensor(boost::replace_all_copy(sensorName, " ", "_"),
- std::move(_thresholds), sensorConfiguration, objectType, max, min,
+ std::move(thresholdsIn), sensorConfiguration, objectType, max, min,
conn),
std::enable_shared_from_this<PSUSensor>(), objServer(objectServer),
inputDev(io), waitTimer(io), path(path), pathRatedMax(""), pathRatedMin(""),
sensorFactor(factor), minMaxReadCounter(0)
{
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Constructed sensor: path " << path << " type "
<< objectType << " config " << sensorConfiguration
@@ -88,7 +87,7 @@
// This should be called before initializing association.
// createInventoryAssoc() does add more associations before doing
// register and initialize "Associations" property.
- if (label.empty() || tSize == _thresholds.size())
+ if (label.empty() || tSize == thresholds.size())
{
setInitialProperties(conn);
}
@@ -110,7 +109,7 @@
pathRatedMin = boost::replace_all_copy(path, item, "rated_min");
}
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "File: " << pathRatedMax
<< " will be used to update MaxValue\n";
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index b8966a6..3397ea8 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -14,10 +14,9 @@
// limitations under the License.
*/
-#include "PSUEvent.hpp"
-#include "PSUSensor.hpp"
-#include "Utils.hpp"
-
+#include <PSUEvent.hpp>
+#include <PSUSensor.hpp>
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
@@ -38,7 +37,7 @@
#include <variant>
#include <vector>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
static constexpr std::array<const char*, 17> sensorTypes = {
"xyz.openbmc_project.Configuration.ADM1272",
@@ -102,7 +101,9 @@
const std::string& eventName = match.first;
for (const auto& eventAttr : eventAttrs)
{
- auto eventPath = directory + "/" + eventAttr;
+ std::string eventPath = directory;
+ eventPath += "/";
+ eventPath += eventAttr;
std::ifstream eventFile(eventPath);
if (!eventFile.good())
@@ -141,7 +142,9 @@
const std::vector<std::string>& eventAttrs = match.second;
for (const auto& eventAttr : eventAttrs)
{
- auto eventPath = directory + "/" + eventAttr;
+ std::string eventPath = directory;
+ eventPath += "/";
+ eventPath += eventAttr;
std::ifstream eventFile(eventPath);
if (!eventFile.good())
{
@@ -279,7 +282,7 @@
fs::path device = directory / "device";
std::string deviceName = fs::canonical(device).stem();
- auto findHyphen = deviceName.find("-");
+ auto findHyphen = deviceName.find('-');
if (findHyphen == std::string::npos)
{
std::cerr << "found bad device" << deviceName << "\n";
@@ -294,7 +297,7 @@
try
{
bus = std::stoi(busStr);
- addr = std::stoi(addrStr, 0, 16);
+ addr = std::stoi(addrStr, nullptr, 16);
}
catch (std::invalid_argument&)
{
@@ -432,7 +435,7 @@
/* read max value in sysfs for in, curr, power, temp, ... */
if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
{
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "No max name in PSU \n";
}
@@ -473,7 +476,7 @@
std::string labelPath;
/* find and differentiate _max and _input to replace "label" */
- size_t pos = sensorPathStr.find("_");
+ size_t pos = sensorPathStr.find('_');
if (pos != std::string::npos)
{
@@ -499,14 +502,14 @@
std::ifstream labelFile(labelPath);
if (!labelFile.good())
{
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Input file " << sensorPath
<< " has no corresponding label file\n";
}
// hwmon *_input filename with number:
// temp1, temp2, temp3, ...
- labelHead = sensorNameStr.substr(0, sensorNameStr.find("_"));
+ labelHead = sensorNameStr.substr(0, sensorNameStr.find('_'));
}
else
{
@@ -521,16 +524,16 @@
// hwmon corresponding *_label file contents:
// vin1, vout1, ...
- labelHead = label.substr(0, label.find(" "));
+ labelHead = label.substr(0, label.find(' '));
}
/* append "max" for labelMatch */
if (maxLabel)
{
- labelHead = "max" + labelHead;
+ labelHead.insert(0, "max");
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Sensor type=\"" << sensorNameSubStr
<< "\" label=\"" << labelHead << "\"\n";
@@ -545,7 +548,7 @@
if (std::find(findLabels.begin(), findLabels.end(),
labelHead) == findLabels.end())
{
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "could not find " << labelHead
<< " in the Labels list\n";
@@ -557,7 +560,7 @@
auto findProperty = labelMatch.find(labelHead);
if (findProperty == labelMatch.end())
{
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Could not find matching default property for "
<< labelHead << "\n";
@@ -697,7 +700,7 @@
psuNameFromIndex = psuNames[nameIndex];
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Sensor label head " << labelHead
<< " paired with " << psuNameFromIndex
@@ -717,7 +720,8 @@
factor = std::pow(10.0, factor);
/* Change first char of substring to uppercase */
- char firstChar = sensorNameSubStr[0] - 0x20;
+ char firstChar =
+ static_cast<char>(std::toupper(sensorNameSubStr[0]));
std::string strScaleFactor =
firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
@@ -730,7 +734,7 @@
findScaleFactor->second);
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Sensor scaling factor " << factor
<< " string " << strScaleFactor << "\n";
@@ -753,7 +757,7 @@
continue;
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Sensor properties: Name \""
<< psuProperty->labelTypeName << "\" Scale "
@@ -781,7 +785,7 @@
psuNameFromIndex + " " + psuProperty->labelTypeName;
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Sensor name \"" << sensorName << "\" path \""
<< sensorPathStr << "\" type \"" << sensorType
@@ -796,7 +800,7 @@
psuProperty->minReading, labelHead, thresholdConfSize);
sensors[sensorName]->setupRead();
++numCreated;
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Created " << numCreated << " sensors so far\n";
}
@@ -810,7 +814,7 @@
groupEventPathList, "OperationalStatus");
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
std::cerr << "Created total of " << numCreated << " sensors\n";
}
@@ -953,7 +957,7 @@
{
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "timer error\n";
}
diff --git a/src/PwmSensor.cpp b/src/PwmSensor.cpp
index 8993f2b..bd9c9d6 100644
--- a/src/PwmSensor.cpp
+++ b/src/PwmSensor.cpp
@@ -13,10 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
*/
-#include "PwmSensor.hpp"
-
-#include "Utils.hpp"
-
+#include <PwmSensor.hpp>
+#include <Utils.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <fstream>
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index 0490135..bffc30e 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -14,12 +14,10 @@
// limitations under the License.
*/
-#include "TachSensor.hpp"
-
-#include "Utils.hpp"
-
#include <unistd.h>
+#include <TachSensor.hpp>
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/read_until.hpp>
@@ -48,12 +46,12 @@
std::unique_ptr<PresenceSensor>&& presenceSensor,
std::optional<RedundancySensor>* redundancy,
boost::asio::io_service& io, const std::string& fanName,
- std::vector<thresholds::Threshold>&& _thresholds,
+ std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration,
const std::pair<size_t, size_t>& limits,
const PowerState& powerState,
const std::optional<std::string>& ledIn) :
- Sensor(boost::replace_all_copy(fanName, " ", "_"), std::move(_thresholds),
+ Sensor(boost::replace_all_copy(fanName, " ", "_"), std::move(thresholds),
sensorConfiguration, objectType, limits.second, limits.first, conn,
powerState),
objServer(objectServer), redundancy(redundancy),
@@ -255,7 +253,7 @@
{
return; // we're being destroyed
}
- else if (ec)
+ if (ec)
{
std::cerr << "Error on presence sensor " << name
<< " \n";
@@ -330,7 +328,7 @@
newState = redundancy::failed;
break;
}
- else if (failedCount)
+ if (failedCount)
{
newState = redundancy::degraded;
}
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index f4d4ed0..df56b21 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -1,11 +1,8 @@
-#include "Thresholds.hpp"
-
-#include "VariantVisitors.hpp"
-#include "sensor.hpp"
-
+#include <Thresholds.hpp>
+#include <VariantVisitors.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
-#include <boost/lexical_cast.hpp>
+#include <sensor.hpp>
#include <array>
#include <cmath>
@@ -19,7 +16,7 @@
#include <variant>
#include <vector>
-static constexpr bool DEBUG = false;
+static constexpr bool debug = false;
namespace thresholds
{
unsigned int toBusValue(const Level& level)
@@ -75,10 +72,14 @@
{
auto labelFind = item.second.find("Label");
if (labelFind == item.second.end())
+ {
continue;
+ }
if (std::visit(VariantToStringVisitor(), labelFind->second) !=
*matchLabel)
+ {
continue;
+ }
}
auto directionFind = item.second.find("Direction");
auto severityFind = item.second.find("Severity");
@@ -323,7 +324,7 @@
}
}
- if constexpr (DEBUG)
+ if constexpr (debug)
{
// Throttle debug output, so that it does not continuously spam
++cDebugThrottle;
@@ -491,7 +492,7 @@
if (auto val = readFile(attrPath, scaleFactor))
{
*val += offset;
- if (DEBUG)
+ if (debug)
{
std::cout << "Threshold: " << attrPath << ": " << *val
<< "\n";
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 899ec98..5217129 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -14,8 +14,7 @@
// limitations under the License.
*/
-#include "Utils.hpp"
-
+#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/container/flat_map.hpp>
#include <sdbusplus/asio/connection.hpp>
@@ -130,6 +129,14 @@
bool getSensorConfiguration(
const std::string& type,
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+ ManagedObjectType& resp)
+{
+ return getSensorConfiguration(type, dbusConnection, resp, false);
+}
+
+bool getSensorConfiguration(
+ const std::string& type,
+ const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
ManagedObjectType& resp, bool useCache)
{
static ManagedObjectType managedObj;
@@ -182,25 +189,31 @@
return true;
}
-bool findFiles(const fs::path dirPath, const std::string& matchString,
- std::vector<fs::path>& foundPaths, unsigned int symlinkDepth)
+bool findFiles(const fs::path& dirPath, const std::string& matchString,
+ std::vector<fs::path>& foundPaths, int symlinkDepth)
{
if (!fs::exists(dirPath))
+ {
return false;
+ }
std::regex search(matchString);
std::smatch match;
- for (auto& p : fs::recursive_directory_iterator(dirPath))
+ for (auto p = fs::recursive_directory_iterator(
+ dirPath, fs::directory_options::follow_directory_symlink);
+ p != fs::recursive_directory_iterator(); ++p)
{
- std::string path = p.path().string();
- if (!is_directory(p))
+ std::string path = p->path().string();
+ if (!is_directory(*p))
{
if (std::regex_search(path, match, search))
- foundPaths.emplace_back(p.path());
+ {
+ foundPaths.emplace_back(p->path());
+ }
}
- else if (is_symlink(p) && symlinkDepth)
+ if (p.depth() >= symlinkDepth)
{
- findFiles(p.path(), matchString, foundPaths, symlinkDepth - 1);
+ p.disable_recursion_pending();
}
}
return true;
@@ -328,7 +341,7 @@
{
return;
}
- else if (ec)
+ if (ec)
{
std::cerr << "Timer error " << ec.message() << "\n";
return;
@@ -390,15 +403,15 @@
std::filesystem::path p(path);
std::vector<Association> associations;
- associations.push_back(
- Association("chassis", "all_sensors", p.parent_path().string()));
+ associations.emplace_back("chassis", "all_sensors",
+ p.parent_path().string());
association->register_property("Associations", associations);
association->initialize();
}
}
void setInventoryAssociation(
- std::shared_ptr<sdbusplus::asio::dbus_interface> association,
+ const std::shared_ptr<sdbusplus::asio::dbus_interface>& association,
const std::string& path,
const std::vector<std::string>& chassisPaths = std::vector<std::string>())
{
@@ -408,13 +421,12 @@
std::vector<Association> associations;
std::string objPath(p.parent_path().string());
- associations.push_back(Association("inventory", "sensors", objPath));
- associations.push_back(Association("chassis", "all_sensors", objPath));
+ associations.emplace_back("inventory", "sensors", objPath);
+ associations.emplace_back("chassis", "all_sensors", objPath);
for (const std::string& chassisPath : chassisPaths)
{
- associations.push_back(
- Association("chassis", "all_sensors", chassisPath));
+ associations.emplace_back("chassis", "all_sensors", chassisPath);
}
association->register_property("Associations", associations);
@@ -423,8 +435,8 @@
}
void createInventoryAssoc(
- std::shared_ptr<sdbusplus::asio::connection> conn,
- std::shared_ptr<sdbusplus::asio::dbus_interface> association,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::shared_ptr<sdbusplus::asio::dbus_interface>& association,
const std::string& path)
{
if (!association)
diff --git a/tests/test_HwmonTempSensor.cpp b/tests/test_HwmonTempSensor.cpp
index 0368064..2be603a 100644
--- a/tests/test_HwmonTempSensor.cpp
+++ b/tests/test_HwmonTempSensor.cpp
@@ -4,7 +4,7 @@
#include <fstream>
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
TEST(HwmonTempSensor, TestTMP75)
{
diff --git a/tests/test_TachSensor.cpp b/tests/test_TachSensor.cpp
index b28de93..c1326e3 100644
--- a/tests/test_TachSensor.cpp
+++ b/tests/test_TachSensor.cpp
@@ -5,7 +5,7 @@
#include <fstream>
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
TEST(TachSensor, TestTachSensor)
{