gio/auto/
dbus_object.rs
1use 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 #[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
54pub trait DBusObjectExt: IsA<DBusObject> + sealed::Sealed + 'static {
60 #[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 #[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 #[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 #[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 #[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 {}