Return-Path: From: Mikel Astiz To: linux-bluetooth@vger.kernel.org Cc: Mikel Astiz Subject: [RFC obexd v1 1/2] gdbus: Add helper function for error-handling Date: Thu, 3 May 2012 14:41:47 +0200 Message-Id: <1336048908-8685-2-git-send-email-mikel.astiz.oss@gmail.com> In-Reply-To: <1336048908-8685-1-git-send-email-mikel.astiz.oss@gmail.com> References: <1336048908-8685-1-git-send-email-mikel.astiz.oss@gmail.com> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: From: Mikel Astiz The new function is a convenient way to create a D-Bus error message and automatically free the GError object. --- gdbus/gdbus.h | 4 ++++ gdbus/object.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h index a0583e6..485ee01 100644 --- a/gdbus/gdbus.h +++ b/gdbus/gdbus.h @@ -138,6 +138,10 @@ DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name, __attribute__((format(printf, 3, 4))); DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name, const char *format, va_list args); + +DBusMessage *g_dbus_steal_from_gerror(DBusMessage *message, const char *name, + GError **err); + DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...); DBusMessage *g_dbus_create_reply_valist(DBusMessage *message, int type, va_list args); diff --git a/gdbus/object.c b/gdbus/object.c index 8bc12f5..f4128b2 100644 --- a/gdbus/object.c +++ b/gdbus/object.c @@ -765,6 +765,20 @@ DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name, return reply; } +DBusMessage *g_dbus_steal_from_gerror(DBusMessage *message, const char *name, + GError **err) +{ + DBusMessage *reply; + + if ((err == NULL) || (*err == NULL)) + return NULL; + + reply = g_dbus_create_error(message, name, "%s", (*err)->message); + g_clear_error(err); + + return reply; +} + DBusMessage *g_dbus_create_reply_valist(DBusMessage *message, int type, va_list args) { -- 1.7.7.6