From d65c8c30a9a1d71540bf0d669d47d36f9993e5c1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 3 Aug 2020 16:04:12 +0100 Subject: [PATCH] GDBus: Add G_DBUS_METHOD_INVOCATION_HANDLED, _UNHANDLED Like G_SOURCE_REMOVE and G_SOURCE_CONTINUE, these make it clearer what it means to return TRUE or FALSE. In particular, in GDBus methods that fail, the failure case still needs to return TRUE (unlike the typical GError pattern), leading to comments like this: g_dbus_method_invocation_return_error (invocation, ...); return TRUE; /* handled */ which can now be replaced by: g_dbus_method_invocation_return_error (invocation, ...); return G_DUS_METHOD_INVOCATION_HANDLED; G_DBUS_METHOD_INVOCATION_UNHANDLED is added for symmetry, but is very rarely (perhaps never?) useful in practice. Signed-off-by: Simon McVittie --- docs/reference/gio/gio-sections-common.txt | 2 ++ gio/gdbus-2.0/codegen/codegen.py | 2 +- gio/gdbusmethodinvocation.h | 35 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt index 39999c452..314d1009e 100644 --- a/docs/reference/gio/gio-sections-common.txt +++ b/docs/reference/gio/gio-sections-common.txt @@ -3026,6 +3026,8 @@ g_dbus_method_invocation_return_gerror g_dbus_method_invocation_return_dbus_error g_dbus_method_invocation_take_error g_dbus_method_invocation_return_value_with_unix_fd_list +G_DBUS_METHOD_INVOCATION_HANDLED +G_DBUS_METHOD_INVOCATION_UNHANDLED G_DBUS_METHOD_INVOCATION G_IS_DBUS_METHOD_INVOCATION diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py index 5234b3807..cda047173 100644 --- a/gio/gdbus-2.0/codegen/codegen.py +++ b/gio/gdbus-2.0/codegen/codegen.py @@ -1522,7 +1522,7 @@ class CodeGenerator: ' *\n' ' * If a signal handler returns %%TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call %s_complete_%s() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %%G_DBUS_ERROR_UNKNOWN_METHOD error is returned.\n' ' *\n' - ' * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n' + ' * Returns: %%G_DBUS_METHOD_INVOCATION_HANDLED or %%TRUE if the invocation was handled, %%G_DBUS_METHOD_INVOCATION_UNHANDLED or %%FALSE to let other signal handlers run.\n' %(i.name, m.name, i.name_lower, m.name_lower), False)) self.write_gtkdoc_deprecated_and_since_and_close(m, self.outfile, 2) if m.unix_fd: diff --git a/gio/gdbusmethodinvocation.h b/gio/gdbusmethodinvocation.h index 061256ffe..775070a2c 100644 --- a/gio/gdbusmethodinvocation.h +++ b/gio/gdbusmethodinvocation.h @@ -33,6 +33,41 @@ G_BEGIN_DECLS #define G_DBUS_METHOD_INVOCATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_DBUS_METHOD_INVOCATION, GDBusMethodInvocation)) #define G_IS_DBUS_METHOD_INVOCATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_DBUS_METHOD_INVOCATION)) +/** + * G_DBUS_METHOD_INVOCATION_HANDLED: + * + * The value returned by handlers of the signals generated by + * the `gdbus-codegen` tool to indicate that a method call has been + * handled by an implementation. It is equal to %TRUE, but using + * this macro is sometimes more readable. + * + * In code that needs to be backwards-compatible with older GLib, + * use %TRUE instead, often written like this: + * + * |[ + * g_dbus_method_invocation_return_error (invocation, ...); + * return TRUE; // handled + * ]| + * + * Since: 2.68 + */ +#define G_DBUS_METHOD_INVOCATION_HANDLED TRUE GLIB_AVAILABLE_MACRO_IN_2_68 + +/** + * G_DBUS_METHOD_INVOCATION_UNHANDLED: + * + * The value returned by handlers of the signals generated by + * the `gdbus-codegen` tool to indicate that a method call has not been + * handled by an implementation. It is equal to %FALSE, but using + * this macro is sometimes more readable. + * + * In code that needs to be backwards-compatible with older GLib, + * use %FALSE instead. + * + * Since: 2.68 + */ +#define G_DBUS_METHOD_INVOCATION_UNHANDLED FALSE GLIB_AVAILABLE_MACRO_IN_2_68 + GLIB_AVAILABLE_IN_ALL GType g_dbus_method_invocation_get_type (void) G_GNUC_CONST; GLIB_AVAILABLE_IN_ALL