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
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            let f: &F = &*(f as *const F);
124            f(
125                DBusObject::from_glib_borrow(this).unsafe_cast_ref(),
126                &from_glib_borrow(interface),
127            )
128        }
129        unsafe {
130            let f: Box_<F> = Box_::new(f);
131            connect_raw(
132                self.as_ptr() as *mut _,
133                c"interface-added".as_ptr() as *const _,
134                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
135                    interface_added_trampoline::<Self, F> as *const (),
136                )),
137                Box_::into_raw(f),
138            )
139        }
140    }
141
142    /// Emitted when @interface is removed from @object.
143    /// ## `interface`
144    /// The #GDBusInterface that was removed.
145    #[doc(alias = "interface-removed")]
146    fn connect_interface_removed<F: Fn(&Self, &DBusInterface) + 'static>(
147        &self,
148        f: F,
149    ) -> SignalHandlerId {
150        unsafe extern "C" fn interface_removed_trampoline<
151            P: IsA<DBusObject>,
152            F: Fn(&P, &DBusInterface) + 'static,
153        >(
154            this: *mut ffi::GDBusObject,
155            interface: *mut ffi::GDBusInterface,
156            f: glib::ffi::gpointer,
157        ) {
158            let f: &F = &*(f as *const F);
159            f(
160                DBusObject::from_glib_borrow(this).unsafe_cast_ref(),
161                &from_glib_borrow(interface),
162            )
163        }
164        unsafe {
165            let f: Box_<F> = Box_::new(f);
166            connect_raw(
167                self.as_ptr() as *mut _,
168                c"interface-removed".as_ptr() as *const _,
169                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
170                    interface_removed_trampoline::<Self, F> as *const (),
171                )),
172                Box_::into_raw(f),
173            )
174        }
175    }
176}
177
178impl<O: IsA<DBusObject>> DBusObjectExt for O {}