On 29/06/17 13:46, Ben Chan wrote: > --- > src/mm-iface-modem-3gpp.c | 144 > ++++++++++++++++++++++------------------------ > 1 file changed, 70 insertions(+), 74 deletions(-) >
Pushed to git master, thanks. > diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c > index e06e36cf..b9446507 100644 > --- a/src/mm-iface-modem-3gpp.c > +++ b/src/mm-iface-modem-3gpp.c > @@ -1579,7 +1579,7 @@ mm_iface_modem_3gpp_disable (MMIfaceModem3gpp *self, > > /*****************************************************************************/ > > typedef struct _EnablingContext EnablingContext; > -static void interface_enabling_step (EnablingContext *ctx); > +static void interface_enabling_step (GTask *task); > > typedef enum { > ENABLING_STEP_FIRST, > @@ -1591,54 +1591,36 @@ typedef enum { > } EnablingStep; > > struct _EnablingContext { > - MMIfaceModem3gpp *self; > EnablingStep step; > - GSimpleAsyncResult *result; > - GCancellable *cancellable; > MmGdbusModem3gpp *skeleton; > }; > > static void > -enabling_context_complete_and_free (EnablingContext *ctx) > +enabling_context_free (EnablingContext *ctx) > { > - g_simple_async_result_complete_in_idle (ctx->result); > - g_object_unref (ctx->self); > - g_object_unref (ctx->result); > - g_object_unref (ctx->cancellable); > if (ctx->skeleton) > g_object_unref (ctx->skeleton); > g_free (ctx); > } > > -static gboolean > -enabling_context_complete_and_free_if_cancelled (EnablingContext *ctx) > -{ > - if (!g_cancellable_is_cancelled (ctx->cancellable)) > - return FALSE; > - > - g_simple_async_result_set_error (ctx->result, > - MM_CORE_ERROR, > - MM_CORE_ERROR_CANCELLED, > - "Interface enabling cancelled"); > - enabling_context_complete_and_free (ctx); > - return TRUE; > -} > - > gboolean > mm_iface_modem_3gpp_enable_finish (MMIfaceModem3gpp *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 > setup_unsolicited_events_ready (MMIfaceModem3gpp *self, > GAsyncResult *res, > - EnablingContext *ctx) > + GTask *task) > { > + EnablingContext *ctx; > GError *error = NULL; > > + ctx = g_task_get_task_data (task); > + > MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_events_finish (self, res, &error); > if (error) { > /* This error shouldn't be treated as critical */ > @@ -1648,20 +1630,21 @@ setup_unsolicited_events_ready (MMIfaceModem3gpp > *self, > /* If we get an error setting up unsolicited events, don't even > bother trying to > * enable them. */ > ctx->step = ENABLING_STEP_ENABLE_UNSOLICITED_EVENTS + 1; > - interface_enabling_step (ctx); > + interface_enabling_step (task); > return; > } > > /* Go on to next step */ > ctx->step++; > - interface_enabling_step (ctx); > + interface_enabling_step (task); > } > > static void > enable_unsolicited_events_ready (MMIfaceModem3gpp *self, > GAsyncResult *res, > - EnablingContext *ctx) > + GTask *task) > { > + EnablingContext *ctx; > GError *error = NULL; > > MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_events_finish (self, res, &error); > @@ -1672,17 +1655,21 @@ enable_unsolicited_events_ready (MMIfaceModem3gpp > *self, > } > > /* Go on to next step */ > + ctx = g_task_get_task_data (task); > ctx->step++; > - interface_enabling_step (ctx); > + interface_enabling_step (task); > } > > static void > setup_unsolicited_registration_events_ready (MMIfaceModem3gpp *self, > GAsyncResult *res, > - EnablingContext *ctx) > + GTask *task) > { > + EnablingContext *ctx; > GError *error = NULL; > > + ctx = g_task_get_task_data (task); > + > MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_registration_events_finish (self, res, &error); > if (error) { > /* This error shouldn't be treated as critical */ > @@ -1692,22 +1679,23 @@ setup_unsolicited_registration_events_ready > (MMIfaceModem3gpp *self, > /* If we get an error setting up unsolicited events, don't even > bother trying to > * enable them. */ > ctx->step = ENABLING_STEP_ENABLE_UNSOLICITED_REGISTRATION_EVENTS + 1; > - interface_enabling_step (ctx); > + interface_enabling_step (task); > /* If error, setup periodic registration checks */ > - periodic_registration_check_enable (ctx->self); > + periodic_registration_check_enable (self); > return; > } > > /* Go on to next step */ > ctx->step++; > - interface_enabling_step (ctx); > + interface_enabling_step (task); > } > > static void > enable_unsolicited_registration_events_ready (MMIfaceModem3gpp *self, > GAsyncResult *res, > - EnablingContext *ctx) > + GTask *task) > { > + EnablingContext *ctx; > GError *error = NULL; > > MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_registration_events_finish (self, res, &error); > @@ -1716,20 +1704,29 @@ enable_unsolicited_registration_events_ready > (MMIfaceModem3gpp *self, > mm_dbg ("Enabling unsolicited registration events failed: '%s'", > error->message); > g_error_free (error); > /* If error, setup periodic registration checks */ > - periodic_registration_check_enable (ctx->self); > + periodic_registration_check_enable (self); > } > > /* Go on to next step */ > + ctx = g_task_get_task_data (task); > ctx->step++; > - interface_enabling_step (ctx); > + interface_enabling_step (task); > } > > static void > -interface_enabling_step (EnablingContext *ctx) > +interface_enabling_step (GTask *task) > { > + MMIfaceModem3gpp *self; > + EnablingContext *ctx; > + > /* Don't run new steps if we're cancelled */ > - if (enabling_context_complete_and_free_if_cancelled (ctx)) > + if (g_task_return_error_if_cancelled (task)) { > + g_object_unref (task); > return; > + } > + > + self = g_task_get_source_object (task); > + ctx = g_task_get_task_data (task); > > switch (ctx->step) { > case ENABLING_STEP_FIRST: > @@ -1737,36 +1734,36 @@ interface_enabling_step (EnablingContext *ctx) > ctx->step++; > > case ENABLING_STEP_SETUP_UNSOLICITED_EVENTS: > - if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->setup_unsolicited_events && > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->setup_unsolicited_events_finish) { > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->setup_unsolicited_events ( > - ctx->self, > + if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_events && > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_events_finish) { > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_events ( > + self, > (GAsyncReadyCallback)setup_unsolicited_events_ready, > - ctx); > + task); > return; > } > /* Fall down to next step */ > ctx->step++; > > case ENABLING_STEP_ENABLE_UNSOLICITED_EVENTS: > - if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->enable_unsolicited_events && > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->enable_unsolicited_events_finish) { > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->enable_unsolicited_events ( > - ctx->self, > + if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_events && > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_events_finish) { > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_events ( > + self, > (GAsyncReadyCallback)enable_unsolicited_events_ready, > - ctx); > + task); > return; > } > /* Fall down to next step */ > ctx->step++; > > case ENABLING_STEP_SETUP_UNSOLICITED_REGISTRATION_EVENTS: > - if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->setup_unsolicited_registration_events && > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->setup_unsolicited_registration_events_finish) { > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->setup_unsolicited_registration_events ( > - ctx->self, > + if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_registration_events && > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_registration_events_finish) { > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->setup_unsolicited_registration_events ( > + self, > > (GAsyncReadyCallback)setup_unsolicited_registration_events_ready, > - ctx); > + task); > return; > } > /* Fall down to next step */ > @@ -1777,21 +1774,21 @@ interface_enabling_step (EnablingContext *ctx) > gboolean ps_supported = FALSE; > gboolean eps_supported = FALSE; > > - g_object_get (ctx->self, > + g_object_get (self, > MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, > &cs_supported, > MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, > &ps_supported, > MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, > &eps_supported, > NULL); > > - if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->enable_unsolicited_registration_events && > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->enable_unsolicited_registration_events_finish) { > - MM_IFACE_MODEM_3GPP_GET_INTERFACE > (ctx->self)->enable_unsolicited_registration_events ( > - ctx->self, > + if (MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_registration_events && > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_registration_events_finish) { > + MM_IFACE_MODEM_3GPP_GET_INTERFACE > (self)->enable_unsolicited_registration_events ( > + self, > cs_supported, > ps_supported, > eps_supported, > > (GAsyncReadyCallback)enable_unsolicited_registration_events_ready, > - ctx); > + task); > return; > } > /* Fall down to next step */ > @@ -1800,8 +1797,8 @@ interface_enabling_step (EnablingContext *ctx) > > case ENABLING_STEP_LAST: > /* We are done without errors! */ > - g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); > - enabling_context_complete_and_free (ctx); > + g_task_return_boolean (task, TRUE); > + g_object_unref (task); > return; > } > > @@ -1815,28 +1812,27 @@ mm_iface_modem_3gpp_enable (MMIfaceModem3gpp *self, > gpointer user_data) > { > EnablingContext *ctx; > + GTask *task; > > ctx = g_new0 (EnablingContext, 1); > - ctx->self = g_object_ref (self); > - ctx->cancellable = g_object_ref (cancellable); > - ctx->result = g_simple_async_result_new (G_OBJECT (self), > - callback, > - user_data, > - mm_iface_modem_3gpp_enable); > ctx->step = ENABLING_STEP_FIRST; > - g_object_get (ctx->self, > + > + task = g_task_new (self, cancellable, callback, user_data); > + g_task_set_task_data (task, ctx, (GDestroyNotify)enabling_context_free); > + > + g_object_get (self, > MM_IFACE_MODEM_3GPP_DBUS_SKELETON, &ctx->skeleton, > NULL); > if (!ctx->skeleton) { > - g_simple_async_result_set_error (ctx->result, > - MM_CORE_ERROR, > - MM_CORE_ERROR_FAILED, > - "Couldn't get interface skeleton"); > - enabling_context_complete_and_free (ctx); > + g_task_return_new_error (task, > + MM_CORE_ERROR, > + MM_CORE_ERROR_FAILED, > + "Couldn't get interface skeleton"); > + g_object_unref (task); > return; > } > > - interface_enabling_step (ctx); > + interface_enabling_step (task); > } > > > /*****************************************************************************/ > -- Aleksander https://aleksander.es _______________________________________________ ModemManager-devel mailing list ModemManager-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel