diff options
author | Brad Bishop <bradleyb@us.ibm.com> | 2016-10-05 23:39:41 -0400 |
---|---|---|
committer | Brad Bishop <bradleyb@us.ibm.com> | 2016-10-10 14:36:15 -0400 |
commit | 30be0f700ed7259c8b20c50e4fc84ef696d98483 (patch) | |
tree | 4c3fac25ee711d6e412031f0c602c80330b9aa5f | |
parent | 5600345375dc537216ccb13de06036798bcc9de0 (diff) | |
download | phosphor-host-ipmid-30be0f700ed7259c8b20c50e4fc84ef696d98483.tar.gz phosphor-host-ipmid-30be0f700ed7259c8b20c50e4fc84ef696d98483.zip |
global: replace mapper method with library call
Use the sdbus client binding for this to protect
from changes within the binding itself.
Change-Id: I152b254bbf21360a5096d9e0f48bd99fc29d737b
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | globalhandler.cpp | 75 |
1 files changed, 5 insertions, 70 deletions
diff --git a/globalhandler.cpp b/globalhandler.cpp index 2c3c994..34b244f 100644 --- a/globalhandler.cpp +++ b/globalhandler.cpp @@ -3,80 +3,13 @@ #include <stdio.h> #include <string.h> #include <stdint.h> +#include <mapper.h> const char *control_object_name = "/org/openbmc/control/bmc0"; const char *control_intf_name = "org.openbmc.control.Bmc"; -const char *objectmapper_service_name = "org.openbmc.ObjectMapper"; -const char *objectmapper_object_name = "/org/openbmc/ObjectMapper"; -const char *objectmapper_intf_name = "org.openbmc.ObjectMapper"; - void register_netfn_global_functions() __attribute__((constructor)); -int obj_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, - objectmapper_service_name, /* service to contact */ - objectmapper_object_name, /* object path */ - objectmapper_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. - */ - - 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 warm reset"); - 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_reset(const char *method) { sd_bus_error error = SD_BUS_ERROR_NULL; @@ -85,9 +18,11 @@ int dbus_reset(const char *method) char* connection = NULL; int r; - r = obj_mapper_get_connection(&connection, control_object_name); + bus = ipmid_get_sd_bus_connection(); + r = mapper_get_service(bus, control_object_name, &connection); if (r < 0) { - fprintf(stderr, "Failed to get connection, return value: %d.\n", r); + fprintf(stderr, "Failed to get connection for %s: %s\n", + control_object_name, strerror(-r)); goto finish; } |