Get inventory manager service name

Retrieve the inventory manager's service name from object mapper.

Change-Id: I56c67012105b5bc389763608c998ccc756b1104a
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/fan_enclosure.cpp b/fan_enclosure.cpp
index 5461b08..2bed251 100644
--- a/fan_enclosure.cpp
+++ b/fan_enclosure.cpp
@@ -9,6 +9,15 @@
 namespace presence
 {
 
+//TODO Should get these from phosphor-objmgr config.h
+constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
+constexpr auto MAPPER_PATH = "/xyz/openbmc_project/ObjectMapper";
+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";
+
 FanEnclosure::ObjectMap FanEnclosure::getObjectMap()
 {
     ObjectMap invObj;
@@ -28,15 +37,39 @@
     return invObj;
 }
 
-void FanEnclosure::addInventory()
+std::string FanEnclosure::getInvService()
 {
-    //TODO Add this fan to inventory
+    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())
+    {
+        //TODO Retry or throw exception/log error?
+    }
+
+    std::map<std::string, std::vector<std::string>> mapperResponse;
+    mapperResponseMsg.read(mapperResponse);
+
+    if (mapperResponse.empty())
+    {
+        //TODO Nothing found, throw exception/log error?
+    }
+
+    return mapperResponse.begin()->first;
 }
 
 void FanEnclosure::updInventory()
 {
     //Get inventory object for this fan
     ObjectMap invObj = getObjectMap();
+    //Get inventory manager service name from mapper
+    std::string invService = getInvService();
     //TODO Update inventory for this fan
 }