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 gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib_sys;
12use std::boxed::Box as Box_;
13use std::fmt;
14use std::mem::transmute;
15use IOStream;
16use SocketConnection;
17
18glib_wrapper! {
19    pub struct TcpConnection(Object<gio_sys::GTcpConnection, gio_sys::GTcpConnectionClass, TcpConnectionClass>) @extends SocketConnection, IOStream;
20
21    match fn {
22        get_type => || gio_sys::g_tcp_connection_get_type(),
23    }
24}
25
26pub const NONE_TCP_CONNECTION: Option<&TcpConnection> = None;
27
28pub trait TcpConnectionExt: 'static {
29    fn get_graceful_disconnect(&self) -> bool;
30
31    fn set_graceful_disconnect(&self, graceful_disconnect: bool);
32
33    fn connect_property_graceful_disconnect_notify<F: Fn(&Self) + 'static>(
34        &self,
35        f: F,
36    ) -> SignalHandlerId;
37}
38
39impl<O: IsA<TcpConnection>> TcpConnectionExt for O {
40    fn get_graceful_disconnect(&self) -> bool {
41        unsafe {
42            from_glib(gio_sys::g_tcp_connection_get_graceful_disconnect(
43                self.as_ref().to_glib_none().0,
44            ))
45        }
46    }
47
48    fn set_graceful_disconnect(&self, graceful_disconnect: bool) {
49        unsafe {
50            gio_sys::g_tcp_connection_set_graceful_disconnect(
51                self.as_ref().to_glib_none().0,
52                graceful_disconnect.to_glib(),
53            );
54        }
55    }
56
57    fn connect_property_graceful_disconnect_notify<F: Fn(&Self) + 'static>(
58        &self,
59        f: F,
60    ) -> SignalHandlerId {
61        unsafe extern "C" fn notify_graceful_disconnect_trampoline<P, F: Fn(&P) + 'static>(
62            this: *mut gio_sys::GTcpConnection,
63            _param_spec: glib_sys::gpointer,
64            f: glib_sys::gpointer,
65        ) where
66            P: IsA<TcpConnection>,
67        {
68            let f: &F = &*(f as *const F);
69            f(&TcpConnection::from_glib_borrow(this).unsafe_cast())
70        }
71        unsafe {
72            let f: Box_<F> = Box_::new(f);
73            connect_raw(
74                self.as_ptr() as *mut _,
75                b"notify::graceful-disconnect\0".as_ptr() as *const _,
76                Some(transmute(
77                    notify_graceful_disconnect_trampoline::<Self, F> as usize,
78                )),
79                Box_::into_raw(f),
80            )
81        }
82    }
83}
84
85impl fmt::Display for TcpConnection {
86    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87        write!(f, "TcpConnection")
88    }
89}