Skip to content

Commit b3e0e1c

Browse files
Merge pull request gtk-rs#85 from MathieuDuponchelle/async_callbacks
Async callbacks
2 parents d523527 + 65e59e0 commit b3e0e1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+621
-835
lines changed

Gir.toml

Lines changed: 12 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ generate = [
4747
"Gio.SocketProtocol",
4848
"Gio.SocketAddress",
4949
"Gio.InetSocketAddress",
50+
"Gio.SocketAddressEnumerator",
5051
"Gio.SocketConnectable",
5152
"Gio.SocketConnection",
5253
"Gio.SocketService",
5354
"Gio.SocketListenerEvent",
55+
"Gio.SocketClient",
5456
"Gio.SocketClientEvent",
5557
"Gio.ThreadedSocketService",
5658
"Gio.TcpConnection",
59+
"Gio.Resolver",
5760
"Gio.ResolverRecordType",
5861
"Gio.SrvTarget",
5962
"Gio.NetworkAddress",
@@ -76,6 +79,7 @@ manual = [
7679
"GLib.VariantType",
7780
"GLib.IOCondition",
7881
"GLib.Source",
82+
"GLib.Priority",
7983
"GObject.Object",
8084
]
8185

@@ -110,10 +114,6 @@ status = "generate"
110114
[[object]]
111115
name = "Gio.BufferedInputStream"
112116
status = "generate"
113-
[[object.function]]
114-
name = "fill_async"
115-
#manual return type
116-
ignore = true
117117
[[object.function]]
118118
name = "peek"
119119
#have almost same peek_buffer
@@ -127,6 +127,11 @@ status = "generate"
127127
#return vec of u8
128128
ignore = true
129129

130+
[[object.function]]
131+
name = "read_line_async"
132+
#return vec of u8
133+
ignore = true
134+
130135
[[object]]
131136
name = "Gio.File"
132137
status = "generate"
@@ -157,46 +162,6 @@ status = "generate"
157162
name = "find_enclosing_mount_async"
158163
# Mount
159164
ignore = true
160-
[[object.function]]
161-
name = "append_to_async"
162-
# wrong async return
163-
ignore = true
164-
[[object.function]]
165-
name = "create_async"
166-
# wrong async return
167-
ignore = true
168-
[[object.function]]
169-
name = "create_readwrite_async"
170-
# wrong async return
171-
ignore = true
172-
[[object.function]]
173-
name = "open_readwrite_async"
174-
# wrong async return
175-
ignore = true
176-
[[object.function]]
177-
name = "query_filesystem_info_async"
178-
# wrong async return
179-
ignore = true
180-
[[object.function]]
181-
name = "query_info_async"
182-
# wrong async return
183-
ignore = true
184-
[[object.function]]
185-
name = "read_async"
186-
# wrong async return
187-
ignore = true
188-
[[object.function]]
189-
name = "replace_async"
190-
# wrong async return
191-
ignore = true
192-
[[object.function]]
193-
name = "replace_readwrite_async"
194-
# wrong async return
195-
ignore = true
196-
[[object.function]]
197-
name = "set_display_name_async"
198-
# wrong async return
199-
ignore = true
200165

201166
[[object]]
202167
name = "Gio.FilterInputStream"
@@ -237,14 +202,6 @@ status = "generate"
237202
pattern = "read(_all)?(_async)?"
238203
#mutable buffer
239204
ignore = true
240-
[[object.function]]
241-
name = "read_bytes_async"
242-
#wrong async callback type
243-
ignore = true
244-
[[object.function]]
245-
name = "skip_async"
246-
#wrong async callback type
247-
ignore = true
248205

249206
[[object]]
250207
name = "Gio.MemoryInputStream"
@@ -301,22 +258,14 @@ status = "generate"
301258
[[object]]
302259
name = "Gio.OutputStream"
303260
status = "generate"
304-
[[object.function]]
305-
name = "splice_async"
306-
#wrong async callback type
307-
ignore = true
308261
[[object.function]]
309262
name = "write_async"
310-
#wrong async callback type
263+
#AsRef<u8>
311264
ignore = true
312265
[[object.function]]
313266
name = "write_all_async"
314267
#AsRef<u8>
315268
ignore = true
316-
[[object.function]]
317-
name = "write_bytes_async"
318-
#wrong async callback type
319-
ignore = true
320269

321270
[[object]]
322271
name = "Gio.Settings"
@@ -405,36 +354,12 @@ status = "generate"
405354
# broken and needs some closer integration with the corresponding std types
406355
ignore = true
407356

408-
[[object]]
409-
name = "Gio.SocketAddressEnumerator"
410-
status = "generate"
411-
[[object.function]]
412-
name = "next_async"
413-
# broken
414-
ignore = true
415-
416357
[[object]]
417358
name = "Gio.SocketListener"
418359
status = "generate"
419360
[[object.function]]
420-
pattern = ".*_async"
421-
# broken
422-
ignore = true
423-
424-
[[object]]
425-
name = "Gio.SocketClient"
426-
status = "generate"
427-
[[object.function]]
428-
pattern = ".*_async"
429-
# broken
430-
ignore = true
431-
432-
[[object]]
433-
name = "Gio.Resolver"
434-
status = "generate"
435-
[[object.function]]
436-
pattern = ".*_async"
437-
# broken
361+
name = "accept_socket_async"
362+
# finish function misses nullable return annotation
438363
ignore = true
439364

440365
[[object]]

src/auto/action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/action_group.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/action_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/app_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/app_launch_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/application.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/buffered_input_stream.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

@@ -45,6 +45,8 @@ impl BufferedInputStream {
4545
pub trait BufferedInputStreamExt {
4646
fn fill<'a, P: Into<Option<&'a Cancellable>>>(&self, count: isize, cancellable: P) -> Result<isize, Error>;
4747

48+
fn fill_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<isize, Error>) + Send + 'static>(&self, count: isize, io_priority: glib::Priority, cancellable: P, callback: Q);
49+
4850
fn get_available(&self) -> usize;
4951

5052
fn get_buffer_size(&self) -> usize;
@@ -69,6 +71,24 @@ impl<O: IsA<BufferedInputStream> + IsA<glib::object::Object>> BufferedInputStrea
6971
}
7072
}
7173

