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")]
16 pub struct DBusObjectManager(Interface<ffi::GDBusObjectManager, ffi::GDBusObjectManagerIface>);
17
18 match fn {
19 type_ => || ffi::g_dbus_object_manager_get_type(),
20 }
21}
22
23impl DBusObjectManager {
24 pub const NONE: Option<&'static DBusObjectManager> = None;
25}
26
27pub trait DBusObjectManagerExt: IsA<DBusObjectManager> + 'static {
28 #[doc(alias = "g_dbus_object_manager_get_interface")]
29 #[doc(alias = "get_interface")]
30 fn interface(&self, object_path: &str, interface_name: &str) -> Option<DBusInterface> {
31 unsafe {
32 from_glib_full(ffi::g_dbus_object_manager_get_interface(
33 self.as_ref().to_glib_none().0,
34 object_path.to_glib_none().0,
35 interface_name.to_glib_none().0,
36 ))
37 }
38 }
39
40 #[doc(alias = "g_dbus_object_manager_get_object")]
41 #[doc(alias = "get_object")]
42 fn object(&self, object_path: &str) -> Option<DBusObject> {
43 unsafe {
44 from_glib_full(ffi::g_dbus_object_manager_get_object(
45 self.as_ref().to_glib_none().0,
46 object_path.to_glib_none().0,
47 ))
48 }
49 }
50
51 #[doc(alias = "g_dbus_object_manager_get_object_path")]
52 #[doc(alias = "get_object_path")]
53 fn object_path(&self) -> glib::GString {
54 unsafe {
55 from_glib_none(ffi::g_dbus_object_manager_get_object_path(
56 self.as_ref().to_glib_none().0,
57 ))
58 }
59 }
60
61 #[doc(alias = "g_dbus_object_manager_get_objects")]
62 #[doc(alias = "get_objects")]
63 fn objects(&self) -> Vec<DBusObject> {
64 unsafe {
65 FromGlibPtrContainer::from_glib_full(ffi::g_dbus_object_manager_get_objects(
66 self.as_ref().to_glib_none().0,
67 ))
68 }
69 }
70
71 #[doc(alias = "interface-added")]
72 fn connect_interface_added<F: Fn(&Self, &DBusObject, &DBusInterface) + 'static>(
73 &self,
74 f: F,
75 ) -> SignalHandlerId {
76 unsafe extern "C" fn interface_added_trampoline<
77 P: IsA<DBusObjectManager>,
78 F: Fn(&P, &DBusObject, &DBusInterface) + 'static,
79 >(
80 this: *mut ffi::GDBusObjectManager,
81 object: *mut ffi::GDBusObject,
82 interface: *mut ffi::GDBusInterface,
83 f: glib::ffi::gpointer,
84 ) {
85 let f: &F = &*(f as *const F);
86 f(
87 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
88 &from_glib_borrow(object),
89 &from_glib_borrow(interface),
90 )
91 }
92 unsafe {
93 let f: Box_<F> = Box_::new(f);
94 connect_raw(
95 self.as_ptr() as *mut _,
96 c"interface-added".as_ptr() as *const _,
97 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
98 interface_added_trampoline::<Self, F> as *const (),
99 )),
100 Box_::into_raw(f),
101 )
102 }
103 }
104
105 #[doc(alias = "interface-removed")]
106 fn connect_interface_removed<F: Fn(&Self, &DBusObject, &DBusInterface) + 'static>(
107 &self,
108 f: F,
109 ) -> SignalHandlerId {
110 unsafe extern "C" fn interface_removed_trampoline<
111 P: IsA<DBusObjectManager>,
112 F: Fn(&P, &DBusObject, &DBusInterface) + 'static,
113 >(
114 this: *mut ffi::GDBusObjectManager,
115 object: *mut ffi::GDBusObject,
116 interface: *mut ffi::GDBusInterface,
117 f: glib::ffi::gpointer,
118 ) {
119 let f: &F = &*(f as *const F);
120 f(
121 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
122 &from_glib_borrow(object),
123 &from_glib_borrow(interface),
124 )
125 }
126 unsafe {
127 let f: Box_<F> = Box_::new(f);
128 connect_raw(
129 self.as_ptr() as *mut _,
130 c"interface-removed".as_ptr() as *const _,
131 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
132 interface_removed_trampoline::<Self, F> as *const (),
133 )),
134 Box_::into_raw(f),
135 )
136 }
137 }
138
139 #[doc(alias = "object-added")]
140 fn connect_object_added<F: Fn(&Self, &DBusObject) + 'static>(&self, f: F) -> SignalHandlerId {
141 unsafe extern "C" fn object_added_trampoline<
142 P: IsA<DBusObjectManager>,
143 F: Fn(&P, &DBusObject) + 'static,
144 >(
145 this: *mut ffi::GDBusObjectManager,
146 object: *mut ffi::GDBusObject,
147 f: glib::ffi::gpointer,
148 ) {
149 let f: &F = &*(f as *const F);
150 f(
151 DBusObjectManager::from_glib_borrow(this).unsafe_cast_ref(),
152 &from_glib_borrow(object),
153 )
154 }
155 unsafe {
156 let f: Box_<F> = Box_::new(f);
157 connect_raw(
158 self.as_ptr() as *mut _,
159 c"object-added".as_ptr() as *const _,
160 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161 object_added_trampoline::<Self, F> as *const (),
162 )),
163 Box_::into_raw(f),
164 )
165 }
166 }
167
168 #[doc(alias = "object-removed")]
169 fn connect_object_removed<F: Fn(&Self, &DBusObject) + 'static>(&self, f: F) -> SignalHandlerId {
170 unsafe extern "C" fn object_removed_trampoline<
171 P: IsA<DBusObjectManager>,
172 F: Fn(&P, &DBusObject) + 'static,
173 >(
174 this: *mut ffi::GDBusObjectManager,
175 object: *mut ffi::GDBusObject,
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 )
183 }
184 unsafe {
185 let f: Box_<F> = Box_::new(f);
186 connect_raw(
187 self.as_ptr() as *mut _,
188 c"object-removed".as_ptr() as *const _,
189 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190 object_removed_trampoline::<Self, F> as *const (),
191 )),
192 Box_::into_raw(f),
193 )
194 }
195 }
196}
197
198impl<O: IsA<DBusObjectManager>> DBusObjectManagerExt for O {}