Skip to content

Commit 7747480

Browse files
bilelmoussaouisdroege
authored andcommitted
gio/win32: Manually implement streams
Copying what we had in gio where it makes sense
1 parent 31ac68b commit 7747480

File tree

10 files changed

+155
-234
lines changed

10 files changed

+155
-234
lines changed

gio-win32/Gir.toml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ deprecate_by_min_version = true
1111
trust_return_value_nullability = true
1212

1313
generate = [
14-
"GioWin32.InputStream",
15-
"GioWin32.OutputStream"
1614
#"GioWin32.NetworkMonitor",
1715
]
1816

@@ -28,3 +26,31 @@ manual = [
2826
[[object]]
2927
name = "GioWin32.*"
3028
status = "generate"
29+
30+
[[object]]
31+
name = "GioWin32.InputStream"
32+
status = "generate"
33+
manual_traits = ["InputStreamExtManual"]
34+
[[object.function]]
35+
name = "new"
36+
manual = true
37+
[[object.function]]
38+
name = "set_close_handle"
39+
unsafe = true
40+
[[object.function]]
41+
name = "get_handle"
42+
manual = true
43+
44+
[[object]]
45+
name = "GioWin32.OutputStream"
46+
status = "generate"
47+
manual_traits = ["OutputStreamExtManual"]
48+
[[object.function]]
49+
name = "new"
50+
manual = true
51+
[[object.function]]
52+
name = "set_close_handle"
53+
unsafe = true
54+
[[object.function]]
55+
name = "get_handle"
56+
manual = true

gio-win32/src/auto/input_stream.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ glib::wrapper! {
2121

2222
impl InputStream {
2323
pub const NONE: Option<&'static InputStream> = None;
24-
25-
//#[doc(alias = "g_win32_input_stream_new")]
26-
//pub fn new(handle: /*Unimplemented*/Option<Basic: Pointer>, close_handle: bool) -> InputStream {
27-
// unsafe { TODO: call ffi:g_win32_input_stream_new() }
28-
//}
2924
}
3025

3126
pub trait InputStreamExt: IsA<InputStream> + 'static {
@@ -40,21 +35,13 @@ pub trait InputStreamExt: IsA<InputStream> + 'static {
4035
}
4136
}
4237

43-
//#[doc(alias = "g_win32_input_stream_get_handle")]
44-
//#[doc(alias = "get_handle")]
45-
//fn handle(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
46-
// unsafe { TODO: call ffi:g_win32_input_stream_get_handle() }
47-
//}
48-
4938
#[doc(alias = "g_win32_input_stream_set_close_handle")]
5039
#[doc(alias = "close-handle")]
51-
fn set_close_handle(&self, close_handle: bool) {
52-
unsafe {
53-
ffi::g_win32_input_stream_set_close_handle(
54-
self.as_ref().to_glib_none().0,
55-
close_handle.into_glib(),
56-
);
57-
}
40+
unsafe fn set_close_handle(&self, close_handle: bool) {
41+
ffi::g_win32_input_stream_set_close_handle(
42+
self.as_ref().to_glib_none().0,
43+
close_handle.into_glib(),
44+
);
5845
}
5946

6047
#[doc(alias = "close-handle")]

gio-win32/src/auto/output_stream.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ glib::wrapper! {
2121

2222
impl OutputStream {
2323
pub const NONE: Option<&'static OutputStream> = None;
24-
25-
//#[doc(alias = "g_win32_output_stream_new")]
26-
//pub fn new(handle: /*Unimplemented*/Option<Basic: Pointer>, close_handle: bool) -> OutputStream {
27-
// unsafe { TODO: call ffi:g_win32_output_stream_new() }
28-
//}
2924
}
3025

3126
pub trait OutputStreamExt: IsA<OutputStream> + 'static {
@@ -40,21 +35,13 @@ pub trait OutputStreamExt: IsA<OutputStream> + 'static {
4035
}
4136
}
4237

43-
//#[doc(alias = "g_win32_output_stream_get_handle")]
44-
//#[doc(alias = "get_handle")]
45-
//fn handle(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
46-
// unsafe { TODO: call ffi:g_win32_output_stream_get_handle() }
47-
//}
48-
4938
#[doc(alias = "g_win32_output_stream_set_close_handle")]
5039
#[doc(alias = "close-handle")]
51-
fn set_close_handle(&self, close_handle: bool) {
52-
unsafe {
53-
ffi::g_win32_output_stream_set_close_handle(
54-
self.as_ref().to_glib_none().0,
55-
close_handle.into_glib(),
56-
);
57-
}
40+
unsafe fn set_close_handle(&self, close_handle: bool) {
41+
ffi::g_win32_output_stream_set_close_handle(
42+
self.as_ref().to_glib_none().0,
43+
close_handle.into_glib(),
44+
);
5845
}
5946

6047
#[doc(alias = "close-handle")]

gio-win32/src/input_stream.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle};
4+
5+
use glib::{prelude::*, translate::*};
6+
7+
use crate::{ffi, InputStream};
8+
9+
impl InputStream {
10+
// rustdoc-stripper-ignore-next
11+
/// Creates a new [`Self`] that takes ownership of the passed in handle.
12+
///
13+
/// # Safety
14+
/// You must not close the handle unless you've previously called [`InputStreamExtManual::set_close_handle`]
15+
/// with `true` on this stream. At which point you may only do so when all references to this
16+
/// stream have been dropped.
17+
#[doc(alias = "g_win32_input_stream_new")]
18+
pub unsafe fn take_handle(handle: impl IntoRawHandle) -> InputStream {
19+
let handle = handle.into_raw_handle();
20+
let close_handle = true.into_glib();
21+
gio::InputStream::from_glib_full(ffi::g_win32_input_stream_new(handle, close_handle))
22+
.unsafe_cast()
23+
}
24+
25+
// rustdoc-stripper-ignore-next
26+
/// Creates a new [`Self`] that does not take ownership of the passed in handle.
27+
///
28+
/// # Safety
29+
/// You may only close the handle if all references to this stream have been dropped.
30+
#[doc(alias = "g_win32_input_stream_new")]
31+
pub unsafe fn with_handle<T: AsRawHandle>(handle: T) -> InputStream {
32+
let handle = handle.as_raw_handle();
33+
let close_handle = false.into_glib();
34+
gio::InputStream::from_glib_full(ffi::g_win32_input_stream_new(handle, close_handle))
35+
.unsafe_cast()
36+
}
37+
}
38+
39+
impl AsRawHandle for InputStream {
40+
fn as_raw_handle(&self) -> RawHandle {
41+
unsafe { ffi::g_win32_input_stream_get_handle(self.to_glib_none().0) as _ }
42+
}
43+
}
44+
45+
pub trait InputStreamExtManual: IsA<InputStream> + Sized {
46+
#[doc(alias = "g_win32_input_stream_get_handle")]
47+
#[doc(alias = "get_handle")]
48+
fn handle<T: FromRawHandle>(&self) -> T {
49+
unsafe {
50+
T::from_raw_handle(ffi::g_win32_input_stream_get_handle(
51+
self.as_ref().to_glib_none().0,
52+
))
53+
}
54+
}
55+
}
56+
57+
impl<O: IsA<InputStream>> InputStreamExtManual for O {}

