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 ffi, DBusConnection, DBusInterface, DBusInterfaceInfo, DBusInterfaceSkeletonFlags,
7 DBusMethodInvocation,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
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 fn flags(&self) -> DBusInterfaceSkeletonFlags {
184 unsafe {
185 from_glib(ffi::g_dbus_interface_skeleton_get_flags(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 /// Gets D-Bus introspection information for the D-Bus interface
192 /// implemented by @self.
193 ///
194 /// # Returns
195 ///
196 /// A #GDBusInterfaceInfo (never [`None`]). Do not free.
197 #[doc(alias = "g_dbus_interface_skeleton_get_info")]
198 #[doc(alias = "get_info")]
199 fn info(&self) -> DBusInterfaceInfo {
200 unsafe {
201 from_glib_none(ffi::g_dbus_interface_skeleton_get_info(
202 self.as_ref().to_glib_none().0,
203 ))
204 }
205 }
206
207 /// Gets the object path that @self is exported on, if any.
208 ///
209 /// # Returns
210 ///
211 /// A string owned by @self or [`None`] if @self is not exported
212 /// anywhere. Do not free, the string belongs to @self.
213 #[doc(alias = "g_dbus_interface_skeleton_get_object_path")]
214 #[doc(alias = "get_object_path")]
215 fn object_path(&self) -> Option<glib::GString> {
216 unsafe {
217 from_glib_none(ffi::g_dbus_interface_skeleton_get_object_path(
218 self.as_ref().to_glib_none().0,
219 ))
220 }
221 }
222
223 /// Gets all D-Bus properties for @self.
224 ///
225 /// # Returns
226 ///
227 /// A #GVariant of type
228 /// ['a{sv}'](../glib/gvariant-text-format.html#dictionaries-and-dictionary-entries).
229 /// Free with g_variant_unref().
230 #[doc(alias = "g_dbus_interface_skeleton_get_properties")]
231 #[doc(alias = "get_properties")]
232 fn properties(&self) -> glib::Variant {
233 unsafe {
234 from_glib_full(ffi::g_dbus_interface_skeleton_get_properties(
235 self.as_ref().to_glib_none().0,
236 ))
237 }
238 }
239
240 //#[doc(alias = "g_dbus_interface_skeleton_get_vtable")]
241 //#[doc(alias = "get_vtable")]
242 //fn vtable(&self) -> /*Ignored*/DBusInterfaceVTable {
243 // unsafe { TODO: call ffi:g_dbus_interface_skeleton_get_vtable() }
244 //}
245
246 /// Checks if @self is exported on @connection.
247 /// ## `connection`
248 /// A #GDBusConnection.
249 ///
250 /// # Returns
251 ///
252 /// [`true`] if @self is exported on @connection, [`false`] otherwise.
253 #[doc(alias = "g_dbus_interface_skeleton_has_connection")]
254 fn has_connection(&self, connection: &DBusConnection) -> bool {
255 unsafe {
256 from_glib(ffi::g_dbus_interface_skeleton_has_connection(
257 self.as_ref().to_glib_none().0,
258 connection.to_glib_none().0,
259 ))
260 }
261 }
262
263 /// Sets flags describing what the behavior of @skeleton should be.
264 /// ## `flags`
265 /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
266 #[doc(alias = "g_dbus_interface_skeleton_set_flags")]
267 fn set_flags(&self, flags: DBusInterfaceSkeletonFlags) {
268 unsafe {
269 ffi::g_dbus_interface_skeleton_set_flags(
270 self.as_ref().to_glib_none().0,
271 flags.into_glib(),
272 );
273 }
274 }
275
276 /// Stops exporting @self on all connections it is exported on.
277 ///
278 /// To unexport @self from only a single connection, use
279 /// g_dbus_interface_skeleton_unexport_from_connection()
280 #[doc(alias = "g_dbus_interface_skeleton_unexport")]
281 fn unexport(&self) {
282 unsafe {
283 ffi::g_dbus_interface_skeleton_unexport(self.as_ref().to_glib_none().0);
284 }
285 }
286
287 /// Stops exporting @self on @connection.
288 ///
289 /// To stop exporting on all connections the interface is exported on,
290 /// use g_dbus_interface_skeleton_unexport().
291 /// ## `connection`
292 /// A #GDBusConnection.
293 #[doc(alias = "g_dbus_interface_skeleton_unexport_from_connection")]
294 fn unexport_from_connection(&self, connection: &DBusConnection) {
295 unsafe {
296 ffi::g_dbus_interface_skeleton_unexport_from_connection(
297 self.as_ref().to_glib_none().0,
298 connection.to_glib_none().0,
299 );
300 }
301 }
302
303 /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
304 #[doc(alias = "g-flags")]
305 fn g_flags(&self) -> DBusInterfaceSkeletonFlags {
306 ObjectExt::property(self.as_ref(), "g-flags")
307 }
308
309 /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
310 #[doc(alias = "g-flags")]
311 fn set_g_flags(&self, g_flags: DBusInterfaceSkeletonFlags) {
312 ObjectExt::set_property(self.as_ref(), "g-flags", g_flags)
313 }
314
315 /// Emitted when a method is invoked by a remote caller and used to
316 /// determine if the method call is authorized.
317 ///
318 /// Note that this signal is emitted in a thread dedicated to
319 /// handling the method call so handlers are allowed to perform
320 /// blocking IO. This means that it is appropriate to call e.g.
321 /// [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
322 /// with the
323 /// [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
324 /// flag set.
325 ///
326 /// If [`false`] is returned then no further handlers are run and the
327 /// signal handler must take a reference to @invocation and finish
328 /// handling the call (e.g. return an error via
329 /// g_dbus_method_invocation_return_error()).
330 ///
331 /// Otherwise, if [`true`] is returned, signal emission continues. If no
332 /// handlers return [`false`], then the method is dispatched. If
333 /// @interface has an enclosing #GDBusObjectSkeleton, then the
334 /// #GDBusObjectSkeleton::authorize-method signal handlers run before
335 /// the handlers for this signal.
336 ///
337 /// The default class handler just returns [`true`].
338 ///
339 /// Please note that the common case is optimized: if no signals
340 /// handlers are connected and the default class handler isn't
341 /// overridden (for both @interface and the enclosing
342 /// #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
343 /// not have the
344 /// [`DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD`][crate::DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD]
345 /// flags set, no dedicated thread is ever used and the call will be
346 /// handled in the same thread as the object that @interface belongs
347 /// to was exported in.
348 /// ## `invocation`
349 /// A #GDBusMethodInvocation.
350 ///
351 /// # Returns
352 ///
353 /// [`true`] if the call is authorized, [`false`] otherwise.
354 #[doc(alias = "g-authorize-method")]
355 fn connect_g_authorize_method<F: Fn(&Self, &DBusMethodInvocation) -> bool + 'static>(
356 &self,
357 f: F,
358 ) -> SignalHandlerId {
359 unsafe extern "C" fn g_authorize_method_trampoline<
360 P: IsA<DBusInterfaceSkeleton>,
361 F: Fn(&P, &DBusMethodInvocation) -> bool + 'static,
362 >(
363 this: *mut ffi::GDBusInterfaceSkeleton,
364 invocation: *mut ffi::GDBusMethodInvocation,
365 f: glib::ffi::gpointer,
366 ) -> glib::ffi::gboolean {
367 let f: &F = &*(f as *const F);
368 f(
369 DBusInterfaceSkeleton::from_glib_borrow(this).unsafe_cast_ref(),
370 &from_glib_borrow(invocation),
371 )
372 .into_glib()
373 }
374 unsafe {
375 let f: Box_<F> = Box_::new(f);
376 connect_raw(
377 self.as_ptr() as *mut _,
378 c"g-authorize-method".as_ptr() as *const _,
379 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
380 g_authorize_method_trampoline::<Self, F> as *const (),
381 )),
382 Box_::into_raw(f),
383 )
384 }
385 }
386
387 #[doc(alias = "g-flags")]
388 fn connect_g_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
389 unsafe extern "C" fn notify_g_flags_trampoline<
390 P: IsA<DBusInterfaceSkeleton>,
391 F: Fn(&P) + 'static,
392 >(
393 this: *mut ffi::GDBusInterfaceSkeleton,
394 _param_spec: glib::ffi::gpointer,
395 f: glib::ffi::gpointer,
396 ) {
397 let f: &F = &*(f as *const F);
398 f(DBusInterfaceSkeleton::from_glib_borrow(this).unsafe_cast_ref())
399 }
400 unsafe {
401 let f: Box_<F> = Box_::new(f);
402 connect_raw(
403 self.as_ptr() as *mut _,
404 c"notify::g-flags".as_ptr() as *const _,
405 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
406 notify_g_flags_trampoline::<Self, F> as *const (),
407 )),
408 Box_::into_raw(f),
409 )
410 }
411 }
412}
413
414impl<O: IsA<DBusInterfaceSkeleton>> DBusInterfaceSkeletonExt for O {}