gio/auto/
dbus_object_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::{ffi, DBusInterfaceSkeleton, DBusMethodInvocation, DBusObject};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A `GDBusObjectSkeleton` instance is essentially a group of D-Bus
16    /// interfaces. The set of exported interfaces on the object may be
17    /// dynamic and change at runtime.
18    ///
19    /// This type is intended to be used with [`DBusObjectManager`][crate::DBusObjectManager].
20    ///
21    /// ## Properties
22    ///
23    ///
24    /// #### `g-object-path`
25    ///  The object path where the object is exported.
26    ///
27    /// Readable | Writeable | Construct
28    ///
29    /// ## Signals
30    ///
31    ///
32    /// #### `authorize-method`
33    ///  Emitted when a method is invoked by a remote caller and used to
34    /// determine if the method call is authorized.
35    ///
36    /// This signal is like #GDBusInterfaceSkeleton's
37    /// #GDBusInterfaceSkeleton::g-authorize-method signal,
38    /// except that it is for the enclosing object.
39    ///
40    /// The default class handler just returns [`true`].
41    ///
42    ///
43    /// <details><summary><h4>DBusObject</h4></summary>
44    ///
45    ///
46    /// #### `interface-added`
47    ///  Emitted when @interface is added to @object.
48    ///
49    ///
50    ///
51    ///
52    /// #### `interface-removed`
53    ///  Emitted when @interface is removed from @object.
54    ///
55    ///
56    /// </details>
57    ///
58    /// # Implements
59    ///
60    /// [`DBusObjectSkeletonExt`][trait@crate::prelude::DBusObjectSkeletonExt], [`trait@glib::ObjectExt`], [`DBusObjectExt`][trait@crate::prelude::DBusObjectExt]
61    #[doc(alias = "GDBusObjectSkeleton")]
62    pub struct DBusObjectSkeleton(Object<ffi::GDBusObjectSkeleton, ffi::GDBusObjectSkeletonClass>) @implements DBusObject;
63
64    match fn {
65        type_ => || ffi::g_dbus_object_skeleton_get_type(),
66    }
67}
68
69impl DBusObjectSkeleton {
70    pub const NONE: Option<&'static DBusObjectSkeleton> = None;
71
72    /// Creates a new #GDBusObjectSkeleton.
73    /// ## `object_path`
74    /// An object path.
75    ///
76    /// # Returns
77    ///
78    /// A #GDBusObjectSkeleton. Free with g_object_unref().
79    #[doc(alias = "g_dbus_object_skeleton_new")]
80    pub fn new(object_path: &str) -> DBusObjectSkeleton {
81        unsafe {
82            from_glib_full(ffi::g_dbus_object_skeleton_new(
83                object_path.to_glib_none().0,
84            ))
85        }
86    }
87}
88
89/// Trait containing all [`struct@DBusObjectSkeleton`] methods.
90///
91/// # Implementors
92///
93/// [`DBusObjectSkeleton`][struct@crate::DBusObjectSkeleton]
94pub trait DBusObjectSkeletonExt: IsA<DBusObjectSkeleton> + 'static {
95    /// Adds @interface_ to @self.
96    ///
97    /// If @self already contains a #GDBusInterfaceSkeleton with the same
98    /// interface name, it is removed before @interface_ is added.
99    ///
100    /// Note that @self takes its own reference on @interface_ and holds
101    /// it until removed.
102    /// ## `interface_`
103    /// A #GDBusInterfaceSkeleton.
104    #[doc(alias = "g_dbus_object_skeleton_add_interface")]
105    fn add_interface(&self, interface_: &impl IsA<DBusInterfaceSkeleton>) {
106        unsafe {
107            ffi::g_dbus_object_skeleton_add_interface(
108                self.as_ref().to_glib_none().0,
109                interface_.as_ref().to_glib_none().0,
110            );
111        }
112    }
113
114    /// This method simply calls g_dbus_interface_skeleton_flush() on all
115    /// interfaces belonging to @self. See that method for when flushing
116    /// is useful.
117    #[doc(alias = "g_dbus_object_skeleton_flush")]
118    fn flush(&self) {
119        unsafe {
120            ffi::g_dbus_object_skeleton_flush(self.as_ref().to_glib_none().0);
121        }
122    }
123
124    /// Removes @interface_ from @self.
125    /// ## `interface_`
126    /// A #GDBusInterfaceSkeleton.
127    #[doc(alias = "g_dbus_object_skeleton_remove_interface")]
128    fn remove_interface(&self, interface_: &impl IsA<DBusInterfaceSkeleton>) {
129        unsafe {
130            ffi::g_dbus_object_skeleton_remove_interface(
131                self.as_ref().to_glib_none().0,
132                interface_.as_ref().to_glib_none().0,
133            );
134        }
135    }
136
137    /// Removes the #GDBusInterface with @interface_name from @self.
138    ///
139    /// If no D-Bus interface of the given interface exists, this function
140    /// does nothing.
141    /// ## `interface_name`
142    /// A D-Bus interface name.
143    #[doc(alias = "g_dbus_object_skeleton_remove_interface_by_name")]
144    fn remove_interface_by_name(&self, interface_name: &str) {
145        unsafe {
146            ffi::g_dbus_object_skeleton_remove_interface_by_name(
147                self.as_ref().to_glib_none().0,
148                interface_name.to_glib_none().0,
149            );
150        }
151    }
152
153    /// Sets the object path for @self.
154    /// ## `object_path`
155    /// A valid D-Bus object path.
156    #[doc(alias = "g_dbus_object_skeleton_set_object_path")]
157    fn set_object_path(&self, object_path: &str) {
158        unsafe {
159            ffi::g_dbus_object_skeleton_set_object_path(
160                self.as_ref().to_glib_none().0,
161                object_path.to_glib_none().0,
162            );
163        }
164    }
165
166    /// The object path where the object is exported.
167    #[doc(alias = "g-object-path")]
168    fn g_object_path(&self) -> Option<glib::GString> {
169        ObjectExt::property(self.as_ref(), "g-object-path")
170    }
171
172    /// The object path where the object is exported.
173    #[doc(alias = "g-object-path")]
174    fn set_g_object_path(&self, g_object_path: Option<&str>) {
175        ObjectExt::set_property(self.as_ref(), "g-object-path", g_object_path)
176    }
177
178    /// Emitted when a method is invoked by a remote caller and used to
179    /// determine if the method call is authorized.
180    ///
181    /// This signal is like #GDBusInterfaceSkeleton's
182    /// #GDBusInterfaceSkeleton::g-authorize-method signal,
183    /// except that it is for the enclosing object.
184    ///
185    /// The default class handler just returns [`true`].
186    /// ## `interface`
187    /// The #GDBusInterfaceSkeleton that @invocation is for.
188    /// ## `invocation`
189    /// A #GDBusMethodInvocation.
190    ///
191    /// # Returns
192    ///
193    /// [`true`] if the call is authorized, [`false`] otherwise.
194    #[doc(alias = "authorize-method")]
195    fn connect_authorize_method<
196        F: Fn(&Self, &DBusInterfaceSkeleton, &DBusMethodInvocation) -> bool + 'static,
197    >(
198        &self,
199        f: F,
200    ) -> SignalHandlerId {
201        unsafe extern "C" fn authorize_method_trampoline<
202            P: IsA<DBusObjectSkeleton>,
203            F: Fn(&P, &DBusInterfaceSkeleton, &DBusMethodInvocation) -> bool + 'static,
204        >(
205            this: *mut ffi::GDBusObjectSkeleton,
206            interface: *mut ffi::GDBusInterfaceSkeleton,
207            invocation: *mut ffi::GDBusMethodInvocation,
208            f: glib::ffi::gpointer,
209        ) -> glib::ffi::gboolean {
210            let f: &F = &*(f as *const F);
211            f(
212                DBusObjectSkeleton::from_glib_borrow(this).unsafe_cast_ref(),
213                &from_glib_borrow(interface),
214                &from_glib_borrow(invocation),
215            )
216            .into_glib()
217        }
218        unsafe {
219            let f: Box_<F> = Box_::new(f);
220            connect_raw(
221                self.as_ptr() as *mut _,
222                c"authorize-method".as_ptr() as *const _,
223                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
224                    authorize_method_trampoline::<Self, F> as *const (),
225                )),
226                Box_::into_raw(f),
227            )
228        }
229    }
230
231    #[doc(alias = "g-object-path")]
232    fn connect_g_object_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
233        unsafe extern "C" fn notify_g_object_path_trampoline<
234            P: IsA<DBusObjectSkeleton>,
235            F: Fn(&P) + 'static,
236        >(
237            this: *mut ffi::GDBusObjectSkeleton,
238            _param_spec: glib::ffi::gpointer,
239            f: glib::ffi::gpointer,
240        ) {
241            let f: &F = &*(f as *const F);
242            f(DBusObjectSkeleton::from_glib_borrow(this).unsafe_cast_ref())
243        }
244        unsafe {
245            let f: Box_<F> = Box_::new(f);
246            connect_raw(
247                self.as_ptr() as *mut _,
248                c"notify::g-object-path".as_ptr() as *const _,
249                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
250                    notify_g_object_path_trampoline::<Self, F> as *const (),
251                )),
252                Box_::into_raw(f),
253            )
254        }
255    }
256}
257
258impl<O: IsA<DBusObjectSkeleton>> DBusObjectSkeletonExt for O {}