tracker-rs 0.8.0

Rust bindings for tracker
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{ffi, Endpoint, SparqlConnection};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "TrackerEndpointDBus")]
    pub struct EndpointDBus(Object<ffi::TrackerEndpointDBus>) @extends Endpoint, @implements gio::Initable;

    match fn {
        type_ => || ffi::tracker_endpoint_dbus_get_type(),
    }
}

impl EndpointDBus {
    #[doc(alias = "tracker_endpoint_dbus_new")]
    pub fn new(
        sparql_connection: &SparqlConnection,
        dbus_connection: &gio::DBusConnection,
        object_path: Option<&str>,
        cancellable: Option<&impl IsA<gio::Cancellable>>,
    ) -> Result<EndpointDBus, glib::Error> {
        skip_assert_initialized!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::tracker_endpoint_dbus_new(
                sparql_connection.to_glib_none().0,
                dbus_connection.to_glib_none().0,
                object_path.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "dbus-connection")]
    pub fn dbus_connection(&self) -> Option<gio::DBusConnection> {
        ObjectExt::property(self, "dbus-connection")
    }

    #[doc(alias = "object-path")]
    pub fn object_path(&self) -> Option<glib::GString> {
        ObjectExt::property(self, "object-path")
    }

    #[doc(alias = "block-call")]
    pub fn connect_block_call<F: Fn(&Self, &str) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn block_call_trampoline<F: Fn(&EndpointDBus, &str) -> bool + 'static>(
            this: *mut ffi::TrackerEndpointDBus,
            object: *mut std::ffi::c_char,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    &from_glib_borrow(this),
                    &glib::GString::from_glib_borrow(object),
                )
                .into_glib()
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"block-call".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    block_call_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}