Follow secure coding standards for interactions with the mapper
This patchset updates phosphor-time-manager to follow secure coding
guidelines when interacting with the mapper. Specifically, it replaces
uses of std::map with std::vector<std::pair<>>, which should net some
small performance wins. This change also causes time-manager to
properly enumerate each response.
Tested-By:
Built with changeset, and verified via d-feet that
/xyz/openbmc_project/time/host and /xyz/openbmc_project/time/bmc were
present, and verified reading of the "Elapsed" parameter returned the
expected time result.
Change-Id: If4329d533641595cf0b50c4e50e2dda69b299f52
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/settings.cpp b/settings.cpp
index a3eada9..704905a 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -35,7 +35,8 @@
}
using Interfaces = std::vector<Interface>;
- using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
+ using MapperResponse = std::vector<
+ std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
MapperResponse result;
response.read(result);
if (result.empty())
@@ -47,19 +48,23 @@
for (const auto& iter : result)
{
const Path& path = iter.first;
- const Interface& interface = iter.second.begin()->second.front();
-
- if (timeOwnerIntf == interface)
+ for (const auto& service_iter: iter.second)
{
- timeOwner = path;
- }
- else if (timeSyncIntf == interface)
- {
- timeSyncMethod = path;
- }
- else if (hostStateIntf == interface)
- {
- hostState = path;
+ for (const Interface& interface: service_iter.second)
+ {
+ if (timeOwnerIntf == interface)
+ {
+ timeOwner = path;
+ }
+ else if (timeSyncIntf == interface)
+ {
+ timeSyncMethod = path;
+ }
+ else if (hostStateIntf == interface)
+ {
+ hostState = path;
+ }
+ }
}
}
}
diff --git a/utils.cpp b/utils.cpp
index 25b8f8c..778487f 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -47,7 +47,8 @@
MethodError::MISC({}));
}
- std::map<std::string, std::vector<std::string>> mapperResponse;
+ std::vector<std::pair<std::string, std::vector<std::string>>>
+ mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
@@ -57,8 +58,10 @@
MethodError::INTERFACE(interface),
MethodError::MISC("Error reading mapper response"));
}
-
- return mapperResponse.begin()->first;
+ if (mapperResponse.size() < 1){
+ return "";
+ }
+ return mapperResponse[0].first;
}
Mode strToMode(const std::string& mode)