clang-tidy: Enable readability-convert-member-functions-to-static
This check finds non-static member functions that can be made
static because the functions don’t use this.
This check also triggers readability-static-accessed-through
-instance check as we are trying to access a static member
function through an instance.
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I6efe76666f75fb4f65621796466d9347cea25d01
diff --git a/.clang-tidy b/.clang-tidy
index dd69f53..43d168b 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -254,6 +254,7 @@
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
readability-const-return-type,
+readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-deleted-default,
readability-function-size,
diff --git a/fault-monitor/fru-fault-monitor.hpp b/fault-monitor/fru-fault-monitor.hpp
index fc6cafa..adb6e9b 100644
--- a/fault-monitor/fru-fault-monitor.hpp
+++ b/fault-monitor/fru-fault-monitor.hpp
@@ -67,7 +67,7 @@
/** @brief function to create fault remove match for a fru
* @param[in] path - Inventory path of the faulty unit.
*/
- std::string match(const std::string& path)
+ static std::string match(const std::string& path)
{
namespace MatchRules = sdbusplus::bus::match::rules;
diff --git a/manager/lamptest/lamptest.cpp b/manager/lamptest/lamptest.cpp
index e7c9d5a..f91a085 100644
--- a/manager/lamptest/lamptest.cpp
+++ b/manager/lamptest/lamptest.cpp
@@ -31,8 +31,8 @@
if (iter != forceUpdateLEDs.end())
{
- manager.drivePhysicalLED(path, Layout::Action::Off, it.dutyOn,
- it.period);
+ phosphor::led::Manager::drivePhysicalLED(
+ path, Layout::Action::Off, it.dutyOn, it.period);
}
}
@@ -45,7 +45,8 @@
if (iter != forceUpdateLEDs.end())
{
- manager.drivePhysicalLED(path, it.action, it.dutyOn, it.period);
+ phosphor::led::Manager::drivePhysicalLED(path, it.action,
+ it.dutyOn, it.period);
}
}
@@ -80,7 +81,8 @@
continue;
}
- manager.drivePhysicalLED(path, Layout::Action::Off, 0, 0);
+ phosphor::led::Manager::drivePhysicalLED(path, Layout::Action::Off, 0,
+ 0);
}
if (std::filesystem::exists(lampTestIndicator))
@@ -146,7 +148,9 @@
uint8_t dutyOn{};
try
{
- auto properties = dBusHandler.getAllProperties(path, phyLedIntf);
+ auto properties =
+ phosphor::led::utils::DBusHandler::getAllProperties(path,
+ phyLedIntf);
state = std::get<std::string>(properties["State"]);
period = std::get<uint16_t>(properties["Period"]);
@@ -187,7 +191,8 @@
// Get paths of all the Physical LED objects
try
{
- physicalLEDPaths = dBusHandler.getSubTreePaths(phyLedPath, phyLedIntf);
+ physicalLEDPaths = phosphor::led::utils::DBusHandler::getSubTreePaths(
+ phyLedPath, phyLedIntf);
}
catch (const sdbusplus::exception_t& e)
{
@@ -233,7 +238,8 @@
continue;
}
- manager.drivePhysicalLED(path, Layout::Action::On, 0, 0);
+ phosphor::led::Manager::drivePhysicalLED(path, Layout::Action::On, 0,
+ 0);
}
}
@@ -307,9 +313,9 @@
try
{
PropertyValue assertedValue{value};
- dBusHandler.setProperty(HOST_LAMP_TEST_OBJECT,
- "xyz.openbmc_project.Led.Group", "Asserted",
- assertedValue);
+ phosphor::led::utils::DBusHandler::setProperty(
+ HOST_LAMP_TEST_OBJECT, "xyz.openbmc_project.Led.Group", "Asserted",
+ assertedValue);
}
catch (const sdbusplus::exception_t& e)
{
@@ -357,14 +363,14 @@
if (std::filesystem::exists(lampTestIndicator))
{
// we need to off all the LEDs.
- phosphor::led::utils::DBusHandler dBusHandler;
- std::vector<std::string> physicalLedPaths = dBusHandler.getSubTreePaths(
- phosphor::led::phyLedPath, phosphor::led::phyLedIntf);
+ std::vector<std::string> physicalLedPaths =
+ phosphor::led::utils::DBusHandler::getSubTreePaths(
+ phosphor::led::phyLedPath, phosphor::led::phyLedIntf);
for (const auto& path : physicalLedPaths)
{
- manager.drivePhysicalLED(path, phosphor::led::Layout::Action::Off,
- 0, 0);
+ phosphor::led::Manager::drivePhysicalLED(
+ path, phosphor::led::Layout::Action::Off, 0, 0);
}
// Also remove the lamp test on indicator file.
diff --git a/manager/lamptest/lamptest.hpp b/manager/lamptest/lamptest.hpp
index 5e312e2..ce7bae1 100644
--- a/manager/lamptest/lamptest.hpp
+++ b/manager/lamptest/lamptest.hpp
@@ -79,7 +79,7 @@
* with the persisted lamp test indicator file so that there is no sign of
* lamptest.
*/
- void clearLamps();
+ static void clearLamps();
private:
/** @brief Timer used for LEDs lamp test period */
@@ -88,9 +88,6 @@
/** @brief Reference to Manager object */
Manager& manager;
- /** DBusHandler class handles the D-Bus operations */
- DBusHandler dBusHandler;
-
/** @brief Pointer to Group object */
Group* groupObj;
@@ -137,13 +134,13 @@
*
* @return enumeration equivalent of the passed in string
*/
- Layout::Action getActionFromString(const std::string& str);
+ static Layout::Action getActionFromString(const std::string& str);
/** @brief Notify host to start / stop the lamp test
*
* @param[in] value - the Asserted property value
*/
- void doHostLampTest(bool value);
+ static void doHostLampTest(bool value);
/** @brief Get physical LED names from lamp test JSON config file
*
diff --git a/manager/manager.cpp b/manager/manager.cpp
index 6a31e93..7c7d730 100644
--- a/manager/manager.cpp
+++ b/manager/manager.cpp
@@ -218,12 +218,15 @@
PropertyValue dutyOnValue{dutyOn};
PropertyValue periodValue{period};
- dBusHandler.setProperty(objPath, phyLedIntf, "DutyOn", dutyOnValue);
- dBusHandler.setProperty(objPath, phyLedIntf, "Period", periodValue);
+ phosphor::led::utils::DBusHandler::setProperty(
+ objPath, phyLedIntf, "DutyOn", dutyOnValue);
+ phosphor::led::utils::DBusHandler::setProperty(
+ objPath, phyLedIntf, "Period", periodValue);
}
PropertyValue actionValue{getPhysicalAction(action)};
- dBusHandler.setProperty(objPath, phyLedIntf, "State", actionValue);
+ phosphor::led::utils::DBusHandler::setProperty(objPath, phyLedIntf,
+ "State", actionValue);
}
catch (const sdbusplus::exception_t& e)
{
diff --git a/manager/manager.hpp b/manager/manager.hpp
index ea37798..0177241 100644
--- a/manager/manager.hpp
+++ b/manager/manager.hpp
@@ -130,8 +130,9 @@
*
* @return: - 0: success, -1: LED set failed
*/
- int drivePhysicalLED(const std::string& objPath, Layout::Action action,
- uint8_t dutyOn, const uint16_t period);
+ static int drivePhysicalLED(const std::string& objPath,
+ Layout::Action action, uint8_t dutyOn,
+ const uint16_t period);
/** @brief Set lamp test callback when enabled lamp test.
*
@@ -148,9 +149,6 @@
/** Map of physical LED path to service name */
std::unordered_map<std::string, std::string> phyLeds{};
- /** DBusHandler class handles the D-Bus operations */
- DBusHandler dBusHandler;
-
/** @brief Pointers to groups that are in asserted state */
std::set<const Layout::GroupLayout*> assertedGroups;
diff --git a/utils.cpp b/utils.cpp
index a2a72cb..1da9602 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -11,7 +11,7 @@
// Get service name
std::string DBusHandler::getService(const std::string& path,
- const std::string& interface) const
+ const std::string& interface)
{
using InterfaceList = std::vector<std::string>;
std::unordered_map<std::string, std::vector<std::string>> mapperResponse;
@@ -38,7 +38,7 @@
// Get all properties
PropertyMap DBusHandler::getAllProperties(const std::string& objectPath,
- const std::string& interface) const
+ const std::string& interface)
{
PropertyMap properties;
@@ -62,7 +62,7 @@
// Get the property name
PropertyValue DBusHandler::getProperty(const std::string& objectPath,
const std::string& interface,
- const std::string& propertyName) const
+ const std::string& propertyName)
{
PropertyValue value{};
@@ -86,7 +86,7 @@
// Set property
void DBusHandler::setProperty(
const std::string& objectPath, const std::string& interface,
- const std::string& propertyName, const PropertyValue& value) const
+ const std::string& propertyName, const PropertyValue& value)
{
auto& bus = DBusHandler::getBus();
auto service = getService(objectPath, interface);
@@ -103,7 +103,7 @@
}
std::vector<std::string> DBusHandler::getSubTreePaths(
- const std::string& objectPath, const std::string& interface) const
+ const std::string& objectPath, const std::string& interface)
{
std::vector<std::string> paths;
diff --git a/utils.hpp b/utils.hpp
index cd79fd5..456188a 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -52,8 +52,8 @@
* @return std::string - the D-Bus service name
*
*/
- std::string getService(const std::string& path,
- const std::string& interface) const;
+ static std::string getService(const std::string& path,
+ const std::string& interface);
/** @brief Get All properties
*
@@ -64,8 +64,8 @@
*
* @throw sdbusplus::exception_t when it fails
*/
- PropertyMap getAllProperties(const std::string& objectPath,
- const std::string& interface) const;
+ static PropertyMap getAllProperties(const std::string& objectPath,
+ const std::string& interface);
/** @brief Get property(type: variant)
*
@@ -77,9 +77,9 @@
*
* @throw sdbusplus::exception_t when it fails
*/
- PropertyValue getProperty(const std::string& objectPath,
- const std::string& interface,
- const std::string& propertyName) const;
+ static PropertyValue getProperty(const std::string& objectPath,
+ const std::string& interface,
+ const std::string& propertyName);
/** @brief Set D-Bus property
*
@@ -90,10 +90,10 @@
*
* @throw sdbusplus::exception_t when it fails
*/
- void setProperty(const std::string& objectPath,
- const std::string& interface,
- const std::string& propertyName,
- const PropertyValue& value) const;
+ static void setProperty(const std::string& objectPath,
+ const std::string& interface,
+ const std::string& propertyName,
+ const PropertyValue& value);
/** @brief Get sub tree paths by the path and interface of the DBus.
*
@@ -102,8 +102,8 @@
*
* @return std::vector<std::string> vector of subtree paths
*/
- std::vector<std::string> getSubTreePaths(
- const std::string& objectPath, const std::string& interface) const;
+ static std::vector<std::string> getSubTreePaths(
+ const std::string& objectPath, const std::string& interface);
};
} // namespace utils