use Error;
use Manager;
use Object;
#[cfg(feature = "futures")]
use futures::future;
use gio;
use gio_sys;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_sys;
use goa_sys;
use gobject_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use std::ptr;
glib_wrapper! {
pub struct Client(Object<goa_sys::GoaClient, goa_sys::GoaClientClass, ClientClass>);
match fn {
get_type => || goa_sys::goa_client_get_type(),
}
}
impl Client {
pub fn new_sync<P: IsA<gio::Cancellable>>(cancellable: Option<&P>) -> Result<Client, Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = goa_sys::goa_client_new_sync(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)) }
}
}
pub fn new<P: IsA<gio::Cancellable>, Q: FnOnce(Result<Client, Error>) + Send + 'static>(cancellable: Option<&P>, callback: Q) {
let user_data: Box<Q> = Box::new(callback);
unsafe extern "C" fn new_trampoline<Q: FnOnce(Result<Client, Error>) + Send + 'static>(_source_object: *mut gobject_sys::GObject, res: *mut gio_sys::GAsyncResult, user_data: glib_sys::gpointer) {
let mut error = ptr::null_mut();
let ret = goa_sys::goa_client_new_finish(res, &mut error);
let result = if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) };
let callback: Box<Q> = Box::from_raw(user_data as *mut _);
callback(result);
}
let callback = new_trampoline::<Q>;
unsafe {
goa_sys::goa_client_new(cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _);
}
}
#[cfg(feature = "futures")]
pub fn new_future() -> Box_<dyn future::Future<Output = Result<Client, Error>> + std::marker::Unpin> {
use gio::GioFuture;
use fragile::Fragile;
GioFuture::new(&(), move |_obj, send| {
let cancellable = gio::Cancellable::new();
let send = Fragile::new(send);
Self::new(
Some(&cancellable),
move |res| {
let _ = send.into_inner().send(res);
},
);
cancellable
})
}
}
pub const NONE_CLIENT: Option<&Client> = None;
pub trait ClientExt: 'static {
fn get_accounts(&self) -> Vec<Object>;
fn get_manager(&self) -> Option<Manager>;
#[cfg(any(feature = "v3_6", feature = "dox"))]
fn lookup_by_id(&self, id: &str) -> Option<Object>;
fn connect_account_added<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_account_changed<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_account_removed<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_object_manager_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Client>> ClientExt for O {
fn get_accounts(&self) -> Vec<Object> {
unsafe {
FromGlibPtrContainer::from_glib_full(goa_sys::goa_client_get_accounts(self.as_ref().to_glib_none().0))
}
}
fn get_manager(&self) -> Option<Manager> {
unsafe {
from_glib_none(goa_sys::goa_client_get_manager(self.as_ref().to_glib_none().0))
}
}
#[cfg(any(feature = "v3_6", feature = "dox"))]
fn lookup_by_id(&self, id: &str) -> Option<Object> {
unsafe {
from_glib_full(goa_sys::goa_client_lookup_by_id(self.as_ref().to_glib_none().0, id.to_glib_none().0))
}
}
fn connect_account_added<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn account_added_trampoline<P, F: Fn(&P, &Object) + 'static>(this: *mut goa_sys::GoaClient, object: *mut goa_sys::GoaObject, f: glib_sys::gpointer)
where P: IsA<Client>
{
let f: &F = &*(f as *const F);
f(&Client::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(object))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"account-added\0".as_ptr() as *const _,
Some(transmute(account_added_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_account_changed<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn account_changed_trampoline<P, F: Fn(&P, &Object) + 'static>(this: *mut goa_sys::GoaClient, object: *mut goa_sys::GoaObject, f: glib_sys::gpointer)
where P: IsA<Client>
{
let f: &F = &*(f as *const F);
f(&Client::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(object))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"account-changed\0".as_ptr() as *const _,
Some(transmute(account_changed_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_account_removed<F: Fn(&Self, &Object) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn account_removed_trampoline<P, F: Fn(&P, &Object) + 'static>(this: *mut goa_sys::GoaClient, object: *mut goa_sys::GoaObject, f: glib_sys::gpointer)
where P: IsA<Client>
{
let f: &F = &*(f as *const F);
f(&Client::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(object))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"account-removed\0".as_ptr() as *const _,
Some(transmute(account_removed_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_property_object_manager_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_object_manager_trampoline<P, F: Fn(&P) + 'static>(this: *mut goa_sys::GoaClient, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer)
where P: IsA<Client>
{
let f: &F = &*(f as *const F);
f(&Client::from_glib_borrow(this).unsafe_cast())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"notify::object-manager\0".as_ptr() as *const _,
Some(transmute(notify_object_manager_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
}
impl fmt::Display for Client {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Client")
}
}