Exemplo n.º 1
0
void
rbgio_gasyncinitable_new_async(GType type,
                               VALUE parameters,
                               VALUE io_priority,
                               VALUE cancellable,
                               VALUE block)
{
        static ID s_id_length;
        struct rbgio_gasyncinitable_new_async_data data;

        if (s_id_length == 0)
                s_id_length = rb_intern("length");

        if (!g_type_is_a(type, G_TYPE_OBJECT))
                rb_raise(rb_eArgError,
                         "%s is not a descendant of GObject",
                         g_type_name(type));

        if (NIL_P(parameters)) {
                SAVE_BLOCK(block);
                g_async_initable_newv_async(type,
                                            0,
                                            NULL,
                                            RVAL2IOPRIORITYDEFAULT(io_priority),
                                            RVAL2GCANCELLABLE(cancellable),
                                            rbgio_async_ready_callback,
                                            (gpointer)block);

                return;
        } else {
                parameters = rb_convert_type(parameters,
                                             T_HASH,
                                             "Hash",
                                             "to_hash");
        }

        data.gclass = G_OBJECT_CLASS(g_type_class_ref(type));
        data.io_priority = RVAL2IOPRIORITYDEFAULT(io_priority);
        data.cancellable = RVAL2GCANCELLABLE(cancellable);
        data.block = block;
        data.rbparameters = parameters;
        data.index = 0;
        data.n_parameters = RVAL2GUINT(rb_funcall(parameters, s_id_length, 0));
        data.parameters = ALLOCA_N(GParameter, data.n_parameters);

        rb_ensure(rbgio_gasyncinitable_new_async_body, (VALUE)&data,
                  rbgio_gasyncinitable_new_async_ensure, (VALUE)&data);

        return;
}
Exemplo n.º 2
0
static VALUE
rg_splice_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbsource, rbflags, rbio_priority, rbcancellable, block;
        GInputStream *source;
        GOutputStreamSpliceFlags flags;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "12&", &rbsource, &rbflags, &rbio_priority, &rbcancellable, &block);
        source = RVAL2GINPUTSTREAM(rbsource);
        flags = RVAL2GOUTPUTSTREAMSPLICEFLAGSDEFAULT(rbflags);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_output_stream_splice_async(_SELF(self),
                                     source,
                                     flags,
                                     io_priority,
                                     cancellable,
                                     rbgio_async_ready_callback,
                                     (gpointer)block);

        return self;
}
Exemplo n.º 3
0
/* TODO: Does it make sense to use buffer and count?  We should probably
 * provide a better wrapper that simply pumps out buffer while count hasn't
 * been reached, calling the callback with the bytes written, then with the
 * result. */
static VALUE
rg_write_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbbuffer, rbcount, rbio_priority, rbcancellable, block;
        const gchar *buffer;
        gsize count;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "22&", &rbbuffer, &rbcount, &rbio_priority, &rbcancellable, &block);
        buffer = RVAL2CSTR(rbbuffer);
        count = RVAL2GSIZE(rbcount);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_output_stream_write_async(_SELF(self),
                                    buffer,
                                    count,
                                    io_priority,
                                    cancellable,
                                    rbgio_async_ready_callback,
                                    (gpointer)block);

        return self;
}
Exemplo n.º 4
0
static VALUE
rg_close_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbio_priority, rbcancellable, block;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "01&", &rbio_priority, &rbcancellable, &block);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_io_stream_close_async(_SELF(self),
                                io_priority,
                                cancellable,
                                rbgio_async_ready_callback,
                                (gpointer)block);

        return self;
}
Exemplo n.º 5
0
static VALUE
rg_s_push_job(int argc, VALUE *argv, VALUE self)
{
        VALUE rbio_priority, rbcancellable, block;
        gint io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "02", &rbio_priority, &rbcancellable);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        block = rb_block_proc();
        SAVE_BLOCK(block);
        g_io_scheduler_push_job(ioscheduler_job_callback,
                                (gpointer)block,
                                ioscheduler_job_callback_free,
                                io_priority,
                                cancellable);

        return self;
}
Exemplo n.º 6
0
static VALUE
fileenumerator_next_files_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbnum_files, rbio_priority, rbcancellable, block;
        int num_files;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "12&", &rbnum_files, &rbio_priority, &rbcancellable, &block);
        num_files = NUM2INT(rbnum_files);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_file_enumerator_next_files_async(_SELF(self),
                                           num_files,
                                           io_priority,
                                           cancellable,
                                           rbgio_async_ready_callback,
                                           (gpointer)block);

        return self;
}
Exemplo n.º 7
0
static VALUE
rg_fill_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbcount, rbio_priority, rbcancellable, block;
        gssize count;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "03&", &rbcount, &rbio_priority, &rbcancellable, &block);
        count = NIL_P(rbcount) ? -1 : RVAL2GSSIZE(rbcount);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_buffered_input_stream_fill_async(_SELF(self),
                                           count,
                                           io_priority,
                                           cancellable,
                                           rbgio_async_ready_callback,
                                           (gpointer)block);

        return self;
}
Exemplo n.º 8
0
static VALUE
rg_query_info_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbattributes, rbio_priority, rbcancellable, block;
        const char *attributes;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "03&", &rbattributes, &rbio_priority, &rbcancellable, &block);
        attributes = RVAL2ATTRIBUTESDEFAULT(rbattributes);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_file_input_stream_query_info_async(_SELF(self),
                                             attributes,
                                             io_priority,
                                             cancellable,
                                             rbgio_async_ready_callback,
                                             (gpointer)block);

        return self;
}