psusensor: Optimize the naming of some variables
Some variable declarations and parameter types use
`boost::container::flat_map`. The long type names make it difficult
for other developers to read.
This commit makes some minor optimizations, using `using` to declare
an alias to increase the readability of the code.
Tested: built psusensor successfully and works fine.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I9b632c27fc67694d2de384f6e7c88bf66b97f78e
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index c5ad0fe..f8cee21 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -37,14 +37,9 @@
sdbusplus::asio::object_server& objectServer,
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_context& io, const std::string& psuName,
- const PowerState& powerState,
- boost::container::flat_map<std::string, std::vector<std::string>>&
- eventPathList,
- boost::container::flat_map<
- std::string,
- boost::container::flat_map<std::string, std::vector<std::string>>>&
- groupEventPathList,
- const std::string& combineEventName, double pollRate) :
+ const PowerState& powerState, EventPathList& eventPathList,
+ GroupEventPathList& groupEventPathList, const std::string& combineEventName,
+ double pollRate) :
objServer(objectServer)
{
std::string psuNameEscaped = sensor_paths::escapePathForDbus(psuName);
diff --git a/src/PSUEvent.hpp b/src/PSUEvent.hpp
index 3e066cf..4c705a4 100644
--- a/src/PSUEvent.hpp
+++ b/src/PSUEvent.hpp
@@ -30,6 +30,11 @@
#include <string>
#include <vector>
+using EventPathList =
+ boost::container::flat_map<std::string, std::vector<std::string>>;
+using GroupEventPathList =
+ boost::container::flat_map<std::string, EventPathList>;
+
class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent>
{
public:
@@ -78,18 +83,12 @@
class PSUCombineEvent
{
public:
- PSUCombineEvent(
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_context& io, const std::string& psuName,
- const PowerState& powerState,
- boost::container::flat_map<std::string, std::vector<std::string>>&
- eventPathList,
- boost::container::flat_map<
- std::string,
- boost::container::flat_map<std::string, std::vector<std::string>>>&
- groupEventPathList,
- const std::string& combineEventName, double pollRate);
+ PSUCombineEvent(sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& psuName,
+ const PowerState& powerState, EventPathList& eventPathList,
+ GroupEventPathList& groupEventPathList,
+ const std::string& combineEventName, double pollRate);
~PSUCombineEvent();
sdbusplus::asio::object_server& objServer;
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index 4073d72..cf98f9b 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -131,14 +131,9 @@
static boost::container::flat_map<std::string, std::string> sensorTable;
static boost::container::flat_map<std::string, PSUProperty> labelMatch;
static boost::container::flat_map<std::string, std::string> pwmTable;
-static boost::container::flat_map<std::string, std::vector<std::string>>
- eventMatch;
-static boost::container::flat_map<
- std::string,
- boost::container::flat_map<std::string, std::vector<std::string>>>
- groupEventMatch;
-static boost::container::flat_map<std::string, std::vector<std::string>>
- limitEventMatch;
+static EventPathList eventMatch;
+static GroupEventPathList groupEventMatch;
+static EventPathList limitEventMatch;
static std::vector<PSUProperty> psuProperties;
static boost::container::flat_map<size_t, bool> cpuPresence;
@@ -147,12 +142,8 @@
// Function CheckEvent will check each attribute from eventMatch table in the
// sysfs. If the attributes exists in sysfs, then store the complete path
// of the attribute into eventPathList.
-void checkEvent(
- const std::string& directory,
- const boost::container::flat_map<std::string, std::vector<std::string>>&
- eventMatch,
- boost::container::flat_map<std::string, std::vector<std::string>>&
- eventPathList)
+void checkEvent(const std::string& directory, const EventPathList& eventMatch,
+ EventPathList& eventPathList)
{
for (const auto& match : eventMatch)
{
@@ -177,24 +168,15 @@
// Check Group Events which contains more than one targets in each combine
// events.
-void checkGroupEvent(
- const std::string& directory,
- const boost::container::flat_map<
- std::string,
- boost::container::flat_map<std::string, std::vector<std::string>>>&
- groupEventMatch,
- boost::container::flat_map<
- std::string,
- boost::container::flat_map<std::string, std::vector<std::string>>>&
- groupEventPathList)
+void checkGroupEvent(const std::string& directory,
+ const GroupEventPathList& groupEventMatch,
+ GroupEventPathList& groupEventPathList)
{
for (const auto& match : groupEventMatch)
{
const std::string& groupEventName = match.first;
- const boost::container::flat_map<std::string, std::vector<std::string>>
- events = match.second;
- boost::container::flat_map<std::string, std::vector<std::string>>
- pathList;
+ const EventPathList events = match.second;
+ EventPathList pathList;
for (const auto& match : events)
{
const std::string& eventName = match.first;
@@ -221,12 +203,9 @@
// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
// xxx_min_alarm exist, then store the existing paths of the alarm attributes
// to eventPathList.
-void checkEventLimits(
- const std::string& sensorPathStr,
- const boost::container::flat_map<std::string, std::vector<std::string>>&
- limitEventMatch,
- boost::container::flat_map<std::string, std::vector<std::string>>&
- eventPathList)
+void checkEventLimits(const std::string& sensorPathStr,
+ const EventPathList& limitEventMatch,
+ EventPathList& eventPathList)
{
auto attributePartPos = sensorPathStr.find_last_of('_');
if (attributePartPos == std::string::npos)
@@ -328,12 +307,8 @@
boost::container::flat_set<std::string> directories;
for (const auto& pmbusPath : pmbusPaths)
{
- boost::container::flat_map<std::string, std::vector<std::string>>
- eventPathList;
- boost::container::flat_map<
- std::string,
- boost::container::flat_map<std::string, std::vector<std::string>>>
- groupEventPathList;
+ EventPathList eventPathList;
+ GroupEventPathList groupEventPathList;
std::ifstream nameFile(pmbusPath);
if (!nameFile.good())