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::{DBusInterface, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
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
49/// Trait containing all [`struct@DBusObject`] methods.
50///
51/// # Implementors
52///
53/// [`DBusObjectProxy`][struct@crate::DBusObjectProxy], [`DBusObjectSkeleton`][struct@crate::DBusObjectSkeleton], [`DBusObject`][struct@crate::DBusObject]
54pub trait DBusObjectExt: IsA<DBusObject> + 'static {
55    /// Gets the D-Bus interface with name @interface_name associated with
56    /// @self, if any.
57    /// ## `interface_name`
58    /// A D-Bus interface name.
59    ///
60    /// # Returns
61    ///
62    /// [`None`] if not found, otherwise a
63    ///   #GDBusInterface that must be freed with g_object_unref().
64    #[doc(alias = "g_dbus_object_get_interface")]
65    #[doc(alias = "get_interface")]
66    fn interface(&self, interface_name: &str) -> Option<DBusInterface> {
67        unsafe {
68            from_glib_full(ffi::g_dbus_object_get_interface(
69                self.as_ref().to_glib_none().0,
70                interface_name.to_glib_none().0,
71            ))
72        }
73    }
74
75    /// Gets the D-Bus interfaces associated with @self.
76    ///
77    /// # Returns
78    ///
79    /// A list of #GDBusInterface instances.
80    ///   The returned list must be freed by g_list_free() after each element has been freed
81    ///   with g_object_unref().
82    #[doc(alias = "g_dbus_object_get_interfaces")]
83    #[doc(alias = "get_interfaces")]
84    fn interfaces(&self) -> Vec<DBusInterface> {
85        unsafe {
86            FromGlibPtrContainer::from_glib_full(ffi::g_dbus_object_get_interfaces(
87                self.as_ref().to_glib_none().0,
88            ))
89        }
90    }
91
92    /// Gets the object path for @self.
93    ///
94    /// # Returns
95    ///
96    /// A string owned by @self. Do not free.
97    #[doc(alias = "g_dbus_object_get_object_path")]
98    #[doc(alias = "get_object_path")]
99    fn object_path(&self) -> glib::GString {
100        unsafe {
101            from_glib_none(ffi::g_dbus_object_get_object_path(
102                self.as_ref().to_glib_none().0,
103            ))
104        }
105    }
106
107    /// Emitted when @interface is added to @object.
108    /// ## `interface`
109    /// The #GDBusInterface that was added.
110    #[doc(alias = "interface-added")]
111    fn connect_interface_added<F: Fn(&Self, &DBusInterface) + 'static>(
112        &self,
113        f: F,
114    ) -> SignalHandlerId {
115        unsafe extern "C" fn interface_added_trampoline<
116            P: IsA<DBusObject>,
117            F: Fn(&P, &DBusInterface) + 'static,
118        >(
119            this: *mut ffi::GDBusObject,
120            interface: *mut ffi::GDBusInterface,
121            f: glib::ffi::gpointer,
122        ) {
123            unsafe {
124                let f: &F = &*(f as *const F);
125                f(
126                    DBusObject::from_glib_borrow(this).unsafe_cast_ref(),
127                    &from_glib_borrow(interface),
128                )
129            }
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                c"interface-added".as_ptr() as *const _,
136                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
137                    interface_added_trampoline::<Self, F> as *const (),
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143
144    /// Emitted when @interface is removed from @object.
145    /// ## `interface`
146    /// The #GDBusInterface that was removed.
147    #[doc(alias = "interface-removed")]
148    fn connect_interface_removed<F: Fn(&Self, &DBusInterface) + 'static>(
149        &self,
150        f: F,
151    ) -> SignalHandlerId {
152        unsafe extern "C" fn interface_removed_trampoline<
153            P: IsA<DBusObject>,
154            F: Fn(&P, &DBusInterface) + 'static,
155        >(
156            this: *mut ffi::GDBusObject,
157            interface: *mut ffi::GDBusInterface,
158            f: glib::ffi::gpointer,
159        ) {
160            unsafe {
161                let f: &F = &*(f as *const F);
162                f(
163                    DBusObject::from_glib_borrow(this).unsafe_cast_ref(),
164                    &from_glib_borrow(interface),
165                )
166            }
167        }
168        unsafe {
169            let f: Box_<F> = Box_::new(f);
170            connect_raw(
171                self.as_ptr() as *mut _,
172                c"interface-removed".as_ptr() as *const _,
173                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174                    interface_removed_trampoline::<Self, F> as *const (),
175                )),
176                Box_::into_raw(f),
177            )
178        }
179    }
180}
181
182impl<O: IsA<DBusObject>> DBusObjectExt for O {}