gio/auto/
tls_server_connection.rs1use crate::{ffi, IOStream, TlsAuthenticationMode, TlsCertificate, TlsConnection};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GTlsServerConnection")]
15 pub struct TlsServerConnection(Interface<ffi::GTlsServerConnection, ffi::GTlsServerConnectionInterface>) @requires TlsConnection, IOStream;
16
17 match fn {
18 type_ => || ffi::g_tls_server_connection_get_type(),
19 }
20}
21
22impl TlsServerConnection {
23 pub const NONE: Option<&'static TlsServerConnection> = None;
24
25 #[doc(alias = "g_tls_server_connection_new")]
26 pub fn new(
27 base_io_stream: &impl IsA<IOStream>,
28 certificate: Option<&impl IsA<TlsCertificate>>,
29 ) -> Result<TlsServerConnection, glib::Error> {
30 unsafe {
31 let mut error = std::ptr::null_mut();
32 let ret = ffi::g_tls_server_connection_new(
33 base_io_stream.as_ref().to_glib_none().0,
34 certificate.map(|p| p.as_ref()).to_glib_none().0,
35 &mut error,
36 );
37 if error.is_null() {
38 Ok(from_glib_full(ret))
39 } else {
40 Err(from_glib_full(error))
41 }
42 }
43 }
44}
45
46mod sealed {
47 pub trait Sealed {}
48 impl<T: super::IsA<super::TlsServerConnection>> Sealed for T {}
49}
50
51pub trait TlsServerConnectionExt: IsA<TlsServerConnection> + sealed::Sealed + 'static {
52 #[doc(alias = "authentication-mode")]
53 fn authentication_mode(&self) -> TlsAuthenticationMode {
54 ObjectExt::property(self.as_ref(), "authentication-mode")
55 }
56
57 #[doc(alias = "authentication-mode")]
58 fn set_authentication_mode(&self, authentication_mode: TlsAuthenticationMode) {
59 ObjectExt::set_property(self.as_ref(), "authentication-mode", authentication_mode)
60 }
61
62 #[doc(alias = "authentication-mode")]
63 fn connect_authentication_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
64 unsafe extern "C" fn notify_authentication_mode_trampoline<
65 P: IsA<TlsServerConnection>,
66 F: Fn(&P) + 'static,
67 >(
68 this: *mut ffi::GTlsServerConnection,
69 _param_spec: glib::ffi::gpointer,
70 f: glib::ffi::gpointer,
71 ) {
72 let f: &F = &*(f as *const F);
73 f(TlsServerConnection::from_glib_borrow(this).unsafe_cast_ref())
74 }
75 unsafe {
76 let f: Box_<F> = Box_::new(f);
77 connect_raw(
78 self.as_ptr() as *mut _,
79 b"notify::authentication-mode\0".as_ptr() as *const _,
80 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
81 notify_authentication_mode_trampoline::<Self, F> as *const (),
82 )),
83 Box_::into_raw(f),
84 )
85 }
86 }
87}
88
89impl<O: IsA<TlsServerConnection>> TlsServerConnectionExt for O {}