tracker/auto/
endpoint_dbus.rs1use crate::{ffi, Endpoint, SparqlConnection};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "TrackerEndpointDBus")]
17 pub struct EndpointDBus(Object<ffi::TrackerEndpointDBus>) @extends Endpoint, @implements gio::Initable;
18
19 match fn {
20 type_ => || ffi::tracker_endpoint_dbus_get_type(),
21 }
22}
23
24impl EndpointDBus {
25 #[doc(alias = "tracker_endpoint_dbus_new")]
26 pub fn new(
27 sparql_connection: &SparqlConnection,
28 dbus_connection: &gio::DBusConnection,
29 object_path: Option<&str>,
30 cancellable: Option<&impl IsA<gio::Cancellable>>,
31 ) -> Result<EndpointDBus, glib::Error> {
32 skip_assert_initialized!();
33 unsafe {
34 let mut error = std::ptr::null_mut();
35 let ret = ffi::tracker_endpoint_dbus_new(
36 sparql_connection.to_glib_none().0,
37 dbus_connection.to_glib_none().0,
38 object_path.to_glib_none().0,
39 cancellable.map(|p| p.as_ref()).to_glib_none().0,
40 &mut error,
41 );
42 if error.is_null() {
43 Ok(from_glib_full(ret))
44 } else {
45 Err(from_glib_full(error))
46 }
47 }
48 }
49
50 #[doc(alias = "dbus-connection")]
51 pub fn dbus_connection(&self) -> Option<gio::DBusConnection> {
52 ObjectExt::property(self, "dbus-connection")
53 }
54
55 #[doc(alias = "object-path")]
56 pub fn object_path(&self) -> Option<glib::GString> {
57 ObjectExt::property(self, "object-path")
58 }
59
60 #[doc(alias = "block-call")]
61 pub fn connect_block_call<F: Fn(&Self, &str) -> bool + 'static>(
62 &self,
63 f: F,
64 ) -> SignalHandlerId {
65 unsafe extern "C" fn block_call_trampoline<F: Fn(&EndpointDBus, &str) -> bool + 'static>(
66 this: *mut ffi::TrackerEndpointDBus,
67 object: *mut std::ffi::c_char,
68 f: glib::ffi::gpointer,
69 ) -> glib::ffi::gboolean {
70 unsafe {
71 let f: &F = &*(f as *const F);
72 f(
73 &from_glib_borrow(this),
74 &glib::GString::from_glib_borrow(object),
75 )
76 .into_glib()
77 }
78 }
79 unsafe {
80 let f: Box_<F> = Box_::new(f);
81 connect_raw(
82 self.as_ptr() as *mut _,
83 c"block-call".as_ptr(),
84 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
85 block_call_trampoline::<F> as *const (),
86 )),
87 Box_::into_raw(f),
88 )
89 }
90 }
91}