mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
gio: (belatedly) port gdbus from GSimpleAsyncResult to GTask
https://bugzilla.gnome.org/show_bug.cgi?id=661767
This commit is contained in:
parent
e2655cd455
commit
f10b6550ff
@ -34,7 +34,7 @@
|
|||||||
#include "gsocketclient.h"
|
#include "gsocketclient.h"
|
||||||
#include "giostream.h"
|
#include "giostream.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "glib-private.h"
|
#include "glib-private.h"
|
||||||
#include "gdbusprivate.h"
|
#include "gdbusprivate.h"
|
||||||
#include "giomodule-priv.h"
|
#include "giomodule-priv.h"
|
||||||
@ -794,7 +794,6 @@ out:
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
gchar *address;
|
gchar *address;
|
||||||
GIOStream *stream;
|
|
||||||
gchar *guid;
|
gchar *guid;
|
||||||
} GetStreamData;
|
} GetStreamData;
|
||||||
|
|
||||||
@ -802,29 +801,28 @@ static void
|
|||||||
get_stream_data_free (GetStreamData *data)
|
get_stream_data_free (GetStreamData *data)
|
||||||
{
|
{
|
||||||
g_free (data->address);
|
g_free (data->address);
|
||||||
if (data->stream != NULL)
|
|
||||||
g_object_unref (data->stream);
|
|
||||||
g_free (data->guid);
|
g_free (data->guid);
|
||||||
g_free (data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_stream_thread_func (GSimpleAsyncResult *res,
|
get_stream_thread_func (GTask *task,
|
||||||
GObject *object,
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
GetStreamData *data;
|
GetStreamData *data = task_data;
|
||||||
GError *error;
|
GIOStream *stream;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (res);
|
stream = g_dbus_address_get_stream_sync (data->address,
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
data->stream = g_dbus_address_get_stream_sync (data->address,
|
|
||||||
&data->guid,
|
&data->guid,
|
||||||
cancellable,
|
cancellable,
|
||||||
&error);
|
&error);
|
||||||
if (data->stream == NULL)
|
if (stream)
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_pointer (task, stream, g_object_unref);
|
||||||
|
else
|
||||||
|
g_task_return_error (task, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -853,26 +851,18 @@ g_dbus_address_get_stream (const gchar *address,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
GetStreamData *data;
|
GetStreamData *data;
|
||||||
|
|
||||||
g_return_if_fail (address != NULL);
|
g_return_if_fail (address != NULL);
|
||||||
|
|
||||||
res = g_simple_async_result_new (NULL,
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
g_dbus_address_get_stream);
|
|
||||||
g_simple_async_result_set_check_cancellable (res, cancellable);
|
|
||||||
data = g_new0 (GetStreamData, 1);
|
data = g_new0 (GetStreamData, 1);
|
||||||
data->address = g_strdup (address);
|
data->address = g_strdup (address);
|
||||||
g_simple_async_result_set_op_res_gpointer (res,
|
|
||||||
data,
|
task = g_task_new (NULL, cancellable, callback, user_data);
|
||||||
(GDestroyNotify) get_stream_data_free);
|
g_task_set_task_data (task, data, (GDestroyNotify) get_stream_data_free);
|
||||||
g_simple_async_result_run_in_thread (res,
|
g_task_run_in_thread (task, get_stream_thread_func);
|
||||||
get_stream_thread_func,
|
g_object_unref (task);
|
||||||
G_PRIORITY_DEFAULT,
|
|
||||||
cancellable);
|
|
||||||
g_object_unref (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -892,26 +882,23 @@ g_dbus_address_get_stream_finish (GAsyncResult *res,
|
|||||||
gchar **out_guid,
|
gchar **out_guid,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
GTask *task;
|
||||||
GetStreamData *data;
|
GetStreamData *data;
|
||||||
GIOStream *ret;
|
GIOStream *ret;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
g_return_val_if_fail (g_task_is_valid (res, NULL), NULL);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_address_get_stream);
|
task = G_TASK (res);
|
||||||
|
ret = g_task_propagate_pointer (task, error);
|
||||||
|
|
||||||
ret = NULL;
|
if (ret != NULL && out_guid != NULL)
|
||||||
|
{
|
||||||
|
data = g_task_get_task_data (task);
|
||||||
|
*out_guid = data->guid;
|
||||||
|
data->guid = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = g_object_ref (data->stream);
|
|
||||||
if (out_guid != NULL)
|
|
||||||
*out_guid = g_strdup (data->guid);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@
|
|||||||
#include "gasyncinitable.h"
|
#include "gasyncinitable.h"
|
||||||
#include "giostream.h"
|
#include "giostream.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
#include "gunixconnection.h"
|
#include "gunixconnection.h"
|
||||||
@ -432,7 +432,7 @@ struct _GDBusConnection
|
|||||||
GDBusConnectionFlags flags;
|
GDBusConnectionFlags flags;
|
||||||
|
|
||||||
/* Map used for managing method replies, protected by @lock */
|
/* Map used for managing method replies, protected by @lock */
|
||||||
GHashTable *map_method_serial_to_send_message_data; /* guint32 -> SendMessageData* */
|
GHashTable *map_method_serial_to_task; /* guint32 -> GTask* */
|
||||||
|
|
||||||
/* Maps used for managing signal subscription, protected by @lock */
|
/* Maps used for managing signal subscription, protected by @lock */
|
||||||
GHashTable *map_rule_to_signal_data; /* match rule (gchar*) -> SignalData */
|
GHashTable *map_rule_to_signal_data; /* match rule (gchar*) -> SignalData */
|
||||||
@ -679,7 +679,7 @@ g_dbus_connection_finalize (GObject *object)
|
|||||||
if (connection->initialization_error != NULL)
|
if (connection->initialization_error != NULL)
|
||||||
g_error_free (connection->initialization_error);
|
g_error_free (connection->initialization_error);
|
||||||
|
|
||||||
g_hash_table_unref (connection->map_method_serial_to_send_message_data);
|
g_hash_table_unref (connection->map_method_serial_to_task);
|
||||||
|
|
||||||
g_hash_table_unref (connection->map_rule_to_signal_data);
|
g_hash_table_unref (connection->map_rule_to_signal_data);
|
||||||
g_hash_table_unref (connection->map_id_to_signal_data);
|
g_hash_table_unref (connection->map_id_to_signal_data);
|
||||||
@ -1077,7 +1077,7 @@ g_dbus_connection_init (GDBusConnection *connection)
|
|||||||
g_mutex_init (&connection->lock);
|
g_mutex_init (&connection->lock);
|
||||||
g_mutex_init (&connection->init_lock);
|
g_mutex_init (&connection->init_lock);
|
||||||
|
|
||||||
connection->map_method_serial_to_send_message_data = g_hash_table_new (g_direct_hash, g_direct_equal);
|
connection->map_method_serial_to_task = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
|
|
||||||
connection->map_rule_to_signal_data = g_hash_table_new (g_str_hash,
|
connection->map_rule_to_signal_data = g_hash_table_new (g_str_hash,
|
||||||
g_str_equal);
|
g_str_equal);
|
||||||
@ -1210,17 +1210,19 @@ g_dbus_connection_get_capabilities (GDBusConnection *connection)
|
|||||||
|
|
||||||
/* Called in a temporary thread without holding locks. */
|
/* Called in a temporary thread without holding locks. */
|
||||||
static void
|
static void
|
||||||
flush_in_thread_func (GSimpleAsyncResult *res,
|
flush_in_thread_func (GTask *task,
|
||||||
GObject *object,
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
|
|
||||||
error = NULL;
|
if (g_dbus_connection_flush_sync (source_object,
|
||||||
if (!g_dbus_connection_flush_sync (G_DBUS_CONNECTION (object),
|
|
||||||
cancellable,
|
cancellable,
|
||||||
&error))
|
&error))
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_boolean (task, TRUE);
|
||||||
|
else
|
||||||
|
g_task_return_error (task, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1254,20 +1256,13 @@ g_dbus_connection_flush (GDBusConnection *connection,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
|
|
||||||
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
|
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
|
||||||
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (connection),
|
task = g_task_new (connection, cancellable, callback, user_data);
|
||||||
callback,
|
g_task_run_in_thread (task, flush_in_thread_func);
|
||||||
user_data,
|
g_object_unref (task);
|
||||||
g_dbus_connection_flush);
|
|
||||||
g_simple_async_result_set_check_cancellable (simple, cancellable);
|
|
||||||
g_simple_async_result_run_in_thread (simple,
|
|
||||||
flush_in_thread_func,
|
|
||||||
G_PRIORITY_DEFAULT,
|
|
||||||
cancellable);
|
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1288,24 +1283,11 @@ g_dbus_connection_flush_finish (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
ret = FALSE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
|
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
|
||||||
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
|
g_return_val_if_fail (g_task_is_valid (res, connection), FALSE);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_connection_flush);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1464,7 +1446,7 @@ g_dbus_connection_close (GDBusConnection *connection,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
|
|
||||||
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
|
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
|
||||||
|
|
||||||
@ -1474,13 +1456,9 @@ g_dbus_connection_close (GDBusConnection *connection,
|
|||||||
|
|
||||||
g_assert (connection->worker != NULL);
|
g_assert (connection->worker != NULL);
|
||||||
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (connection),
|
task = g_task_new (connection, cancellable, callback, user_data);
|
||||||
callback,
|
_g_dbus_worker_close (connection->worker, task);
|
||||||
user_data,
|
g_object_unref (task);
|
||||||
g_dbus_connection_close);
|
|
||||||
g_simple_async_result_set_check_cancellable (simple, cancellable);
|
|
||||||
_g_dbus_worker_close (connection->worker, cancellable, simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1501,24 +1479,11 @@ g_dbus_connection_close_finish (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
ret = FALSE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
|
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
|
||||||
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
|
g_return_val_if_fail (g_task_is_valid (res, connection), FALSE);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_connection_close);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -1781,14 +1746,7 @@ g_dbus_connection_send_message (GDBusConnection *connection,
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
volatile gint ref_count;
|
|
||||||
GDBusConnection *connection;
|
|
||||||
guint32 serial;
|
guint32 serial;
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
|
|
||||||
GMainContext *main_context;
|
|
||||||
|
|
||||||
GCancellable *cancellable;
|
|
||||||
|
|
||||||
gulong cancellable_handler_id;
|
gulong cancellable_handler_id;
|
||||||
|
|
||||||
@ -1797,47 +1755,31 @@ typedef struct
|
|||||||
gboolean delivered;
|
gboolean delivered;
|
||||||
} SendMessageData;
|
} SendMessageData;
|
||||||
|
|
||||||
/* Can be called from any thread with or without lock held */
|
|
||||||
static SendMessageData *
|
|
||||||
send_message_data_ref (SendMessageData *data)
|
|
||||||
{
|
|
||||||
g_atomic_int_inc (&data->ref_count);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Can be called from any thread with or without lock held */
|
/* Can be called from any thread with or without lock held */
|
||||||
static void
|
static void
|
||||||
send_message_data_unref (SendMessageData *data)
|
send_message_data_free (SendMessageData *data)
|
||||||
{
|
{
|
||||||
if (g_atomic_int_dec_and_test (&data->ref_count))
|
|
||||||
{
|
|
||||||
g_assert (data->timeout_source == NULL);
|
g_assert (data->timeout_source == NULL);
|
||||||
g_assert (data->simple == NULL);
|
|
||||||
g_assert (data->cancellable_handler_id == 0);
|
g_assert (data->cancellable_handler_id == 0);
|
||||||
g_object_unref (data->connection);
|
|
||||||
if (data->cancellable != NULL)
|
g_slice_free (SendMessageData, data);
|
||||||
g_object_unref (data->cancellable);
|
|
||||||
g_main_context_unref (data->main_context);
|
|
||||||
g_free (data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* can be called from any thread with lock held - caller must have prepared GSimpleAsyncResult already */
|
/* can be called from any thread with lock held */
|
||||||
static void
|
static void
|
||||||
send_message_with_reply_deliver (SendMessageData *data, gboolean remove)
|
send_message_with_reply_cleanup (GTask *task, gboolean remove)
|
||||||
{
|
{
|
||||||
CONNECTION_ENSURE_LOCK (data->connection);
|
GDBusConnection *connection = g_task_get_source_object (task);
|
||||||
|
SendMessageData *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
|
CONNECTION_ENSURE_LOCK (connection);
|
||||||
|
|
||||||
g_assert (!data->delivered);
|
g_assert (!data->delivered);
|
||||||
|
|
||||||
data->delivered = TRUE;
|
data->delivered = TRUE;
|
||||||
|
|
||||||
g_simple_async_result_complete_in_idle (data->simple);
|
|
||||||
g_object_unref (data->simple);
|
|
||||||
data->simple = NULL;
|
|
||||||
|
|
||||||
if (data->timeout_source != NULL)
|
if (data->timeout_source != NULL)
|
||||||
{
|
{
|
||||||
g_source_destroy (data->timeout_source);
|
g_source_destroy (data->timeout_source);
|
||||||
@ -1845,34 +1787,35 @@ send_message_with_reply_deliver (SendMessageData *data, gboolean remove)
|
|||||||
}
|
}
|
||||||
if (data->cancellable_handler_id > 0)
|
if (data->cancellable_handler_id > 0)
|
||||||
{
|
{
|
||||||
g_cancellable_disconnect (data->cancellable, data->cancellable_handler_id);
|
g_cancellable_disconnect (g_task_get_cancellable (task), data->cancellable_handler_id);
|
||||||
data->cancellable_handler_id = 0;
|
data->cancellable_handler_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove)
|
if (remove)
|
||||||
{
|
{
|
||||||
g_warn_if_fail (g_hash_table_remove (data->connection->map_method_serial_to_send_message_data,
|
gboolean removed = g_hash_table_remove (connection->map_method_serial_to_task,
|
||||||
GUINT_TO_POINTER (data->serial)));
|
GUINT_TO_POINTER (data->serial));
|
||||||
|
g_warn_if_fail (removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
send_message_data_unref (data);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* Can be called from any thread with lock held */
|
/* Can be called from any thread with lock held */
|
||||||
static void
|
static void
|
||||||
send_message_data_deliver_reply_unlocked (SendMessageData *data,
|
send_message_data_deliver_reply_unlocked (GTask *task,
|
||||||
GDBusMessage *reply)
|
GDBusMessage *reply)
|
||||||
{
|
{
|
||||||
|
SendMessageData *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
if (data->delivered)
|
if (data->delivered)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gpointer (data->simple,
|
g_task_return_pointer (task, g_object_ref (reply), g_object_unref);
|
||||||
g_object_ref (reply),
|
|
||||||
g_object_unref);
|
|
||||||
|
|
||||||
send_message_with_reply_deliver (data, TRUE);
|
send_message_with_reply_cleanup (task, TRUE);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
;
|
;
|
||||||
@ -1884,21 +1827,23 @@ send_message_data_deliver_reply_unlocked (SendMessageData *data,
|
|||||||
static gboolean
|
static gboolean
|
||||||
send_message_with_reply_cancelled_idle_cb (gpointer user_data)
|
send_message_with_reply_cancelled_idle_cb (gpointer user_data)
|
||||||
{
|
{
|
||||||
SendMessageData *data = user_data;
|
GTask *task = user_data;
|
||||||
|
GDBusConnection *connection = g_task_get_source_object (task);
|
||||||
|
SendMessageData *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
CONNECTION_LOCK (data->connection);
|
CONNECTION_LOCK (connection);
|
||||||
if (data->delivered)
|
if (data->delivered)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_simple_async_result_set_error (data->simple,
|
g_task_return_new_error (task,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_CANCELLED,
|
G_IO_ERROR_CANCELLED,
|
||||||
_("Operation was cancelled"));
|
_("Operation was cancelled"));
|
||||||
|
|
||||||
send_message_with_reply_deliver (data, TRUE);
|
send_message_with_reply_cleanup (task, TRUE);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
CONNECTION_UNLOCK (data->connection);
|
CONNECTION_UNLOCK (connection);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1907,20 +1852,15 @@ static void
|
|||||||
send_message_with_reply_cancelled_cb (GCancellable *cancellable,
|
send_message_with_reply_cancelled_cb (GCancellable *cancellable,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
SendMessageData *data = user_data;
|
GTask *task = user_data;
|
||||||
GSource *idle_source;
|
GSource *idle_source;
|
||||||
|
|
||||||
/* postpone cancellation to idle handler since we may be called directly
|
/* postpone cancellation to idle handler since we may be called directly
|
||||||
* via g_cancellable_connect() (e.g. holding lock)
|
* via g_cancellable_connect() (e.g. holding lock)
|
||||||
*/
|
*/
|
||||||
idle_source = g_idle_source_new ();
|
idle_source = g_idle_source_new ();
|
||||||
g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
|
|
||||||
g_source_set_callback (idle_source,
|
|
||||||
send_message_with_reply_cancelled_idle_cb,
|
|
||||||
send_message_data_ref (data),
|
|
||||||
(GDestroyNotify) send_message_data_unref);
|
|
||||||
g_source_set_name (idle_source, "[gio] send_message_with_reply_cancelled_idle_cb");
|
g_source_set_name (idle_source, "[gio] send_message_with_reply_cancelled_idle_cb");
|
||||||
g_source_attach (idle_source, data->main_context);
|
g_task_attach_source (task, idle_source, send_message_with_reply_cancelled_idle_cb);
|
||||||
g_source_unref (idle_source);
|
g_source_unref (idle_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1930,21 +1870,23 @@ send_message_with_reply_cancelled_cb (GCancellable *cancellable,
|
|||||||
static gboolean
|
static gboolean
|
||||||
send_message_with_reply_timeout_cb (gpointer user_data)
|
send_message_with_reply_timeout_cb (gpointer user_data)
|
||||||
{
|
{
|
||||||
SendMessageData *data = user_data;
|
GTask *task = user_data;
|
||||||
|
GDBusConnection *connection = g_task_get_source_object (task);
|
||||||
|
SendMessageData *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
CONNECTION_LOCK (data->connection);
|
CONNECTION_LOCK (connection);
|
||||||
if (data->delivered)
|
if (data->delivered)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_simple_async_result_set_error (data->simple,
|
g_task_return_new_error (task,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_TIMED_OUT,
|
G_IO_ERROR_TIMED_OUT,
|
||||||
_("Timeout was reached"));
|
_("Timeout was reached"));
|
||||||
|
|
||||||
send_message_with_reply_deliver (data, TRUE);
|
send_message_with_reply_cleanup (task, TRUE);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
CONNECTION_UNLOCK (data->connection);
|
CONNECTION_UNLOCK (connection);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1962,79 +1904,54 @@ g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection *connect
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
SendMessageData *data;
|
SendMessageData *data;
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
volatile guint32 serial;
|
volatile guint32 serial;
|
||||||
|
|
||||||
data = NULL;
|
|
||||||
|
|
||||||
if (out_serial == NULL)
|
if (out_serial == NULL)
|
||||||
out_serial = &serial;
|
out_serial = &serial;
|
||||||
|
|
||||||
if (timeout_msec == -1)
|
if (timeout_msec == -1)
|
||||||
timeout_msec = 25 * 1000;
|
timeout_msec = 25 * 1000;
|
||||||
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (connection),
|
data = g_slice_new0 (SendMessageData);
|
||||||
callback,
|
task = g_task_new (connection, cancellable, callback, user_data);
|
||||||
user_data,
|
g_task_set_task_data (task, data, (GDestroyNotify) send_message_data_free);
|
||||||
g_dbus_connection_send_message_with_reply);
|
|
||||||
g_simple_async_result_set_check_cancellable (simple, cancellable);
|
|
||||||
|
|
||||||
if (g_cancellable_is_cancelled (cancellable))
|
if (g_task_return_error_if_cancelled (task))
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_error (simple,
|
g_object_unref (task);
|
||||||
G_IO_ERROR,
|
return;
|
||||||
G_IO_ERROR_CANCELLED,
|
|
||||||
_("Operation was cancelled"));
|
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
if (!g_dbus_connection_send_message_unlocked (connection, message, flags, out_serial, &error))
|
if (!g_dbus_connection_send_message_unlocked (connection, message, flags, out_serial, &error))
|
||||||
{
|
{
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
return;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = g_new0 (SendMessageData, 1);
|
|
||||||
data->ref_count = 1;
|
|
||||||
data->connection = g_object_ref (connection);
|
|
||||||
data->simple = simple;
|
|
||||||
data->serial = *out_serial;
|
data->serial = *out_serial;
|
||||||
data->main_context = g_main_context_ref_thread_default ();
|
|
||||||
|
|
||||||
if (cancellable != NULL)
|
if (cancellable != NULL)
|
||||||
{
|
{
|
||||||
data->cancellable = g_object_ref (cancellable);
|
|
||||||
data->cancellable_handler_id = g_cancellable_connect (cancellable,
|
data->cancellable_handler_id = g_cancellable_connect (cancellable,
|
||||||
G_CALLBACK (send_message_with_reply_cancelled_cb),
|
G_CALLBACK (send_message_with_reply_cancelled_cb),
|
||||||
send_message_data_ref (data),
|
g_object_ref (task),
|
||||||
(GDestroyNotify) send_message_data_unref);
|
g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout_msec != G_MAXINT)
|
if (timeout_msec != G_MAXINT)
|
||||||
{
|
{
|
||||||
data->timeout_source = g_timeout_source_new (timeout_msec);
|
data->timeout_source = g_timeout_source_new (timeout_msec);
|
||||||
g_source_set_priority (data->timeout_source, G_PRIORITY_DEFAULT);
|
g_task_attach_source (task, data->timeout_source,
|
||||||
g_source_set_callback (data->timeout_source,
|
(GSourceFunc) send_message_with_reply_timeout_cb);
|
||||||
send_message_with_reply_timeout_cb,
|
|
||||||
send_message_data_ref (data),
|
|
||||||
(GDestroyNotify) send_message_data_unref);
|
|
||||||
g_source_attach (data->timeout_source, data->main_context);
|
|
||||||
g_source_unref (data->timeout_source);
|
g_source_unref (data->timeout_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_insert (connection->map_method_serial_to_send_message_data,
|
g_hash_table_insert (connection->map_method_serial_to_task,
|
||||||
GUINT_TO_POINTER (*out_serial),
|
GUINT_TO_POINTER (*out_serial),
|
||||||
data);
|
task);
|
||||||
|
|
||||||
out:
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2135,23 +2052,11 @@ g_dbus_connection_send_message_with_reply_finish (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
||||||
GDBusMessage *reply;
|
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
||||||
|
g_return_val_if_fail (g_task_is_valid (res, connection), NULL);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
reply = NULL;
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_connection_send_message_with_reply);
|
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
reply = g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
|
|
||||||
|
|
||||||
out:
|
|
||||||
return reply;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -2229,7 +2134,7 @@ g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connecti
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
SendMessageSyncData *data;
|
SendMessageSyncData data;
|
||||||
GDBusMessage *reply;
|
GDBusMessage *reply;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
||||||
@ -2238,11 +2143,11 @@ g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connecti
|
|||||||
g_return_val_if_fail (timeout_msec >= 0 || timeout_msec == -1, NULL);
|
g_return_val_if_fail (timeout_msec >= 0 || timeout_msec == -1, NULL);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
data = g_new0 (SendMessageSyncData, 1);
|
data.res = NULL;
|
||||||
data->context = g_main_context_new ();
|
data.context = g_main_context_new ();
|
||||||
data->loop = g_main_loop_new (data->context, FALSE);
|
data.loop = g_main_loop_new (data.context, FALSE);
|
||||||
|
|
||||||
g_main_context_push_thread_default (data->context);
|
g_main_context_push_thread_default (data.context);
|
||||||
|
|
||||||
g_dbus_connection_send_message_with_reply (connection,
|
g_dbus_connection_send_message_with_reply (connection,
|
||||||
message,
|
message,
|
||||||
@ -2251,18 +2156,18 @@ g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connecti
|
|||||||
out_serial,
|
out_serial,
|
||||||
cancellable,
|
cancellable,
|
||||||
(GAsyncReadyCallback) send_message_with_reply_sync_cb,
|
(GAsyncReadyCallback) send_message_with_reply_sync_cb,
|
||||||
data);
|
&data);
|
||||||
g_main_loop_run (data->loop);
|
g_main_loop_run (data.loop);
|
||||||
reply = g_dbus_connection_send_message_with_reply_finish (connection,
|
reply = g_dbus_connection_send_message_with_reply_finish (connection,
|
||||||
data->res,
|
data.res,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
g_main_context_pop_thread_default (data->context);
|
g_main_context_pop_thread_default (data.context);
|
||||||
|
|
||||||
g_main_context_unref (data->context);
|
g_main_context_unref (data.context);
|
||||||
g_main_loop_unref (data->loop);
|
g_main_loop_unref (data.loop);
|
||||||
g_object_unref (data->res);
|
if (data.res)
|
||||||
g_free (data);
|
g_object_unref (data.res);
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
@ -2348,16 +2253,16 @@ on_worker_message_received (GDBusWorker *worker,
|
|||||||
if (message_type == G_DBUS_MESSAGE_TYPE_METHOD_RETURN || message_type == G_DBUS_MESSAGE_TYPE_ERROR)
|
if (message_type == G_DBUS_MESSAGE_TYPE_METHOD_RETURN || message_type == G_DBUS_MESSAGE_TYPE_ERROR)
|
||||||
{
|
{
|
||||||
guint32 reply_serial;
|
guint32 reply_serial;
|
||||||
SendMessageData *send_message_data;
|
GTask *task;
|
||||||
|
|
||||||
reply_serial = g_dbus_message_get_reply_serial (message);
|
reply_serial = g_dbus_message_get_reply_serial (message);
|
||||||
CONNECTION_LOCK (connection);
|
CONNECTION_LOCK (connection);
|
||||||
send_message_data = g_hash_table_lookup (connection->map_method_serial_to_send_message_data,
|
task = g_hash_table_lookup (connection->map_method_serial_to_task,
|
||||||
GUINT_TO_POINTER (reply_serial));
|
GUINT_TO_POINTER (reply_serial));
|
||||||
if (send_message_data != NULL)
|
if (task != NULL)
|
||||||
{
|
{
|
||||||
//g_debug ("delivering reply/error for serial %d for %p", reply_serial, connection);
|
//g_debug ("delivering reply/error for serial %d for %p", reply_serial, connection);
|
||||||
send_message_data_deliver_reply_unlocked (send_message_data, message);
|
send_message_data_deliver_reply_unlocked (task, message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2444,21 +2349,22 @@ on_worker_message_about_to_be_sent (GDBusWorker *worker,
|
|||||||
static gboolean
|
static gboolean
|
||||||
cancel_method_on_close (gpointer key, gpointer value, gpointer user_data)
|
cancel_method_on_close (gpointer key, gpointer value, gpointer user_data)
|
||||||
{
|
{
|
||||||
SendMessageData *data = value;
|
GTask *task = value;
|
||||||
|
SendMessageData *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
if (data->delivered)
|
if (data->delivered)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
g_simple_async_result_set_error (data->simple,
|
g_task_return_new_error (task,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_CLOSED,
|
G_IO_ERROR_CLOSED,
|
||||||
_("The connection is closed"));
|
_("The connection is closed"));
|
||||||
|
|
||||||
/* Ask send_message_with_reply_deliver not to remove the element from the
|
/* Ask send_message_with_reply_cleanup not to remove the element from the
|
||||||
* hash table - we're in the middle of a foreach; that would be unsafe.
|
* hash table - we're in the middle of a foreach; that would be unsafe.
|
||||||
* Instead, return TRUE from this function so that it gets removed safely.
|
* Instead, return TRUE from this function so that it gets removed safely.
|
||||||
*/
|
*/
|
||||||
send_message_with_reply_deliver (data, FALSE);
|
send_message_with_reply_cleanup (task, FALSE);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2495,7 +2401,7 @@ on_worker_closed (GDBusWorker *worker,
|
|||||||
|
|
||||||
if (!(old_atomic_flags & FLAG_CLOSED))
|
if (!(old_atomic_flags & FLAG_CLOSED))
|
||||||
{
|
{
|
||||||
g_hash_table_foreach_remove (connection->map_method_serial_to_send_message_data, cancel_method_on_close, NULL);
|
g_hash_table_foreach_remove (connection->map_method_serial_to_task, cancel_method_on_close, NULL);
|
||||||
schedule_closed_unlocked (connection, remote_peer_vanished, error);
|
schedule_closed_unlocked (connection, remote_peer_vanished, error);
|
||||||
}
|
}
|
||||||
CONNECTION_UNLOCK (connection);
|
CONNECTION_UNLOCK (connection);
|
||||||
@ -5432,12 +5338,10 @@ decode_method_reply (GDBusMessage *reply,
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
GVariantType *reply_type;
|
GVariantType *reply_type;
|
||||||
gchar *method_name; /* for error message */
|
gchar *method_name; /* for error message */
|
||||||
guint32 serial;
|
guint32 serial;
|
||||||
|
|
||||||
GVariant *value;
|
|
||||||
GUnixFDList *fd_list;
|
GUnixFDList *fd_list;
|
||||||
} CallState;
|
} CallState;
|
||||||
|
|
||||||
@ -5447,8 +5351,6 @@ call_state_free (CallState *state)
|
|||||||
g_variant_type_free (state->reply_type);
|
g_variant_type_free (state->reply_type);
|
||||||
g_free (state->method_name);
|
g_free (state->method_name);
|
||||||
|
|
||||||
if (state->value != NULL)
|
|
||||||
g_variant_unref (state->value);
|
|
||||||
if (state->fd_list != NULL)
|
if (state->fd_list != NULL)
|
||||||
g_object_unref (state->fd_list);
|
g_object_unref (state->fd_list);
|
||||||
g_slice_free (CallState, state);
|
g_slice_free (CallState, state);
|
||||||
@ -5460,13 +5362,13 @@ g_dbus_connection_call_done (GObject *source,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
GDBusConnection *connection = G_DBUS_CONNECTION (source);
|
GDBusConnection *connection = G_DBUS_CONNECTION (source);
|
||||||
CallState *state = user_data;
|
GTask *task = user_data;
|
||||||
GError *error;
|
CallState *state = g_task_get_task_data (task);
|
||||||
|
GError *error = NULL;
|
||||||
GDBusMessage *reply;
|
GDBusMessage *reply;
|
||||||
|
GVariant *value = NULL;
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
reply = g_dbus_connection_send_message_with_reply_finish (connection,
|
reply = g_dbus_connection_send_message_with_reply_finish (connection,
|
||||||
result,
|
result,
|
||||||
&error);
|
&error);
|
||||||
@ -5493,22 +5395,15 @@ g_dbus_connection_call_done (GObject *source,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reply != NULL)
|
if (reply != NULL)
|
||||||
state->value = decode_method_reply (reply, state->method_name, state->reply_type, &state->fd_list, &error);
|
value = decode_method_reply (reply, state->method_name, state->reply_type, &state->fd_list, &error);
|
||||||
|
|
||||||
simple = state->simple; /* why? because state is freed before we unref simple.. */
|
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
{
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_take_error (state->simple, error);
|
|
||||||
g_simple_async_result_complete (state->simple);
|
|
||||||
call_state_free (state);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
g_task_return_pointer (task, value, (GDestroyNotify) g_variant_unref);
|
||||||
g_simple_async_result_set_op_res_gpointer (state->simple, state, (GDestroyNotify) call_state_free);
|
|
||||||
g_simple_async_result_complete (state->simple);
|
|
||||||
}
|
|
||||||
g_clear_object (&reply);
|
g_clear_object (&reply);
|
||||||
g_object_unref (simple);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called in any thread, with the connection's lock not held */
|
/* called in any thread, with the connection's lock not held */
|
||||||
@ -5565,12 +5460,9 @@ g_dbus_connection_call_internal (GDBusConnection *connection,
|
|||||||
if (callback != NULL)
|
if (callback != NULL)
|
||||||
{
|
{
|
||||||
CallState *state;
|
CallState *state;
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
state = g_slice_new0 (CallState);
|
state = g_slice_new0 (CallState);
|
||||||
state->simple = g_simple_async_result_new (G_OBJECT (connection),
|
|
||||||
callback, user_data,
|
|
||||||
g_dbus_connection_call_internal);
|
|
||||||
g_simple_async_result_set_check_cancellable (state->simple, cancellable);
|
|
||||||
state->method_name = g_strjoin (".", interface_name, method_name, NULL);
|
state->method_name = g_strjoin (".", interface_name, method_name, NULL);
|
||||||
|
|
||||||
if (reply_type == NULL)
|
if (reply_type == NULL)
|
||||||
@ -5578,6 +5470,9 @@ g_dbus_connection_call_internal (GDBusConnection *connection,
|
|||||||
|
|
||||||
state->reply_type = g_variant_type_copy (reply_type);
|
state->reply_type = g_variant_type_copy (reply_type);
|
||||||
|
|
||||||
|
task = g_task_new (connection, cancellable, callback, user_data);
|
||||||
|
g_task_set_task_data (task, state, (GDestroyNotify) call_state_free);
|
||||||
|
|
||||||
g_dbus_connection_send_message_with_reply (connection,
|
g_dbus_connection_send_message_with_reply (connection,
|
||||||
message,
|
message,
|
||||||
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
|
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
|
||||||
@ -5585,7 +5480,7 @@ g_dbus_connection_call_internal (GDBusConnection *connection,
|
|||||||
&state->serial,
|
&state->serial,
|
||||||
cancellable,
|
cancellable,
|
||||||
g_dbus_connection_call_done,
|
g_dbus_connection_call_done,
|
||||||
state);
|
task);
|
||||||
serial = state->serial;
|
serial = state->serial;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -5629,23 +5524,24 @@ g_dbus_connection_call_finish_internal (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
CallState *state;
|
CallState *state;
|
||||||
|
GVariant *ret;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
|
||||||
g_return_val_if_fail (g_simple_async_result_is_valid (res, G_OBJECT (connection),
|
g_return_val_if_fail (g_task_is_valid (res, connection), NULL);
|
||||||
g_dbus_connection_call_internal), NULL);
|
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
simple = G_SIMPLE_ASYNC_RESULT (res);
|
task = G_TASK (res);
|
||||||
|
state = g_task_get_task_data (task);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
ret = g_task_propagate_pointer (task, error);
|
||||||
|
if (!ret)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
state = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
if (out_fd_list != NULL)
|
if (out_fd_list != NULL)
|
||||||
*out_fd_list = state->fd_list != NULL ? g_object_ref (state->fd_list) : NULL;
|
*out_fd_list = state->fd_list != NULL ? g_object_ref (state->fd_list) : NULL;
|
||||||
return g_variant_ref (state->value);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called in any user thread, with the connection's lock not held */
|
/* called in any user thread, with the connection's lock not held */
|
||||||
@ -7069,26 +6965,22 @@ bus_get_async_initable_cb (GObject *source_object,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = user_data;
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source_object),
|
if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source_object),
|
||||||
res,
|
res,
|
||||||
&error))
|
&error))
|
||||||
{
|
{
|
||||||
g_assert (error != NULL);
|
g_assert (error != NULL);
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
g_object_unref (source_object);
|
g_object_unref (source_object);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_op_res_gpointer (simple,
|
g_task_return_pointer (task, source_object, g_object_unref);
|
||||||
source_object,
|
|
||||||
g_object_unref);
|
|
||||||
}
|
}
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7115,23 +7007,17 @@ g_bus_get (GBusType bus_type,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GDBusConnection *connection;
|
GDBusConnection *connection;
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
|
|
||||||
simple = g_simple_async_result_new (NULL,
|
task = g_task_new (NULL, cancellable, callback, user_data);
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
g_bus_get);
|
|
||||||
g_simple_async_result_set_check_cancellable (simple, cancellable);
|
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
connection = get_uninitialized_connection (bus_type, cancellable, &error);
|
connection = get_uninitialized_connection (bus_type, cancellable, &error);
|
||||||
if (connection == NULL)
|
if (connection == NULL)
|
||||||
{
|
{
|
||||||
g_assert (error != NULL);
|
g_assert (error != NULL);
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -7139,7 +7025,7 @@ g_bus_get (GBusType bus_type,
|
|||||||
G_PRIORITY_DEFAULT,
|
G_PRIORITY_DEFAULT,
|
||||||
cancellable,
|
cancellable,
|
||||||
bus_get_async_initable_cb,
|
bus_get_async_initable_cb,
|
||||||
simple);
|
task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7169,25 +7055,10 @@ GDBusConnection *
|
|||||||
g_bus_get_finish (GAsyncResult *res,
|
g_bus_get_finish (GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
g_return_val_if_fail (g_task_is_valid (res, NULL), NULL);
|
||||||
GObject *object;
|
|
||||||
GDBusConnection *ret;
|
|
||||||
|
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_bus_get);
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
|
||||||
ret = NULL;
|
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
object = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
g_assert (object != NULL);
|
|
||||||
ret = g_object_ref (G_DBUS_CONNECTION (object));
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
#include "gdbusmessage.h"
|
#include "gdbusmessage.h"
|
||||||
#include "gdbuserror.h"
|
#include "gdbuserror.h"
|
||||||
#include "gdbusintrospection.h"
|
#include "gdbusintrospection.h"
|
||||||
#include "gasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "ginputstream.h"
|
#include "ginputstream.h"
|
||||||
#include "gmemoryinputstream.h"
|
#include "gmemoryinputstream.h"
|
||||||
#include "giostream.h"
|
#include "giostream.h"
|
||||||
@ -99,28 +98,17 @@ _g_dbus_hexdump (const gchar *data, gsize len, guint indent)
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GSocket *socket;
|
|
||||||
GCancellable *cancellable;
|
|
||||||
|
|
||||||
void *buffer;
|
void *buffer;
|
||||||
gsize count;
|
gsize count;
|
||||||
|
|
||||||
GSocketControlMessage ***messages;
|
GSocketControlMessage ***messages;
|
||||||
gint *num_messages;
|
gint *num_messages;
|
||||||
|
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
|
|
||||||
gboolean from_mainloop;
|
|
||||||
} ReadWithControlData;
|
} ReadWithControlData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_with_control_data_free (ReadWithControlData *data)
|
read_with_control_data_free (ReadWithControlData *data)
|
||||||
{
|
{
|
||||||
g_object_unref (data->socket);
|
g_slice_free (ReadWithControlData, data);
|
||||||
if (data->cancellable != NULL)
|
|
||||||
g_object_unref (data->cancellable);
|
|
||||||
g_object_unref (data->simple);
|
|
||||||
g_free (data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -128,7 +116,8 @@ _g_socket_read_with_control_messages_ready (GSocket *socket,
|
|||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ReadWithControlData *data = user_data;
|
GTask *task = user_data;
|
||||||
|
ReadWithControlData *data = g_task_get_task_data (task);
|
||||||
GError *error;
|
GError *error;
|
||||||
gssize result;
|
gssize result;
|
||||||
GInputVector vector;
|
GInputVector vector;
|
||||||
@ -136,29 +125,28 @@ _g_socket_read_with_control_messages_ready (GSocket *socket,
|
|||||||
error = NULL;
|
error = NULL;
|
||||||
vector.buffer = data->buffer;
|
vector.buffer = data->buffer;
|
||||||
vector.size = data->count;
|
vector.size = data->count;
|
||||||
result = g_socket_receive_message (data->socket,
|
result = g_socket_receive_message (socket,
|
||||||
NULL, /* address */
|
NULL, /* address */
|
||||||
&vector,
|
&vector,
|
||||||
1,
|
1,
|
||||||
data->messages,
|
data->messages,
|
||||||
data->num_messages,
|
data->num_messages,
|
||||||
NULL,
|
NULL,
|
||||||
data->cancellable,
|
g_task_get_cancellable (task),
|
||||||
&error);
|
&error);
|
||||||
if (result >= 0)
|
|
||||||
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_op_res_gssize (data->simple, result);
|
g_error_free (error);
|
||||||
}
|
return TRUE;
|
||||||
else
|
|
||||||
{
|
|
||||||
g_assert (error != NULL);
|
|
||||||
g_simple_async_result_take_error (data->simple, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->from_mainloop)
|
g_assert (result >= 0 || error != NULL);
|
||||||
g_simple_async_result_complete (data->simple);
|
if (result >= 0)
|
||||||
|
g_task_return_int (task, result);
|
||||||
else
|
else
|
||||||
g_simple_async_result_complete_in_idle (data->simple);
|
g_task_return_error (task, error);
|
||||||
|
g_object_unref (task);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -174,41 +162,30 @@ _g_socket_read_with_control_messages (GSocket *socket,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
GTask *task;
|
||||||
ReadWithControlData *data;
|
ReadWithControlData *data;
|
||||||
|
GSource *source;
|
||||||
|
|
||||||
data = g_new0 (ReadWithControlData, 1);
|
data = g_slice_new0 (ReadWithControlData);
|
||||||
data->socket = g_object_ref (socket);
|
|
||||||
data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
|
|
||||||
data->buffer = buffer;
|
data->buffer = buffer;
|
||||||
data->count = count;
|
data->count = count;
|
||||||
data->messages = messages;
|
data->messages = messages;
|
||||||
data->num_messages = num_messages;
|
data->num_messages = num_messages;
|
||||||
|
|
||||||
data->simple = g_simple_async_result_new (G_OBJECT (socket),
|
task = g_task_new (socket, cancellable, callback, user_data);
|
||||||
callback,
|
g_task_set_task_data (task, data, (GDestroyNotify) read_with_control_data_free);
|
||||||
user_data,
|
|
||||||
_g_socket_read_with_control_messages);
|
|
||||||
g_simple_async_result_set_check_cancellable (data->simple, cancellable);
|
|
||||||
|
|
||||||
if (!g_socket_condition_check (socket, G_IO_IN))
|
if (g_socket_condition_check (socket, G_IO_IN))
|
||||||
{
|
{
|
||||||
GSource *source;
|
if (!_g_socket_read_with_control_messages_ready (socket, G_IO_IN, task))
|
||||||
data->from_mainloop = TRUE;
|
return;
|
||||||
source = g_socket_create_source (data->socket,
|
}
|
||||||
|
|
||||||
|
source = g_socket_create_source (socket,
|
||||||
G_IO_IN | G_IO_HUP | G_IO_ERR,
|
G_IO_IN | G_IO_HUP | G_IO_ERR,
|
||||||
cancellable);
|
cancellable);
|
||||||
g_source_set_callback (source,
|
g_task_attach_source (task, source, (GSourceFunc) _g_socket_read_with_control_messages_ready);
|
||||||
(GSourceFunc) _g_socket_read_with_control_messages_ready,
|
|
||||||
data,
|
|
||||||
(GDestroyNotify) read_with_control_data_free);
|
|
||||||
g_source_attach (source, g_main_context_get_thread_default ());
|
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_g_socket_read_with_control_messages_ready (data->socket, G_IO_IN, data);
|
|
||||||
read_with_control_data_free (data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
@ -216,15 +193,10 @@ _g_socket_read_with_control_messages_finish (GSocket *socket,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_SOCKET (socket), -1);
|
g_return_val_if_fail (G_IS_SOCKET (socket), -1);
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == _g_socket_read_with_control_messages);
|
g_return_val_if_fail (g_task_is_valid (result, socket), -1);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
return g_task_propagate_int (G_TASK (result), error);
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return g_simple_async_result_get_op_res_gssize (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -252,7 +224,7 @@ ensure_required_types (void)
|
|||||||
{
|
{
|
||||||
g_assert (ensured_classes == NULL);
|
g_assert (ensured_classes == NULL);
|
||||||
ensured_classes = g_ptr_array_new ();
|
ensured_classes = g_ptr_array_new ();
|
||||||
ensure_type (G_TYPE_SIMPLE_ASYNC_RESULT);
|
ensure_type (G_TYPE_TASK);
|
||||||
ensure_type (G_TYPE_MEMORY_INPUT_STREAM);
|
ensure_type (G_TYPE_MEMORY_INPUT_STREAM);
|
||||||
}
|
}
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -422,17 +394,12 @@ static void write_message_print_transport_debug (gssize bytes_written,
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GDBusWorker *worker;
|
GDBusWorker *worker;
|
||||||
GCancellable *cancellable;
|
GTask *task;
|
||||||
GSimpleAsyncResult *result;
|
|
||||||
} CloseData;
|
} CloseData;
|
||||||
|
|
||||||
static void close_data_free (CloseData *close_data)
|
static void close_data_free (CloseData *close_data)
|
||||||
{
|
{
|
||||||
if (close_data->cancellable != NULL)
|
g_clear_object (&close_data->task);
|
||||||
g_object_unref (close_data->cancellable);
|
|
||||||
|
|
||||||
if (close_data->result != NULL)
|
|
||||||
g_object_unref (close_data->result);
|
|
||||||
|
|
||||||
_g_dbus_worker_unref (close_data->worker);
|
_g_dbus_worker_unref (close_data->worker);
|
||||||
g_slice_free (CloseData, close_data);
|
g_slice_free (CloseData, close_data);
|
||||||
@ -891,8 +858,7 @@ struct _MessageToWriteData
|
|||||||
gsize blob_size;
|
gsize blob_size;
|
||||||
|
|
||||||
gsize total_written;
|
gsize total_written;
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -902,7 +868,7 @@ message_to_write_data_free (MessageToWriteData *data)
|
|||||||
if (data->message)
|
if (data->message)
|
||||||
g_object_unref (data->message);
|
g_object_unref (data->message);
|
||||||
g_free (data->blob);
|
g_free (data->blob);
|
||||||
g_free (data);
|
g_slice_free (MessageToWriteData, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -920,14 +886,14 @@ write_message_async_cb (GObject *source_object,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MessageToWriteData *data = user_data;
|
MessageToWriteData *data = user_data;
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
gssize bytes_written;
|
gssize bytes_written;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
/* Note: we can't access data->simple after calling g_async_result_complete () because the
|
/* Note: we can't access data->task after calling g_task_return_* () because the
|
||||||
* callback can free @data and we're not completing in idle. So use a copy of the pointer.
|
* callback can free @data and we're not completing in idle. So use a copy of the pointer.
|
||||||
*/
|
*/
|
||||||
simple = data->simple;
|
task = data->task;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
bytes_written = g_output_stream_write_finish (G_OUTPUT_STREAM (source_object),
|
bytes_written = g_output_stream_write_finish (G_OUTPUT_STREAM (source_object),
|
||||||
@ -935,9 +901,8 @@ write_message_async_cb (GObject *source_object,
|
|||||||
&error);
|
&error);
|
||||||
if (bytes_written == -1)
|
if (bytes_written == -1)
|
||||||
{
|
{
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
g_assert (bytes_written > 0); /* zero is never returned */
|
g_assert (bytes_written > 0); /* zero is never returned */
|
||||||
@ -948,8 +913,8 @@ write_message_async_cb (GObject *source_object,
|
|||||||
g_assert (data->total_written <= data->blob_size);
|
g_assert (data->total_written <= data->blob_size);
|
||||||
if (data->total_written == data->blob_size)
|
if (data->total_written == data->blob_size)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete (simple);
|
g_task_return_boolean (task, TRUE);
|
||||||
g_object_unref (simple);
|
g_object_unref (task);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,15 +951,15 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
{
|
{
|
||||||
GOutputStream *ostream;
|
GOutputStream *ostream;
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
GUnixFDList *fd_list;
|
GUnixFDList *fd_list;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
/* Note: we can't access data->simple after calling g_async_result_complete () because the
|
/* Note: we can't access data->task after calling g_task_return_* () because the
|
||||||
* callback can free @data and we're not completing in idle. So use a copy of the pointer.
|
* callback can free @data and we're not completing in idle. So use a copy of the pointer.
|
||||||
*/
|
*/
|
||||||
simple = data->simple;
|
task = data->task;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ostream = g_io_stream_get_output_stream (data->worker->stream);
|
ostream = g_io_stream_get_output_stream (data->worker->stream);
|
||||||
@ -1024,12 +989,11 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
{
|
{
|
||||||
if (!(data->worker->capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING))
|
if (!(data->worker->capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING))
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_error (simple,
|
g_task_return_new_error (task,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_FAILED,
|
G_IO_ERROR_FAILED,
|
||||||
"Tried sending a file descriptor but remote peer does not support this capability");
|
"Tried sending a file descriptor but remote peer does not support this capability");
|
||||||
g_simple_async_result_complete (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
control_message = g_unix_fd_message_new_with_fd_list (fd_list);
|
control_message = g_unix_fd_message_new_with_fd_list (fd_list);
|
||||||
@ -1066,9 +1030,8 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
g_assert (bytes_written > 0); /* zero is never returned */
|
g_assert (bytes_written > 0); /* zero is never returned */
|
||||||
@ -1079,8 +1042,8 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
g_assert (data->total_written <= data->blob_size);
|
g_assert (data->total_written <= data->blob_size);
|
||||||
if (data->total_written == data->blob_size)
|
if (data->total_written == data->blob_size)
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete (simple);
|
g_task_return_boolean (task, TRUE);
|
||||||
g_object_unref (simple);
|
g_object_unref (task);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1092,13 +1055,12 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
if (fd_list != NULL)
|
if (fd_list != NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_error (simple,
|
g_task_return_new_error (task,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_FAILED,
|
G_IO_ERROR_FAILED,
|
||||||
"Tried sending a file descriptor on unsupported stream of type %s",
|
"Tried sending a file descriptor on unsupported stream of type %s",
|
||||||
g_type_name (G_TYPE_FROM_INSTANCE (ostream)));
|
g_type_name (G_TYPE_FROM_INSTANCE (ostream)));
|
||||||
g_simple_async_result_complete (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1128,10 +1090,7 @@ write_message_async (GDBusWorker *worker,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
data->simple = g_simple_async_result_new (NULL,
|
data->task = g_task_new (NULL, NULL, callback, user_data);
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
write_message_async);
|
|
||||||
data->total_written = 0;
|
data->total_written = 0;
|
||||||
write_message_continue_writing (data);
|
write_message_continue_writing (data);
|
||||||
}
|
}
|
||||||
@ -1141,11 +1100,9 @@ static gboolean
|
|||||||
write_message_finish (GAsyncResult *res,
|
write_message_finish (GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == write_message_async);
|
g_return_val_if_fail (g_task_is_valid (res, NULL), FALSE);
|
||||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
|
||||||
return FALSE;
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
else
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@ -1398,15 +1355,12 @@ iostream_close_cb (GObject *source_object,
|
|||||||
pending_close_attempts = g_list_delete_link (pending_close_attempts,
|
pending_close_attempts = g_list_delete_link (pending_close_attempts,
|
||||||
pending_close_attempts);
|
pending_close_attempts);
|
||||||
|
|
||||||
if (close_data->result != NULL)
|
if (close_data->task != NULL)
|
||||||
{
|
{
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
g_simple_async_result_set_from_error (close_data->result, error);
|
g_task_return_error (close_data->task, g_error_copy (error));
|
||||||
|
else
|
||||||
/* this must be in an idle because the result is likely to be
|
g_task_return_boolean (close_data->task, TRUE);
|
||||||
* intended for another thread
|
|
||||||
*/
|
|
||||||
g_simple_async_result_complete_in_idle (close_data->result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close_data_free (close_data);
|
close_data_free (close_data);
|
||||||
@ -1640,7 +1594,7 @@ _g_dbus_worker_send_message (GDBusWorker *worker,
|
|||||||
g_return_if_fail (blob != NULL);
|
g_return_if_fail (blob != NULL);
|
||||||
g_return_if_fail (blob_len > 16);
|
g_return_if_fail (blob_len > 16);
|
||||||
|
|
||||||
data = g_new0 (MessageToWriteData, 1);
|
data = g_slice_new0 (MessageToWriteData);
|
||||||
data->worker = _g_dbus_worker_ref (worker);
|
data->worker = _g_dbus_worker_ref (worker);
|
||||||
data->message = g_object_ref (message);
|
data->message = g_object_ref (message);
|
||||||
data->blob = blob; /* steal! */
|
data->blob = blob; /* steal! */
|
||||||
@ -1717,16 +1671,13 @@ _g_dbus_worker_new (GIOStream *stream,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
_g_dbus_worker_close (GDBusWorker *worker,
|
_g_dbus_worker_close (GDBusWorker *worker,
|
||||||
GCancellable *cancellable,
|
GTask *task)
|
||||||
GSimpleAsyncResult *result)
|
|
||||||
{
|
{
|
||||||
CloseData *close_data;
|
CloseData *close_data;
|
||||||
|
|
||||||
close_data = g_slice_new0 (CloseData);
|
close_data = g_slice_new0 (CloseData);
|
||||||
close_data->worker = _g_dbus_worker_ref (worker);
|
close_data->worker = _g_dbus_worker_ref (worker);
|
||||||
close_data->cancellable =
|
close_data->task = (task == NULL ? NULL : g_object_ref (task));
|
||||||
(cancellable == NULL ? NULL : g_object_ref (cancellable));
|
|
||||||
close_data->result = (result == NULL ? NULL : g_object_ref (result));
|
|
||||||
|
|
||||||
/* Don't set worker->close_expected here - we're in the wrong thread.
|
/* Don't set worker->close_expected here - we're in the wrong thread.
|
||||||
* It'll be set before the actual close happens.
|
* It'll be set before the actual close happens.
|
||||||
@ -1752,7 +1703,7 @@ _g_dbus_worker_stop (GDBusWorker *worker)
|
|||||||
/* Cancel any pending operations and schedule a close of the underlying I/O
|
/* Cancel any pending operations and schedule a close of the underlying I/O
|
||||||
* stream in the worker thread
|
* stream in the worker thread
|
||||||
*/
|
*/
|
||||||
_g_dbus_worker_close (worker, NULL, NULL);
|
_g_dbus_worker_close (worker, NULL);
|
||||||
|
|
||||||
/* _g_dbus_worker_close holds a ref until after an idle in the worker
|
/* _g_dbus_worker_close holds a ref until after an idle in the worker
|
||||||
* thread has run, so we no longer need to unref in an idle like in
|
* thread has run, so we no longer need to unref in an idle like in
|
||||||
|
@ -76,8 +76,7 @@ gboolean _g_dbus_worker_flush_sync (GDBusWorker *worker,
|
|||||||
|
|
||||||
/* can be called from any thread */
|
/* can be called from any thread */
|
||||||
void _g_dbus_worker_close (GDBusWorker *worker,
|
void _g_dbus_worker_close (GDBusWorker *worker,
|
||||||
GCancellable *cancellable,
|
GTask *task);
|
||||||
GSimpleAsyncResult *result);
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
256
gio/gdbusproxy.c
256
gio/gdbusproxy.c
@ -32,8 +32,7 @@
|
|||||||
#include "ginitable.h"
|
#include "ginitable.h"
|
||||||
#include "gasyncinitable.h"
|
#include "gasyncinitable.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "gasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "gdbusinterface.h"
|
#include "gdbusinterface.h"
|
||||||
|
|
||||||
@ -1411,29 +1410,12 @@ on_name_owner_changed (GDBusConnection *connection,
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GDBusProxy *proxy;
|
|
||||||
GCancellable *cancellable;
|
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
} AsyncInitData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
async_init_data_free (AsyncInitData *data)
|
|
||||||
{
|
|
||||||
g_object_unref (data->proxy);
|
|
||||||
if (data->cancellable != NULL)
|
|
||||||
g_object_unref (data->cancellable);
|
|
||||||
g_object_unref (data->simple);
|
|
||||||
g_free (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
async_init_get_all_cb (GDBusConnection *connection,
|
async_init_get_all_cb (GDBusConnection *connection,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
AsyncInitData *data = user_data;
|
GTask *task = user_data;
|
||||||
GVariant *result;
|
GVariant *result;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
@ -1456,40 +1438,35 @@ async_init_get_all_cb (GDBusConnection *connection,
|
|||||||
//g_debug ("error: %d %d %s", error->domain, error->code, error->message);
|
//g_debug ("error: %d %d %s", error->domain, error->code, error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
g_simple_async_result_set_op_res_gpointer (data->simple,
|
|
||||||
result,
|
|
||||||
(GDestroyNotify) g_variant_unref);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_simple_async_result_complete_in_idle (data->simple);
|
g_task_return_pointer (task, result,
|
||||||
async_init_data_free (data);
|
(GDestroyNotify) g_variant_unref);
|
||||||
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
async_init_data_set_name_owner (AsyncInitData *data,
|
async_init_data_set_name_owner (GTask *task,
|
||||||
const gchar *name_owner)
|
const gchar *name_owner)
|
||||||
{
|
{
|
||||||
|
GDBusProxy *proxy = g_task_get_source_object (task);
|
||||||
gboolean get_all;
|
gboolean get_all;
|
||||||
|
|
||||||
|
|
||||||
if (name_owner != NULL)
|
if (name_owner != NULL)
|
||||||
{
|
{
|
||||||
/* it starts as NULL anyway */
|
/* it starts as NULL anyway */
|
||||||
G_LOCK (properties_lock);
|
G_LOCK (properties_lock);
|
||||||
data->proxy->priv->name_owner = g_strdup (name_owner);
|
proxy->priv->name_owner = g_strdup (name_owner);
|
||||||
G_UNLOCK (properties_lock);
|
G_UNLOCK (properties_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
get_all = TRUE;
|
get_all = TRUE;
|
||||||
|
|
||||||
if (data->proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
|
if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
|
||||||
{
|
{
|
||||||
/* Don't load properties if the API user doesn't want them */
|
/* Don't load properties if the API user doesn't want them */
|
||||||
get_all = FALSE;
|
get_all = FALSE;
|
||||||
}
|
}
|
||||||
else if (name_owner == NULL && data->proxy->priv->name != NULL)
|
else if (name_owner == NULL && proxy->priv->name != NULL)
|
||||||
{
|
{
|
||||||
/* Don't attempt to load properties if the name_owner is NULL (which
|
/* Don't attempt to load properties if the name_owner is NULL (which
|
||||||
* usually means the name isn't owned), unless name is also NULL (which
|
* usually means the name isn't owned), unless name is also NULL (which
|
||||||
@ -1502,23 +1479,23 @@ async_init_data_set_name_owner (AsyncInitData *data,
|
|||||||
if (get_all)
|
if (get_all)
|
||||||
{
|
{
|
||||||
/* load all properties asynchronously */
|
/* load all properties asynchronously */
|
||||||
g_dbus_connection_call (data->proxy->priv->connection,
|
g_dbus_connection_call (proxy->priv->connection,
|
||||||
name_owner,
|
name_owner,
|
||||||
data->proxy->priv->object_path,
|
proxy->priv->object_path,
|
||||||
"org.freedesktop.DBus.Properties",
|
"org.freedesktop.DBus.Properties",
|
||||||
"GetAll",
|
"GetAll",
|
||||||
g_variant_new ("(s)", data->proxy->priv->interface_name),
|
g_variant_new ("(s)", proxy->priv->interface_name),
|
||||||
G_VARIANT_TYPE ("(a{sv})"),
|
G_VARIANT_TYPE ("(a{sv})"),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1, /* timeout */
|
-1, /* timeout */
|
||||||
data->cancellable,
|
g_task_get_cancellable (task),
|
||||||
(GAsyncReadyCallback) async_init_get_all_cb,
|
(GAsyncReadyCallback) async_init_get_all_cb,
|
||||||
data);
|
task);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_simple_async_result_complete_in_idle (data->simple);
|
g_task_return_pointer (task, NULL, NULL);
|
||||||
async_init_data_free (data);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1527,7 +1504,7 @@ async_init_get_name_owner_cb (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
AsyncInitData *data = user_data;
|
GTask *task = user_data;
|
||||||
GError *error;
|
GError *error;
|
||||||
GVariant *result;
|
GVariant *result;
|
||||||
|
|
||||||
@ -1541,13 +1518,12 @@ async_init_get_name_owner_cb (GDBusConnection *connection,
|
|||||||
error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
|
error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
|
||||||
{
|
{
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
async_init_data_set_name_owner (data, NULL);
|
async_init_data_set_name_owner (task, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_simple_async_result_take_error (data->simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete_in_idle (data->simple);
|
g_object_unref (task);
|
||||||
async_init_data_free (data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1556,27 +1532,29 @@ async_init_get_name_owner_cb (GDBusConnection *connection,
|
|||||||
const gchar *name_owner;
|
const gchar *name_owner;
|
||||||
|
|
||||||
g_variant_get (result, "(&s)", &name_owner);
|
g_variant_get (result, "(&s)", &name_owner);
|
||||||
async_init_data_set_name_owner (data, name_owner);
|
async_init_data_set_name_owner (task, name_owner);
|
||||||
g_variant_unref (result);
|
g_variant_unref (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
async_init_call_get_name_owner (AsyncInitData *data)
|
async_init_call_get_name_owner (GTask *task)
|
||||||
{
|
{
|
||||||
g_dbus_connection_call (data->proxy->priv->connection,
|
GDBusProxy *proxy = g_task_get_source_object (task);
|
||||||
|
|
||||||
|
g_dbus_connection_call (proxy->priv->connection,
|
||||||
"org.freedesktop.DBus", /* name */
|
"org.freedesktop.DBus", /* name */
|
||||||
"/org/freedesktop/DBus", /* object path */
|
"/org/freedesktop/DBus", /* object path */
|
||||||
"org.freedesktop.DBus", /* interface */
|
"org.freedesktop.DBus", /* interface */
|
||||||
"GetNameOwner",
|
"GetNameOwner",
|
||||||
g_variant_new ("(s)",
|
g_variant_new ("(s)",
|
||||||
data->proxy->priv->name),
|
proxy->priv->name),
|
||||||
G_VARIANT_TYPE ("(s)"),
|
G_VARIANT_TYPE ("(s)"),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1, /* timeout */
|
-1, /* timeout */
|
||||||
data->cancellable,
|
g_task_get_cancellable (task),
|
||||||
(GAsyncReadyCallback) async_init_get_name_owner_cb,
|
(GAsyncReadyCallback) async_init_get_name_owner_cb,
|
||||||
data);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1584,7 +1562,8 @@ async_init_start_service_by_name_cb (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
AsyncInitData *data = user_data;
|
GTask *task = user_data;
|
||||||
|
GDBusProxy *proxy = g_task_get_source_object (task);
|
||||||
GError *error;
|
GError *error;
|
||||||
GVariant *result;
|
GVariant *result;
|
||||||
|
|
||||||
@ -1628,7 +1607,7 @@ async_init_start_service_by_name_cb (GDBusConnection *connection,
|
|||||||
{
|
{
|
||||||
g_prefix_error (&error,
|
g_prefix_error (&error,
|
||||||
_("Error calling StartServiceByName for %s: "),
|
_("Error calling StartServiceByName for %s: "),
|
||||||
data->proxy->priv->name);
|
proxy->priv->name);
|
||||||
g_free (remote_error);
|
g_free (remote_error);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -1652,38 +1631,39 @@ async_init_start_service_by_name_cb (GDBusConnection *connection,
|
|||||||
G_IO_ERROR_FAILED,
|
G_IO_ERROR_FAILED,
|
||||||
_("Unexpected reply %d from StartServiceByName(\"%s\") method"),
|
_("Unexpected reply %d from StartServiceByName(\"%s\") method"),
|
||||||
start_service_result,
|
start_service_result,
|
||||||
data->proxy->priv->name);
|
proxy->priv->name);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async_init_call_get_name_owner (data);
|
async_init_call_get_name_owner (task);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
g_warn_if_fail (error != NULL);
|
g_warn_if_fail (error != NULL);
|
||||||
g_simple_async_result_take_error (data->simple, error);
|
g_task_return_error (task, error);
|
||||||
g_simple_async_result_complete_in_idle (data->simple);
|
g_object_unref (task);
|
||||||
async_init_data_free (data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
async_init_call_start_service_by_name (AsyncInitData *data)
|
async_init_call_start_service_by_name (GTask *task)
|
||||||
{
|
{
|
||||||
g_dbus_connection_call (data->proxy->priv->connection,
|
GDBusProxy *proxy = g_task_get_source_object (task);
|
||||||
|
|
||||||
|
g_dbus_connection_call (proxy->priv->connection,
|
||||||
"org.freedesktop.DBus", /* name */
|
"org.freedesktop.DBus", /* name */
|
||||||
"/org/freedesktop/DBus", /* object path */
|
"/org/freedesktop/DBus", /* object path */
|
||||||
"org.freedesktop.DBus", /* interface */
|
"org.freedesktop.DBus", /* interface */
|
||||||
"StartServiceByName",
|
"StartServiceByName",
|
||||||
g_variant_new ("(su)",
|
g_variant_new ("(su)",
|
||||||
data->proxy->priv->name,
|
proxy->priv->name,
|
||||||
0),
|
0),
|
||||||
G_VARIANT_TYPE ("(u)"),
|
G_VARIANT_TYPE ("(u)"),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1, /* timeout */
|
-1, /* timeout */
|
||||||
data->cancellable,
|
g_task_get_cancellable (task),
|
||||||
(GAsyncReadyCallback) async_init_start_service_by_name_cb,
|
(GAsyncReadyCallback) async_init_start_service_by_name_cb,
|
||||||
data);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1694,37 +1674,31 @@ async_initable_init_second_async (GAsyncInitable *initable,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GDBusProxy *proxy = G_DBUS_PROXY (initable);
|
GDBusProxy *proxy = G_DBUS_PROXY (initable);
|
||||||
AsyncInitData *data;
|
GTask *task;
|
||||||
|
|
||||||
data = g_new0 (AsyncInitData, 1);
|
task = g_task_new (proxy, cancellable, callback, user_data);
|
||||||
data->proxy = g_object_ref (proxy);
|
g_task_set_priority (task, io_priority);
|
||||||
data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
|
|
||||||
data->simple = g_simple_async_result_new (G_OBJECT (proxy),
|
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
NULL);
|
|
||||||
g_simple_async_result_set_check_cancellable (data->simple, cancellable);
|
|
||||||
|
|
||||||
/* Check name ownership asynchronously - possibly also start the service */
|
/* Check name ownership asynchronously - possibly also start the service */
|
||||||
if (proxy->priv->name == NULL)
|
if (proxy->priv->name == NULL)
|
||||||
{
|
{
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
async_init_data_set_name_owner (data, NULL);
|
async_init_data_set_name_owner (task, NULL);
|
||||||
}
|
}
|
||||||
else if (g_dbus_is_unique_name (proxy->priv->name))
|
else if (g_dbus_is_unique_name (proxy->priv->name))
|
||||||
{
|
{
|
||||||
async_init_data_set_name_owner (data, proxy->priv->name);
|
async_init_data_set_name_owner (task, proxy->priv->name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START) ||
|
if ((proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START) ||
|
||||||
(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION))
|
(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION))
|
||||||
{
|
{
|
||||||
async_init_call_get_name_owner (data);
|
async_init_call_get_name_owner (task);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
async_init_call_start_service_by_name (data);
|
async_init_call_start_service_by_name (task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1735,24 +1709,18 @@ async_initable_init_second_finish (GAsyncInitable *initable,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GDBusProxy *proxy = G_DBUS_PROXY (initable);
|
GDBusProxy *proxy = G_DBUS_PROXY (initable);
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
GTask *task = G_TASK (res);
|
||||||
GVariant *result;
|
GVariant *result;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
ret = FALSE;
|
ret = !g_task_had_error (task);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
result = g_task_propagate_pointer (task, error);
|
||||||
goto out;
|
|
||||||
|
|
||||||
result = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
if (result != NULL)
|
if (result != NULL)
|
||||||
{
|
{
|
||||||
process_get_all_reply (proxy, result);
|
process_get_all_reply (proxy, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
|
|
||||||
out:
|
|
||||||
proxy->priv->initialized = TRUE;
|
proxy->priv->initialized = TRUE;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1815,7 +1783,7 @@ async_initable_init_first (GAsyncInitable *initable)
|
|||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* initialization is split into two parts - the first is the
|
/* initialization is split into two parts - the first is the
|
||||||
* non-blocing part that requires the callers GMainContext - the
|
* non-blocking part that requires the callers GMainContext - the
|
||||||
* second is a blocking part async part that doesn't require the
|
* second is a blocking part async part that doesn't require the
|
||||||
* callers GMainContext.. we do this split so the code can be reused
|
* callers GMainContext.. we do this split so the code can be reused
|
||||||
* in the GInitable implementation below.
|
* in the GInitable implementation below.
|
||||||
@ -1824,52 +1792,46 @@ async_initable_init_first (GAsyncInitable *initable)
|
|||||||
* paths.
|
* paths.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct
|
static void
|
||||||
|
init_second_async_cb (GObject *source_object,
|
||||||
|
GAsyncResult *res,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GDBusProxy *proxy;
|
GTask *task = user_data;
|
||||||
gint io_priority;
|
GError *error = NULL;
|
||||||
GCancellable *cancellable;
|
|
||||||
GAsyncReadyCallback callback;
|
if (async_initable_init_second_finish (G_ASYNC_INITABLE (source_object), res, &error))
|
||||||
gpointer user_data;
|
g_task_return_boolean (task, TRUE);
|
||||||
} GetConnectionData;
|
else
|
||||||
|
g_task_return_error (task, error);
|
||||||
|
g_object_unref (task);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_connection_cb (GObject *source_object,
|
get_connection_cb (GObject *source_object,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GetConnectionData *data = user_data;
|
GTask *task = user_data;
|
||||||
|
GDBusProxy *proxy = g_task_get_source_object (task);
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
data->proxy->priv->connection = g_bus_get_finish (res, &error);
|
proxy->priv->connection = g_bus_get_finish (res, &error);
|
||||||
if (data->proxy->priv->connection == NULL)
|
if (proxy->priv->connection == NULL)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
g_task_return_error (task, error);
|
||||||
simple = g_simple_async_result_new (G_OBJECT (data->proxy),
|
g_object_unref (task);
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
NULL);
|
|
||||||
g_simple_async_result_set_check_cancellable (simple, data->cancellable);
|
|
||||||
g_simple_async_result_take_error (simple, error);
|
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
async_initable_init_first (G_ASYNC_INITABLE (data->proxy));
|
async_initable_init_first (G_ASYNC_INITABLE (proxy));
|
||||||
async_initable_init_second_async (G_ASYNC_INITABLE (data->proxy),
|
async_initable_init_second_async (G_ASYNC_INITABLE (proxy),
|
||||||
data->io_priority,
|
g_task_get_priority (task),
|
||||||
data->cancellable,
|
g_task_get_cancellable (task),
|
||||||
data->callback,
|
init_second_async_cb,
|
||||||
data->user_data);
|
task);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancellable != NULL)
|
|
||||||
g_object_unref (data->cancellable);
|
|
||||||
|
|
||||||
g_object_unref (data->proxy);
|
|
||||||
g_free (data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1880,28 +1842,25 @@ async_initable_init_async (GAsyncInitable *initable,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GDBusProxy *proxy = G_DBUS_PROXY (initable);
|
GDBusProxy *proxy = G_DBUS_PROXY (initable);
|
||||||
|
GTask *task;
|
||||||
|
|
||||||
|
task = g_task_new (proxy, cancellable, callback, user_data);
|
||||||
|
g_task_set_priority (task, io_priority);
|
||||||
|
|
||||||
if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
|
if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
|
||||||
{
|
{
|
||||||
GetConnectionData *data;
|
|
||||||
|
|
||||||
g_assert (proxy->priv->connection == NULL);
|
g_assert (proxy->priv->connection == NULL);
|
||||||
|
|
||||||
data = g_new0 (GetConnectionData, 1);
|
|
||||||
data->proxy = g_object_ref (proxy);
|
|
||||||
data->io_priority = io_priority;
|
|
||||||
data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
|
|
||||||
data->callback = callback;
|
|
||||||
data->user_data = user_data;
|
|
||||||
g_bus_get (proxy->priv->bus_type,
|
g_bus_get (proxy->priv->bus_type,
|
||||||
cancellable,
|
cancellable,
|
||||||
get_connection_cb,
|
get_connection_cb,
|
||||||
data);
|
task);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
async_initable_init_first (initable);
|
async_initable_init_first (initable);
|
||||||
async_initable_init_second_async (initable, io_priority, cancellable, callback, user_data);
|
async_initable_init_second_async (initable, io_priority, cancellable,
|
||||||
|
init_second_async_cb, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1910,7 +1869,7 @@ async_initable_init_finish (GAsyncInitable *initable,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return async_initable_init_second_finish (initable, res, error);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2586,7 +2545,7 @@ reply_cb (GDBusConnection *connection,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
|
GTask *task = user_data;
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
GError *error;
|
GError *error;
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
@ -2606,7 +2565,7 @@ reply_cb (GDBusConnection *connection,
|
|||||||
#endif
|
#endif
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_result_take_error (simple, error);
|
g_task_return_error (task, error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2616,12 +2575,10 @@ reply_cb (GDBusConnection *connection,
|
|||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
data->fd_list = fd_list;
|
data->fd_list = fd_list;
|
||||||
#endif
|
#endif
|
||||||
g_simple_async_result_set_op_res_gpointer (simple, data, (GDestroyNotify) reply_data_free);
|
g_task_return_pointer (task, data, (GDestroyNotify) reply_data_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no need to complete in idle since the method GDBusConnection already does */
|
g_object_unref (task);
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* properties_lock must be held for as long as you will keep the
|
/* properties_lock must be held for as long as you will keep the
|
||||||
@ -2683,7 +2640,7 @@ g_dbus_proxy_call_internal (GDBusProxy *proxy,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task;
|
||||||
gboolean was_split;
|
gboolean was_split;
|
||||||
gchar *split_interface_name;
|
gchar *split_interface_name;
|
||||||
const gchar *split_method_name;
|
const gchar *split_method_name;
|
||||||
@ -2713,16 +2670,12 @@ g_dbus_proxy_call_internal (GDBusProxy *proxy,
|
|||||||
if (callback != NULL)
|
if (callback != NULL)
|
||||||
{
|
{
|
||||||
my_callback = (GAsyncReadyCallback) reply_cb;
|
my_callback = (GAsyncReadyCallback) reply_cb;
|
||||||
simple = g_simple_async_result_new (G_OBJECT (proxy),
|
task = g_task_new (proxy, cancellable, callback, user_data);
|
||||||
callback,
|
|
||||||
user_data,
|
|
||||||
g_dbus_proxy_call_internal);
|
|
||||||
g_simple_async_result_set_check_cancellable (simple, cancellable);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
my_callback = NULL;
|
my_callback = NULL;
|
||||||
simple = NULL;
|
task = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_LOCK (properties_lock);
|
G_LOCK (properties_lock);
|
||||||
@ -2746,14 +2699,13 @@ g_dbus_proxy_call_internal (GDBusProxy *proxy,
|
|||||||
destination = g_strdup (get_destination_for_call (proxy));
|
destination = g_strdup (get_destination_for_call (proxy));
|
||||||
if (destination == NULL)
|
if (destination == NULL)
|
||||||
{
|
{
|
||||||
if (simple != NULL)
|
if (task != NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_error (simple,
|
g_task_return_new_error (task,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_FAILED,
|
G_IO_ERROR_FAILED,
|
||||||
_("Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag"));
|
_("Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag"));
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
g_object_unref (task);
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
G_UNLOCK (properties_lock);
|
G_UNLOCK (properties_lock);
|
||||||
goto out;
|
goto out;
|
||||||
@ -2775,7 +2727,7 @@ g_dbus_proxy_call_internal (GDBusProxy *proxy,
|
|||||||
fd_list,
|
fd_list,
|
||||||
cancellable,
|
cancellable,
|
||||||
my_callback,
|
my_callback,
|
||||||
simple);
|
task);
|
||||||
#else
|
#else
|
||||||
g_dbus_connection_call (proxy->priv->connection,
|
g_dbus_connection_call (proxy->priv->connection,
|
||||||
destination,
|
destination,
|
||||||
@ -2788,7 +2740,7 @@ g_dbus_proxy_call_internal (GDBusProxy *proxy,
|
|||||||
timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
|
timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
|
||||||
cancellable,
|
cancellable,
|
||||||
my_callback,
|
my_callback,
|
||||||
simple);
|
task);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -2805,27 +2757,25 @@ g_dbus_proxy_call_finish_internal (GDBusProxy *proxy,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
ReplyData *data;
|
ReplyData *data;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
|
g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
|
||||||
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
g_return_val_if_fail (g_task_is_valid (res, proxy), NULL);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_proxy_call_internal);
|
|
||||||
|
|
||||||
value = NULL;
|
value = NULL;
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
data = g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
if (!data)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
value = g_variant_ref (data->value);
|
value = g_variant_ref (data->value);
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
if (out_fd_list != NULL)
|
if (out_fd_list != NULL)
|
||||||
*out_fd_list = data->fd_list != NULL ? g_object_ref (data->fd_list) : NULL;
|
*out_fd_list = data->fd_list != NULL ? g_object_ref (data->fd_list) : NULL;
|
||||||
#endif
|
#endif
|
||||||
|
reply_data_free (data);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return value;
|
return value;
|
||||||
|
Loading…
Reference in New Issue
Block a user