summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2018-09-11 08:26:10 -0500
committerMatt Spinler <spinler@us.ibm.com>2018-09-28 08:24:53 -0500
commit9f0958e18c3ba36f6ec8e58101654d69e4e34799 (patch)
tree7e62404d105a7f98b2ba4102cbbb6940e0a1eefe /src
parentdd9458613b8745177ad2a7e0519277654f4834f5 (diff)
downloadphosphor-objmgr-9f0958e18c3ba36f6ec8e58101654d69e4e34799.tar.gz
phosphor-objmgr-9f0958e18c3ba36f6ec8e58101654d69e4e34799.zip
Filter results of GetSubTree
GetSubTree should only return service names and their interfaces for services that implement the interfaces passed into the function. The previous code would return every service/interface list if any service implemented the specified interfaces. Change-Id: I351af0aedd553e45125bffe2dd72aa352ec8d403 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c291250..a1e6be8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -482,6 +482,34 @@ void splitArgs(const std::string& stringArgs,
}
}
+void addSubtreeResult(
+ std::vector<interface_map_type::value_type>& subtree,
+ const std::string& objectPath,
+ const std::pair<std::string, boost::container::flat_set<std::string>>&
+ interfaceMap)
+{
+ // Adds an object path/service name/interface list entry to
+ // the results of GetSubTree.
+ // If an entry for the object path already exists, just add the
+ // service name and interfaces to that entry, otherwise create
+ // a new entry.
+ auto entry = std::find_if(
+ subtree.begin(), subtree.end(),
+ [&objectPath](const auto& i) { return objectPath == i.first; });
+
+ if (entry != subtree.end())
+ {
+ entry->second.emplace(interfaceMap);
+ }
+ else
+ {
+ interface_map_type::value_type object;
+ object.first = objectPath;
+ object.second.emplace(interfaceMap);
+ subtree.push_back(object);
+ }
+}
+
int main(int argc, char** argv)
{
std::cerr << "started\n";
@@ -797,22 +825,22 @@ int main(int argc, char** argv)
this_path.end(), '/');
if (this_depth <= depth)
{
- bool add = interfaces.empty();
for (auto& interface_map : object_path.second)
{
if (intersect(interfaces.begin(), interfaces.end(),
interface_map.second.begin(),
- interface_map.second.end()))
+ interface_map.second.end()) ||
+ interfaces.empty())
{
- add = true;
- break;
+ addSubtreeResult(ret, this_path, interface_map);
+
+ // if not just adding every interface, then done
+ if (!interfaces.empty())
+ {
+ break;
+ }
}
}
- if (add)
- {
- // todo(ed) this is a copy
- ret.emplace_back(object_path);
- }
}
}
}
OpenPOWER on IntegriCloud