[PATCH 1/5] base-call: port call_start to use GTask
Aleksander Morgado
aleksander at aleksander.es
Thu Jul 6 09:12:31 UTC 2017
On 06/07/17 00:12, Ben Chan wrote:
> ---
> src/mm-base-call.c | 59 ++++++++++++++++++------------------------------------
> 1 file changed, 20 insertions(+), 39 deletions(-)
>
Pushed to git master, thanks.
Also please note that I pushed a follow up commit removing the unneeded g_task_set_task_data() call.
> diff --git a/src/mm-base-call.c b/src/mm-base-call.c
> index 606d24f2..d9bb4f37 100644
> --- a/src/mm-base-call.c
> +++ b/src/mm-base-call.c
> @@ -567,38 +567,25 @@ void mm_base_call_received_dtmf (MMBaseCall *self, gchar *dtmf)
> /*****************************************************************************/
> /* Start the CALL */
>
> -typedef struct {
> - MMBaseCall *self;
> - MMBaseModem *modem;
> - GSimpleAsyncResult *result;
> -} CallStartContext;
> -
> -static void
> -call_start_context_complete_and_free (CallStartContext *ctx)
> -{
> - g_simple_async_result_complete_in_idle (ctx->result);
> - g_object_unref (ctx->result);
> - g_object_unref (ctx->modem);
> - g_object_unref (ctx->self);
> - g_free (ctx);
> -}
> -
> static gboolean
> call_start_finish (MMBaseCall *self,
> GAsyncResult *res,
> GError **error)
> {
> - return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
> + return g_task_propagate_boolean (G_TASK (res), error);
> }
>
> static void
> call_start_ready (MMBaseModem *modem,
> GAsyncResult *res,
> - CallStartContext *ctx)
> + GTask *task)
> {
> + MMBaseCall *self;
> GError *error = NULL;
> const gchar *response = NULL;
>
> + self = g_task_get_source_object (task);
> +
> response = mm_base_modem_at_command_finish (modem, res, &error);
> if (error) {
> if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
> @@ -607,19 +594,19 @@ call_start_ready (MMBaseModem *modem,
>
> if (g_error_matches (error, MM_CONNECTION_ERROR, MM_CONNECTION_ERROR_NO_DIALTONE)) {
> /* Update state */
> - mm_base_call_change_state(ctx->self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_ERROR);
> + mm_base_call_change_state(self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_ERROR);
> }
>
> if (g_error_matches (error, MM_CONNECTION_ERROR, MM_CONNECTION_ERROR_BUSY) ||
> g_error_matches (error, MM_CONNECTION_ERROR, MM_CONNECTION_ERROR_NO_ANSWER) ||
> g_error_matches (error, MM_CONNECTION_ERROR, MM_CONNECTION_ERROR_NO_CARRIER)) {
> /* Update state */
> - mm_base_call_change_state(ctx->self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_REFUSED_OR_BUSY);
> + mm_base_call_change_state(self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_REFUSED_OR_BUSY);
> }
>
> mm_dbg ("Couldn't start call : '%s'", error->message);
> - g_simple_async_result_take_error (ctx->result, error);
> - call_start_context_complete_and_free (ctx);
> + g_task_return_error (task, error);
> + g_object_unref (task);
> return;
> }
>
> @@ -629,20 +616,20 @@ call_start_ready (MMBaseModem *modem,
> "Couldn't start the call: "
> "Modem response '%s'", response);
> /* Update state */
> - mm_base_call_change_state (ctx->self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_REFUSED_OR_BUSY);
> + mm_base_call_change_state (self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_REFUSED_OR_BUSY);
> } else {
> /* Update state */
> - mm_base_call_change_state (ctx->self, MM_CALL_STATE_ACTIVE, MM_CALL_STATE_REASON_ACCEPTED);
> + mm_base_call_change_state (self, MM_CALL_STATE_ACTIVE, MM_CALL_STATE_REASON_ACCEPTED);
> }
>
> if (error) {
> - g_simple_async_result_take_error (ctx->result, error);
> - call_start_context_complete_and_free (ctx);
> + g_task_return_error (task, error);
> + g_object_unref (task);
> return;
> }
>
> - g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> - call_start_context_complete_and_free (ctx);
> + g_task_return_boolean (task, TRUE);
> + g_object_unref (task);
> }
>
> static void
> @@ -650,25 +637,19 @@ call_start (MMBaseCall *self,
> GAsyncReadyCallback callback,
> gpointer user_data)
> {
> - CallStartContext *ctx;
> + GTask *task;
> gchar *cmd;
>
> - /* Setup the context */
> - ctx = g_new0 (CallStartContext, 1);
> - ctx->result = g_simple_async_result_new (G_OBJECT (self),
> - callback,
> - user_data,
> - call_start);
> - ctx->self = g_object_ref (self);
> - ctx->modem = g_object_ref (self->priv->modem);
> + task = g_task_new (self, NULL, callback, user_data);
> + g_task_set_task_data (task, g_object_ref (self->priv->modem), g_object_unref);
>
> cmd = g_strdup_printf ("ATD%s;", mm_gdbus_call_get_number (MM_GDBUS_CALL (self)));
> - mm_base_modem_at_command (ctx->modem,
> + mm_base_modem_at_command (self->priv->modem,
> cmd,
> 90,
> FALSE,
> (GAsyncReadyCallback)call_start_ready,
> - ctx);
> + task);
>
> /* Update state */
> mm_base_call_change_state(self, MM_CALL_STATE_RINGING_OUT, MM_CALL_STATE_REASON_OUTGOING_STARTED);
>
--
Aleksander
https://aleksander.es
More information about the ModemManager-devel
mailing list