gio/auto/
dbus_auth_observer.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, Credentials, IOStream};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GDBusAuthObserver")]
16    pub struct DBusAuthObserver(Object<ffi::GDBusAuthObserver>);
17
18    match fn {
19        type_ => || ffi::g_dbus_auth_observer_get_type(),
20    }
21}
22
23impl DBusAuthObserver {
24    #[doc(alias = "g_dbus_auth_observer_new")]
25    pub fn new() -> DBusAuthObserver {
26        unsafe { from_glib_full(ffi::g_dbus_auth_observer_new()) }
27    }
28
29    #[doc(alias = "g_dbus_auth_observer_allow_mechanism")]
30    pub fn allow_mechanism(&self, mechanism: &str) -> bool {
31        unsafe {
32            from_glib(ffi::g_dbus_auth_observer_allow_mechanism(
33                self.to_glib_none().0,
34                mechanism.to_glib_none().0,
35            ))
36        }
37    }
38
39    #[doc(alias = "g_dbus_auth_observer_authorize_authenticated_peer")]
40    pub fn authorize_authenticated_peer(
41        &self,
42        stream: &impl IsA<IOStream>,
43        credentials: Option<&Credentials>,
44    ) -> bool {
45        unsafe {
46            from_glib(ffi::g_dbus_auth_observer_authorize_authenticated_peer(
47                self.to_glib_none().0,
48                stream.as_ref().to_glib_none().0,
49                credentials.to_glib_none().0,
50            ))
51        }
52    }
53
54    #[doc(alias = "allow-mechanism")]
55    pub fn connect_allow_mechanism<F: Fn(&Self, &str) -> bool + 'static>(
56        &self,
57        f: F,
58    ) -> SignalHandlerId {
59        unsafe extern "C" fn allow_mechanism_trampoline<
60            F: Fn(&DBusAuthObserver, &str) -> bool + 'static,
61        >(
62            this: *mut ffi::GDBusAuthObserver,
63            mechanism: *mut std::ffi::c_char,
64            f: glib::ffi::gpointer,
65        ) -> glib::ffi::gboolean {
66            let f: &F = &*(f as *const F);
67            f(
68                &from_glib_borrow(this),
69                &glib::GString::from_glib_borrow(mechanism),
70            )
71            .into_glib()
72        }
73        unsafe {
74            let f: Box_<F> = Box_::new(f);
75            connect_raw(
76                self.as_ptr() as *mut _,
77                c"allow-mechanism".as_ptr() as *const _,
78                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
79                    allow_mechanism_trampoline::<F> as *const (),
80                )),
81                Box_::into_raw(f),
82            )
83        }
84    }
85
86    #[doc(alias = "authorize-authenticated-peer")]
87    pub fn connect_authorize_authenticated_peer<
88        F: Fn(&Self, &IOStream, Option<&Credentials>) -> bool + 'static,
89    >(
90        &self,
91        f: F,
92    ) -> SignalHandlerId {
93        unsafe extern "C" fn authorize_authenticated_peer_trampoline<
94            F: Fn(&DBusAuthObserver, &IOStream, Option<&Credentials>) -> bool + 'static,
95        >(
96            this: *mut ffi::GDBusAuthObserver,
97            stream: *mut ffi::GIOStream,
98            credentials: *mut ffi::GCredentials,
99            f: glib::ffi::gpointer,
100        ) -> glib::ffi::gboolean {
101            let f: &F = &*(f as *const F);
102            f(
103                &from_glib_borrow(this),
104                &from_glib_borrow(stream),
105                Option::<Credentials>::from_glib_borrow(credentials)
106                    .as_ref()
107                    .as_ref(),
108            )
109            .into_glib()
110        }
111        unsafe {
112            let f: Box_<F> = Box_::new(f);
113            connect_raw(
114                self.as_ptr() as *mut _,
115                c"authorize-authenticated-peer".as_ptr() as *const _,
116                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
117                    authorize_authenticated_peer_trampoline::<F> as *const (),
118                )),
119                Box_::into_raw(f),
120            )
121        }
122    }
123}
124
125impl Default for DBusAuthObserver {
126    fn default() -> Self {
127        Self::new()
128    }
129}