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/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)