Skip to main content

gio/auto/
debug_controller_dbus.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::{Cancellable, DBusConnection, DBusMethodInvocation, DebugController, Initable, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// message);
16    ///         return FALSE;
17    ///       }
18    ///
19    ///     return polkit_authorization_result_get_is_authorized (auth_result);
20    ///   }
21    /// ```text
22    ///
23    ///
24    /// ## Properties
25    ///
26    ///
27    /// #### `connection`
28    ///  s D-Bus objects are registered
29    /// on.
30    ///
31    /// Readable | Writable | Construct Only
32    /// <details><summary><h4>DebugController</h4></summary>
33    ///
34    ///
35    /// #### `debug-enabled`
36    ///  [`true`] if debug output should be exposed (for example by forwarding it to
37    /// the journal), [`false`] otherwise.
38    ///
39    /// Readable | Writable
40    /// </details>
41    ///
42    /// ## Signals
43    ///
44    ///
45    /// #### `authorize`
46    ///  Emitted when a D-Bus peer is trying to change the debug settings and used
47    /// to determine if that is authorized.
48    ///
49    /// This signal is emitted in a dedicated worker thread, so handlers are
50    /// allowed to perform blocking I/O. This means that, for example, it is
51    /// appropriate to call `polkit_authority_check_authorization_sync()` to check
52    /// authorization using polkit.
53    ///
54    /// If [`false`] is returned then no further handlers are run and the request to
55    /// change the debug settings is rejected.
56    ///
57    /// Otherwise, if [`true`] is returned, signal emission continues. If no handlers
58    /// return [`false`], then the debug settings are allowed to be changed.
59    ///
60    /// Signal handlers must not modify @invocation, or cause it to return a value.
61    ///
62    /// The default class handler just returns [`true`].
63    ///
64    ///
65    ///
66    /// # Implements
67    ///
68    /// [`DebugControllerDBusExt`][trait@crate::prelude::DebugControllerDBusExt], [`trait@glib::ObjectExt`], [`DebugControllerExt`][trait@crate::prelude::DebugControllerExt], [`InitableExt`][trait@crate::prelude::InitableExt], [`DebugControllerDBusExtManual`][trait@crate::prelude::DebugControllerDBusExtManual]
69    #[doc(alias = "GDebugControllerDBus")]
70    pub struct DebugControllerDBus(Object<ffi::GDebugControllerDBus, ffi::GDebugControllerDBusClass>) @implements DebugController, Initable;
71
72    match fn {
73        type_ => || ffi::g_debug_controller_dbus_get_type(),
74    }
75}
76
77impl DebugControllerDBus {
78    pub const NONE: Option<&'static DebugControllerDBus> = None;
79
80    /// Create a new #GDebugControllerDBus and synchronously initialize it.
81    ///
82    /// Initializing the object will export the debug object on @connection. The
83    /// object will remain registered until the last reference to the
84    /// #GDebugControllerDBus is dropped.
85    ///
86    /// Initialization may fail if registering the object on @connection fails.
87    /// ## `connection`
88    /// a #GDBusConnection to register the debug object on
89    /// ## `cancellable`
90    /// a #GCancellable, or [`None`]
91    ///
92    /// # Returns
93    ///
94    /// a new #GDebugControllerDBus, or [`None`]
95    ///   on failure
96    #[doc(alias = "g_debug_controller_dbus_new")]
97    pub fn new(
98        connection: &DBusConnection,
99        cancellable: Option<&impl IsA<Cancellable>>,
100    ) -> Result<Option<DebugControllerDBus>, glib::Error> {
101        unsafe {
102            let mut error = std::ptr::null_mut();
103            let ret = ffi::g_debug_controller_dbus_new(
104                connection.to_glib_none().0,
105                cancellable.map(|p| p.as_ref()).to_glib_none().0,
106                &mut error,
107            );
108            if error.is_null() {
109                Ok(from_glib_full(ret))
110            } else {
111                Err(from_glib_full(error))
112            }
113        }
114    }
115}
116
117/// Trait containing all [`struct@DebugControllerDBus`] methods.
118///
119/// # Implementors
120///
121/// [`DebugControllerDBus`][struct@crate::DebugControllerDBus]
122pub trait DebugControllerDBusExt: IsA<DebugControllerDBus> + 'static {
123    /// Stop the debug controller, unregistering its object from the bus.
124    ///
125    /// Any pending method calls to the object will complete successfully, but new
126    /// ones will return an error. This method will block until all pending
127    /// #GDebugControllerDBus::authorize signals have been handled. This is expected
128    /// to not take long, as it will just be waiting for threads to join. If any
129    /// #GDebugControllerDBus::authorize signal handlers are still executing in other
130    /// threads, this will block until after they have returned.
131    ///
132    /// This method will be called automatically when the final reference to the
133    /// #GDebugControllerDBus is dropped. You may want to call it explicitly to know
134    /// when the controller has been fully removed from the bus, or to break
135    /// reference count cycles.
136    ///
137    /// Calling this method from within a #GDebugControllerDBus::authorize signal
138    /// handler will cause a deadlock and must not be done.
139    #[doc(alias = "g_debug_controller_dbus_stop")]
140    fn stop(&self) {
141        unsafe {
142            ffi::g_debug_controller_dbus_stop(self.as_ref().to_glib_none().0);
143        }
144    }
145
146    /// Emitted when a D-Bus peer is trying to change the debug settings and used
147    /// to determine if that is authorized.
148    ///
149    /// This signal is emitted in a dedicated worker thread, so handlers are
150    /// allowed to perform blocking I/O. This means that, for example, it is
151    /// appropriate to call `polkit_authority_check_authorization_sync()` to check
152    /// authorization using polkit.
153    ///
154    /// If [`false`] is returned then no further handlers are run and the request to
155    /// change the debug settings is rejected.
156    ///
157    /// Otherwise, if [`true`] is returned, signal emission continues. If no handlers
158    /// return [`false`], then the debug settings are allowed to be changed.
159    ///
160    /// Signal handlers must not modify @invocation, or cause it to return a value.
161    ///
162    /// The default class handler just returns [`true`].
163    /// ## `invocation`
164    /// A #GDBusMethodInvocation.
165    ///
166    /// # Returns
167    ///
168    /// [`true`] if the call is authorized, [`false`] otherwise.
169    #[cfg(feature = "v2_72")]
170    #[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
171    #[doc(alias = "authorize")]
172    fn connect_authorize<F: Fn(&Self, &DBusMethodInvocation) -> bool + 'static>(
173        &self,
174        f: F,
175    ) -> SignalHandlerId {
176        unsafe extern "C" fn authorize_trampoline<
177            P: IsA<DebugControllerDBus>,
178            F: Fn(&P, &DBusMethodInvocation) -> bool + 'static,
179        >(
180            this: *mut ffi::GDebugControllerDBus,
181            invocation: *mut ffi::GDBusMethodInvocation,
182            f: glib::ffi::gpointer,
183        ) -> glib::ffi::gboolean {
184            unsafe {
185                let f: &F = &*(f as *const F);
186                f(
187                    DebugControllerDBus::from_glib_borrow(this).unsafe_cast_ref(),
188                    &from_glib_borrow(invocation),
189                )
190                .into_glib()
191            }
192        }
193        unsafe {
194            let f: Box_<F> = Box_::new(f);
195            connect_raw(
196                self.as_ptr() as *mut _,
197                c"authorize".as_ptr(),
198                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
199                    authorize_trampoline::<Self, F> as *const (),
200                )),
201                Box_::into_raw(f),
202            )
203        }
204    }
205}
206
207impl<O: IsA<DebugControllerDBus>> DebugControllerDBusExt for O {}