gio/auto/
dbus_object.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, DBusInterface};
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    /// The `GDBusObject` type is the base type for D-Bus objects on both
16    /// the service side (see [`DBusObjectSkeleton`][crate::DBusObjectSkeleton]) and the client side
17    /// (see [`DBusObjectProxy`][crate::DBusObjectProxy]). It is essentially just a container of
18    /// interfaces.
19    ///
20    /// ## Signals
21    ///
22    ///
23    /// #### `interface-added`
24    ///  Emitted when @interface is added to @object.
25    ///
26    ///
27    ///
28    ///
29    /// #### `interface-removed`
30    ///  Emitted when @interface is removed from @object.
31    ///
32    ///
33    ///
34    /// # Implements
35    ///
36    /// [`DBusObjectExt`][trait@crate::prelude::DBusObjectExt]
37    #[doc(alias = "GDBusObject")]
38    pub struct DBusObject(Interface<ffi::GDBusObject, ffi::GDBusObjectIface>);
39
40    match fn {
41        type_ => || ffi::g_dbus_object_get_type(),
42    }
43}
44
45impl DBusObject {
46    pub const NONE: Option<&'static DBusObject> = None;
47}
48
49mod sealed {
50    pub trait Sealed {}
51    impl<T: super::IsA<super::DBusObject>> Sealed for T {}
52}
53
54/// Trait containing all [`struct@DBusObject`] methods.
55///
56/// # Implementors
57///
58/// [`DBusObjectProxy`][struct@crate::DBusObjectProxy], [`DBusObjectSkeleton`][struct@crate::DBusObjectSkeleton], [`DBusObject`][struct@crate::DBusObject]
59pub trait DBusObjectExt: IsA<DBusObject> + sealed::Sealed + 'static {
60    /// Gets the D-Bus interface with name @interface_name associated with
61    /// @self, if any.
62    /// ## `interface_name`
63    /// A D-Bus interface name.
64    ///
65    /// # Returns
66    ///
67    /// [`None`] if not found, otherwise a
68    ///   #GDBusInterface that must be freed with g_object_unref().
69    #[doc(alias = "g_dbus_object_get_interface")]
70    #[doc(alias = "get_interface")]
71    fn interface(&self, interface_name: &str) -> Option<DBusInterface> {
72        unsafe {
73            from_glib_full(ffi::g_dbus_object_get_interface(
74                self.as_ref().to_glib_none().0,
75                interface_name.to_glib_none().0,
76            ))
77        }
78    }
79
80    /// Gets the D-Bus interfaces associated with @self.
81    ///
82    /// # Returns
83    ///
84    /// A list of #GDBusInterface instances.
85    ///   The returned list must be freed by g_list_free() after each element has been freed
86    ///   with g_object_unref().
87    #[doc(alias = "g_dbus_object_get_interfaces")]
88    #[doc(alias = "get_interfaces")]
89    fn interfaces(&self) -> Vec<DBusInterface> {
90        unsafe {
91            FromGlibPtrContainer::from_glib_full(ffi::g_dbus_object_get_interfaces(
92                self.as_ref().to_glib_none().0,
93            ))
94        }
95    }
96
97    /// Gets the object path for @self.
98    ///
99    /// # Returns
100    ///
101    /// A string owned by @self. Do not free.
102    #[doc(alias = "g_dbus_object_get_object_path")]
103    #[doc(alias = "get_object_path")]
104    fn object_path(&self) -> glib::GString {
105        unsafe {
106            from_glib_none(ffi::g_dbus_object_get_object_path(
107                self.as_ref().to_glib_none().0,
108            ))
109        }
110    }
111
112    /// Emitted when @interface is added to @object.
113    /// ## `interface`
114    /// The #GDBusInterface that was added.
115    #[doc(alias = "interface-added")]
116    fn connect_interface_added<F: Fn(&Self, &DBusInterface) + 'static>(
117        &self,
118        f: F,
119    ) -> SignalHandlerId {
120        unsafe extern "C" fn interface_added_trampoline<
121            P: IsA<DBusObject>,
122            F: Fn(&P, &DBusInterface) + 'static,
123        >(
124            this: *mut ffi::GDBusObject,
125            interface: *mut ffi::GDBusInterface,
126            f: glib::ffi::gpointer,
127        ) {
128            let f: &F = &*(f as *const F);
129            f(
130                DBusObject::from_glib_borrow(this).unsafe_cast_ref(),
131                &from_glib_borrow(interface),
132            )
133        }
134        unsafe {
135            let f: Box_<F> = Box_::new(f);
136            connect_raw(
137                self.as_ptr() as *mut _,
138                b"interface-added\0".as_ptr() as *const _,
139                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
140                    interface_added_trampoline::<Self, F> as *const (),
141                )),
142                Box_::into_raw(f),
143            )
144        }
145    }
146
147    /// Emitted when @interface is removed from @object.
148    /// ## `interface`
149    /// The #GDBusInterface that was removed.
150    #[doc(alias = "interface-removed")]
151    fn connect_interface_removed<F: Fn(&Self, &DBusInterface) + 'static>(
152        &self,
153        f: F,
154    ) -> SignalHandlerId {
155        unsafe extern "C" fn interface_removed_trampoline<
156            P: IsA<DBusObject>,
157            F: Fn(&P, &DBusInterface) + 'static,
158        >(
159            this: *mut ffi::GDBusObject,
160            interface: *mut ffi::GDBusInterface,
161            f: glib::ffi::gpointer,
162        ) {
163            let f: &F = &*(f as *const F);
164            f(
165                DBusObject::from_glib_borrow(this).unsafe_cast_ref(),
166                &from_glib_borrow(interface),
167            )
168        }
169        unsafe {
170            let f: Box_<F> = Box_::new(f);
171            connect_raw(
172                self.as_ptr() as *mut _,
173                b"interface-removed\0".as_ptr() as *const _,
174                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
175                    interface_removed_trampoline::<Self, F> as *const (),
176                )),
177                Box_::into_raw(f),
178            )
179        }
180    }
181}
182
183impl<O: IsA<DBusObject>> DBusObjectExt for O {}