74+
fn fill_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<isize, Error>) + Send + 'static>(&self, count: isize, io_priority: glib::Priority, cancellable: P, callback: Q) {
75+
let cancellable = cancellable.into();
76+
let cancellable = cancellable.to_glib_none();
77+
let user_data: Box<Box<Q>> = Box::new(Box::new(callback));
78+
unsafe extern "C" fn fill_async_trampoline<Q: FnOnce(Result<isize, Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
79+
{
80+
let mut error = ptr::null_mut();
81+
let ret = ffi::g_buffered_input_stream_fill_finish(_source_object as *mut _, res, &mut error);
82+
let result = if error.is_null() { Ok(ret) } else { Err(from_glib_full(error)) };
83+
let callback: Box<Box<Q>> = Box::from_raw(user_data as *mut _);
84+
callback(result);
85+
}
86+
let callback = fill_async_trampoline::<Q>;
87+
unsafe {
88+
ffi::g_buffered_input_stream_fill_async(self.to_glib_none().0, count, io_priority.to_glib(), cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
89+
}
90+
}
91+
7292
fn get_available(&self) -> usize {
7393
unsafe {
7494
ffi::g_buffered_input_stream_get_available(self.to_glib_none().0)

src/auto/buffered_output_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/cancellable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/data_input_stream.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

@@ -52,8 +52,6 @@ pub trait DataInputStreamExt {
5252

5353
fn read_int64<'a, P: Into<Option<&'a Cancellable>>>(&self, cancellable: P) -> Result<i64, Error>;
5454

55-
fn read_line_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<usize, Error>) + Send + 'static>(&self, io_priority: i32, cancellable: P, callback: Q);
56-
5755
//fn read_line_finish_utf8<P: IsA</*Ignored*/AsyncResult>>(&self, result: &P) -> Result<(Option<String>, usize), Error>;
5856

5957
fn read_line_utf8<'a, P: Into<Option<&'a Cancellable>>>(&self, cancellable: P) -> Result<(Option<String>, usize), Error>;
@@ -66,11 +64,11 @@ pub trait DataInputStreamExt {
6664

6765
fn read_until<'a, P: Into<Option<&'a Cancellable>>>(&self, stop_chars: &str, cancellable: P) -> Result<(String, usize), Error>;
6866

69-
fn read_until_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<usize, Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: i32, cancellable: P, callback: Q);
67+
fn read_until_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<(String, usize), Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: glib::Priority, cancellable: P, callback: Q);
7068

7169
fn read_upto<'a, P: Into<Option<&'a Cancellable>>>(&self, stop_chars: &str, cancellable: P) -> Result<(String, usize), Error>;
7270

73-
fn read_upto_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<usize, Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: i32, cancellable: P, callback: Q);
71+
fn read_upto_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<(String, usize), Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: glib::Priority, cancellable: P, callback: Q);
7472

7573
fn set_byte_order(&self, order: DataStreamByteOrder);
7674

@@ -134,25 +132,6 @@ impl<O: IsA<DataInputStream> + IsA<glib::object::Object>> DataInputStreamExt for
134132
}
135133
}
136134

