Use mapper calls to lookup objects

This is a reaction to a managers.System API update.  The
update removes the bus name field from the 'GetObject'
method responses.

Change-Id: I51fb1d1bad20317a429e5b06712475929b6fb4fb
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/chassishandler.C b/chassishandler.C
index 6a9a28f..ded9157 100644
--- a/chassishandler.C
+++ b/chassishandler.C
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <mapper.h>
 
 
 //Defines
@@ -27,80 +28,6 @@
 const char *settings_intf_name    =  "org.freedesktop.DBus.Properties";
 const char *host_intf_name        =  "org.openbmc.settings.Host";
 
-const char *objmapper_service_name =  "org.openbmc.ObjectMapper";
-const char *objmapper_object_name  =  "/org/openbmc/ObjectMapper";
-const char *objmapper_intf_name    =  "org.openbmc.ObjectMapper";
-
-int object_mapper_get_connection(char **buf, const char *obj_path)
-{
-    sd_bus_error error = SD_BUS_ERROR_NULL;
-    sd_bus_message *m = NULL;
-    sd_bus *bus = NULL;
-    char *temp_buf = NULL, *intf = NULL;
-    size_t buf_size = 0;
-    int r;
-
-    // Get the system bus where most system services are provided.
-    bus = ipmid_get_sd_bus_connection();
-
-    /*
-     * Bus, service, object path, interface and method are provided to call
-     * the method.
-     * Signatures and input arguments are provided by the arguments at the
-     * end.
-     */
-    r = sd_bus_call_method(bus,
-                           objmapper_service_name,                      /* service to contact */
-                           objmapper_object_name,                       /* object path */
-                           objmapper_intf_name,                         /* interface name */
-                           "GetObject",                                 /* method name */
-                           &error,                                      /* object to return error in */
-                           &m,                                          /* return message on success */
-                           "s",                                         /* input signature */
-                           obj_path                                     /* first argument */
-                          );
-
-    if (r < 0) {
-        fprintf(stderr, "Failed to issue method call: %s\n", error.message);
-        goto finish;
-    }
-
-    // Get the key, aka, the connection name
-    sd_bus_message_read(m, "a{sas}", 1, &temp_buf, 1, &intf);
-
-    /*
-     * TODO: check the return code. Currently for no reason the message
-     * parsing of object mapper is always complaining about
-     * "Device or resource busy", but the result seems OK for now. Need
-     * further checks.
-     * TODO: The following code is preserved in the comments so that it can be
-     * resumed after the problem aforementioned is resolved.
-     *r = sd_bus_message_read(m, "a{sas}", 1, &temp_buf, 1, &intf);
-     *if (r < 0) {
-     *    fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));
-     *    goto finish;
-     *}
-     */
-
-    buf_size = strlen(temp_buf) + 1;
-    printf("IPMID connection name: %s\n", temp_buf);
-    *buf = (char *)malloc(buf_size);
-
-    if (*buf == NULL) {
-        fprintf(stderr, "Malloc failed for get_sys_boot_options");
-        r = -1;
-        goto finish;
-    }
-
-    memcpy(*buf, temp_buf, buf_size);
-
-finish:
-    sd_bus_error_free(&error);
-    sd_bus_message_unref(m);
-
-    return r;
-}
-
 int dbus_get_property(const char *name, char **buf)
 {
     sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -110,18 +37,15 @@
     char *connection = NULL;
     int r;
 
-    r = object_mapper_get_connection(&connection, settings_object_name);
+    // Get the system bus where most system services are provided.
+    bus = ipmid_get_sd_bus_connection();
 
+    r = mapper_get_service(bus, settings_object_name, &connection);
     if (r < 0) {
         fprintf(stderr, "Failed to get connection, return value: %d.\n", r);
         goto finish;
     }
 
-    printf("connection: %s\n", connection);
-
-    // Get the system bus where most system services are provided.
-    bus = ipmid_get_sd_bus_connection();
-
     /*
      * Bus, service, object path, interface and method are provided to call
      * the method.
@@ -178,18 +102,15 @@
     char *connection = NULL;
     int r;
 
-    r = object_mapper_get_connection(&connection, settings_object_name);
+    // Get the system bus where most system services are provided.
+    bus = ipmid_get_sd_bus_connection();
 
+    r = mapper_get_service(bus, settings_object_name, &connection);
     if (r < 0) {
         fprintf(stderr, "Failed to get connection, return value: %d.\n", r);
         goto finish;
     }
 
-    printf("connection: %s\n", connection);
-
-    // Get the system bus where most system services are provided.
-    bus = ipmid_get_sd_bus_connection();
-
     /*
      * Bus, service, object path, interface and method are provided to call
      * the method.