1use crate::{ffi, DBusInterface, 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 #[doc(alias = "GDBusObjectManager")]
59 pub struct DBusObjectManager(Interface<ffi::GDBusObjectManager, ffi::GDBusObjectManagerIface>);
60
61 match fn {
62 type_ => || ffi::g_dbus_object_manager_get_type(),
63 }
64}
65
66impl DBusObjectManager {
67 pub const NONE: Option<&'static DBusObjectManager> = None;
68}
69
70mod sealed {
71 pub trait Sealed {}
72 impl<T: super::IsA<super::DBusObjectManager>> Sealed for T {}
73}
74
75pub trait DBusObjectManagerExt: IsA<DBusObjectManager> + sealed::Sealed + 'static {
81 #[doc(alias = "g_dbus_object_manager_get_interface")]
93 #[doc(alias = "get_interface")]
94 fn interface(&self, object_path: &str, interface_name: &str) -> Option<DBusInterface> {
95 unsafe {
96 from_glib_full(ffi::g_dbus_object_manager_get_interface(
97 self.as_ref().to_glib_none().0,
98 object_path.to_glib_none().0,
99 interface_name.to_glib_none().0,
100 ))
101 }
102 }
103
104 #[doc(alias = "g_dbus_object_manager_get_object")]
113 #[doc(alias = "get_object")]
114 fn object(&self, object_path: &str) -> Option<DBusObject> {
115 unsafe {
116 from_glib_full(ffi::g_dbus_object_manager_get_object(
117 self.as_ref().to_glib_none().0,
118 object_path.to_glib_none().0,
119 ))
120 }
121 }
122
123 #[doc(alias = "g_dbus_object_manager_get_object_path")]
129 #[doc(alias = "get_object_path")]
130 fn object_path(&self) -> glib::GString {
131 unsafe {
132 from_glib_none(ffi::g_dbus_object_manager_get_object_path(
133 self.as_ref().to_glib_none().0,
134 ))
135 }
136 }
137
138 #[doc(alias = "g_dbus_object_manager_get_objects")]
147 #[doc(alias = "get_objects")]
148 fn objects(&self) -> Vec<DBusObject> {
149 unsafe {
150 FromGlibPtrContainer::from_glib_full(ffi::g_dbus_object_manager_get_objects(
151 self.as_ref().to_glib_none().0,
152 ))
153 }
154 }
155
156 #[doc(alias = "interface-added")]
165 fn connect_interface_added<F: Fn(&Self, &DBusObject, &DBusInterface) + 'static>(
166 &self,
167 f: F,
168 ) -> SignalHandlerId {
169 unsafe extern "C" fn interface_added_trampoline<
170 P: IsA<DBusObjectManager>,
171 F: Fn(&P, &DBusObject, &DBusInterface) + 'static,
172 >(
173 this: *mut ffi::GDBusObjectManager,
174 object: *mut ffi::GDBusObject,
175 interface: *mut ffi::GDBusInterface,
176 f: glib::ffi::gpointer,
177 ) {
178 let f: &F = &*(f as *const F);
179 f(
180 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
181 &from_glib_borrow(object),
182 &from_glib_borrow(interface),
183 )
184 }
185 unsafe {
186 let f: Box_<F> = Box_::new(f);
187 connect_raw(
188 self.as_ptr() as *mut _,
189 b"interface-added\0".as_ptr() as *const _,
190 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191 interface_added_trampoline::<Self, F> as *const (),
192 )),
193 Box_::into_raw(f),
194 )
195 }
196 }
197
198 #[doc(alias = "interface-removed")]
207 fn connect_interface_removed<F: Fn(&Self, &DBusObject, &DBusInterface) + 'static>(
208 &self,
209 f: F,
210 ) -> SignalHandlerId {
211 unsafe extern "C" fn interface_removed_trampoline<
212 P: IsA<DBusObjectManager>,
213 F: Fn(&P, &DBusObject, &DBusInterface) + 'static,
214 >(
215 this: *mut ffi::GDBusObjectManager,
216 object: *mut ffi::GDBusObject,
217 interface: *mut ffi::GDBusInterface,
218 f: glib::ffi::gpointer,
219 ) {
220 let f: &F = &*(f as *const F);
221 f(
222 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
223 &from_glib_borrow(object),
224 &from_glib_borrow(interface),
225 )
226 }
227 unsafe {
228 let f: Box_<F> = Box_::new(f);
229 connect_raw(
230 self.as_ptr() as *mut _,
231 b"interface-removed\0".as_ptr() as *const _,
232 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
233 interface_removed_trampoline::<Self, F> as *const (),
234 )),
235 Box_::into_raw(f),
236 )
237 }
238 }
239
240 #[doc(alias = "object-added")]
244 fn connect_object_added<F: Fn(&Self, &DBusObject) + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn object_added_trampoline<
246 P: IsA<DBusObjectManager>,
247 F: Fn(&P, &DBusObject) + 'static,
248 >(
249 this: *mut ffi::GDBusObjectManager,
250 object: *mut ffi::GDBusObject,
251 f: glib::ffi::gpointer,
252 ) {
253 let f: &F = &*(f as *const F);
254 f(
255 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
256 &from_glib_borrow(object),
257 )
258 }
259 unsafe {
260 let f: Box_<F> = Box_::new(f);
261 connect_raw(
262 self.as_ptr() as *mut _,
263 b"object-added\0".as_ptr() as *const _,
264 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265 object_added_trampoline::<Self, F> as *const (),
266 )),
267 Box_::into_raw(f),
268 )
269 }
270 }
271
272 #[doc(alias = "object-removed")]
276 fn connect_object_removed<F: Fn(&Self, &DBusObject) + 'static>(&self, f: F) -> SignalHandlerId {
277 unsafe extern "C" fn object_removed_trampoline<
278 P: IsA<DBusObjectManager>,
279 F: Fn(&P, &DBusObject) + 'static,
280 >(
281 this: *mut ffi::GDBusObjectManager,
282 object: *mut ffi::GDBusObject,
283 f: glib::ffi::gpointer,
284 ) {
285 let f: &F = &*(f as *const F);
286 f(
287 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
288 &from_glib_borrow(object),
289 )
290 }
291 unsafe {
292 let f: Box_<F> = Box_::new(f);
293 connect_raw(
294 self.as_ptr() as *mut _,
295 b"object-removed\0".as_ptr() as *const _,
296 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
297 object_removed_trampoline::<Self, F> as *const (),
298 )),
299 Box_::into_raw(f),
300 )
301 }
302 }
303}
304
305impl<O: IsA<DBusObjectManager>> DBusObjectManagerExt for O {}