[RFC obexd v1 1/2] gdbus: Add helper function for error-handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx>

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

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux