[glib/wip/smcv/invocation-handled: 2/3] GDBus: Add G_DBUS_METHOD_INVOCATION_HANDLED, _UNHANDLED
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/smcv/invocation-handled: 2/3] GDBus: Add G_DBUS_METHOD_INVOCATION_HANDLED, _UNHANDLED
- Date: Mon, 3 Aug 2020 15:12:46 +0000 (UTC)
commit 35e63f267f5d0093349076e738a583258f7eee17
Author: Simon McVittie <smcv collabora com>
Date: Mon Aug 3 16:04:12 2020 +0100
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 <smcv collabora com>
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 442b2247b..7f5f8a76c 100644
--- a/docs/reference/gio/gio-sections-common.txt
+++ b/docs/reference/gio/gio-sections-common.txt
@@ -3025,6 +3025,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
<SUBSECTION Standard>
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..e8df3c0e3 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.66
+ */
+#define G_DBUS_METHOD_INVOCATION_HANDLED TRUE GLIB_AVAILABLE_MACRO_IN_2_66
+
+/**
+ * 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.66
+ */
+#define G_DBUS_METHOD_INVOCATION_UNHANDLED FALSE GLIB_AVAILABLE_MACRO_IN_2_66
+
GLIB_AVAILABLE_IN_ALL
GType g_dbus_method_invocation_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]