gio/auto/
tcp_connection.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, IOStream, SocketConnection};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GTcpConnection")]
15    pub struct TcpConnection(Object<ffi::GTcpConnection, ffi::GTcpConnectionClass>) @extends SocketConnection, IOStream;
16
17    match fn {
18        type_ => || ffi::g_tcp_connection_get_type(),
19    }
20}
21
22impl TcpConnection {
23    pub const NONE: Option<&'static TcpConnection> = None;
24}
25
26pub trait TcpConnectionExt: IsA<TcpConnection> + 'static {
27    #[doc(alias = "g_tcp_connection_get_graceful_disconnect")]
28    #[doc(alias = "get_graceful_disconnect")]
29    #[doc(alias = "graceful-disconnect")]
30    fn is_graceful_disconnect(&self) -> bool {
31        unsafe {
32            from_glib(ffi::g_tcp_connection_get_graceful_disconnect(
33                self.as_ref().to_glib_none().0,
34            ))
35        }
36    }
37
38    #[doc(alias = "g_tcp_connection_set_graceful_disconnect")]
39    #[doc(alias = "graceful-disconnect")]
40    fn set_graceful_disconnect(&self, graceful_disconnect: bool) {
41        unsafe {
42            ffi::g_tcp_connection_set_graceful_disconnect(
43                self.as_ref().to_glib_none().0,
44                graceful_disconnect.into_glib(),
45            );
46        }
47    }
48
49    #[doc(alias = "graceful-disconnect")]
50    fn connect_graceful_disconnect_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
51        unsafe extern "C" fn notify_graceful_disconnect_trampoline<
52            P: IsA<TcpConnection>,
53            F: Fn(&P) + 'static,
54        >(
55            this: *mut ffi::GTcpConnection,
56            _param_spec: glib::ffi::gpointer,
57            f: glib::ffi::gpointer,
58        ) {
59            let f: &F = &*(f as *const F);
60            f(TcpConnection::from_glib_borrow(this).unsafe_cast_ref())
61        }
62        unsafe {
63            let f: Box_<F> = Box_::new(f);
64            connect_raw(
65                self.as_ptr() as *mut _,
66                c"notify::graceful-disconnect".as_ptr() as *const _,
67                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
68                    notify_graceful_disconnect_trampoline::<Self, F> as *const (),
69                )),
70                Box_::into_raw(f),
71            )
72        }
73    }
74}
75
76impl<O: IsA<TcpConnection>> TcpConnectionExt for O {}