Implement clang-tidy fixes
clang-tidy allows the CI robot to check many things via static analysis.
All changes here were made by the clang-tidy robot, and include a number
of modernization fixes. updating the tidy file will be done at a later
date.
Signed-off-by: Ed Tanous <etanous@nvidia.com>
Change-Id: I98cc4d600a3c589675507958f6d2350b2141216b
diff --git a/pid/builder.cpp b/pid/builder.cpp
index 1164355..afb6989 100644
--- a/pid/builder.cpp
+++ b/pid/builder.cpp
@@ -45,7 +45,7 @@
return std::string(objectPath) + std::to_string(zone);
}
-static std::string getPidControlPath(int64_t zone, std::string pidname)
+static std::string getPidControlPath(int64_t zone, const std::string& pidname)
{
return std::string(objectPath) + std::to_string(zone) + "/" + pidname;
}
diff --git a/pid/ec/logging.hpp b/pid/ec/logging.hpp
index 3cef589..049d2ed 100644
--- a/pid/ec/logging.hpp
+++ b/pid/ec/logging.hpp
@@ -53,24 +53,24 @@
std::ofstream fileCoeffs;
std::chrono::milliseconds lastLog;
PidCoreContext lastContext;
- bool moved;
+ bool moved = false;
PidCoreLog() :
nameOriginal(), nameClean(), fileContext(), fileCoeffs(), lastLog(),
- lastContext(), moved(false)
+ lastContext()
{}
PidCoreLog(const PidCoreLog& copy) = delete;
PidCoreLog& operator=(const PidCoreLog& copy) = delete;
- PidCoreLog(PidCoreLog&& move)
+ PidCoreLog(PidCoreLog&& move) noexcept
{
// Reuse assignment operator below
*this = std::move(move);
}
- PidCoreLog& operator=(PidCoreLog&& move)
+ PidCoreLog& operator=(PidCoreLog&& move) noexcept
{
if (this != &move)
{
@@ -79,8 +79,8 @@
nameClean = std::move(move.nameClean);
fileContext = std::move(move.fileContext);
fileCoeffs = std::move(move.fileCoeffs);
- lastLog = std::move(move.lastLog);
- lastContext = std::move(move.lastContext);
+ lastLog = move.lastLog;
+ lastContext = move.lastContext;
// Mark the moved object, so destructor knows it was moved
move.moved = true;
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp
index 762513a..ad547d9 100644
--- a/pid/ec/pid.cpp
+++ b/pid/ec/pid.cpp
@@ -34,7 +34,7 @@
{
return min;
}
- else if (x > max)
+ if (x > max)
{
return max;
}
diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp
index ac77f05..02138cd 100644
--- a/pid/ec/pid.hpp
+++ b/pid/ec/pid.hpp
@@ -8,16 +8,16 @@
namespace ec
{
-typedef struct limits_t
+struct limits_t
{
double min = 0.0;
double max = 0.0;
-} limits_t;
+};
/* Note: If you update these structs you need to update the copy code in
* pid/util.cpp and the initialization code in pid/buildjson.hpp files.
*/
-typedef struct pid_info_t
+struct pid_info_t
{
bool initialized = false; // has pid been initialized
bool checkHysterWithSetpt = false; // compare current input and setpoint to
@@ -40,7 +40,7 @@
double slewPos = 0.0;
double positiveHysteresis = 0.0;
double negativeHysteresis = 0.0;
-} pid_info_t;
+};
double pid(pid_info_t* pidinfoptr, double input, double setpoint,
const std::string* nameptr = nullptr);
diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp
index 700f651..cfcaf99 100644
--- a/pid/fancontroller.hpp
+++ b/pid/fancontroller.hpp
@@ -25,10 +25,10 @@
FanController(const std::string& id, const std::vector<std::string>& inputs,
ZoneInterface* owner) :
- PIDController(id, owner), _inputs(inputs),
- _direction(FanSpeedDirection::NEUTRAL)
+ PIDController(id, owner), _inputs(inputs)
{}
- ~FanController();
+
+ ~FanController() override;
double inputProc(void) override;
double setptProc(void) override;
void outputProc(double value) override;
@@ -45,7 +45,7 @@
private:
std::vector<std::string> _inputs;
- FanSpeedDirection _direction;
+ FanSpeedDirection _direction = FanSpeedDirection::NEUTRAL;
// Cosmetic only, to reduce frequency of repetitive messages
bool failsafeTransition = true;
diff --git a/pid/pidcontroller.hpp b/pid/pidcontroller.hpp
index 91147d9..e1868f4 100644
--- a/pid/pidcontroller.hpp
+++ b/pid/pidcontroller.hpp
@@ -43,11 +43,11 @@
_pid_info.positiveHysteresis = static_cast<double>(0.0);
}
- virtual ~PIDController() {}
+ ~PIDController() override = default;
- virtual double inputProc(void) override = 0;
+ double inputProc(void) override = 0;
virtual double setptProc(void) = 0;
- virtual void outputProc(double value) override = 0;
+ void outputProc(double value) override = 0;
void process(void) override;
diff --git a/pid/pidloop.cpp b/pid/pidloop.cpp
index 888419b..9d30798 100644
--- a/pid/pidloop.cpp
+++ b/pid/pidloop.cpp
@@ -32,7 +32,7 @@
namespace pid_control
{
-static void processThermals(std::shared_ptr<ZoneInterface> zone)
+static void processThermals(const std::shared_ptr<ZoneInterface>& zone)
{
// Get the latest margins.
zone->updateSensors();
@@ -45,12 +45,14 @@
zone->determineMaxSetPointRequest();
}
-void pidControlLoop(std::shared_ptr<ZoneInterface> zone,
- std::shared_ptr<boost::asio::steady_timer> timer,
+void pidControlLoop(const std::shared_ptr<ZoneInterface>& zone,
+ const std::shared_ptr<boost::asio::steady_timer>& timer,
const bool* isCanceling, bool first, uint64_t cycleCnt)
{
if (*isCanceling)
+ {
return;
+ }
std::chrono::steady_clock::time_point nextTime;
diff --git a/pid/pidloop.hpp b/pid/pidloop.hpp
index 0a143e7..70e0415 100644
--- a/pid/pidloop.hpp
+++ b/pid/pidloop.hpp
@@ -19,8 +19,8 @@
* @param[in] first - boolean to denote if initialization needs to be run.
* @param[in] cycleCnt - loop timer counter.
*/
-void pidControlLoop(std::shared_ptr<ZoneInterface> zone,
- std::shared_ptr<boost::asio::steady_timer> timer,
+void pidControlLoop(const std::shared_ptr<ZoneInterface>& zone,
+ const std::shared_ptr<boost::asio::steady_timer>& timer,
const bool* isCanceling, bool first = true,
uint64_t cycleCnt = 0);
diff --git a/pid/zone.cpp b/pid/zone.cpp
index f8272bf..dfa5123 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -149,14 +149,14 @@
* If the name of controller is Linear_Temp_CPU0.
* The profile name will be Temp_CPU0.
*/
- profileName = name.substr(name.find("_") + 1);
- _SetPoints[profileName] += setPoint;
+ profileName = name.substr(name.find('_') + 1);
+ setPoints[profileName] += setPoint;
}
else
{
- if (_SetPoints[profileName] < setPoint)
+ if (setPoints[profileName] < setPoint)
{
- _SetPoints[profileName] = setPoint;
+ setPoints[profileName] = setPoint;
}
}
@@ -164,26 +164,26 @@
* if there are multiple thermal controllers with the same
* value, pick the first one in the iterator
*/
- if (_maximumSetPoint < _SetPoints[profileName])
+ if (_maximumSetPoint < setPoints[profileName])
{
- _maximumSetPoint = _SetPoints[profileName];
+ _maximumSetPoint = setPoints[profileName];
_maximumSetPointName = profileName;
}
}
void DbusPidZone::addRPMCeiling(double ceiling)
{
- _RPMCeilings.push_back(ceiling);
+ rpmCeilings.push_back(ceiling);
}
void DbusPidZone::clearRPMCeilings(void)
{
- _RPMCeilings.clear();
+ rpmCeilings.clear();
}
void DbusPidZone::clearSetPoints(void)
{
- _SetPoints.clear();
+ setPoints.clear();
_maximumSetPoint = 0;
_maximumSetPointName.clear();
}
@@ -197,8 +197,8 @@
FailSafeSensorsMap::iterator maxData = std::max_element(
_failSafeSensors.begin(), _failSafeSensors.end(),
- [](const FailSafeSensorPair firstData,
- const FailSafeSensorPair secondData) {
+ [](const FailSafeSensorPair& firstData,
+ const FailSafeSensorPair& secondData) {
return firstData.second.second < secondData.second.second;
});
@@ -210,10 +210,8 @@
{
return _zoneFailSafePercent;
}
- else
- {
- return (*maxData).second.second;
- }
+
+ return (*maxData).second.second;
}
double DbusPidZone::getMinThermalSetPoint(void) const
@@ -344,9 +342,9 @@
std::vector<double>::iterator result;
double minThermalThreshold = getMinThermalSetPoint();
- if (_RPMCeilings.size() > 0)
+ if (rpmCeilings.size() > 0)
{
- result = std::min_element(_RPMCeilings.begin(), _RPMCeilings.end());
+ result = std::min_element(rpmCeilings.begin(), rpmCeilings.end());
// if Max set point is larger than the lowest ceiling, reset to lowest
// ceiling.
if (*result < _maximumSetPoint)
@@ -595,9 +593,9 @@
return getFailSafeMode();
}
-void DbusPidZone::addPidControlProcess(std::string name, std::string type,
- double setpoint, sdbusplus::bus_t& bus,
- std::string objPath, bool defer)
+void DbusPidZone::addPidControlProcess(
+ const std::string& name, const std::string& type, double setpoint,
+ sdbusplus::bus_t& bus, const std::string& objPath, bool defer)
{
_pidsControlProcess[name] = std::make_unique<ProcessObject>(
bus, objPath.c_str(),
@@ -625,12 +623,12 @@
}
}
-bool DbusPidZone::isPidProcessEnabled(std::string name)
+bool DbusPidZone::isPidProcessEnabled(const std::string& name)
{
return _pidsControlProcess[name]->enabled();
}
-void DbusPidZone::addPidFailSafePercent(std::vector<std::string> inputs,
+void DbusPidZone::addPidFailSafePercent(const std::vector<std::string>& inputs,
double percent)
{
for (const auto& sensorName : inputs)
diff --git a/pid/zone.hpp b/pid/zone.hpp
index 325eb6c..7223f76 100644
--- a/pid/zone.hpp
+++ b/pid/zone.hpp
@@ -59,8 +59,7 @@
ModeObject(bus, objPath,
defer ? ModeObject::action::defer_emit
: ModeObject::action::emit_object_added),
- _zoneId(zone), _maximumSetPoint(),
- _accumulateSetPoint(accumulateSetPoint),
+ _zoneId(zone), _accumulateSetPoint(accumulateSetPoint),
_minThermalOutputSetPt(minThermalOutput),
_zoneFailSafePercent(failSafePercent), _cycleTime(cycleTime), _mgr(mgr)
{
@@ -124,12 +123,13 @@
/* Method for recording the maximum SetPoint PID config name */
std::string leader() const override;
/* Method for control process for each loop at runtime */
- void addPidControlProcess(std::string name, std::string type,
+ void addPidControlProcess(const std::string& name, const std::string& type,
double setpoint, sdbusplus::bus_t& bus,
- std::string objPath, bool defer);
- bool isPidProcessEnabled(std::string name);
+ const std::string& objPath, bool defer);
+ bool isPidProcessEnabled(const std::string& name);
- void addPidFailSafePercent(std::vector<std::string> inputs, double percent);
+ void addPidFailSafePercent(const std::vector<std::string>& inputs,
+ double percent);
void updateThermalPowerDebugInterface(std::string pidName,
std::string leader, double input,
@@ -237,8 +237,8 @@
FailSafeSensorsMap _failSafeSensors;
std::set<std::string> _missingAcceptable;
- std::map<std::string, double> _SetPoints;
- std::vector<double> _RPMCeilings;
+ std::map<std::string, double> setPoints;
+ std::vector<double> rpmCeilings;
std::vector<std::string> _fanInputs;
std::vector<std::string> _thermalInputs;
std::map<std::string, ValueCacheEntry> _cachedValuesByName;