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
70pub trait DBusObjectManagerExt: IsA<DBusObjectManager> + 'static {
76 #[doc(alias = "g_dbus_object_manager_get_interface")]
88 #[doc(alias = "get_interface")]
89 fn interface(&self, object_path: &str, interface_name: &str) -> Option<DBusInterface> {
90 unsafe {
91 from_glib_full(ffi::g_dbus_object_manager_get_interface(
92 self.as_ref().to_glib_none().0,
93 object_path.to_glib_none().0,
94 interface_name.to_glib_none().0,
95 ))
96 }
97 }
98
99 #[doc(alias = "g_dbus_object_manager_get_object")]
108 #[doc(alias = "get_object")]
109 fn object(&self, object_path: &str) -> Option<DBusObject> {
110 unsafe {
111 from_glib_full(ffi::g_dbus_object_manager_get_object(
112 self.as_ref().to_glib_none().0,
113 object_path.to_glib_none().0,
114 ))
115 }
116 }
117
118 #[doc(alias = "g_dbus_object_manager_get_object_path")]
124 #[doc(alias = "get_object_path")]
125 fn object_path(&self) -> glib::GString {
126 unsafe {
127 from_glib_none(ffi::g_dbus_object_manager_get_object_path(
128 self.as_ref().to_glib_none().0,
129 ))
130 }
131 }
132
133 #[doc(alias = "g_dbus_object_manager_get_objects")]
142 #[doc(alias = "get_objects")]
143 fn objects(&self) -> Vec<DBusObject> {
144 unsafe {
145 FromGlibPtrContainer::from_glib_full(ffi::g_dbus_object_manager_get_objects(
146 self.as_ref().to_glib_none().0,
147 ))
148 }
149 }
150
151 #[doc(alias = "interface-added")]
160 fn connect_interface_added<F: Fn(&Self, &DBusObject, &DBusInterface) + 'static>(
161 &self,
162 f: F,
163 ) -> SignalHandlerId {
164 unsafe extern "C" fn interface_added_trampoline<
165 P: IsA<DBusObjectManager>,
166 F: Fn(&P, &DBusObject, &DBusInterface) + 'static,
167 >(
168 this: *mut ffi::GDBusObjectManager,
169 object: *mut ffi::GDBusObject,
170 interface: *mut ffi::GDBusInterface,
171 f: glib::ffi::gpointer,
172 ) {
173 let f: &F = &*(f as *const F);
174 f(
175 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
176 &from_glib_borrow(object),
177 &from_glib_borrow(interface),
178 )
179 }
180 unsafe {
181 let f: Box_<F> = Box_::new(f);
182 connect_raw(
183 self.as_ptr() as *mut _,
184 c"interface-added".as_ptr() as *const _,
185 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186 interface_added_trampoline::<Self, F> as *const (),
187 )),
188 Box_::into_raw(f),
189 )
190 }
191 }
192
193 #[doc(alias = "interface-removed")]
202 fn connect_interface_removed<F: Fn(&Self, &DBusObject, &DBusInterface) + 'static>(
203 &self,
204 f: F,
205 ) -> SignalHandlerId {
206 unsafe extern "C" fn interface_removed_trampoline<
207 P: IsA<DBusObjectManager>,
208 F: Fn(&P, &DBusObject, &DBusInterface) + 'static,
209 >(
210 this: *mut ffi::GDBusObjectManager,
211 object: *mut ffi::GDBusObject,
212 interface: *mut ffi::GDBusInterface,
213 f: glib::ffi::gpointer,
214 ) {
215 let f: &F = &*(f as *const F);
216 f(
217 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
218 &from_glib_borrow(object),
219 &from_glib_borrow(interface),
220 )
221 }
222 unsafe {
223 let f: Box_<F> = Box_::new(f);
224 connect_raw(
225 self.as_ptr() as *mut _,
226 c"interface-removed".as_ptr() as *const _,
227 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
228 interface_removed_trampoline::<Self, F> as *const (),
229 )),
230 Box_::into_raw(f),
231 )
232 }
233 }
234
235 #[doc(alias = "object-added")]
239 fn connect_object_added<F: Fn(&Self, &DBusObject) + 'static>(&self, f: F) -> SignalHandlerId {
240 unsafe extern "C" fn object_added_trampoline<
241 P: IsA<DBusObjectManager>,
242 F: Fn(&P, &DBusObject) + 'static,
243 >(
244 this: *mut ffi::GDBusObjectManager,
245 object: *mut ffi::GDBusObject,
246 f: glib::ffi::gpointer,
247 ) {
248 let f: &F = &*(f as *const F);
249 f(
250 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
251 &from_glib_borrow(object),
252 )
253 }
254 unsafe {
255 let f: Box_<F> = Box_::new(f);
256 connect_raw(
257 self.as_ptr() as *mut _,
258 c"object-added".as_ptr() as *const _,
259 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
260 object_added_trampoline::<Self, F> as *const (),
261 )),
262 Box_::into_raw(f),
263 )
264 }
265 }
266
267 #[doc(alias = "object-removed")]
271 fn connect_object_removed<F: Fn(&Self, &DBusObject) + 'static>(&self, f: F) -> SignalHandlerId {
272 unsafe extern "C" fn object_removed_trampoline<
273 P: IsA<DBusObjectManager>,
274 F: Fn(&P, &DBusObject) + 'static,
275 >(
276 this: *mut ffi::GDBusObjectManager,
277 object: *mut ffi::GDBusObject,
278 f: glib::ffi::gpointer,
279 ) {
280 let f: &F = &*(f as *const F);
281 f(
282 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
283 &from_glib_borrow(object),
284 )
285 }
286 unsafe {
287 let f: Box_<F> = Box_::new(f);
288 connect_raw(
289 self.as_ptr() as *mut _,
290 c"object-removed".as_ptr() as *const _,
291 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292 object_removed_trampoline::<Self, F> as *const (),
293 )),
294 Box_::into_raw(f),
295 )
296 }
297 }
298}
299
300impl<O: IsA<DBusObjectManager>> DBusObjectManagerExt for O {}