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