diff --git a/gdk-pixbuf/src/auto/versions.txt b/gdk-pixbuf/src/auto/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/gdk-pixbuf/src/auto/versions.txt +++ b/gdk-pixbuf/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/gdk-pixbuf/sys/versions.txt b/gdk-pixbuf/sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/gdk-pixbuf/sys/versions.txt +++ b/gdk-pixbuf/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/gio/Gir.toml b/gio/Gir.toml index 578d7610b502..dfa27fdf57e1 100644 --- a/gio/Gir.toml +++ b/gio/Gir.toml @@ -699,6 +699,42 @@ status = "generate" # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4414 nullable = true +[[object]] +name = "Gio.DBusObjectManagerClient" +status = "generate" +concurrency = "send+sync" +manual_traits = ["DBusObjectManagerClientExtManual"] + [[object.function]] + name = "new_for_bus_sync" + visibility = "crate" + rename = "for_bus_sync_impl" + [[object.function]] + name = "new_sync" + visibility = "crate" + rename = "new_sync_impl" + [[object.function]] + name = "new" + manual = true + [[object.function]] + name = "new_for_bus" + manual = true + [[object.property]] + name = "get-proxy-type-destroy-notify" + # C API + ignore = true + [[object.property]] + name = "get-proxy-type-func" + # C API + ignore = true + [[object.property]] + name = "get-proxy-type-user-data" + # C API + ignore = true + [[object.signal]] + name = "interface-proxy-properties-changed" + # **libc::c_char not handled by generator + manual = true + [[object]] name = "Gio.DBusProxy" status = "generate" diff --git a/gio/src/auto/dbus_object_manager_client.rs b/gio/src/auto/dbus_object_manager_client.rs new file mode 100644 index 000000000000..9148f1d654bc --- /dev/null +++ b/gio/src/auto/dbus_object_manager_client.rs @@ -0,0 +1,345 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from gir-files (https://github.com/gtk-rs/gir-files) +// DO NOT EDIT + +use crate::{ + ffi, AsyncInitable, AsyncResult, BusType, Cancellable, DBusConnection, DBusObjectManager, + DBusObjectManagerClientFlags, DBusObjectProxy, DBusProxy, Initable, +}; +use glib::{ + object::ObjectType as _, + prelude::*, + signal::{connect_raw, SignalHandlerId}, + translate::*, +}; +use std::boxed::Box as Box_; + +glib::wrapper! { + #[doc(alias = "GDBusObjectManagerClient")] + pub struct DBusObjectManagerClient(Object) @implements AsyncInitable, DBusObjectManager, Initable; + + match fn { + type_ => || ffi::g_dbus_object_manager_client_get_type(), + } +} + +impl DBusObjectManagerClient { + pub const NONE: Option<&'static DBusObjectManagerClient> = None; + + #[doc(alias = "g_dbus_object_manager_client_new_for_bus_sync")] + #[doc(alias = "new_for_bus_sync")] + #[allow(dead_code)] + pub(crate) fn for_bus_sync_impl( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + 'static, + >, + >, + cancellable: Option<&impl IsA>, + ) -> Result { + let get_proxy_type_func_data: Box_< + Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >, + > = Box_::new(get_proxy_type_func); + unsafe extern "C" fn get_proxy_type_func_func( + manager: *mut ffi::GDBusObjectManagerClient, + object_path: *const std::ffi::c_char, + interface_name: *const std::ffi::c_char, + data: glib::ffi::gpointer, + ) -> glib::ffi::GType { + let manager = from_glib_borrow(manager); + let object_path: Borrowed = from_glib_borrow(object_path); + let interface_name: Borrowed> = from_glib_borrow(interface_name); + let callback = &*(data as *mut Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >); + if let Some(ref callback) = *callback { + callback( + &manager, + object_path.as_str(), + (*interface_name).as_ref().map(|s| s.as_str()), + ) + } else { + panic!("cannot get closure...") + } + .into_glib() + } + let get_proxy_type_func = if get_proxy_type_func_data.is_some() { + Some(get_proxy_type_func_func as _) + } else { + None + }; + unsafe extern "C" fn get_proxy_type_destroy_notify_func(data: glib::ffi::gpointer) { + let _callback = Box_::from_raw( + data as *mut Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >, + ); + } + let destroy_call6 = Some(get_proxy_type_destroy_notify_func as _); + let super_callback0: Box_< + Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >, + > = get_proxy_type_func_data; + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::g_dbus_object_manager_client_new_for_bus_sync( + bus_type.into_glib(), + flags.into_glib(), + name.to_glib_none().0, + object_path.to_glib_none().0, + get_proxy_type_func, + Box_::into_raw(super_callback0) as *mut _, + destroy_call6, + 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 = "g_dbus_object_manager_client_new_sync")] + #[doc(alias = "new_sync")] + #[allow(dead_code)] + pub(crate) fn new_sync_impl( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: Option<&str>, + object_path: &str, + get_proxy_type_func: Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + 'static, + >, + >, + cancellable: Option<&impl IsA>, + ) -> Result { + let get_proxy_type_func_data: Box_< + Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >, + > = Box_::new(get_proxy_type_func); + unsafe extern "C" fn get_proxy_type_func_func( + manager: *mut ffi::GDBusObjectManagerClient, + object_path: *const std::ffi::c_char, + interface_name: *const std::ffi::c_char, + data: glib::ffi::gpointer, + ) -> glib::ffi::GType { + let manager = from_glib_borrow(manager); + let object_path: Borrowed = from_glib_borrow(object_path); + let interface_name: Borrowed> = from_glib_borrow(interface_name); + let callback = &*(data as *mut Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >); + if let Some(ref callback) = *callback { + callback( + &manager, + object_path.as_str(), + (*interface_name).as_ref().map(|s| s.as_str()), + ) + } else { + panic!("cannot get closure...") + } + .into_glib() + } + let get_proxy_type_func = if get_proxy_type_func_data.is_some() { + Some(get_proxy_type_func_func as _) + } else { + None + }; + unsafe extern "C" fn get_proxy_type_destroy_notify_func(data: glib::ffi::gpointer) { + let _callback = Box_::from_raw( + data as *mut Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >, + ); + } + let destroy_call6 = Some(get_proxy_type_destroy_notify_func as _); + let super_callback0: Box_< + Option< + Box_< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + 'static, + >, + >, + > = get_proxy_type_func_data; + unsafe { + let mut error = std::ptr::null_mut(); + let ret = ffi::g_dbus_object_manager_client_new_sync( + connection.to_glib_none().0, + flags.into_glib(), + name.to_glib_none().0, + object_path.to_glib_none().0, + get_proxy_type_func, + Box_::into_raw(super_callback0) as *mut _, + destroy_call6, + 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)) + } + } + } +} + +impl std::fmt::Display for DBusObjectManagerClient { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_str(&DBusObjectManagerClientExt::name(self)) + } +} + +unsafe impl Send for DBusObjectManagerClient {} +unsafe impl Sync for DBusObjectManagerClient {} + +pub trait DBusObjectManagerClientExt: IsA + 'static { + #[doc(alias = "g_dbus_object_manager_client_get_connection")] + #[doc(alias = "get_connection")] + fn connection(&self) -> DBusConnection { + unsafe { + from_glib_none(ffi::g_dbus_object_manager_client_get_connection( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "g_dbus_object_manager_client_get_flags")] + #[doc(alias = "get_flags")] + fn flags(&self) -> DBusObjectManagerClientFlags { + unsafe { + from_glib(ffi::g_dbus_object_manager_client_get_flags( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "g_dbus_object_manager_client_get_name")] + #[doc(alias = "get_name")] + fn name(&self) -> glib::GString { + unsafe { + from_glib_none(ffi::g_dbus_object_manager_client_get_name( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "g_dbus_object_manager_client_get_name_owner")] + #[doc(alias = "get_name_owner")] + #[doc(alias = "name-owner")] + fn name_owner(&self) -> Option { + unsafe { + from_glib_full(ffi::g_dbus_object_manager_client_get_name_owner( + self.as_ref().to_glib_none().0, + )) + } + } + + #[doc(alias = "interface-proxy-signal")] + fn connect_interface_proxy_signal< + F: Fn(&Self, &DBusObjectProxy, &DBusProxy, &str, &str, &glib::Variant) + Send + Sync + 'static, + >( + &self, + f: F, + ) -> SignalHandlerId { + unsafe extern "C" fn interface_proxy_signal_trampoline< + P: IsA, + F: Fn(&P, &DBusObjectProxy, &DBusProxy, &str, &str, &glib::Variant) + + Send + + Sync + + 'static, + >( + this: *mut ffi::GDBusObjectManagerClient, + object_proxy: *mut ffi::GDBusObjectProxy, + interface_proxy: *mut ffi::GDBusProxy, + sender_name: *mut std::ffi::c_char, + signal_name: *mut std::ffi::c_char, + parameters: *mut glib::ffi::GVariant, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f( + DBusObjectManagerClient::from_glib_borrow(this).unsafe_cast_ref(), + &from_glib_borrow(object_proxy), + &from_glib_borrow(interface_proxy), + &glib::GString::from_glib_borrow(sender_name), + &glib::GString::from_glib_borrow(signal_name), + &from_glib_borrow(parameters), + ) + } + unsafe { + let f: Box_ = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + c"interface-proxy-signal".as_ptr() as *const _, + Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( + interface_proxy_signal_trampoline:: as *const (), + )), + Box_::into_raw(f), + ) + } + } + + #[doc(alias = "name-owner")] + fn connect_name_owner_notify( + &self, + f: F, + ) -> SignalHandlerId { + unsafe extern "C" fn notify_name_owner_trampoline< + P: IsA, + F: Fn(&P) + Send + Sync + 'static, + >( + this: *mut ffi::GDBusObjectManagerClient, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(DBusObjectManagerClient::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_ = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + c"notify::name-owner".as_ptr() as *const _, + Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( + notify_name_owner_trampoline:: as *const (), + )), + Box_::into_raw(f), + ) + } + } +} + +impl> DBusObjectManagerClientExt for O {} diff --git a/gio/src/auto/mod.rs b/gio/src/auto/mod.rs index e8b3c5958f6c..96507da8639a 100644 --- a/gio/src/auto/mod.rs +++ b/gio/src/auto/mod.rs @@ -89,6 +89,9 @@ pub use self::dbus_object::DBusObject; mod dbus_object_manager; pub use self::dbus_object_manager::DBusObjectManager; +mod dbus_object_manager_client; +pub use self::dbus_object_manager_client::DBusObjectManagerClient; + mod dbus_object_manager_server; pub use self::dbus_object_manager_server::DBusObjectManagerServer; @@ -828,6 +831,7 @@ pub(crate) mod traits { pub use super::dbus_interface_skeleton::DBusInterfaceSkeletonExt; pub use super::dbus_object::DBusObjectExt; pub use super::dbus_object_manager::DBusObjectManagerExt; + pub use super::dbus_object_manager_client::DBusObjectManagerClientExt; pub use super::dbus_object_manager_server::DBusObjectManagerServerExt; pub use super::dbus_object_proxy::DBusObjectProxyExt; pub use super::dbus_object_skeleton::DBusObjectSkeletonExt; diff --git a/gio/src/auto/versions.txt b/gio/src/auto/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/gio/src/auto/versions.txt +++ b/gio/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/gio/src/dbus_object_manager_client.rs b/gio/src/dbus_object_manager_client.rs new file mode 100644 index 000000000000..3d953bc01c0e --- /dev/null +++ b/gio/src/dbus_object_manager_client.rs @@ -0,0 +1,545 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::{ + ffi, BusType, Cancellable, DBusConnection, DBusObjectManagerClient, + DBusObjectManagerClientFlags, DBusObjectProxy, DBusProxy, GioFuture, +}; +use glib::object::{Cast as _, IsA}; +use glib::signal::connect_raw; +use glib::translate::{ + from_glib_borrow, from_glib_full, Borrowed, FromGlibPtrBorrow as _, IntoGlib as _, + ToGlibPtr as _, +}; +use glib::{SignalHandlerId, StrVRef}; +use std::future::Future; +use std::pin::Pin; + +type DBusProxyTypeFn = Box< + dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, +>; + +impl DBusObjectManagerClient { + #[doc(alias = "g_dbus_object_manager_client_new_sync")] + pub fn new_sync( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: Option<&str>, + object_path: &str, + cancellable: Option<&impl IsA>, + ) -> Result { + Self::new_sync_impl(connection, flags, name, object_path, None, cancellable) + } + + #[doc(alias = "g_dbus_object_manager_client_new_sync")] + pub fn new_sync_with_fn< + F: Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, + >( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: Option<&str>, + object_path: &str, + get_proxy_type_func: F, + cancellable: Option<&impl IsA>, + ) -> Result { + Self::new_sync_impl( + connection, + flags, + name, + object_path, + Some(Box::new(get_proxy_type_func)), + cancellable, + ) + } + + #[doc(alias = "g_dbus_object_manager_client_new_for_bus_sync")] + pub fn for_bus_sync( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + cancellable: Option<&impl IsA>, + ) -> Result { + Self::for_bus_sync_impl(bus_type, flags, name, object_path, None, cancellable) + } + + #[doc(alias = "g_dbus_object_manager_client_new_for_bus_sync")] + pub fn for_bus_sync_with_fn< + F: Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, + >( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: F, + cancellable: Option<&impl IsA>, + ) -> Result { + Self::for_bus_sync_impl( + bus_type, + flags, + name, + object_path, + Some(Box::new(get_proxy_type_func)), + cancellable, + ) + } + + #[allow(clippy::new_ret_no_self)] + #[doc(alias = "g_dbus_object_manager_client_new")] + pub fn new) + Send + Sync + 'static>( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + cancellable: Option<&impl IsA>, + callback: P, + ) { + Self::new_impl( + connection, + flags, + name, + object_path, + None, + cancellable, + callback, + ) + } + + #[allow(clippy::new_ret_no_self)] + #[doc(alias = "g_dbus_object_manager_client_new")] + pub fn new_with_fn< + P: FnOnce(Result) + Send + Sync + 'static, + F: Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, + >( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: F, + cancellable: Option<&impl IsA>, + callback: P, + ) { + Self::new_impl( + connection, + flags, + name, + object_path, + Some(Box::new(get_proxy_type_func)), + cancellable, + callback, + ) + } + + #[allow(clippy::new_ret_no_self)] + fn new_impl) + Send + Sync + 'static>( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: Option, + cancellable: Option<&impl IsA>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + unsafe extern "C" fn get_proxy_type_func_func( + manager: *mut ffi::GDBusObjectManagerClient, + object_path: *const std::ffi::c_char, + interface_name: *const std::ffi::c_char, + data: glib::ffi::gpointer, + ) -> glib::ffi::GType { + let manager = from_glib_borrow(manager); + let object_path: Borrowed = from_glib_borrow(object_path); + let interface_name: Borrowed> = from_glib_borrow(interface_name); + let callback = &*(data as *mut Option); + if let Some(ref callback) = *callback { + callback( + &manager, + object_path.as_str(), + (*interface_name).as_ref().map(|s| s.as_str()), + ) + } else { + panic!("cannot get closure...") + } + .into_glib() + } + + unsafe extern "C" fn get_proxy_type_destroy_notify_func(data: glib::ffi::gpointer) { + let _callback = Box::from_raw(data as *mut Option); + } + + unsafe extern "C" fn new_trampoline< + P: FnOnce(Result) + Send + Sync + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut crate::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::g_dbus_object_manager_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> = + Box::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let get_proxy_type_user_data = Box::new(get_proxy_type_func); + let get_proxy_type_func = if get_proxy_type_user_data.is_some() { + Some(get_proxy_type_func_func as _) + } else { + None + }; + let get_proxy_type_destroy_notify = if get_proxy_type_user_data.is_some() { + Some(get_proxy_type_destroy_notify_func as _) + } else { + None + }; + + let user_data: Box> = + Box::new(glib::thread_guard::ThreadGuard::new(callback)); + let callback = new_trampoline::

