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