From bec34c428cca88e6afed134c070b6f1916d394ab Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Tue, 13 Dec 2011 21:57:02 +0200 Subject: [PATCH] dbus: New helper function: pa_dbus_get_error_message(). --- src/pulsecore/dbus-util.c | 14 ++++++++++++++ src/pulsecore/dbus-util.h | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/pulsecore/dbus-util.c b/src/pulsecore/dbus-util.c index b79b752..3daf90f 100644 --- a/src/pulsecore/dbus-util.c +++ b/src/pulsecore/dbus-util.c @@ -452,6 +452,20 @@ void pa_dbus_free_pending_list(pa_dbus_pending **p) { } } +const char *pa_dbus_get_error_message(DBusMessage *m) { + const char *message; + + pa_assert(m); + pa_assert(dbus_message_get_type(m) == DBUS_MESSAGE_TYPE_ERROR); + + if (dbus_message_get_signature(m)[0] != 's') + return ""; + + pa_assert_se(dbus_message_get_args(m, NULL, DBUS_TYPE_STRING, &message, DBUS_TYPE_INVALID)); + + return message; +} + void pa_dbus_send_error(DBusConnection *c, DBusMessage *in_reply_to, const char *name, const char *format, ...) { va_list ap; char *message; diff --git a/src/pulsecore/dbus-util.h b/src/pulsecore/dbus-util.h index 347f9f3..e3d6e4f 100644 --- a/src/pulsecore/dbus-util.h +++ b/src/pulsecore/dbus-util.h @@ -67,6 +67,14 @@ void pa_dbus_sync_pending_list(pa_dbus_pending **p); /* Free up a list of pa_dbus_pending_call objects */ void pa_dbus_free_pending_list(pa_dbus_pending **p); +/* When receiving a DBusMessage with type DBUS_MESSAGE_TYPE_ERROR, the + * DBusMessage may or may not contain an error message (a human-readable + * explanation of what went wrong). Extracting the error message from the + * DBusMessage object is a bit tedious, so here's a helper function that does + * that. If the DBusMessage doesn't contain any error message, + * "" is returned. */ +const char *pa_dbus_get_error_message(DBusMessage *m); + /* Sends an error message as the reply to the given message. */ void pa_dbus_send_error( DBusConnection *c, -- 2.7.4