gio/auto/
dtls_server_connection.rs1use crate::{ffi, DatagramBased, DtlsConnection, TlsAuthenticationMode, TlsCertificate};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GDtlsServerConnection")]
15 pub struct DtlsServerConnection(Interface<ffi::GDtlsServerConnection, ffi::GDtlsServerConnectionInterface>) @requires DatagramBased, DtlsConnection;
16
17 match fn {
18 type_ => || ffi::g_dtls_server_connection_get_type(),
19 }
20}
21
22impl DtlsServerConnection {
23 pub const NONE: Option<&'static DtlsServerConnection> = None;
24
25 #[doc(alias = "g_dtls_server_connection_new")]
26 pub fn new(
27 base_socket: &impl IsA<DatagramBased>,
28 certificate: Option<&impl IsA<TlsCertificate>>,
29 ) -> Result<DtlsServerConnection, glib::Error> {
30 unsafe {
31 let mut error = std::ptr::null_mut();
32 let ret = ffi::g_dtls_server_connection_new(
33 base_socket.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
46pub trait DtlsServerConnectionExt: IsA<DtlsServerConnection> + 'static {
47 #[doc(alias = "authentication-mode")]
48 fn authentication_mode(&self) -> TlsAuthenticationMode {
49 ObjectExt::property(self.as_ref(), "authentication-mode")
50 }
51
52 #[doc(alias = "authentication-mode")]
53 fn set_authentication_mode(&self, authentication_mode: TlsAuthenticationMode) {
54 ObjectExt::set_property(self.as_ref(), "authentication-mode", authentication_mode)
55 }
56
57 #[doc(alias = "authentication-mode")]
58 fn connect_authentication_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
59 unsafe extern "C" fn notify_authentication_mode_trampoline<
60 P: IsA<DtlsServerConnection>,
61 F: Fn(&P) + 'static,
62 >(
63 this: *mut ffi::GDtlsServerConnection,
64 _param_spec: glib::ffi::gpointer,
65 f: glib::ffi::gpointer,
66 ) {
67 let f: &F = &*(f as *const F);
68 f(DtlsServerConnection::from_glib_borrow(this).unsafe_cast_ref())
69 }
70 unsafe {
71 let f: Box_<F> = Box_::new(f);
72 connect_raw(
73 self.as_ptr() as *mut _,
74 c"notify::authentication-mode".as_ptr() as *const _,
75 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
76 notify_authentication_mode_trampoline::<Self, F> as *const (),
77 )),
78 Box_::into_raw(f),
79 )
80 }
81 }
82}
83
84impl<O: IsA<DtlsServerConnection>> DtlsServerConnectionExt for O {}