gio-win32/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pub use ffi;
55
mod auto;
66
pub use auto::*;
77

8+
mod input_stream;
9+
mod output_stream;
10+
811
pub mod functions {
912
pub use super::auto::functions::*;
1013
}

gio-win32/src/output_stream.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle};
4+
5+
use glib::{prelude::*, translate::*};
6+
7+
use crate::{ffi, OutputStream};
8+
9+
impl OutputStream {
10+
// rustdoc-stripper-ignore-next
11+
/// Creates a new [`Self`] that takes ownership of the passed in handle.
12+
///
13+
/// # Safety
14+
/// You must not close the handle unless you've previously called [`OutputStreamExtManual::set_close_handle`]
15+
/// with `true` on this stream. At which point you may only do so when all references to this
16+
/// stream have been dropped.
17+
#[doc(alias = "g_win32_output_stream_new")]
18+
pub unsafe fn take_handle(handle: impl IntoRawHandle) -> OutputStream {
19+
let handle = handle.into_raw_handle();
20+
let close_handle = true.into_glib();
21+
gio::OutputStream::from_glib_full(ffi::g_win32_output_stream_new(handle, close_handle))
22+
.unsafe_cast()
23+
}
24+
25+
// rustdoc-stripper-ignore-next
26+
/// Creates a new [`Self`] that does not take ownership of the passed in handle.
27+
///
28+
/// # Safety
29+
/// You may only close the handle if all references to this stream have been dropped.
30+
#[doc(alias = "g_win32_output_stream_new")]
31+
pub unsafe fn with_handle<T: AsRawHandle>(handle: T) -> OutputStream {
32+
let handle = handle.as_raw_handle();
33+
let close_handle = false.into_glib();
34+
gio::OutputStream::from_glib_full(ffi::g_win32_output_stream_new(handle, close_handle))
35+
.unsafe_cast()
36+
}
37+
}
38+
39+
impl AsRawHandle for OutputStream {
40+
fn as_raw_handle(&self) -> RawHandle {
41+
unsafe { ffi::g_win32_output_stream_get_handle(self.to_glib_none().0) as _ }
42+
}
43+
}
44+
45+
pub trait OutputStreamExtManual: IsA<OutputStream> + Sized {
46+
#[doc(alias = "g_win32_output_stream_get_handle")]
47+
#[doc(alias = "get_handle")]
48+
fn handle<T: FromRawHandle>(&self) -> T {
49+
unsafe {
50+
T::from_raw_handle(ffi::g_win32_output_stream_get_handle(
51+
self.as_ref().to_glib_none().0,
52+
))
53+
}
54+
}
55+
}
56+
57+
impl<O: IsA<OutputStream>> OutputStreamExtManual for O {}

gio/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,3 @@ mod write_output_stream;
132132
pub use crate::write_output_stream::WriteOutputStream;
133133
mod dbus_proxy;
134134
mod tls_connection;
135-
136-
#[cfg(windows)]
137-
mod win32_input_stream;
138-
#[cfg(windows)]
139-
pub use self::win32_input_stream::Win32InputStream;
140-
141-
#[cfg(windows)]
142-
mod win32_output_stream;
143-
#[cfg(windows)]
144-
pub use self::win32_output_stream::Win32OutputStream;

gio/src/prelude.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ pub use crate::app_info::AppInfoExtManual;
1111
#[cfg(feature = "v2_72")]
1212
#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
1313
pub use crate::debug_controller_dbus::DebugControllerDBusExtManual;
14-
#[cfg(windows)]
15-
pub use crate::win32_input_stream::Win32InputStreamExt;
16-
#[cfg(windows)]
17-
pub use crate::win32_output_stream::Win32OutputStreamExt;
1814
pub use crate::{
1915
action_map::ActionMapExtManual, application::ApplicationExtManual,
2016
application_command_line::ApplicationCommandLineExtManual, auto::traits::*,

gio/src/win32_input_stream.rs

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)