; + + unsafe { + ffi::g_dbus_object_manager_client_new( + connection.to_glib_none().0, + flags.into_glib(), + name.to_glib_none().0, + object_path.to_glib_none().0, + get_proxy_type_func, + Box::into_raw(get_proxy_type_user_data) as *mut _, + get_proxy_type_destroy_notify, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box::into_raw(user_data) as *mut _, + ); + } + } + + pub fn new_future( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + ) -> Pin> + 'static>> { + Self::new_future_impl(connection, flags, name, object_path, None) + } + + pub fn new_future_with_fn< + F: Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, + >( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: F, + ) -> Pin> + 'static>> { + Self::new_future_impl( + connection, + flags, + name, + object_path, + Some(Box::new(get_proxy_type_func)), + ) + } + + fn new_future_impl( + connection: &DBusConnection, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: Option, + ) -> Pin> + 'static>> { + let connection = connection.clone(); + let name = String::from(name); + let object_path = String::from(object_path); + Box::pin(GioFuture::new(&(), move |_obj, cancellable, send| { + Self::new_impl( + &connection, + flags, + &name, + &object_path, + get_proxy_type_func, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } + + #[doc(alias = "g_dbus_object_manager_client_new_for_bus")] + #[allow(clippy::new_ret_no_self)] + pub fn new_for_bus< + P: FnOnce(Result) + Send + Sync + 'static, + >( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + cancellable: Option<&impl IsA>, + callback: P, + ) { + Self::new_for_bus_impl( + bus_type, + flags, + name, + object_path, + None, + cancellable, + callback, + ); + } + + #[doc(alias = "g_dbus_object_manager_client_new_for_bus")] + #[allow(clippy::new_ret_no_self)] + pub fn new_for_bus_with_fn< + P: FnOnce(Result) + Send + Sync + 'static, + F: Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, + >( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: F, + cancellable: Option<&impl IsA>, + callback: P, + ) { + Self::new_for_bus_impl( + bus_type, + flags, + name, + object_path, + Some(Box::new(get_proxy_type_func)), + cancellable, + callback, + ); + } + + #[allow(clippy::new_ret_no_self)] + fn new_for_bus_impl< + P: FnOnce(Result) + Send + Sync + 'static, + >( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: Option, + cancellable: Option<&impl IsA>, + callback: P, + ) { + let main_context = glib::MainContext::ref_thread_default(); + let is_main_context_owner = main_context.is_owner(); + let has_acquired_main_context = (!is_main_context_owner) + .then(|| main_context.acquire().ok()) + .flatten(); + assert!( + is_main_context_owner || has_acquired_main_context.is_some(), + "Async operations only allowed if the thread is owning the MainContext" + ); + + unsafe extern "C" fn get_proxy_type_func_func( + manager: *mut ffi::GDBusObjectManagerClient, + object_path: *const std::ffi::c_char, + interface_name: *const std::ffi::c_char, + data: glib::ffi::gpointer, + ) -> glib::ffi::GType { + let manager = from_glib_borrow(manager); + let object_path: Borrowed = from_glib_borrow(object_path); + let interface_name: Borrowed> = from_glib_borrow(interface_name); + let callback = &*(data as *mut Option); + if let Some(ref callback) = *callback { + callback( + &manager, + object_path.as_str(), + (*interface_name).as_ref().map(|s| s.as_str()), + ) + } else { + panic!("cannot get closure...") + } + .into_glib() + } + + unsafe extern "C" fn get_proxy_type_destroy_notify_func(data: glib::ffi::gpointer) { + let _callback = Box::from_raw(data as *mut Option); + } + + unsafe extern "C" fn new_for_bus_trampoline< + P: FnOnce(Result) + Send + Sync + 'static, + >( + _source_object: *mut glib::gobject_ffi::GObject, + res: *mut crate::ffi::GAsyncResult, + user_data: glib::ffi::gpointer, + ) { + let mut error = std::ptr::null_mut(); + let ret = ffi::g_dbus_object_manager_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> = + Box::from_raw(user_data as *mut _); + let callback: P = callback.into_inner(); + callback(result); + } + + let get_proxy_type_user_data = Box::new(get_proxy_type_func); + let get_proxy_type_func = if get_proxy_type_user_data.is_some() { + Some(get_proxy_type_func_func as _) + } else { + None + }; + let get_proxy_type_destroy_notify = if get_proxy_type_user_data.is_some() { + Some(get_proxy_type_destroy_notify_func as _) + } else { + None + }; + + let user_data: Box> = + Box::new(glib::thread_guard::ThreadGuard::new(callback)); + let callback = new_for_bus_trampoline::

