summaryrefslogtreecommitdiffstats
path: root/globalhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'globalhandler.cpp')
-rw-r--r--globalhandler.cpp75
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;
}
OpenPOWER on IntegriCloud