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
49pub trait DBusObjectExt: IsA<DBusObject> + 'static {
55 #[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 #[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 #[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 #[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 #[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 {}