static void
list_build_object_ready (GDBusConnection *connection,
                         GAsyncResult *res,
                         ListSmsContext *ctx)
{
    GError *error = NULL;
    GObject *sms;
    GObject *source_object;

    source_object = g_async_result_get_source_object (res);
    sms = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, &error);
    g_object_unref (source_object);

    if (error) {
        g_simple_async_result_take_error (ctx->result, error);
        list_sms_context_complete_and_free (ctx);
        return;
    }

    /* Keep the object */
    ctx->sms_objects = g_list_prepend (ctx->sms_objects, sms);

    /* If no more smss, just end here. */
    if (!ctx->sms_paths[++ctx->i]) {
        g_simple_async_result_set_op_res_gpointer (ctx->result,
                                                   ctx->sms_objects,
                                                   (GDestroyNotify)sms_object_list_free);
        ctx->sms_objects = NULL;
        list_sms_context_complete_and_free (ctx);
        return;
    }

    /* Keep on creating next object */
    create_next_sms (ctx);
}
static void
list_ready (MMModemMessaging *self,
            GAsyncResult *res,
            ListSmsContext *ctx)
{
    GError *error = NULL;

    mm_gdbus_modem_messaging_call_list_finish (MM_GDBUS_MODEM_MESSAGING (self), &ctx->sms_paths, res, &error);
    if (error) {
        g_simple_async_result_take_error (ctx->result, error);
        list_sms_context_complete_and_free (ctx);
        return;
    }

    /* If no SMS, just end here. */
    if (!ctx->sms_paths || !ctx->sms_paths[0]) {
        g_simple_async_result_set_op_res_gpointer (ctx->result, NULL, NULL);
        list_sms_context_complete_and_free (ctx);
        return;
    }

    /* Got list of paths. If at least one found, start creating objects for each */
    ctx->i = 0;
    create_next_sms (ctx);
}
示例#3
0
/**
 * mm_modem_messaging_list:
 * @self: A #MMModemMessaging.
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
 * @user_data: User data to pass to @callback.
 *
 * Asynchronously lists the #MMSms objects in the modem.
 *
 * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
 * You can then call mm_modem_messaging_list_finish() to get the result of the operation.
 *
 * See mm_modem_messaging_list_sync() for the synchronous, blocking version of this method.
 */
void
mm_modem_messaging_list (MMModemMessaging *self,
                         GCancellable *cancellable,
                         GAsyncReadyCallback callback,
                         gpointer user_data)
{
    ListSmsContext *ctx;

    g_return_if_fail (MM_IS_MODEM_MESSAGING (self));

    ctx = g_slice_new0 (ListSmsContext);
    ctx->self = g_object_ref (self);
    ctx->result = g_simple_async_result_new (G_OBJECT (self),
                                             callback,
                                             user_data,
                                             mm_modem_messaging_list);
    if (cancellable)
        ctx->cancellable = g_object_ref (cancellable);

    ctx->sms_paths = mm_gdbus_modem_messaging_dup_messages (MM_GDBUS_MODEM_MESSAGING (self));

    /* If no SMS, just end here. */
    if (!ctx->sms_paths || !ctx->sms_paths[0]) {
        g_simple_async_result_set_op_res_gpointer (ctx->result, NULL, NULL);
        list_sms_context_complete_and_free (ctx);
        return;
    }

    /* Got list of paths. If at least one found, start creating objects for each */
    ctx->i = 0;
    create_next_sms (ctx);
}