utils: Add the getSubTree method
The purpose of this patch is to prevent other methods from calling
ObjectMapper's `GetSubTree` property, but to obtain the correct the
objectTree values by calling the standard the getSubTree method.
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: Ia719f92ca31fa75f83a7ffd07fdcb680bd4243b0
diff --git a/libipmid/utils.cpp b/libipmid/utils.cpp
index f7e9802..81cc4c4 100644
--- a/libipmid/utils.cpp
+++ b/libipmid/utils.cpp
@@ -47,18 +47,7 @@
std::vector<DbusInterface> interfaces;
interfaces.emplace_back(interface);
- auto depth = 0;
-
- auto mapperCall = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ,
- MAPPER_INTF, "GetSubTree");
-
- mapperCall.append(serviceRoot, depth, interfaces);
-
- auto mapperReply = bus.call(mapperCall);
-
- ObjectTree objectTree;
- mapperReply.read(objectTree);
-
+ ObjectTree objectTree = getSubTree(bus, interfaces, serviceRoot);
if (objectTree.empty())
{
log<level::ERR>("No Object has implemented the interface",
@@ -229,6 +218,21 @@
return mapperResponse.begin()->first;
}
+ObjectTree getSubTree(sdbusplus::bus_t& bus, const InterfaceList& interfaces,
+ const std::string& subtreePath, int32_t depth)
+{
+ auto mapperCall = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ,
+ MAPPER_INTF, "GetSubTree");
+
+ mapperCall.append(subtreePath, depth, interfaces);
+
+ auto mapperReply = bus.call(mapperCall);
+ ObjectTree objectTree;
+ mapperReply.read(objectTree);
+
+ return objectTree;
+}
+
ipmi::ObjectTree getAllDbusObjects(sdbusplus::bus_t& bus,
const std::string& serviceRoot,
const std::string& interface,
@@ -237,17 +241,7 @@
std::vector<std::string> interfaces;
interfaces.emplace_back(interface);
- auto depth = 0;
-
- auto mapperCall = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ,
- MAPPER_INTF, "GetSubTree");
-
- mapperCall.append(serviceRoot, depth, interfaces);
-
- auto mapperReply = bus.call(mapperCall);
- ObjectTree objectTree;
- mapperReply.read(objectTree);
-
+ ObjectTree objectTree = getSubTree(bus, interfaces, serviceRoot);
for (auto it = objectTree.begin(); it != objectTree.end();)
{
if (it->first.find(match) == std::string::npos)
@@ -356,6 +350,19 @@
return ec;
}
+boost::system::error_code getSubTree(Context::ptr ctx,
+ const InterfaceList& interfaces,
+ const std::string& subtreePath,
+ int32_t depth, ObjectTree& objectTree)
+{
+ boost::system::error_code ec;
+ objectTree = ctx->bus->yield_method_call<ObjectTree>(
+ ctx->yield, ec, MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF, "GetSubTree",
+ subtreePath, depth, interfaces);
+
+ return ec;
+}
+
boost::system::error_code getDbusObject(Context::ptr ctx,
const std::string& interface,
const std::string& subtreePath,
@@ -366,10 +373,9 @@
interfaces.emplace_back(interface);
auto depth = 0;
- boost::system::error_code ec;
- ObjectTree objectTree = ctx->bus->yield_method_call<ObjectTree>(
- ctx->yield, ec, MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF, "GetSubTree",
- subtreePath, depth, interfaces);
+ ObjectTree objectTree;
+ boost::system::error_code ec = getSubTree(ctx, interfaces, subtreePath,
+ depth, objectTree);
if (ec)
{
@@ -448,16 +454,12 @@
const std::string& match,
ObjectTree& objectTree)
{
- boost::system::error_code ec;
std::vector<std::string> interfaces;
interfaces.emplace_back(interface);
auto depth = 0;
-
- objectTree = ctx->bus->yield_method_call<ObjectTree>(
- ctx->yield, ec, MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF, "GetSubTree",
- serviceRoot, depth, interfaces);
-
+ boost::system::error_code ec = getSubTree(ctx, interfaces, serviceRoot,
+ depth, objectTree);
if (ec)
{
return ec;