137-
fn read_line_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<usize, Error>) + Send + 'static>(&self, io_priority: i32, cancellable: P, callback: Q) {
138-
let cancellable = cancellable.into();
139-
let cancellable = cancellable.to_glib_none();
140-
let user_data: Box<Box<Q>> = Box::new(Box::new(callback));
141-
unsafe extern "C" fn read_line_async_trampoline<Q: FnOnce(Result<usize, Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
142-
{
143-
let mut error = ptr::null_mut();
144-
let mut length = mem::uninitialized();
145-
let _ = ffi::g_data_input_stream_read_line_finish(_source_object as *mut _, res, &mut length, &mut error);
146-
let result = if error.is_null() { Ok(length) } else { Err(from_glib_full(error)) };
147-
let callback: Box<Box<Q>> = Box::from_raw(user_data as *mut _);
148-
callback(result);
149-
}
150-
let callback = read_line_async_trampoline::<Q>;
151-
unsafe {
152-
ffi::g_data_input_stream_read_line_async(self.to_glib_none().0, io_priority, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
153-
}
154-
}
155-
156135
//fn read_line_finish_utf8<P: IsA</*Ignored*/AsyncResult>>(&self, result: &P) -> Result<(Option<String>, usize), Error> {
157136
// unsafe { TODO: call ffi::g_data_input_stream_read_line_finish_utf8() }
158137
//}
@@ -209,22 +188,22 @@ impl<O: IsA<DataInputStream> + IsA<glib::object::Object>> DataInputStreamExt for
209188
}
210189
}
211190

212-
fn read_until_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<usize, Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: i32, cancellable: P, callback: Q) {
191+
fn read_until_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<(String, usize), Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: glib::Priority, cancellable: P, callback: Q) {
213192
let cancellable = cancellable.into();
214193
let cancellable = cancellable.to_glib_none();
215194
let user_data: Box<Box<Q>> = Box::new(Box::new(callback));
216-
unsafe extern "C" fn read_until_async_trampoline<Q: FnOnce(Result<usize, Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
195+
unsafe extern "C" fn read_until_async_trampoline<Q: FnOnce(Result<(String, usize), Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
217196
{
218197
let mut error = ptr::null_mut();
219198
let mut length = mem::uninitialized();
220-
let _ = ffi::g_data_input_stream_read_until_finish(_source_object as *mut _, res, &mut length, &mut error);
221-
let result = if error.is_null() { Ok(length) } else { Err(from_glib_full(error)) };
199+
let ret = ffi::g_data_input_stream_read_until_finish(_source_object as *mut _, res, &mut length, &mut error);
200+
let result = if error.is_null() { Ok((from_glib_full(ret), length)) } else { Err(from_glib_full(error)) };
222201
let callback: Box<Box<Q>> = Box::from_raw(user_data as *mut _);
223202
callback(result);
224203
}
225204
let callback = read_until_async_trampoline::<Q>;
226205
unsafe {
227-
ffi::g_data_input_stream_read_until_async(self.to_glib_none().0, stop_chars.to_glib_none().0, io_priority, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
206+
ffi::g_data_input_stream_read_until_async(self.to_glib_none().0, stop_chars.to_glib_none().0, io_priority.to_glib(), cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
228207
}
229208
}
230209

@@ -240,23 +219,23 @@ impl<O: IsA<DataInputStream> + IsA<glib::object::Object>> DataInputStreamExt for
240219
}
241220
}
242221

243-
fn read_upto_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<usize, Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: i32, cancellable: P, callback: Q) {
222+
fn read_upto_async<'a, P: Into<Option<&'a Cancellable>>, Q: FnOnce(Result<(String, usize), Error>) + Send + 'static>(&self, stop_chars: &str, io_priority: glib::Priority, cancellable: P, callback: Q) {
244223
let cancellable = cancellable.into();
245224
let cancellable = cancellable.to_glib_none();
246225
let stop_chars_len = stop_chars.len() as isize;
247226
let user_data: Box<Box<Q>> = Box::new(Box::new(callback));
248-
unsafe extern "C" fn read_upto_async_trampoline<Q: FnOnce(Result<usize, Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
227+
unsafe extern "C" fn read_upto_async_trampoline<Q: FnOnce(Result<(String, usize), Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
249228
{
250229
let mut error = ptr::null_mut();
251230
let mut length = mem::uninitialized();
252-
let _ = ffi::g_data_input_stream_read_upto_finish(_source_object as *mut _, res, &mut length, &mut error);
253-
let result = if error.is_null() { Ok(length) } else { Err(from_glib_full(error)) };
231+
let ret = ffi::g_data_input_stream_read_upto_finish(_source_object as *mut _, res, &mut length, &mut error);
232+
let result = if error.is_null() { Ok((from_glib_full(ret), length)) } else { Err(from_glib_full(error)) };
254233
let callback: Box<Box<Q>> = Box::from_raw(user_data as *mut _);
255234
callback(result);
256235
}
257236
let callback = read_upto_async_trampoline::<Q>;
258237
unsafe {
259-
ffi::g_data_input_stream_read_upto_async(self.to_glib_none().0, stop_chars.to_glib_none().0, stop_chars_len, io_priority, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
238+
ffi::g_data_input_stream_read_upto_async(self.to_glib_none().0, stop_chars.to_glib_none().0, stop_chars_len, io_priority.to_glib(), cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
260239
}
261240
}
262241

src/auto/data_output_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

src/auto/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was generated by gir (https://github.com/gtk-rs/gir @ 8b9d0bb)
1+
// This file was generated by gir (https://github.com/gtk-rs/gir @ 72ba992)
22
// from gir-files (https://github.com/gtk-rs/gir-files @ 77d1f70)
33
// DO NOT EDIT
44

0 commit comments

Comments
 (0)