Merge branch 'wip/smcv/invocation-handled' into 'master'

GDBus: Add G_DBUS_METHOD_INVOCATION_HANDLED, _UNHANDLED

See merge request GNOME/glib!1603
This commit is contained in:
Philip Withnall 2020-10-01 15:50:16 +00:00
commit 42961e819d
15 changed files with 77 additions and 35 deletions

View File

@ -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
<SUBSECTION Standard>
G_DBUS_METHOD_INVOCATION
G_IS_DBUS_METHOD_INVOCATION

View File

@ -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:

View File

@ -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

View File

@ -121,7 +121,7 @@ test_auth_on_timeout (gpointer user_data)
{
g_error ("Timeout waiting for client");
g_assert_not_reached ();
return FALSE;
return G_SOURCE_REMOVE;
}

View File

@ -188,7 +188,7 @@ delayed_close_cb (gpointer data)
close_async (df->stream, df->io_priority, df->cancellable, df->callback,
df->user_data);
return FALSE;
return G_SOURCE_REMOVE;
}
static void

View File

@ -53,7 +53,7 @@ on_timeout (gpointer user_data)
{
/* tear down bus */
session_bus_stop ();
return FALSE; /* remove source */
return G_SOURCE_REMOVE;
}
static void

View File

@ -49,7 +49,7 @@ test_connection_flush_on_timeout (gpointer user_data)
guint iteration = GPOINTER_TO_UINT (user_data);
g_printerr ("Timeout waiting 1000 msec on iteration %d\n", iteration);
g_assert_not_reached ();
return FALSE;
return G_SOURCE_REMOVE;
}
static void
@ -125,7 +125,7 @@ large_message_timeout_cb (gpointer data)
g_error ("Error: timeout waiting for dbus name to appear");
return FALSE;
return G_SOURCE_REMOVE;
}
static void

View File

@ -65,7 +65,7 @@ test_connection_quit_mainloop (gpointer user_data)
_log ("quit_mainloop_fired");
*quit_mainloop_fired = TRUE;
g_main_loop_quit (loop);
return TRUE;
return G_SOURCE_CONTINUE;
}
/* ---------------------------------------------------------------------------------------------------- */
@ -934,7 +934,7 @@ test_connection_filter_on_timeout (gpointer user_data)
{
g_printerr ("Timeout waiting 30 sec on service\n");
g_assert_not_reached ();
return FALSE;
return G_SOURCE_REMOVE;
}
static void

View File

@ -53,7 +53,7 @@ on_animal_poke (ExampleAnimal *animal,
g_assert_not_reached ();
out:
return TRUE; /* to indicate that the method was handled */
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

View File

@ -315,7 +315,7 @@ on_timeout_cb (gpointer user_data)
g_assert_no_error (error);
return TRUE;
return G_SOURCE_CONTINUE;
}
/* ---------------------------------------------------------------------------------------------------- */

View File

@ -57,7 +57,7 @@ quit_later_cb (gpointer data G_GNUC_UNUSED)
{
g_main_loop_quit (loop);
return FALSE;
return G_SOURCE_REMOVE;
}
static void

View File

@ -95,7 +95,7 @@ static gboolean
overflow_on_500ms_later_func (gpointer user_data)
{
g_main_loop_quit (loop);
return FALSE; /* don't keep the idle */
return G_SOURCE_REMOVE;
}
static void

View File

