gio/auto/dbus_interface_skeleton.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::{
6 DBusConnection, DBusInterface, DBusInterfaceInfo, DBusInterfaceSkeletonFlags,
7 DBusMethodInvocation, ffi,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// Abstract base class for D-Bus interfaces on the service side.
19 ///
20 /// This is an Abstract Base Class, you cannot instantiate it.
21 ///
22 /// ## Properties
23 ///
24 ///
25 /// #### `g-flags`
26 /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
27 ///
28 /// Readable | Writeable
29 ///
30 /// ## Signals
31 ///
32 ///
33 /// #### `g-authorize-method`
34 /// Emitted when a method is invoked by a remote caller and used to
35 /// determine if the method call is authorized.
36 ///
37 /// Note that this signal is emitted in a thread dedicated to
38 /// handling the method call so handlers are allowed to perform
39 /// blocking IO. This means that it is appropriate to call e.g.
40 /// [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
41 /// with the
42 /// [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
43 /// flag set.
44 ///
45 /// If [`false`] is returned then no further handlers are run and the
46 /// signal handler must take a reference to @invocation and finish
47 /// handling the call (e.g. return an error via
48 /// g_dbus_method_invocation_return_error()).
49 ///
50 /// Otherwise, if [`true`] is returned, signal emission continues. If no
51 /// handlers return [`false`], then the method is dispatched. If
52 /// @interface has an enclosing #GDBusObjectSkeleton, then the
53 /// #GDBusObjectSkeleton::authorize-method signal handlers run before
54 /// the handlers for this signal.
55 ///
56 /// The default class handler just returns [`true`].
57 ///
58 /// Please note that the common case is optimized: if no signals
59 /// handlers are connected and the default class handler isn't
60 /// overridden (for both @interface and the enclosing
61 /// #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
62 /// not have the
63 /// [`DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD`][crate::DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD]
64 /// flags set, no dedicated thread is ever used and the call will be
65 /// handled in the same thread as the object that @interface belongs
66 /// to was exported in.
67 ///
68 ///
69 ///
70 /// # Implements
71 ///
72 /// [`DBusInterfaceSkeletonExt`][trait@crate::prelude::DBusInterfaceSkeletonExt], [`trait@glib::ObjectExt`], [`DBusInterfaceExt`][trait@crate::prelude::DBusInterfaceExt]
73 #[doc(alias = "GDBusInterfaceSkeleton")]
74 pub struct DBusInterfaceSkeleton(Object<ffi::GDBusInterfaceSkeleton, ffi::GDBusInterfaceSkeletonClass>) @implements DBusInterface;
75
76 match fn {
77 type_ => || ffi::g_dbus_interface_skeleton_get_type(),
78 }
79}
80
81impl DBusInterfaceSkeleton {
82 pub const NONE: Option<&'static DBusInterfaceSkeleton> = None;
83}
84
85/// Trait containing all [`struct@DBusInterfaceSkeleton`] methods.
86///
87/// # Implementors
88///
89/// [`DBusInterfaceSkeleton`][struct@crate::DBusInterfaceSkeleton]
90pub trait DBusInterfaceSkeletonExt: IsA<DBusInterfaceSkeleton> + 'static {
91 /// Exports @self at @object_path on @connection.
92 ///
93 /// This can be called multiple times to export the same @self
94 /// onto multiple connections however the @object_path provided must be
95 /// the same for all connections.
96 ///
97 /// Use g_dbus_interface_skeleton_unexport() to unexport the object.
98 /// ## `connection`
99 /// A #GDBusConnection to export @self on.
100 /// ## `object_path`
101 /// The path to export the interface at.
102 ///
103 /// # Returns
104 ///
105 /// [`true`] if the interface was exported on @connection, otherwise [`false`] with
106 /// @error set.
107 #[doc(alias = "g_dbus_interface_skeleton_export")]
108 fn export(&self, connection: &DBusConnection, object_path: &str) -> Result<(), glib::Error> {
109 unsafe {
110 let mut error = std::ptr::null_mut();
111 let is_ok = ffi::g_dbus_interface_skeleton_export(
112 self.as_ref().to_glib_none().0,
113 connection.to_glib_none().0,
114 object_path.to_glib_none().0,
115 &mut error,
116 );
117 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
118 if error.is_null() {
119 Ok(())
120 } else {
121 Err(from_glib_full(error))
122 }
123 }
124 }
125
126 /// If @self has outstanding changes, request for these changes to be
127 /// emitted immediately.
128 ///
129 /// For example, an exported D-Bus interface may queue up property
130 /// changes and emit the
131 /// `org.freedesktop.DBus.Properties.PropertiesChanged`
132 /// signal later (e.g. in an idle handler). This technique is useful
133 /// for collapsing multiple property changes into one.
134 #[doc(alias = "g_dbus_interface_skeleton_flush")]
135 fn flush(&self) {
136 unsafe {
137 ffi::g_dbus_interface_skeleton_flush(self.as_ref().to_glib_none().0);
138 }
139 }
140
141 /// Gets the first connection that @self is exported on, if any.
142 ///
143 /// # Returns
144 ///
145 /// A #GDBusConnection or [`None`] if @self is
146 /// not exported anywhere. Do not free, the object belongs to @self.
147 #[doc(alias = "g_dbus_interface_skeleton_get_connection")]
148 #[doc(alias = "get_connection")]
149 fn connection(&self) -> Option<DBusConnection> {
150 unsafe {
151 from_glib_none(ffi::g_dbus_interface_skeleton_get_connection(
152 self.as_ref().to_glib_none().0,
153 ))
154 }
155 }
156
157 /// Gets a list of the connections that @self is exported on.
158 ///
159 /// # Returns
160 ///
161 /// A list of
162 /// all the connections that @self is exported on. The returned
163 /// list should be freed with g_list_free() after each element has
164 /// been freed with g_object_unref().
165 #[doc(alias = "g_dbus_interface_skeleton_get_connections")]
166 #[doc(alias = "get_connections")]
167 fn connections(&self) -> Vec<DBusConnection> {
168 unsafe {
169 FromGlibPtrContainer::from_glib_full(ffi::g_dbus_interface_skeleton_get_connections(
170 self.as_ref().to_glib_none().0,
171 ))
172 }
173 }
174
175 /// Gets the #GDBusInterfaceSkeletonFlags that describes what the behavior
176 /// of @self
177 ///
178 /// # Returns
179 ///
180 /// One or more flags from the #GDBusInterfaceSkeletonFlags enumeration.
181 #[doc(alias = "g_dbus_interface_skeleton_get_flags")]
182 #[doc(alias = "get_flags")]
183 #[doc(alias = "g-flags")]
184 fn flags(&self) -> DBusInterfaceSkeletonFlags {
185 unsafe {
186 from_glib(ffi::g_dbus_interface_skeleton_get_flags(
187 self.as_ref().to_glib_none().0,
188 ))
189 }
190 }
191
192 /// Gets D-Bus introspection information for the D-Bus interface
193 /// implemented by @self.
194 ///
195 /// # Returns
196 ///
197 /// A #GDBusInterfaceInfo (never [`None`]). Do not free.
198 #[doc(alias = "g_dbus_interface_skeleton_get_info")]
199 #[doc(alias = "get_info")]
200 fn info(&self) -> DBusInterfaceInfo {
201 unsafe {
202 from_glib_none(ffi::g_dbus_interface_skeleton_get_info(
203 self.as_ref().to_glib_none().0,
204 ))
205 }
206 }
207
208 /// Gets the object path that @self is exported on, if any.
209 ///
210 /// # Returns
211 ///
212 /// A string owned by @self or [`None`] if @self is not exported
213 /// anywhere. Do not free, the string belongs to @self.
214 #[doc(alias = "g_dbus_interface_skeleton_get_object_path")]
215 #[doc(alias = "get_object_path")]
216 fn object_path(&self) -> Option<glib::GString> {
217 unsafe {
218 from_glib_none(ffi::g_dbus_interface_skeleton_get_object_path(
219 self.as_ref().to_glib_none().0,
220 ))
221 }
222 }
223
224 /// Gets all D-Bus properties for @self.
225 ///
226 /// # Returns
227 ///
228 /// A #GVariant of type
229 /// ['a{sv}'](../glib/gvariant-text-format.html#dictionaries-and-dictionary-entries).
230 /// Free with g_variant_unref().
231 #[doc(alias = "g_dbus_interface_skeleton_get_properties")]
232 #[doc(alias = "get_properties")]
233 fn properties(&self) -> glib::Variant {
234 unsafe {
235 from_glib_full(ffi::g_dbus_interface_skeleton_get_properties(
236 self.as_ref().to_glib_none().0,
237 ))
238 }
239 }
240
241 //#[doc(alias = "g_dbus_interface_skeleton_get_vtable")]
242 //#[doc(alias = "get_vtable")]
243 //fn vtable(&self) -> /*Ignored*/DBusInterfaceVTable {
244 // unsafe { TODO: call ffi:g_dbus_interface_skeleton_get_vtable() }
245 //}
246
247 /// Checks if @self is exported on @connection.
248 /// ## `connection`
249 /// A #GDBusConnection.
250 ///
251 /// # Returns
252 ///
253 /// [`true`] if @self is exported on @connection, [`false`] otherwise.
254 #[doc(alias = "g_dbus_interface_skeleton_has_connection")]
255 fn has_connection(&self, connection: &DBusConnection) -> bool {
256 unsafe {
257 from_glib(ffi::g_dbus_interface_skeleton_has_connection(
258 self.as_ref().to_glib_none().0,
259 connection.to_glib_none().0,
260 ))
261 }
262 }
263
264 /// Sets flags describing what the behavior of @skeleton should be.
265 /// ## `flags`
266 /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
267 #[doc(alias = "g_dbus_interface_skeleton_set_flags")]
268 #[doc(alias = "g-flags")]
269 fn set_flags(&self, flags: DBusInterfaceSkeletonFlags) {
270 unsafe {
271 ffi::g_dbus_interface_skeleton_set_flags(
272 self.as_ref().to_glib_none().0,
273 flags.into_glib(),
274 );
275 }
276 }
277
278 /// Stops exporting @self on all connections it is exported on.
279 ///
280 /// To unexport @self from only a single connection, use
281 /// g_dbus_interface_skeleton_unexport_from_connection()
282 #[doc(alias = "g_dbus_interface_skeleton_unexport")]
283 fn unexport(&self) {
284 unsafe {
285 ffi::g_dbus_interface_skeleton_unexport(self.as_ref().to_glib_none().0);
286 }
287 }
288
289 /// Stops exporting @self on @connection.
290 ///
291 /// To stop exporting on all connections the interface is exported on,
292 /// use g_dbus_interface_skeleton_unexport().
293 /// ## `connection`
294 /// A #GDBusConnection.
295 #[doc(alias = "g_dbus_interface_skeleton_unexport_from_connection")]
296 fn unexport_from_connection(&self, connection: &DBusConnection) {
297 unsafe {
298 ffi::g_dbus_interface_skeleton_unexport_from_connection(
299 self.as_ref().to_glib_none().0,
300 connection.to_glib_none().0,
301 );
302 }
303 }
304
305 /// Emitted when a method is invoked by a remote caller and used to
306 /// determine if the method call is authorized.
307 ///
308 /// Note that this signal is emitted in a thread dedicated to
309 /// handling the method call so handlers are allowed to perform
310 /// blocking IO. This means that it is appropriate to call e.g.
311 /// [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
312 /// with the
313 /// [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
314 /// flag set.
315 ///
316 /// If [`false`] is returned then no further handlers are run and the
317 /// signal handler must take a reference to @invocation and finish
318 /// handling the call (e.g. return an error via
319 /// g_dbus_method_invocation_return_error()).
320 ///
321 /// Otherwise, if [`true`] is returned, signal emission continues. If no
322 /// handlers return [`false`], then the method is dispatched. If
323 /// @interface has an enclosing #GDBusObjectSkeleton, then the
324 /// #GDBusObjectSkeleton::authorize-method signal handlers run before
325 /// the handlers for this signal.
326 ///
327 /// The default class handler just returns [`true`].
328 ///
329 /// Please note that the common case is optimized: if no signals
330 /// handlers are connected and the default class handler isn't
331 /// overridden (for both @interface and the enclosing
332 /// #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
333 /// not have the
334 /// [`DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD`][crate::DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD]
335 /// flags set, no dedicated thread is ever used and the call will be
336 /// handled in the same thread as the object that @interface belongs
337 /// to was exported in.
338 /// ## `invocation`
339 /// A #GDBusMethodInvocation.
340 ///
341 /// # Returns
342 ///
343 /// [`true`] if the call is authorized, [`false`] otherwise.
344 #[doc(alias = "g-authorize-method")]
345 fn connect_g_authorize_method<F: Fn(&Self, &DBusMethodInvocation) -> bool + 'static>(
346 &self,
347 f: F,
348 ) -> SignalHandlerId {
349 unsafe extern "C" fn g_authorize_method_trampoline<
350 P: IsA<DBusInterfaceSkeleton>,
351 F: Fn(&P, &DBusMethodInvocation) -> bool + 'static,
352 >(
353 this: *mut ffi::GDBusInterfaceSkeleton,
354 invocation: *mut ffi::GDBusMethodInvocation,
355 f: glib::ffi::gpointer,
356 ) -> glib::ffi::gboolean {
357 unsafe {
358 let f: &F = &*(f as *const F);
359 f(
360 DBusInterfaceSkeleton::from_glib_borrow(this).unsafe_cast_ref(),
361 &from_glib_borrow(invocation),
362 )
363 .into_glib()
364 }
365 }
366 unsafe {
367 let f: Box_<F> = Box_::new(f);
368 connect_raw(
369 self.as_ptr() as *mut _,
370 c"g-authorize-method".as_ptr(),
371 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
372 g_authorize_method_trampoline::<Self, F> as *const (),
373 )),
374 Box_::into_raw(f),
375 )
376 }
377 }
378
379 #[doc(alias = "g-flags")]
380 fn connect_g_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
381 unsafe extern "C" fn notify_g_flags_trampoline<
382 P: IsA<DBusInterfaceSkeleton>,
383 F: Fn(&P) + 'static,
384 >(
385 this: *mut ffi::GDBusInterfaceSkeleton,
386 _param_spec: glib::ffi::gpointer,
387 f: glib::ffi::gpointer,
388 ) {
389 unsafe {
390 let f: &F = &*(f as *const F);
391 f(DBusInterfaceSkeleton::from_glib_borrow(this).unsafe_cast_ref())
392 }
393 }
394 unsafe {
395 let f: Box_<F> = Box_::new(f);
396 connect_raw(
397 self.as_ptr() as *mut _,
398 c"notify::g-flags".as_ptr(),
399 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
400 notify_g_flags_trampoline::<Self, F> as *const (),
401 )),
402 Box_::into_raw(f),
403 )
404 }
405 }
406}
407
408impl<O: IsA<DBusInterfaceSkeleton>> DBusInterfaceSkeletonExt for O {}