Move getInvService() into utility function.

Resolves openbmc/openbmc#1299

Change-Id: I61f511dcc15e67393a47bd0395b752d2e6f17f11
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/fan_enclosure.cpp b/fan_enclosure.cpp
index cb0c423..262876e 100644
--- a/fan_enclosure.cpp
+++ b/fan_enclosure.cpp
@@ -16,7 +16,7 @@
 #include <algorithm>
 #include <phosphor-logging/log.hpp>
 #include "fan_enclosure.hpp"
-
+#include "utility.hpp"
 
 namespace phosphor
 {
@@ -27,11 +27,6 @@
 
 using namespace phosphor::logging;
 
-//TODO Should get these from phosphor-objmgr config.h
-constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
-constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
-constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
-
 //TODO Should get these from phosphor-inventory-manager config.h
 constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
 constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";
@@ -62,35 +57,6 @@
     return invObj;
 }
 
-std::string FanEnclosure::getInvService()
-{
-    auto mapperCall = bus.new_method_call(MAPPER_BUSNAME,
-                                          MAPPER_PATH,
-                                          MAPPER_INTERFACE,
-                                          "GetObject");
-
-    mapperCall.append(INVENTORY_PATH);
-    mapperCall.append(std::vector<std::string>({INVENTORY_INTF}));
-
-    auto mapperResponseMsg = bus.call(mapperCall);
-    if (mapperResponseMsg.is_method_error())
-    {
-        throw std::runtime_error(
-            "Error in mapper call to get inventory service name");
-    }
-
-    std::map<std::string, std::vector<std::string>> mapperResponse;
-    mapperResponseMsg.read(mapperResponse);
-
-    if (mapperResponse.empty())
-    {
-        throw std::runtime_error(
-            "Error in mapper response for inventory service name");
-    }
-
-    return mapperResponse.begin()->first;
-}
-
 void FanEnclosure::updInventory()
 {
     auto curPresState = getCurPresState();
@@ -103,7 +69,7 @@
         std::string invService;
         try
         {
-            invService = getInvService();
+            invService = getInvService(bus);
         }
         catch (const std::runtime_error& err)
         {