[PATCH 1/2] sms-mbim: port sms_send to use GTask
Aleksander Morgado
aleksander at aleksander.es
Fri Apr 7 09:07:55 UTC 2017
On 06/04/17 21:57, Ben Chan wrote:
> ---
> src/mm-sms-mbim.c | 46 ++++++++++++++++++++++------------------------
> 1 file changed, 22 insertions(+), 24 deletions(-)
>
Pushed to git master, thanks!
> diff --git a/src/mm-sms-mbim.c b/src/mm-sms-mbim.c
> index eded51fc..085a2d59 100644
> --- a/src/mm-sms-mbim.c
> +++ b/src/mm-sms-mbim.c
> @@ -74,21 +74,16 @@ peek_device (gpointer self,
> /* Send the SMS */
>
> typedef struct {
> - MMBaseSms *self;
> MMBaseModem *modem;
> MbimDevice *device;
> - GSimpleAsyncResult *result;
> GList *current;
> } SmsSendContext;
>
> static void
> -sms_send_context_complete_and_free (SmsSendContext *ctx)
> +sms_send_context_free (SmsSendContext *ctx)
> {
> - g_simple_async_result_complete_in_idle (ctx->result);
> - g_object_unref (ctx->result);
> g_object_unref (ctx->device);
> g_object_unref (ctx->modem);
> - g_object_unref (ctx->self);
> g_slice_free (SmsSendContext, ctx);
> }
>
> @@ -97,20 +92,22 @@ sms_send_finish (MMBaseSms *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 sms_send_next_part (SmsSendContext *ctx);
> +static void sms_send_next_part (GTask *task);
>
> static void
> sms_send_set_ready (MbimDevice *device,
> GAsyncResult *res,
> - SmsSendContext *ctx)
> + GTask *task)
> {
> + SmsSendContext *ctx;
> MbimMessage *response;
> GError *error = NULL;
> guint32 message_reference;
>
> + ctx = g_task_get_task_data (task);
> response = mbim_device_command_finish (device, res, &error);
> if (response &&
> mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error) &&
> @@ -127,19 +124,20 @@ sms_send_set_ready (MbimDevice *device,
>
> if (error) {
> g_prefix_error (&error, "Couldn't send SMS part: ");
> - g_simple_async_result_take_error (ctx->result, error);
> - sms_send_context_complete_and_free (ctx);
> + g_task_return_error (task, error);
> + g_object_unref (task);
> return;
> }
>
> /* Go on with next part */
> ctx->current = g_list_next (ctx->current);
> - sms_send_next_part (ctx);
> + sms_send_next_part (task);
> }
>
> static void
> -sms_send_next_part (SmsSendContext *ctx)
> +sms_send_next_part (GTask *task)
> {
> + SmsSendContext *ctx;
> MbimMessage *message;
> guint8 *pdu;
> guint pdulen = 0;
> @@ -147,18 +145,19 @@ sms_send_next_part (SmsSendContext *ctx)
> GError *error = NULL;
> MbimSmsPduSendRecord send_record;
>
> + ctx = g_task_get_task_data (task);
> if (!ctx->current) {
> /* Done we are */
> - g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
> - sms_send_context_complete_and_free (ctx);
> + g_task_return_boolean (task, TRUE);
> + g_object_unref (task);
> return;
> }
>
> /* Get PDU */
> pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error);
> if (!pdu) {
> - g_simple_async_result_take_error (ctx->result, error);
> - sms_send_context_complete_and_free (ctx);
> + g_task_return_error (task, error);
> + g_object_unref (task);
> return;
> }
>
> @@ -174,7 +173,7 @@ sms_send_next_part (SmsSendContext *ctx)
> 30,
> NULL,
> (GAsyncReadyCallback)sms_send_set_ready,
> - ctx);
> + task);
> mbim_message_unref (message);
> g_free (pdu);
> }
> @@ -186,24 +185,23 @@ sms_send (MMBaseSms *self,
> {
> SmsSendContext *ctx;
> MbimDevice *device;
> + GTask *task;
>
> if (!peek_device (self, &device, callback, user_data))
> return;
>
> /* Setup the context */
> ctx = g_slice_new0 (SmsSendContext);
> - ctx->result = g_simple_async_result_new (G_OBJECT (self),
> - callback,
> - user_data,
> - sms_send);
> - ctx->self = g_object_ref (self);
> ctx->device = g_object_ref (device);
> g_object_get (self,
> MM_BASE_SMS_MODEM, &ctx->modem,
> NULL);
>
> + task = g_task_new (self, NULL, callback, user_data);
> + g_task_set_task_data (task, ctx, (GDestroyNotify)sms_send_context_free);
> +
> ctx->current = mm_base_sms_get_parts (self);;
> - sms_send_next_part (ctx);
> + sms_send_next_part (task);
> }
>
> /*****************************************************************************/
>
--
Aleksander
https://aleksander.es
More information about the ModemManager-devel
mailing list