@ -644,7 +644,7 @@ check_connection (gpointer user_data)
}
}
return FALSE;
return G_SOURCE_REMOVE;
}
static gboolean
@ -654,7 +654,7 @@ on_do_disconnect_in_idle (gpointer data)
g_debug ("GDC %p has ref_count %d", c, G_OBJECT (c)->ref_count);
g_dbus_connection_disconnect (c);
g_object_unref (c);
return FALSE;
return G_SOURCE_REMOVE;
}
#endif
@ -1719,7 +1719,7 @@ codegen_on_animal_poke (ExampleAnimal *animal,
g_assert_not_reached ();
out:
return TRUE; /* to indicate that the method was handled */
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
/* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */
@ -1794,7 +1794,7 @@ static gboolean
codegen_quit_mainloop_timeout (gpointer data)
{
g_main_loop_quit (loop);
return FALSE;
return G_SOURCE_REMOVE;
}
static void

View File

@ -33,6 +33,11 @@
#include "gdbus-test-codegen-generated-interface-info.h"
#if GLIB_VERSION_MIN_REQUIRED < GLIB_VERSION_2_68
# undef G_DBUS_METHOD_INVOCATION_HANDLED
# define G_DBUS_METHOD_INVOCATION_HANDLED TRUE
#endif
/* ---------------------------------------------------------------------------------------------------- */
static guint
@ -100,7 +105,7 @@ on_handle_hello_world (FooiGenBar *object,
response = g_strdup_printf ("Word! You said '%s'. I'm Skeleton, btw!", greeting);
foo_igen_bar_complete_hello_world (object, invocation, response);
g_free (response);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -145,7 +150,7 @@ on_handle_test_primitive_types (FooiGenBar *object,
g_free (s1);
g_free (s2);
g_free (s3);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -185,7 +190,7 @@ on_handle_test_non_primitive_types (FooiGenBar *object,
array_of_bytestrings,
str->str);
g_string_free (str, TRUE);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -202,7 +207,7 @@ on_handle_request_signal_emission (FooiGenBar *object,
foo_igen_bar_emit_test_signal (object, 43, a_strv, a_bytestring_array, a_variant); /* consumes a_variant */
foo_igen_bar_complete_request_signal_emission (object, invocation);
}
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -218,7 +223,7 @@ on_handle_request_multi_property_mods (FooiGenBar *object,
foo_igen_bar_set_y (object, foo_igen_bar_get_y (object) + 1);
foo_igen_bar_set_i (object, foo_igen_bar_get_i (object) + 1);
foo_igen_bar_complete_request_multi_property_mods (object, invocation);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -238,7 +243,7 @@ on_handle_property_cancellation (FooiGenBar *object,
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (object));
/* this makes us return the reply D-Bus method */
foo_igen_bar_complete_property_cancellation (object, invocation);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
/* ---------------------------------------------------------------------------------------------------- */
@ -293,7 +298,7 @@ on_handle_force_method (FooiGenBat *object,
g_variant_unref (ret_ay);
g_variant_unref (ret_struct);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
@ -382,7 +387,7 @@ on_handle_check_not_authorized (FooiGenAuthorize *object,
gpointer user_data)
{
foo_igen_authorize_complete_check_not_authorized (object, invocation);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -391,7 +396,7 @@ on_handle_check_authorized (FooiGenAuthorize *object,
gpointer user_data)
{
foo_igen_authorize_complete_check_authorized (object, invocation);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -400,7 +405,7 @@ on_handle_check_not_authorized_from_object (FooiGenAuthorize *object,
gpointer user_data)
{
foo_igen_authorize_complete_check_not_authorized_from_object (object, invocation);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
/* ---------------------------------------------------------------------------------------------------- */
@ -414,7 +419,7 @@ on_handle_get_self (FooiGenMethodThreads *object,
s = g_strdup_printf ("%p", (void *)g_thread_self ());
foo_igen_method_threads_complete_get_self (object, invocation, s);
g_free (s);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
/* ---------------------------------------------------------------------------------------------------- */
@ -2645,7 +2650,7 @@ handle_hello_fd (FooiGenFDPassing *object,
const gchar *arg_greeting)
{
foo_igen_fdpassing_complete_hello_fd (object, invocation, fd_list, arg_greeting);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_64
@ -2657,7 +2662,7 @@ handle_no_annotation (FooiGenFDPassing *object,
const gchar *arg_greeting_locale)
{
foo_igen_fdpassing_complete_no_annotation (object, invocation, fd_list, arg_greeting, arg_greeting_locale);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -2667,7 +2672,7 @@ handle_no_annotation_nested (FooiGenFDPassing *object,
GVariant *arg_files)
{
foo_igen_fdpassing_complete_no_annotation_nested (object, invocation, fd_list);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
#else
static gboolean
@ -2677,7 +2682,7 @@ handle_no_annotation (FooiGenFDPassing *object,
const gchar *arg_greeting_locale)
{
foo_igen_fdpassing_complete_no_annotation (object, invocation, arg_greeting, arg_greeting_locale);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
static gboolean
@ -2686,7 +2691,7 @@ handle_no_annotation_nested (FooiGenFDPassing *object,
GVariant *arg_files)
{
foo_igen_fdpassing_complete_no_annotation_nested (object, invocation);
return TRUE;
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
#endif

View File

@ -48,7 +48,7 @@ on_property_notify_timeout (gpointer user_data)
PropertyNotifyData *data = user_data;
data->timed_out = TRUE;
g_main_loop_quit (data->loop);
return TRUE;
return G_SOURCE_CONTINUE;
}
gboolean
@ -83,7 +83,7 @@ static gboolean
_give_up (gpointer data)
{
g_error ("%s", (const gchar *) data);
g_return_val_if_reached (TRUE);
g_return_val_if_reached (G_SOURCE_CONTINUE);
}
typedef struct
@ -175,7 +175,7 @@ on_signal_received_timeout (gpointer user_data)
SignalReceivedData *data = user_data;
data->timed_out = TRUE;
g_main_loop_quit (data->loop);
return TRUE;
return G_SOURCE_CONTINUE;
}
gboolean