gio/auto/
tls_server_connection.rs1use gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::Value;
13use glib_sys;
14use gobject_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use std::ptr;
19use Error;
20use IOStream;
21use TlsAuthenticationMode;
22use TlsCertificate;
23use TlsConnection;
24
25glib_wrapper! {
26 pub struct TlsServerConnection(Interface<gio_sys::GTlsServerConnection>) @requires TlsConnection, IOStream;
27
28 match fn {
29 get_type => || gio_sys::g_tls_server_connection_get_type(),
30 }
31}
32
33impl TlsServerConnection {
34 pub fn new<P: IsA<IOStream>, Q: IsA<TlsCertificate>>(
35 base_io_stream: &P,
36 certificate: Option<&Q>,
37 ) -> Result<TlsServerConnection, Error> {
38 unsafe {
39 let mut error = ptr::null_mut();
40 let ret = gio_sys::g_tls_server_connection_new(
41 base_io_stream.as_ref().to_glib_none().0,
42 certificate.map(|p| p.as_ref()).to_glib_none().0,
43 &mut error,
44 );
45 if error.is_null() {
46 Ok(from_glib_full(ret))
47 } else {
48 Err(from_glib_full(error))
49 }
50 }
51 }
52}
53
54pub const NONE_TLS_SERVER_CONNECTION: Option<&TlsServerConnection> = None;
55
56pub trait TlsServerConnectionExt: 'static {
57 fn get_property_authentication_mode(&self) -> TlsAuthenticationMode;
58
59 fn set_property_authentication_mode(&self, authentication_mode: TlsAuthenticationMode);
60
61 fn connect_property_authentication_mode_notify<F: Fn(&Self) + 'static>(
62 &self,
63 f: F,
64 ) -> SignalHandlerId;
65}
66
67impl<O: IsA<TlsServerConnection>> TlsServerConnectionExt for O {
68 fn get_property_authentication_mode(&self) -> TlsAuthenticationMode {
69 unsafe {
70 let mut value = Value::from_type(<TlsAuthenticationMode as StaticType>::static_type());
71 gobject_sys::g_object_get_property(
72 self.to_glib_none().0 as *mut gobject_sys::GObject,
73 b"authentication-mode\0".as_ptr() as *const _,
74 value.to_glib_none_mut().0,
75 );
76 value.get().unwrap()
77 }
78 }
79
80 fn set_property_authentication_mode(&self, authentication_mode: TlsAuthenticationMode) {
81 unsafe {
82 gobject_sys::g_object_set_property(
83 self.to_glib_none().0 as *mut gobject_sys::GObject,
84 b"authentication-mode\0".as_ptr() as *const _,
85 Value::from(&authentication_mode).to_glib_none().0,
86 );
87 }
88 }
89
90 fn connect_property_authentication_mode_notify<F: Fn(&Self) + 'static>(
91 &self,
92 f: F,
93 ) -> SignalHandlerId {
94 unsafe extern "C" fn notify_authentication_mode_trampoline<P, F: Fn(&P) + 'static>(
95 this: *mut gio_sys::GTlsServerConnection,
96 _param_spec: glib_sys::gpointer,
97 f: glib_sys::gpointer,
98 ) where
99 P: IsA<TlsServerConnection>,
100 {
101 let f: &F = &*(f as *const F);
102 f(&TlsServerConnection::from_glib_borrow(this).unsafe_cast())
103 }
104 unsafe {
105 let f: Box_<F> = Box_::new(f);
106 connect_raw(
107 self.as_ptr() as *mut _,
108 b"notify::authentication-mode\0".as_ptr() as *const _,
109 Some(transmute(
110 notify_authentication_mode_trampoline::<Self, F> as usize,
111 )),
112 Box_::into_raw(f),
113 )
114 }
115 }
116}
117
118impl fmt::Display for TlsServerConnection {
119 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120 write!(f, "TlsServerConnection")
121 }
122}