libmm-glib,voice: port mm_modem_voice_create_call to use GTask

This commit is contained in:
Ben Chan
2017-06-23 20:00:52 -07:00
committed by Aleksander Morgado
parent 135fc84cf1
commit 9bf9d036ec

View File

@@ -300,21 +300,6 @@ mm_modem_voice_list_calls_sync (MMModemVoice *self,
/*****************************************************************************/ /*****************************************************************************/
typedef struct {
GSimpleAsyncResult *result;
GCancellable *cancellable;
} CreateCallContext;
static void
create_call_context_complete_and_free (CreateCallContext *ctx)
{
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
if (ctx->cancellable)
g_object_unref (ctx->cancellable);
g_slice_free (CreateCallContext, ctx);
}
/** /**
* mm_modem_voice_create_call_finish: * mm_modem_voice_create_call_finish:
* @self: A #MMModemVoice. * @self: A #MMModemVoice.
@@ -327,21 +312,18 @@ create_call_context_complete_and_free (CreateCallContext *ctx)
*/ */
MMCall * MMCall *
mm_modem_voice_create_call_finish (MMModemVoice *self, mm_modem_voice_create_call_finish (MMModemVoice *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL); g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) return g_task_propagate_pointer (G_TASK (res), error);
return NULL;
return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
} }
static void static void
new_call_object_ready (GDBusConnection *connection, new_call_object_ready (GDBusConnection *connection,
GAsyncResult *res, GAsyncResult *res,
CreateCallContext *ctx) GTask *task)
{ {
GError *error = NULL; GError *error = NULL;
GObject *call; GObject *call;
@@ -352,19 +334,17 @@ new_call_object_ready (GDBusConnection *connection,
g_object_unref (source_object); g_object_unref (source_object);
if (error) if (error)
g_simple_async_result_take_error (ctx->result, error); g_task_return_error (task, error);
else else
g_simple_async_result_set_op_res_gpointer (ctx->result, g_task_return_pointer (task, call, g_object_unref);
call,
g_object_unref);
create_call_context_complete_and_free (ctx); g_object_unref (task);
} }
static void static void
create_call_ready (MMModemVoice *self, create_call_ready (MMModemVoice *self,
GAsyncResult *res, GAsyncResult *res,
CreateCallContext *ctx) GTask *task)
{ {
GError *error = NULL; GError *error = NULL;
gchar *call_path = NULL; gchar *call_path = NULL;
@@ -373,17 +353,17 @@ create_call_ready (MMModemVoice *self,
&call_path, &call_path,
res, res,
&error)) { &error)) {
g_simple_async_result_take_error (ctx->result, error); g_task_return_error (task, error);
create_call_context_complete_and_free (ctx); g_object_unref (task);
g_free (call_path); g_free (call_path);
return; return;
} }
g_async_initable_new_async (MM_TYPE_CALL, g_async_initable_new_async (MM_TYPE_CALL,
G_PRIORITY_DEFAULT, G_PRIORITY_DEFAULT,
ctx->cancellable, g_task_get_cancellable (task),
(GAsyncReadyCallback)new_call_object_ready, (GAsyncReadyCallback)new_call_object_ready,
ctx, task,
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"g-name", MM_DBUS_SERVICE, "g-name", MM_DBUS_SERVICE,
"g-connection", g_dbus_proxy_get_connection (G_DBUS_PROXY (self)), "g-connection", g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
@@ -415,26 +395,19 @@ mm_modem_voice_create_call (MMModemVoice *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
CreateCallContext *ctx; GTask *task;
GVariant *dictionary; GVariant *dictionary;
g_return_if_fail (MM_IS_MODEM_VOICE (self)); g_return_if_fail (MM_IS_MODEM_VOICE (self));
ctx = g_slice_new0 (CreateCallContext); task = g_task_new (self, cancellable, callback, user_data);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_modem_voice_create_call);
if (cancellable)
ctx->cancellable = g_object_ref (cancellable);
dictionary = mm_call_properties_get_dictionary (properties); dictionary = mm_call_properties_get_dictionary (properties);
mm_gdbus_modem_voice_call_create_call ( mm_gdbus_modem_voice_call_create_call (
MM_GDBUS_MODEM_VOICE (self), MM_GDBUS_MODEM_VOICE (self),
dictionary, dictionary,
cancellable, cancellable,
(GAsyncReadyCallback)create_call_ready, (GAsyncReadyCallback)create_call_ready,
ctx); task);
g_variant_unref (dictionary); g_variant_unref (dictionary);
} }