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; }
GObject * rbgio_ginitable_new(GType type, VALUE parameters, VALUE cancellable) { static ID s_id_length; GError *error = NULL; GObject *object; struct rbgio_ginitable_new_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)) { object = g_initable_newv(type, 0, NULL, RVAL2GCANCELLABLE(cancellable), &error); if (object == NULL) rbgio_raise_error(error); return object; } else { parameters = rb_convert_type(parameters, T_HASH, "Hash", "to_hash"); } data.gclass = G_OBJECT_CLASS(g_type_class_ref(type)); data.cancellable = RVAL2GCANCELLABLE(cancellable); data.rbparameters = parameters; data.index = 0; data.n_parameters = RVAL2GUINT(rb_funcall(parameters, s_id_length, 0)); data.parameters = g_new(GParameter, data.n_parameters); data.error = NULL; object = (GObject *)rb_ensure(rbgio_ginitable_new_body, (VALUE)&data, rbgio_ginitable_new_ensure, (VALUE)&data); if (object == NULL) rbgio_raise_error(data.error); return object; }
/* 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; }
static VALUE rg_lookup_service_async(int argc, VALUE *argv, VALUE self) { VALUE rbservice, rbprotocol, rbdomain, rbcancellable, block; const gchar *service; const gchar *protocol; const gchar *domain; GCancellable *cancellable; rb_scan_args(argc, argv, "31&", &rbservice, &rbprotocol, &rbdomain, &rbcancellable, &block); service = RVAL2CSTR(rbservice); protocol = RVAL2CSTR(rbprotocol); domain = RVAL2CSTR(rbdomain); cancellable = RVAL2GCANCELLABLE(rbcancellable); SAVE_BLOCK(block); g_resolver_lookup_service_async(_SELF(self), service, protocol, domain, cancellable, rbgio_async_ready_callback, (gpointer)block); return self; }
static VALUE stream_write_all(int argc, VALUE *argv, VALUE self) { VALUE rbbuffer, rbcancellable; const char *buffer; gsize count; gsize bytes_written; GCancellable *cancellable; GError *error = NULL; rb_scan_args(argc, argv, "11", &rbbuffer, &rbcancellable); buffer = RVAL2CSTR(rbbuffer); count = RSTRING_LEN(rbbuffer); cancellable = RVAL2GCANCELLABLE(rbcancellable); if (!g_output_stream_write_all(_SELF(self), buffer, count, &bytes_written, cancellable, &error)) rbgio_raise_io_error(error); return UINT2NUM(bytes_written); }
static VALUE rg_read_all(int argc, VALUE *argv, VALUE self) { VALUE rbcount, cancellable, result; gsize count; GError *error = NULL; gsize bytes_read; rb_scan_args(argc, argv, "11", &rbcount, &cancellable); count = RVAL2GSIZE(rbcount); result = rb_str_new(NULL, count); if (!g_input_stream_read_all(_SELF(self), RSTRING_PTR(result), count, &bytes_read, RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); rb_str_set_len(result, bytes_read); rb_str_resize(result, bytes_read); OBJ_TAINT(result); return result; }
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; }
static VALUE rg_close(VALUE self, VALUE cancellable) { GError *error = NULL; if (!g_io_stream_close(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static VALUE fileenumerator_close(int argc, VALUE *argv, VALUE self) { VALUE cancellable; GError *error = NULL; rb_scan_args(argc, argv, "01", &cancellable); if (!g_file_enumerator_close(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static VALUE cancellable_method(CancellableMethod method, int argc, VALUE *argv, VALUE self) { VALUE cancellable; GError *error = NULL; rb_scan_args(argc, argv, "01", &cancellable); if (!method(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static VALUE rg_send_fd(int argc, VALUE *argv, VALUE self) { VALUE fd, cancellable; GError *error = NULL; rb_scan_args(argc, argv, "11", &fd, &cancellable); if (!g_unix_connection_send_fd(_SELF(self), RVAL2FD(fd), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static VALUE stream_put_int32(int argc, VALUE *argv, VALUE self) { VALUE value, cancellable; GError *error = NULL; rb_scan_args(argc, argv, "11", &value, &cancellable); if (!g_data_output_stream_put_int16(_SELF(self), NUM2INT(value), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_io_error(error); return self; }
static VALUE rg_truncate(int argc, VALUE *argv, VALUE self) { VALUE offset, cancellable; GError *error = NULL; rb_scan_args(argc, argv, "11", &offset, &cancellable); if (!g_seekable_truncate(_SELF(self), RVAL2GOFFSET(offset), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static VALUE rg_lookup_by_name(VALUE self, VALUE hostname, VALUE cancellable) { GError *error = NULL; GList *addresses; addresses = g_resolver_lookup_by_name(_SELF(self), RVAL2CSTR(hostname), RVAL2GCANCELLABLE(cancellable), &error); if (addresses == NULL) rbgio_raise_error(error); return GLIST2ARY_UNREF_FREE(addresses); }
static VALUE fileenumerator_next_file(int argc, VALUE *argv, VALUE self) { VALUE cancellable; GError *error = NULL; GFileInfo *info; rb_scan_args(argc, argv, "01", &cancellable); info = g_file_enumerator_next_file(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error); if (error != NULL) rbgio_raise_error(error); return GOBJ2RVAL_UNREF(info); }
static VALUE rg_seek(int argc, VALUE *argv, VALUE self) { VALUE offset, type, cancellable; GError *error = NULL; rb_scan_args(argc, argv, "12", &offset, &type, &cancellable); if (!g_seekable_seek(_SELF(self), RVAL2GOFFSET(offset), RVAL2GSEEKTYPEDEFAULT(type), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static VALUE rg_read_byte(int argc, VALUE *argv, VALUE self) { VALUE cancellable; GError *error = NULL; int byte; rb_scan_args(argc, argv, "01", &cancellable); byte = g_buffered_input_stream_read_byte(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error); if (error != NULL) rbgio_raise_error(error); return INT2FIX(byte); }
static VALUE rg_receive_fd(int argc, VALUE *argv, VALUE self) { VALUE cancellable; GError *error = NULL; gint fd; rb_scan_args(argc, argv, "01", &cancellable); fd = g_unix_connection_receive_fd(_SELF(self), RVAL2GCANCELLABLE(cancellable), &error); if (fd == -1) rbgio_raise_error(error); return FD2RVAL(fd); }
static VALUE rg_connect(int argc, VALUE *argv, VALUE self) { VALUE connectable, cancellable; GError *error = NULL; GSocketConnection *connection; rb_scan_args(argc, argv, "11", &connectable, &cancellable); connection = g_socket_client_connect(_SELF(self), RVAL2GSOCKETCONNECTABLE(connectable), RVAL2GCANCELLABLE(cancellable), &error); if (connection == NULL) rbgio_raise_error(error); return GOBJ2RVAL_UNREF(connection); }
static VALUE rg_guess_content_type_sync(int argc, VALUE *argv, VALUE self) { VALUE force_rescan, cancellable; GError *error = NULL; gchar **content_types; rb_scan_args(argc, argv, "02", &force_rescan, &cancellable); content_types = g_mount_guess_content_type_sync(_SELF(self), RVAL2CBOOL(force_rescan), RVAL2GCANCELLABLE(cancellable), &error); if (content_types == NULL) rbgio_raise_error(error); return STRV2RVAL_FREE(content_types); }
static VALUE rg_skip(int argc, VALUE *argv, VALUE self) { VALUE count, cancellable; GError *error = NULL; gssize bytes_skipped; rb_scan_args(argc, argv, "11", &count, &cancellable); bytes_skipped = g_input_stream_skip(_SELF(self), RVAL2GSIZE(count), RVAL2GCANCELLABLE(cancellable), &error); if (bytes_skipped == -1) rbgio_raise_error(error); return GSSIZE2RVAL(bytes_skipped); }
static VALUE rg_lookup_by_address(int argc, VALUE *argv, VALUE self) { VALUE address, cancellable; GError *error = NULL; gchar *hostname; rb_scan_args(argc, argv, "11", &address, &cancellable); hostname = g_resolver_lookup_by_address(_SELF(self), RVAL2GINETADDRESS(address), RVAL2GCANCELLABLE(cancellable), &error); if (hostname == NULL) rbgio_raise_error(error); return CSTR2RVAL_FREE(hostname); }
static VALUE rg_query_info(int argc, VALUE *argv, VALUE self) { VALUE attributes, cancellable; GError *error = NULL; GFileInfo *info; rb_scan_args(argc, argv, "02", &attributes, &cancellable); info = g_file_input_stream_query_info(_SELF(self), RVAL2ATTRIBUTESDEFAULT(attributes), RVAL2GCANCELLABLE(cancellable), &error); if (info == NULL) rbgio_raise_error(error); return GOBJ2RVAL_UNREF(info); }
static VALUE rg_connect_to_service(int argc, VALUE *argv, VALUE self) { VALUE domain, service, cancellable; GError *error = NULL; GSocketConnection *connection; rb_scan_args(argc, argv, "21", &domain, &service, &cancellable); connection = g_socket_client_connect_to_service(_SELF(self), RVAL2CSTR(domain), RVAL2CSTR(service), RVAL2GCANCELLABLE(cancellable), &error); if (connection == NULL) rbgio_raise_error(error); return self; }
static VALUE rg_connect_to_host(int argc, VALUE *argv, VALUE self) { VALUE host_and_port, default_port, cancellable; GError *error = NULL; GSocketConnection *connection; rb_scan_args(argc, argv, "21", &host_and_port, &default_port, &cancellable); connection = g_socket_client_connect_to_host(_SELF(self), RVAL2CSTR(host_and_port), RVAL2GUINT16(default_port), RVAL2GCANCELLABLE(cancellable), &error); if (connection == NULL) rbgio_raise_error(error); return self; }
static VALUE rg_splice(int argc, VALUE *argv, VALUE self) { VALUE source, flags, cancellable; GError *error = NULL; gssize bytes_spliced; rb_scan_args(argc, argv, "12", &source, &flags, &cancellable); bytes_spliced = g_output_stream_splice(_SELF(self), RVAL2GINPUTSTREAM(source), RVAL2GOUTPUTSTREAMSPLICEFLAGSDEFAULT(flags), RVAL2GCANCELLABLE(cancellable), &error); if (bytes_spliced == -1) rbgio_raise_error(error); return GSSIZE2RVAL(bytes_spliced); }
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; }
static VALUE rg_lookup_by_name_async(int argc, VALUE *argv, VALUE self) { VALUE rbhostname, rbcancellable, block; const gchar *hostname; GCancellable *cancellable; rb_scan_args(argc, argv, "11&", &hostname, &rbcancellable, &block); hostname = RVAL2CSTR(rbhostname); cancellable = RVAL2GCANCELLABLE(rbcancellable); SAVE_BLOCK(block); g_resolver_lookup_by_name_async(_SELF(self), hostname, cancellable, rbgio_async_ready_callback, (gpointer)block); return self; }
static VALUE rg_lookup_by_address_async(int argc, VALUE *argv, VALUE self) { VALUE rbaddress, rbcancellable, block; GInetAddress *address; GCancellable *cancellable; rb_scan_args(argc, argv, "11&", &rbaddress, &rbcancellable, &block); address = RVAL2GINETADDRESS(rbaddress); cancellable = RVAL2GCANCELLABLE(rbcancellable); SAVE_BLOCK(block); g_resolver_lookup_by_address_async(_SELF(self), address, cancellable, rbgio_async_ready_callback, (gpointer)block); return self; }
static VALUE rg_lookup_service(int argc, VALUE *argv, VALUE self) { VALUE service, protocol, domain, cancellable; GError *error = NULL; GList *targets; rb_scan_args(argc, argv, "31", &service, &protocol, &domain, &cancellable); targets = g_resolver_lookup_service(_SELF(self), RVAL2CSTR(service), RVAL2CSTR(protocol), RVAL2CSTR(domain), RVAL2GCANCELLABLE(cancellable), &error); if (targets == NULL) rbgio_raise_error(error); return GLIST2ARY_UNREF_FREE(targets); }