; + + unsafe { + ffi::g_dbus_object_manager_client_new_for_bus( + bus_type.into_glib(), + flags.into_glib(), + name.to_glib_none().0, + object_path.to_glib_none().0, + get_proxy_type_func, + Box::into_raw(get_proxy_type_user_data) as *mut _, + get_proxy_type_destroy_notify, + cancellable.map(|p| p.as_ref()).to_glib_none().0, + Some(callback), + Box::into_raw(user_data) as *mut _, + ); + } + } + + pub fn new_for_bus_future( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + ) -> Pin> + 'static>> { + Self::new_for_bus_future_impl(bus_type, flags, name, object_path, None) + } + + pub fn new_for_bus_future_with_fn< + F: Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + + Send + + Sync + + 'static, + >( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: F, + ) -> Pin> + 'static>> { + Self::new_for_bus_future_impl( + bus_type, + flags, + name, + object_path, + Some(Box::new(get_proxy_type_func)), + ) + } + + fn new_for_bus_future_impl( + bus_type: BusType, + flags: DBusObjectManagerClientFlags, + name: &str, + object_path: &str, + get_proxy_type_func: Option, + ) -> Pin> + 'static>> { + let name = String::from(name); + let object_path = String::from(object_path); + Box::pin(GioFuture::new(&(), move |_obj, cancellable, send| { + Self::new_for_bus_impl( + bus_type, + flags, + &name, + &object_path, + get_proxy_type_func, + Some(cancellable), + move |res| { + send.resolve(res); + }, + ); + })) + } +} + +pub trait DBusObjectManagerClientExtManual: IsA + 'static { + #[doc(alias = "interface-proxy-properties-changed")] + fn connect_interface_proxy_properties_changed< + F: Fn(&Self, &DBusObjectProxy, &DBusProxy, &glib::Variant, &StrVRef) + Send + Sync + 'static, + >( + &self, + f: F, + ) -> SignalHandlerId { + unsafe extern "C" fn interface_proxy_properties_changed_trampoline< + P: IsA, + F: Fn(&P, &DBusObjectProxy, &DBusProxy, &glib::Variant, &StrVRef) + Send + Sync + 'static, + >( + this: *mut ffi::GDBusObjectManagerClient, + object_proxy: *mut ffi::GDBusObjectProxy, + interface_proxy: *mut ffi::GDBusProxy, + changed_properties: *mut glib::ffi::GVariant, + invalidated_properties: *const *const std::ffi::c_char, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f( + DBusObjectManagerClient::from_glib_borrow(this).unsafe_cast_ref(), + &from_glib_borrow(object_proxy), + &from_glib_borrow(interface_proxy), + &from_glib_borrow(changed_properties), + StrVRef::from_glib_borrow(invalidated_properties), + ) + } + unsafe { + let f: Box = Box::new(f); + connect_raw( + self.as_ptr() as *mut _, + c"interface-proxy-properties-changed".as_ptr() as *const _, + Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( + interface_proxy_properties_changed_trampoline:: as *const (), + )), + Box::into_raw(f), + ) + } + } +} + +impl> DBusObjectManagerClientExtManual for O {} diff --git a/gio/src/lib.rs b/gio/src/lib.rs index cc6e13f840d8..a8e0e9f43ca4 100644 --- a/gio/src/lib.rs +++ b/gio/src/lib.rs @@ -91,6 +91,7 @@ mod socket_control_message; mod socket_listener; mod socket_msg_flags; pub use socket_msg_flags::SocketMsgFlags; +mod dbus_object_manager_client; mod subprocess; mod subprocess_launcher; mod threaded_socket_service; diff --git a/gio/src/prelude.rs b/gio/src/prelude.rs index 1706dec803d1..edbe9ef35a7b 100644 --- a/gio/src/prelude.rs +++ b/gio/src/prelude.rs @@ -36,11 +36,11 @@ pub use crate::{ application_command_line::ApplicationCommandLineExtManual, auto::traits::*, cancellable::CancellableExtManual, converter::ConverterExtManual, data_input_stream::DataInputStreamExtManual, datagram_based::DatagramBasedExtManual, - dbus_connection::DBusMethodCall, dbus_proxy::DBusProxyExtManual, file::FileExtManual, - file_enumerator::FileEnumeratorExtManual, inet_address::InetAddressExtManual, - input_stream::InputStreamExtManual, io_stream::IOStreamExtManual, - list_model::ListModelExtManual, output_stream::OutputStreamExtManual, - pollable_input_stream::PollableInputStreamExtManual, + dbus_connection::DBusMethodCall, dbus_object_manager_client::DBusObjectManagerClientExtManual, + dbus_proxy::DBusProxyExtManual, file::FileExtManual, file_enumerator::FileEnumeratorExtManual, + inet_address::InetAddressExtManual, input_stream::InputStreamExtManual, + io_stream::IOStreamExtManual, list_model::ListModelExtManual, + output_stream::OutputStreamExtManual, pollable_input_stream::PollableInputStreamExtManual, pollable_output_stream::PollableOutputStreamExtManual, settings::SettingsExtManual, simple_proxy_resolver::SimpleProxyResolverExtManual, socket::SocketExtManual, socket_control_message::SocketControlMessageExtManual, diff --git a/gio/sys/versions.txt b/gio/sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/gio/sys/versions.txt +++ b/gio/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/gir b/gir index 7047e1b433e2..c9947f8f47b6 160000 --- a/gir +++ b/gir @@ -1 +1 @@ -Subproject commit 7047e1b433e2ea39d96b25ae3242a2a780d2f59a +Subproject commit c9947f8f47b69d6884ad79738b77d6291fb63467 diff --git a/glib/gobject-sys/versions.txt b/glib/gobject-sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/glib/gobject-sys/versions.txt +++ b/glib/gobject-sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/glib/src/auto/versions.txt b/glib/src/auto/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/glib/src/auto/versions.txt +++ b/glib/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/glib/sys/versions.txt b/glib/sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/glib/sys/versions.txt +++ b/glib/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/glib/tests/value.rs b/glib/tests/value.rs index 1bcdf8fd7f0c..7c10d46a7d17 100644 --- a/glib/tests/value.rs +++ b/glib/tests/value.rs @@ -36,7 +36,7 @@ pub fn to_value_invariants() { ); } -// Test that `ToValue` and `FromValue` handle nexted boxed values correctly (as per the documentation) +// Test that `ToValue` and `FromValue` handle nested boxed values correctly (as per the documentation) #[test] pub fn to_value_boxed() { let x = 0i32.to_value(); diff --git a/graphene/src/auto/versions.txt b/graphene/src/auto/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/graphene/src/auto/versions.txt +++ b/graphene/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/graphene/sys/versions.txt b/graphene/sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/graphene/sys/versions.txt +++ b/graphene/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/pango/src/auto/versions.txt b/pango/src/auto/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/pango/src/auto/versions.txt +++ b/pango/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/pango/sys/versions.txt b/pango/sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/pango/sys/versions.txt +++ b/pango/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/pangocairo/src/auto/versions.txt b/pangocairo/src/auto/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/pangocairo/src/auto/versions.txt +++ b/pangocairo/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8) diff --git a/pangocairo/sys/versions.txt b/pangocairo/sys/versions.txt index 14eea57bb513..ef84c0f9c835 100644 --- a/pangocairo/sys/versions.txt +++ b/pangocairo/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 7047e1b433e2) +Generated by gir (https://github.com/gtk-rs/gir @ c9947f8f47b6) from gir-files (https://github.com/gtk-rs/gir-files @ 1490bcc19dc8)