gio/auto/
dbus_proxy.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(unix)]
6#[cfg_attr(docsrs, doc(cfg(unix)))]
7use crate::UnixFDList;
8use crate::{
9    ffi, AsyncInitable, AsyncResult, BusType, Cancellable, DBusCallFlags, DBusConnection,
10    DBusInterface, DBusInterfaceInfo, DBusProxyFlags, Initable,
11};
12use glib::{
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
15    translate::*,
16};
17use std::{boxed::Box as Box_, pin::Pin};
18
19glib::wrapper! {
20    /// `GDBusProxy` is a base class used for proxies to access a D-Bus
21    /// interface on a remote object. A `GDBusProxy` can be constructed for
22    /// both well-known and unique names.
23    ///
24    /// By default, `GDBusProxy` will cache all properties (and listen to
25    /// changes) of the remote object, and proxy all signals that get
26    /// emitted. This behaviour can be changed by passing suitable
27    /// [`DBusProxyFlags`][crate::DBusProxyFlags] when the proxy is created. If the proxy is for a
28    /// well-known name, the property cache is flushed when the name owner
29    /// vanishes and reloaded when a name owner appears.
30    ///
31    /// The unique name owner of the proxy’s name is tracked and can be read from
32    /// [`g-name-owner`][struct@crate::DBusProxy#g-name-owner]. Connect to the
33    /// [`notify`][struct@crate::glib::Object#notify] signal to get notified of changes.
34    /// Additionally, only signals and property changes emitted from the current name
35    /// owner are considered and calls are always sent to the current name owner.
36    /// This avoids a number of race conditions when the name is lost by one owner
37    /// and claimed by another. However, if no name owner currently exists,
38    /// then calls will be sent to the well-known name which may result in
39    /// the message bus launching an owner (unless
40    /// `G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START` is set).
41    ///
42    /// If the proxy is for a stateless D-Bus service, where the name owner may
43    /// be started and stopped between calls, the
44    /// [`g-name-owner`][struct@crate::DBusProxy#g-name-owner] tracking of `GDBusProxy` will cause the
45    /// proxy to drop signal and property changes from the service after it has
46    /// restarted for the first time. When interacting with a stateless D-Bus
47    /// service, do not use `GDBusProxy` — use direct D-Bus method calls and signal
48    /// connections.
49    ///
50    /// The generic [`g-properties-changed`][struct@crate::DBusProxy#g-properties-changed] and
51    /// [`g-signal`][struct@crate::DBusProxy#g-signal] signals are not very convenient to work
52    /// with. Therefore, the recommended way of working with proxies is to subclass
53    /// `GDBusProxy`, and have more natural properties and signals in your derived
54    /// class. This [example](migrating-gdbus.html#using-gdbus-codegen) shows how
55    /// this can easily be done using the [`gdbus-codegen`](gdbus-codegen.html) tool.
56    ///
57    /// A `GDBusProxy` instance can be used from multiple threads but note
58    /// that all signals (e.g. [`g-signal`][struct@crate::DBusProxy#g-signal],
59    /// [`g-properties-changed`][struct@crate::DBusProxy#g-properties-changed] and
60    /// [`notify`][struct@crate::glib::Object#notify]) are emitted in the thread-default main
61    /// context (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()]) of the thread
62    /// where the instance was constructed.
63    ///
64    ///
65    /// ## A watch proxy example
66    /// An example using a proxy for a well-known name can be found in
67    /// [`gdbus-example-watch-proxy.c`](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-watch-proxy.c).
68    ///
69    /// ## Properties
70    ///
71    ///
72    /// #### `g-bus-type`
73    ///  If this property is not [`BusType::None`][crate::BusType::None], then
74    /// #GDBusProxy:g-connection must be [`None`] and will be set to the
75    /// #GDBusConnection obtained by calling g_bus_get() with the value
76    /// of this property.
77    ///
78    /// Writeable | Construct Only
79    ///
80    ///
81    /// #### `g-connection`
82    ///  The #GDBusConnection the proxy is for.
83    ///
84    /// Readable | Writeable | Construct Only
85    ///
86    ///
87    /// #### `g-default-timeout`
88    ///  The timeout to use if -1 (specifying default timeout) is passed
89    /// as @timeout_msec in the g_dbus_proxy_call() and
90    /// g_dbus_proxy_call_sync() functions.
91    ///
92    /// This allows applications to set a proxy-wide timeout for all
93    /// remote method invocations on the proxy. If this property is -1,
94    /// the default timeout (typically 25 seconds) is used. If set to
95    /// `G_MAXINT`, then no timeout is used.
96    ///
97    /// Readable | Writeable | Construct
98    ///
99    ///
100    /// #### `g-flags`
101    ///  Flags from the #GDBusProxyFlags enumeration.
102    ///
103    /// Readable | Writeable | Construct Only
104    ///
105    ///
106    /// #### `g-interface-info`
107    ///  Ensure that interactions with this proxy conform to the given
108    /// interface. This is mainly to ensure that malformed data received
109    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
110    /// said to be the "expected interface".
111    ///
112    /// The checks performed are:
113    /// - When completing a method call, if the type signature of
114    ///   the reply message isn't what's expected, the reply is
115    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
116    ///
117    /// - Received signals that have a type signature mismatch are dropped and
118    ///   a warning is logged via g_warning().
119    ///
120    /// - Properties received via the initial `GetAll()` call or via the
121    ///   `::PropertiesChanged` signal (on the
122    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
123    ///   interface) or set using g_dbus_proxy_set_cached_property()
124    ///   with a type signature mismatch are ignored and a warning is
125    ///   logged via g_warning().
126    ///
127    /// Note that these checks are never done on methods, signals and
128    /// properties that are not referenced in the given
129    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
130    /// service-side is not considered an ABI break.
131    ///
132    /// Readable | Writeable
133    ///
134    ///
135    /// #### `g-interface-name`
136    ///  The D-Bus interface name the proxy is for.
137    ///
138    /// Readable | Writeable | Construct Only
139    ///
140    ///
141    /// #### `g-name`
142    ///  The well-known or unique name that the proxy is for.
143    ///
144    /// Readable | Writeable | Construct Only
145    ///
146    ///
147    /// #### `g-name-owner`
148    ///  The unique name that owns #GDBusProxy:g-name or [`None`] if no-one
149    /// currently owns that name. You may connect to #GObject::notify signal to
150    /// track changes to this property.
151    ///
152    /// Readable
153    ///
154    ///
155    /// #### `g-object-path`
156    ///  The object path the proxy is for.
157    ///
158    /// Readable | Writeable | Construct Only
159    ///
160    /// ## Signals
161    ///
162    ///
163    /// #### `g-properties-changed`
164    ///  Emitted when one or more D-Bus properties on @proxy changes. The
165    /// local cache has already been updated when this signal fires. Note
166    /// that both @changed_properties and @invalidated_properties are
167    /// guaranteed to never be [`None`] (either may be empty though).
168    ///
169    /// If the proxy has the flag
170    /// [`DBusProxyFlags::GET_INVALIDATED_PROPERTIES`][crate::DBusProxyFlags::GET_INVALIDATED_PROPERTIES] set, then
171    /// @invalidated_properties will always be empty.
172    ///
173    /// This signal corresponds to the
174    /// `PropertiesChanged` D-Bus signal on the
175    /// `org.freedesktop.DBus.Properties` interface.
176    ///
177    ///
178    ///
179    ///
180    /// #### `g-signal`
181    ///  Emitted when a signal from the remote object and interface that @proxy is for, has been received.
182    ///
183    /// Since 2.72 this signal supports detailed connections. You can connect to
184    /// the detailed signal `g-signal::x` in order to receive callbacks only when
185    /// signal `x` is received from the remote object.
186    ///
187    /// Detailed
188    ///
189    /// # Implements
190    ///
191    /// [`DBusProxyExt`][trait@crate::prelude::DBusProxyExt], [`trait@glib::ObjectExt`], [`AsyncInitableExt`][trait@crate::prelude::AsyncInitableExt], [`DBusInterfaceExt`][trait@crate::prelude::DBusInterfaceExt], [`InitableExt`][trait@crate::prelude::InitableExt], [`DBusProxyExtManual`][trait@crate::prelude::DBusProxyExtManual]
192    #[doc(alias = "GDBusProxy")]
193    pub struct DBusProxy(Object<ffi::GDBusProxy, ffi::GDBusProxyClass>) @implements AsyncInitable, DBusInterface, Initable;
194
195    match fn {
196        type_ => || ffi::g_dbus_proxy_get_type(),
197    }
198}
199
200impl DBusProxy {
201    pub const NONE: Option<&'static DBusProxy> = None;
202
203    /// Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
204    ///
205    /// #GDBusProxy is used in this [example][`DBusProxy`][crate::DBusProxy]#a-watch-proxy-example].
206    /// ## `bus_type`
207    /// A #GBusType.
208    /// ## `flags`
209    /// Flags used when constructing the proxy.
210    /// ## `info`
211    /// A #GDBusInterfaceInfo specifying the minimal interface
212    ///        that @proxy conforms to or [`None`].
213    /// ## `name`
214    /// A bus name (well-known or unique).
215    /// ## `object_path`
216    /// An object path.
217    /// ## `interface_name`
218    /// A D-Bus interface name.
219    /// ## `cancellable`
220    /// A #GCancellable or [`None`].
221    ///
222    /// # Returns
223    ///
224    /// A #GDBusProxy or [`None`] if error is set.
225    ///    Free with g_object_unref().
226    #[doc(alias = "g_dbus_proxy_new_for_bus_sync")]
227    #[doc(alias = "new_for_bus_sync")]
228    pub fn for_bus_sync(
229        bus_type: BusType,
230        flags: DBusProxyFlags,
231        info: Option<&DBusInterfaceInfo>,
232        name: &str,
233        object_path: &str,
234        interface_name: &str,
235        cancellable: Option<&impl IsA<Cancellable>>,
236    ) -> Result<DBusProxy, glib::Error> {
237        unsafe {
238            let mut error = std::ptr::null_mut();
239            let ret = ffi::g_dbus_proxy_new_for_bus_sync(
240                bus_type.into_glib(),
241                flags.into_glib(),
242                info.to_glib_none().0,
243                name.to_glib_none().0,
244                object_path.to_glib_none().0,
245                interface_name.to_glib_none().0,
246                cancellable.map(|p| p.as_ref()).to_glib_none().0,
247                &mut error,
248            );
249            if error.is_null() {
250                Ok(from_glib_full(ret))
251            } else {
252                Err(from_glib_full(error))
253            }
254        }
255    }
256
257    /// Creates a proxy for accessing @interface_name on the remote object
258    /// at @object_path owned by @name at @connection and synchronously
259    /// loads D-Bus properties unless the
260    /// [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] flag is used.
261    ///
262    /// If the [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] flag is not set, also sets up
263    /// match rules for signals. Connect to the #GDBusProxy::g-signal signal
264    /// to handle signals from the remote object.
265    ///
266    /// If both [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] and
267    /// [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] are set, this constructor is
268    /// guaranteed to return immediately without blocking.
269    ///
270    /// If @name is a well-known name and the
271    /// [`DBusProxyFlags::DO_NOT_AUTO_START`][crate::DBusProxyFlags::DO_NOT_AUTO_START] and [`DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION`][crate::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION]
272    /// flags aren't set and no name owner currently exists, the message bus
273    /// will be requested to launch a name owner for the name.
274    ///
275    /// This is a synchronous failable constructor. See g_dbus_proxy_new()
276    /// and g_dbus_proxy_new_finish() for the asynchronous version.
277    ///
278    /// #GDBusProxy is used in this [example][`DBusProxy`][crate::DBusProxy]#a-watch-proxy-example].
279    /// ## `connection`
280    /// A #GDBusConnection.
281    /// ## `flags`
282    /// Flags used when constructing the proxy.
283    /// ## `info`
284    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
285    /// ## `name`
286    /// A bus name (well-known or unique) or [`None`] if @connection is not a message bus connection.
287    /// ## `object_path`
288    /// An object path.
289    /// ## `interface_name`
290    /// A D-Bus interface name.
291    /// ## `cancellable`
292    /// A #GCancellable or [`None`].
293    ///
294    /// # Returns
295    ///
296    /// A #GDBusProxy or [`None`] if error is set.
297    ///    Free with g_object_unref().
298    #[doc(alias = "g_dbus_proxy_new_sync")]
299    pub fn new_sync(
300        connection: &DBusConnection,
301        flags: DBusProxyFlags,
302        info: Option<&DBusInterfaceInfo>,
303        name: Option<&str>,
304        object_path: &str,
305        interface_name: &str,
306        cancellable: Option<&impl IsA<Cancellable>>,
307    ) -> Result<DBusProxy, glib::Error> {
308        unsafe {
309            let mut error = std::ptr::null_mut();
310            let ret = ffi::g_dbus_proxy_new_sync(
311                connection.to_glib_none().0,
312                flags.into_glib(),
313                info.to_glib_none().0,
314                name.to_glib_none().0,
315                object_path.to_glib_none().0,
316                interface_name.to_glib_none().0,
317                cancellable.map(|p| p.as_ref()).to_glib_none().0,
318                &mut error,
319            );
320            if error.is_null() {
321                Ok(from_glib_full(ret))
322            } else {
323                Err(from_glib_full(error))
324            }
325        }
326    }
327
328    /// Creates a proxy for accessing @interface_name on the remote object
329    /// at @object_path owned by @name at @connection and asynchronously
330    /// loads D-Bus properties unless the
331    /// [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] flag is used. Connect to
332    /// the #GDBusProxy::g-properties-changed signal to get notified about
333    /// property changes.
334    ///
335    /// If the [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] flag is not set, also sets up
336    /// match rules for signals. Connect to the #GDBusProxy::g-signal signal
337    /// to handle signals from the remote object.
338    ///
339    /// If both [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] and
340    /// [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] are set, this constructor is
341    /// guaranteed to complete immediately without blocking.
342    ///
343    /// If @name is a well-known name and the
344    /// [`DBusProxyFlags::DO_NOT_AUTO_START`][crate::DBusProxyFlags::DO_NOT_AUTO_START] and [`DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION`][crate::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION]
345    /// flags aren't set and no name owner currently exists, the message bus
346    /// will be requested to launch a name owner for the name.
347    ///
348    /// This is a failable asynchronous constructor - when the proxy is
349    /// ready, @callback will be invoked and you can use
350    /// g_dbus_proxy_new_finish() to get the result.
351    ///
352    /// See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
353    ///
354    /// #GDBusProxy is used in this [example][`DBusProxy`][crate::DBusProxy]#a-watch-proxy-example].
355    /// ## `connection`
356    /// A #GDBusConnection.
357    /// ## `flags`
358    /// Flags used when constructing the proxy.
359    /// ## `info`
360    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
361    /// ## `name`
362    /// A bus name (well-known or unique) or [`None`] if @connection is not a message bus connection.
363    /// ## `object_path`
364    /// An object path.
365    /// ## `interface_name`
366    /// A D-Bus interface name.
367    /// ## `cancellable`
368    /// A #GCancellable or [`None`].
369    /// ## `callback`
370    /// Callback function to invoke when the proxy is ready.
371    #[doc(alias = "g_dbus_proxy_new")]
372    pub fn new<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
373        connection: &DBusConnection,
374        flags: DBusProxyFlags,
375        info: Option<&DBusInterfaceInfo>,
376        name: Option<&str>,
377        object_path: &str,
378        interface_name: &str,
379        cancellable: Option<&impl IsA<Cancellable>>,
380        callback: P,
381    ) {
382        let main_context = glib::MainContext::ref_thread_default();
383        let is_main_context_owner = main_context.is_owner();
384        let has_acquired_main_context = (!is_main_context_owner)
385            .then(|| main_context.acquire().ok())
386            .flatten();
387        assert!(
388            is_main_context_owner || has_acquired_main_context.is_some(),
389            "Async operations only allowed if the thread is owning the MainContext"
390        );
391
392        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
393            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
394        unsafe extern "C" fn new_trampoline<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
395            _source_object: *mut glib::gobject_ffi::GObject,
396            res: *mut crate::ffi::GAsyncResult,
397            user_data: glib::ffi::gpointer,
398        ) {
399            let mut error = std::ptr::null_mut();
400            let ret = ffi::g_dbus_proxy_new_finish(res, &mut error);
401            let result = if error.is_null() {
402                Ok(from_glib_full(ret))
403            } else {
404                Err(from_glib_full(error))
405            };
406            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
407                Box_::from_raw(user_data as *mut _);
408            let callback: P = callback.into_inner();
409            callback(result);
410        }
411        let callback = new_trampoline::<P>;
412        unsafe {
413            ffi::g_dbus_proxy_new(
414                connection.to_glib_none().0,
415                flags.into_glib(),
416                info.to_glib_none().0,
417                name.to_glib_none().0,
418                object_path.to_glib_none().0,
419                interface_name.to_glib_none().0,
420                cancellable.map(|p| p.as_ref()).to_glib_none().0,
421                Some(callback),
422                Box_::into_raw(user_data) as *mut _,
423            );
424        }
425    }
426
427    pub fn new_future(
428        connection: &DBusConnection,
429        flags: DBusProxyFlags,
430        info: Option<&DBusInterfaceInfo>,
431        name: Option<&str>,
432        object_path: &str,
433        interface_name: &str,
434    ) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusProxy, glib::Error>> + 'static>> {
435        let connection = connection.clone();
436        let info = info.map(ToOwned::to_owned);
437        let name = name.map(ToOwned::to_owned);
438        let object_path = String::from(object_path);
439        let interface_name = String::from(interface_name);
440        Box_::pin(crate::GioFuture::new(
441            &(),
442            move |_obj, cancellable, send| {
443                Self::new(
444                    &connection,
445                    flags,
446                    info.as_ref().map(::std::borrow::Borrow::borrow),
447                    name.as_ref().map(::std::borrow::Borrow::borrow),
448                    &object_path,
449                    &interface_name,
450                    Some(cancellable),
451                    move |res| {
452                        send.resolve(res);
453                    },
454                );
455            },
456        ))
457    }
458
459    /// Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
460    ///
461    /// #GDBusProxy is used in this [example][`DBusProxy`][crate::DBusProxy]#a-watch-proxy-example].
462    /// ## `bus_type`
463    /// A #GBusType.
464    /// ## `flags`
465    /// Flags used when constructing the proxy.
466    /// ## `info`
467    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
468    /// ## `name`
469    /// A bus name (well-known or unique).
470    /// ## `object_path`
471    /// An object path.
472    /// ## `interface_name`
473    /// A D-Bus interface name.
474    /// ## `cancellable`
475    /// A #GCancellable or [`None`].
476    /// ## `callback`
477    /// Callback function to invoke when the proxy is ready.
478    #[doc(alias = "g_dbus_proxy_new_for_bus")]
479    #[doc(alias = "new_for_bus")]
480    pub fn for_bus<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
481        bus_type: BusType,
482        flags: DBusProxyFlags,
483        info: Option<&DBusInterfaceInfo>,
484        name: &str,
485        object_path: &str,
486        interface_name: &str,
487        cancellable: Option<&impl IsA<Cancellable>>,
488        callback: P,
489    ) {
490        let main_context = glib::MainContext::ref_thread_default();
491        let is_main_context_owner = main_context.is_owner();
492        let has_acquired_main_context = (!is_main_context_owner)
493            .then(|| main_context.acquire().ok())
494            .flatten();
495        assert!(
496            is_main_context_owner || has_acquired_main_context.is_some(),
497            "Async operations only allowed if the thread is owning the MainContext"
498        );
499
500        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
501            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
502        unsafe extern "C" fn for_bus_trampoline<
503            P: FnOnce(Result<DBusProxy, glib::Error>) + 'static,
504        >(
505            _source_object: *mut glib::gobject_ffi::GObject,
506            res: *mut crate::ffi::GAsyncResult,
507            user_data: glib::ffi::gpointer,
508        ) {
509            let mut error = std::ptr::null_mut();
510            let ret = ffi::g_dbus_proxy_new_for_bus_finish(res, &mut error);
511            let result = if error.is_null() {
512                Ok(from_glib_full(ret))
513            } else {
514                Err(from_glib_full(error))
515            };
516            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
517                Box_::from_raw(user_data as *mut _);
518            let callback: P = callback.into_inner();
519            callback(result);
520        }
521        let callback = for_bus_trampoline::<P>;
522        unsafe {
523            ffi::g_dbus_proxy_new_for_bus(
524                bus_type.into_glib(),
525                flags.into_glib(),
526                info.to_glib_none().0,
527                name.to_glib_none().0,
528                object_path.to_glib_none().0,
529                interface_name.to_glib_none().0,
530                cancellable.map(|p| p.as_ref()).to_glib_none().0,
531                Some(callback),
532                Box_::into_raw(user_data) as *mut _,
533            );
534        }
535    }
536
537    pub fn for_bus_future(
538        bus_type: BusType,
539        flags: DBusProxyFlags,
540        info: Option<&DBusInterfaceInfo>,
541        name: &str,
542        object_path: &str,
543        interface_name: &str,
544    ) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusProxy, glib::Error>> + 'static>> {
545        let info = info.map(ToOwned::to_owned);
546        let name = String::from(name);
547        let object_path = String::from(object_path);
548        let interface_name = String::from(interface_name);
549        Box_::pin(crate::GioFuture::new(
550            &(),
551            move |_obj, cancellable, send| {
552                Self::for_bus(
553                    bus_type,
554                    flags,
555                    info.as_ref().map(::std::borrow::Borrow::borrow),
556                    &name,
557                    &object_path,
558                    &interface_name,
559                    Some(cancellable),
560                    move |res| {
561                        send.resolve(res);
562                    },
563                );
564            },
565        ))
566    }
567}
568
569unsafe impl Send for DBusProxy {}
570unsafe impl Sync for DBusProxy {}
571
572/// Trait containing all [`struct@DBusProxy`] methods.
573///
574/// # Implementors
575///
576/// [`DBusProxy`][struct@crate::DBusProxy]
577pub trait DBusProxyExt: IsA<DBusProxy> + 'static {
578    /// Asynchronously invokes the @method_name method on @self.
579    ///
580    /// If @method_name contains any dots, then @name is split into interface and
581    /// method name parts. This allows using @self for invoking methods on
582    /// other interfaces.
583    ///
584    /// If the #GDBusConnection associated with @self is closed then
585    /// the operation will fail with [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. If
586    /// @cancellable is canceled, the operation will fail with
587    /// [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled]. If @parameters contains a value not
588    /// compatible with the D-Bus protocol, the operation fails with
589    /// [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
590    ///
591    /// If the @parameters #GVariant is floating, it is consumed. This allows
592    /// convenient 'inline' use of g_variant_new(), e.g.:
593    ///
594    ///
595    /// **⚠️ The following code is in C ⚠️**
596    ///
597    /// ```C
598    ///  g_dbus_proxy_call (proxy,
599    ///                     "TwoStrings",
600    ///                     g_variant_new ("(ss)",
601    ///                                    "Thing One",
602    ///                                    "Thing Two"),
603    ///                     G_DBUS_CALL_FLAGS_NONE,
604    ///                     -1,
605    ///                     NULL,
606    ///                     (GAsyncReadyCallback) two_strings_done,
607    ///                     &data);
608    /// ```
609    ///
610    /// If @self has an expected interface (see
611    /// #GDBusProxy:g-interface-info) and @method_name is referenced by it,
612    /// then the return value is checked against the return type.
613    ///
614    /// This is an asynchronous method. When the operation is finished,
615    /// @callback will be invoked in the thread-default main context
616    /// (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()])
617    /// of the thread you are calling this method from.
618    /// You can then call g_dbus_proxy_call_finish() to get the result of
619    /// the operation. See g_dbus_proxy_call_sync() for the synchronous
620    /// version of this method.
621    ///
622    /// If @callback is [`None`] then the D-Bus method call message will be sent with
623    /// the [`DBusMessageFlags::NO_REPLY_EXPECTED`][crate::DBusMessageFlags::NO_REPLY_EXPECTED] flag set.
624    /// ## `method_name`
625    /// Name of method to invoke.
626    /// ## `parameters`
627    /// A #GVariant tuple with parameters for the signal or [`None`] if not passing parameters.
628    /// ## `flags`
629    /// Flags from the #GDBusCallFlags enumeration.
630    /// ## `timeout_msec`
631    /// The timeout in milliseconds (with `G_MAXINT` meaning
632    ///                "infinite") or -1 to use the proxy default timeout.
633    /// ## `cancellable`
634    /// A #GCancellable or [`None`].
635    /// ## `callback`
636    /// A #GAsyncReadyCallback to call when the request is satisfied or [`None`] if you don't
637    /// care about the result of the method invocation.
638    #[doc(alias = "g_dbus_proxy_call")]
639    fn call<P: FnOnce(Result<glib::Variant, glib::Error>) + 'static>(
640        &self,
641        method_name: &str,
642        parameters: Option<&glib::Variant>,
643        flags: DBusCallFlags,
644        timeout_msec: i32,
645        cancellable: Option<&impl IsA<Cancellable>>,
646        callback: P,
647    ) {
648        let main_context = glib::MainContext::ref_thread_default();
649        let is_main_context_owner = main_context.is_owner();
650        let has_acquired_main_context = (!is_main_context_owner)
651            .then(|| main_context.acquire().ok())
652            .flatten();
653        assert!(
654            is_main_context_owner || has_acquired_main_context.is_some(),
655            "Async operations only allowed if the thread is owning the MainContext"
656        );
657
658        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
659            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
660        unsafe extern "C" fn call_trampoline<
661            P: FnOnce(Result<glib::Variant, glib::Error>) + 'static,
662        >(
663            _source_object: *mut glib::gobject_ffi::GObject,
664            res: *mut crate::ffi::GAsyncResult,
665            user_data: glib::ffi::gpointer,
666        ) {
667            let mut error = std::ptr::null_mut();
668            let ret = ffi::g_dbus_proxy_call_finish(_source_object as *mut _, res, &mut error);
669            let result = if error.is_null() {
670                Ok(from_glib_full(ret))
671            } else {
672                Err(from_glib_full(error))
673            };
674            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
675                Box_::from_raw(user_data as *mut _);
676            let callback: P = callback.into_inner();
677            callback(result);
678        }
679        let callback = call_trampoline::<P>;
680        unsafe {
681            ffi::g_dbus_proxy_call(
682                self.as_ref().to_glib_none().0,
683                method_name.to_glib_none().0,
684                parameters.to_glib_none().0,
685                flags.into_glib(),
686                timeout_msec,
687                cancellable.map(|p| p.as_ref()).to_glib_none().0,
688                Some(callback),
689                Box_::into_raw(user_data) as *mut _,
690            );
691        }
692    }
693
694    fn call_future(
695        &self,
696        method_name: &str,
697        parameters: Option<&glib::Variant>,
698        flags: DBusCallFlags,
699        timeout_msec: i32,
700    ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Variant, glib::Error>> + 'static>>
701    {
702        let method_name = String::from(method_name);
703        let parameters = parameters.map(ToOwned::to_owned);
704        Box_::pin(crate::GioFuture::new(
705            self,
706            move |obj, cancellable, send| {
707                obj.call(
708                    &method_name,
709                    parameters.as_ref().map(::std::borrow::Borrow::borrow),
710                    flags,
711                    timeout_msec,
712                    Some(cancellable),
713                    move |res| {
714                        send.resolve(res);
715                    },
716                );
717            },
718        ))
719    }
720
721    /// Synchronously invokes the @method_name method on @self.
722    ///
723    /// If @method_name contains any dots, then @name is split into interface and
724    /// method name parts. This allows using @self for invoking methods on
725    /// other interfaces.
726    ///
727    /// If the #GDBusConnection associated with @self is disconnected then
728    /// the operation will fail with [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. If
729    /// @cancellable is canceled, the operation will fail with
730    /// [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled]. If @parameters contains a value not
731    /// compatible with the D-Bus protocol, the operation fails with
732    /// [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
733    ///
734    /// If the @parameters #GVariant is floating, it is consumed. This allows
735    /// convenient 'inline' use of g_variant_new(), e.g.:
736    ///
737    ///
738    /// **⚠️ The following code is in C ⚠️**
739    ///
740    /// ```C
741    ///  g_dbus_proxy_call_sync (proxy,
742    ///                          "TwoStrings",
743    ///                          g_variant_new ("(ss)",
744    ///                                         "Thing One",
745    ///                                         "Thing Two"),
746    ///                          G_DBUS_CALL_FLAGS_NONE,
747    ///                          -1,
748    ///                          NULL,
749    ///                          &error);
750    /// ```
751    ///
752    /// The calling thread is blocked until a reply is received. See
753    /// g_dbus_proxy_call() for the asynchronous version of this
754    /// method.
755    ///
756    /// If @self has an expected interface (see
757    /// #GDBusProxy:g-interface-info) and @method_name is referenced by it,
758    /// then the return value is checked against the return type.
759    /// ## `method_name`
760    /// Name of method to invoke.
761    /// ## `parameters`
762    /// A #GVariant tuple with parameters for the signal
763    ///              or [`None`] if not passing parameters.
764    /// ## `flags`
765    /// Flags from the #GDBusCallFlags enumeration.
766    /// ## `timeout_msec`
767    /// The timeout in milliseconds (with `G_MAXINT` meaning
768    ///                "infinite") or -1 to use the proxy default timeout.
769    /// ## `cancellable`
770    /// A #GCancellable or [`None`].
771    ///
772    /// # Returns
773    ///
774    /// [`None`] if @error is set. Otherwise a #GVariant tuple with
775    /// return values. Free with g_variant_unref().
776    #[doc(alias = "g_dbus_proxy_call_sync")]
777    fn call_sync(
778        &self,
779        method_name: &str,
780        parameters: Option<&glib::Variant>,
781        flags: DBusCallFlags,
782        timeout_msec: i32,
783        cancellable: Option<&impl IsA<Cancellable>>,
784    ) -> Result<glib::Variant, glib::Error> {
785        unsafe {
786            let mut error = std::ptr::null_mut();
787            let ret = ffi::g_dbus_proxy_call_sync(
788                self.as_ref().to_glib_none().0,
789                method_name.to_glib_none().0,
790                parameters.to_glib_none().0,
791                flags.into_glib(),
792                timeout_msec,
793                cancellable.map(|p| p.as_ref()).to_glib_none().0,
794                &mut error,
795            );
796            if error.is_null() {
797                Ok(from_glib_full(ret))
798            } else {
799                Err(from_glib_full(error))
800            }
801        }
802    }
803
804    /// Like g_dbus_proxy_call() but also takes a #GUnixFDList object.
805    ///
806    /// This method is only available on UNIX.
807    /// ## `method_name`
808    /// Name of method to invoke.
809    /// ## `parameters`
810    /// A #GVariant tuple with parameters for the signal or [`None`] if not passing parameters.
811    /// ## `flags`
812    /// Flags from the #GDBusCallFlags enumeration.
813    /// ## `timeout_msec`
814    /// The timeout in milliseconds (with `G_MAXINT` meaning
815    ///                "infinite") or -1 to use the proxy default timeout.
816    /// ## `fd_list`
817    /// A #GUnixFDList or [`None`].
818    /// ## `cancellable`
819    /// A #GCancellable or [`None`].
820    /// ## `callback`
821    /// A #GAsyncReadyCallback to call when the request is satisfied or [`None`] if you don't
822    /// care about the result of the method invocation.
823    #[cfg(unix)]
824    #[cfg_attr(docsrs, doc(cfg(unix)))]
825    #[doc(alias = "g_dbus_proxy_call_with_unix_fd_list")]
826    fn call_with_unix_fd_list<
827        P: FnOnce(Result<(glib::Variant, Option<UnixFDList>), glib::Error>) + 'static,
828    >(
829        &self,
830        method_name: &str,
831        parameters: Option<&glib::Variant>,
832        flags: DBusCallFlags,
833        timeout_msec: i32,
834        fd_list: Option<&impl IsA<UnixFDList>>,
835        cancellable: Option<&impl IsA<Cancellable>>,
836        callback: P,
837    ) {
838        let main_context = glib::MainContext::ref_thread_default();
839        let is_main_context_owner = main_context.is_owner();
840        let has_acquired_main_context = (!is_main_context_owner)
841            .then(|| main_context.acquire().ok())
842            .flatten();
843        assert!(
844            is_main_context_owner || has_acquired_main_context.is_some(),
845            "Async operations only allowed if the thread is owning the MainContext"
846        );
847
848        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
849            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
850        unsafe extern "C" fn call_with_unix_fd_list_trampoline<
851            P: FnOnce(Result<(glib::Variant, Option<UnixFDList>), glib::Error>) + 'static,
852        >(
853            _source_object: *mut glib::gobject_ffi::GObject,
854            res: *mut crate::ffi::GAsyncResult,
855            user_data: glib::ffi::gpointer,
856        ) {
857            let mut error = std::ptr::null_mut();
858            let mut out_fd_list = std::ptr::null_mut();
859            let ret = ffi::g_dbus_proxy_call_with_unix_fd_list_finish(
860                _source_object as *mut _,
861                &mut out_fd_list,
862                res,
863                &mut error,
864            );
865            let result = if error.is_null() {
866                Ok((from_glib_full(ret), from_glib_full(out_fd_list)))
867            } else {
868                Err(from_glib_full(error))
869            };
870            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
871                Box_::from_raw(user_data as *mut _);
872            let callback: P = callback.into_inner();
873            callback(result);
874        }
875        let callback = call_with_unix_fd_list_trampoline::<P>;
876        unsafe {
877            ffi::g_dbus_proxy_call_with_unix_fd_list(
878                self.as_ref().to_glib_none().0,
879                method_name.to_glib_none().0,
880                parameters.to_glib_none().0,
881                flags.into_glib(),
882                timeout_msec,
883                fd_list.map(|p| p.as_ref()).to_glib_none().0,
884                cancellable.map(|p| p.as_ref()).to_glib_none().0,
885                Some(callback),
886                Box_::into_raw(user_data) as *mut _,
887            );
888        }
889    }
890
891    #[cfg(unix)]
892    #[cfg_attr(docsrs, doc(cfg(unix)))]
893    fn call_with_unix_fd_list_future(
894        &self,
895        method_name: &str,
896        parameters: Option<&glib::Variant>,
897        flags: DBusCallFlags,
898        timeout_msec: i32,
899        fd_list: Option<&(impl IsA<UnixFDList> + Clone + 'static)>,
900    ) -> Pin<
901        Box_<
902            dyn std::future::Future<
903                    Output = Result<(glib::Variant, Option<UnixFDList>), glib::Error>,
904                > + 'static,
905        >,
906    > {
907        let method_name = String::from(method_name);
908        let parameters = parameters.map(ToOwned::to_owned);
909        let fd_list = fd_list.map(ToOwned::to_owned);
910        Box_::pin(crate::GioFuture::new(
911            self,
912            move |obj, cancellable, send| {
913                obj.call_with_unix_fd_list(
914                    &method_name,
915                    parameters.as_ref().map(::std::borrow::Borrow::borrow),
916                    flags,
917                    timeout_msec,
918                    fd_list.as_ref().map(::std::borrow::Borrow::borrow),
919                    Some(cancellable),
920                    move |res| {
921                        send.resolve(res);
922                    },
923                );
924            },
925        ))
926    }
927
928    /// Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects.
929    ///
930    /// This method is only available on UNIX.
931    /// ## `method_name`
932    /// Name of method to invoke.
933    /// ## `parameters`
934    /// A #GVariant tuple with parameters for the signal
935    ///              or [`None`] if not passing parameters.
936    /// ## `flags`
937    /// Flags from the #GDBusCallFlags enumeration.
938    /// ## `timeout_msec`
939    /// The timeout in milliseconds (with `G_MAXINT` meaning
940    ///                "infinite") or -1 to use the proxy default timeout.
941    /// ## `fd_list`
942    /// A #GUnixFDList or [`None`].
943    /// ## `cancellable`
944    /// A #GCancellable or [`None`].
945    ///
946    /// # Returns
947    ///
948    /// [`None`] if @error is set. Otherwise a #GVariant tuple with
949    /// return values. Free with g_variant_unref().
950    ///
951    /// ## `out_fd_list`
952    /// Return location for a #GUnixFDList or [`None`].
953    #[cfg(unix)]
954    #[cfg_attr(docsrs, doc(cfg(unix)))]
955    #[doc(alias = "g_dbus_proxy_call_with_unix_fd_list_sync")]
956    fn call_with_unix_fd_list_sync(
957        &self,
958        method_name: &str,
959        parameters: Option<&glib::Variant>,
960        flags: DBusCallFlags,
961        timeout_msec: i32,
962        fd_list: Option<&impl IsA<UnixFDList>>,
963        cancellable: Option<&impl IsA<Cancellable>>,
964    ) -> Result<(glib::Variant, Option<UnixFDList>), glib::Error> {
965        unsafe {
966            let mut out_fd_list = std::ptr::null_mut();
967            let mut error = std::ptr::null_mut();
968            let ret = ffi::g_dbus_proxy_call_with_unix_fd_list_sync(
969                self.as_ref().to_glib_none().0,
970                method_name.to_glib_none().0,
971                parameters.to_glib_none().0,
972                flags.into_glib(),
973                timeout_msec,
974                fd_list.map(|p| p.as_ref()).to_glib_none().0,
975                &mut out_fd_list,
976                cancellable.map(|p| p.as_ref()).to_glib_none().0,
977                &mut error,
978            );
979            if error.is_null() {
980                Ok((from_glib_full(ret), from_glib_full(out_fd_list)))
981            } else {
982                Err(from_glib_full(error))
983            }
984        }
985    }
986
987    /// Looks up the value for a property from the cache. This call does no
988    /// blocking IO.
989    ///
990    /// If @self has an expected interface (see
991    /// #GDBusProxy:g-interface-info) and @property_name is referenced by
992    /// it, then @value is checked against the type of the property.
993    /// ## `property_name`
994    /// Property name.
995    ///
996    /// # Returns
997    ///
998    /// A reference to the #GVariant instance
999    ///    that holds the value for @property_name or [`None`] if the value is not in
1000    ///    the cache. The returned reference must be freed with g_variant_unref().
1001    #[doc(alias = "g_dbus_proxy_get_cached_property")]
1002    #[doc(alias = "get_cached_property")]
1003    fn cached_property(&self, property_name: &str) -> Option<glib::Variant> {
1004        unsafe {
1005            from_glib_full(ffi::g_dbus_proxy_get_cached_property(
1006                self.as_ref().to_glib_none().0,
1007                property_name.to_glib_none().0,
1008            ))
1009        }
1010    }
1011
1012    /// Gets the names of all cached properties on @self.
1013    ///
1014    /// # Returns
1015    ///
1016    /// A
1017    ///          [`None`]-terminated array of strings or [`None`] if
1018    ///          @self has no cached properties. Free the returned array with
1019    ///          g_strfreev().
1020    #[doc(alias = "g_dbus_proxy_get_cached_property_names")]
1021    #[doc(alias = "get_cached_property_names")]
1022    fn cached_property_names(&self) -> Vec<glib::GString> {
1023        unsafe {
1024            FromGlibPtrContainer::from_glib_full(ffi::g_dbus_proxy_get_cached_property_names(
1025                self.as_ref().to_glib_none().0,
1026            ))
1027        }
1028    }
1029
1030    /// Gets the connection @self is for.
1031    ///
1032    /// # Returns
1033    ///
1034    /// A #GDBusConnection owned by @self. Do not free.
1035    #[doc(alias = "g_dbus_proxy_get_connection")]
1036    #[doc(alias = "get_connection")]
1037    fn connection(&self) -> DBusConnection {
1038        unsafe {
1039            from_glib_none(ffi::g_dbus_proxy_get_connection(
1040                self.as_ref().to_glib_none().0,
1041            ))
1042        }
1043    }
1044
1045    /// Gets the timeout to use if -1 (specifying default timeout) is
1046    /// passed as @timeout_msec in the g_dbus_proxy_call() and
1047    /// g_dbus_proxy_call_sync() functions.
1048    ///
1049    /// See the #GDBusProxy:g-default-timeout property for more details.
1050    ///
1051    /// # Returns
1052    ///
1053    /// Timeout to use for @self.
1054    #[doc(alias = "g_dbus_proxy_get_default_timeout")]
1055    #[doc(alias = "get_default_timeout")]
1056    fn default_timeout(&self) -> i32 {
1057        unsafe { ffi::g_dbus_proxy_get_default_timeout(self.as_ref().to_glib_none().0) }
1058    }
1059
1060    /// Gets the flags that @self was constructed with.
1061    ///
1062    /// # Returns
1063    ///
1064    /// Flags from the #GDBusProxyFlags enumeration.
1065    #[doc(alias = "g_dbus_proxy_get_flags")]
1066    #[doc(alias = "get_flags")]
1067    fn flags(&self) -> DBusProxyFlags {
1068        unsafe { from_glib(ffi::g_dbus_proxy_get_flags(self.as_ref().to_glib_none().0)) }
1069    }
1070
1071    /// Returns the #GDBusInterfaceInfo, if any, specifying the interface
1072    /// that @self conforms to. See the #GDBusProxy:g-interface-info
1073    /// property for more details.
1074    ///
1075    /// # Returns
1076    ///
1077    /// A #GDBusInterfaceInfo or [`None`].
1078    ///    Do not unref the returned object, it is owned by @self.
1079    #[doc(alias = "g_dbus_proxy_get_interface_info")]
1080    #[doc(alias = "get_interface_info")]
1081    fn interface_info(&self) -> Option<DBusInterfaceInfo> {
1082        unsafe {
1083            from_glib_none(ffi::g_dbus_proxy_get_interface_info(
1084                self.as_ref().to_glib_none().0,
1085            ))
1086        }
1087    }
1088
1089    /// Gets the D-Bus interface name @self is for.
1090    ///
1091    /// # Returns
1092    ///
1093    /// A string owned by @self. Do not free.
1094    #[doc(alias = "g_dbus_proxy_get_interface_name")]
1095    #[doc(alias = "get_interface_name")]
1096    fn interface_name(&self) -> glib::GString {
1097        unsafe {
1098            from_glib_none(ffi::g_dbus_proxy_get_interface_name(
1099                self.as_ref().to_glib_none().0,
1100            ))
1101        }
1102    }
1103
1104    /// Gets the name that @self was constructed for.
1105    ///
1106    /// When connected to a message bus, this will usually be non-[`None`].
1107    /// However, it may be [`None`] for a proxy that communicates using a peer-to-peer
1108    /// pattern.
1109    ///
1110    /// # Returns
1111    ///
1112    /// A string owned by @self. Do not free.
1113    #[doc(alias = "g_dbus_proxy_get_name")]
1114    #[doc(alias = "get_name")]
1115    fn name(&self) -> Option<glib::GString> {
1116        unsafe { from_glib_none(ffi::g_dbus_proxy_get_name(self.as_ref().to_glib_none().0)) }
1117    }
1118
1119    /// The unique name that owns the name that @self is for or [`None`] if
1120    /// no-one currently owns that name. You may connect to the
1121    /// #GObject::notify signal to track changes to the
1122    /// #GDBusProxy:g-name-owner property.
1123    ///
1124    /// # Returns
1125    ///
1126    /// The name owner or [`None`] if no name
1127    ///    owner exists. Free with g_free().
1128    #[doc(alias = "g_dbus_proxy_get_name_owner")]
1129    #[doc(alias = "get_name_owner")]
1130    fn name_owner(&self) -> Option<glib::GString> {
1131        unsafe {
1132            from_glib_full(ffi::g_dbus_proxy_get_name_owner(
1133                self.as_ref().to_glib_none().0,
1134            ))
1135        }
1136    }
1137
1138    /// Gets the object path @self is for.
1139    ///
1140    /// # Returns
1141    ///
1142    /// A string owned by @self. Do not free.
1143    #[doc(alias = "g_dbus_proxy_get_object_path")]
1144    #[doc(alias = "get_object_path")]
1145    fn object_path(&self) -> glib::GString {
1146        unsafe {
1147            from_glib_none(ffi::g_dbus_proxy_get_object_path(
1148                self.as_ref().to_glib_none().0,
1149            ))
1150        }
1151    }
1152
1153    /// If @value is not [`None`], sets the cached value for the property with
1154    /// name @property_name to the value in @value.
1155    ///
1156    /// If @value is [`None`], then the cached value is removed from the
1157    /// property cache.
1158    ///
1159    /// If @self has an expected interface (see
1160    /// #GDBusProxy:g-interface-info) and @property_name is referenced by
1161    /// it, then @value is checked against the type of the property.
1162    ///
1163    /// If the @value #GVariant is floating, it is consumed. This allows
1164    /// convenient 'inline' use of g_variant_new(), e.g.
1165    ///
1166    ///
1167    /// **⚠️ The following code is in C ⚠️**
1168    ///
1169    /// ```C
1170    ///  g_dbus_proxy_set_cached_property (proxy,
1171    ///                                    "SomeProperty",
1172    ///                                    g_variant_new ("(si)",
1173    ///                                                  "A String",
1174    ///                                                  42));
1175    /// ```
1176    ///
1177    /// Normally you will not need to use this method since @self
1178    /// is tracking changes using the
1179    /// `org.freedesktop.DBus.Properties.PropertiesChanged`
1180    /// D-Bus signal. However, for performance reasons an object may
1181    /// decide to not use this signal for some properties and instead
1182    /// use a proprietary out-of-band mechanism to transmit changes.
1183    ///
1184    /// As a concrete example, consider an object with a property
1185    /// `ChatroomParticipants` which is an array of strings. Instead of
1186    /// transmitting the same (long) array every time the property changes,
1187    /// it is more efficient to only transmit the delta using e.g. signals
1188    /// `ChatroomParticipantJoined(String name)` and
1189    /// `ChatroomParticipantParted(String name)`.
1190    /// ## `property_name`
1191    /// Property name.
1192    /// ## `value`
1193    /// Value for the property or [`None`] to remove it from the cache.
1194    #[doc(alias = "g_dbus_proxy_set_cached_property")]
1195    fn set_cached_property(&self, property_name: &str, value: Option<&glib::Variant>) {
1196        unsafe {
1197            ffi::g_dbus_proxy_set_cached_property(
1198                self.as_ref().to_glib_none().0,
1199                property_name.to_glib_none().0,
1200                value.to_glib_none().0,
1201            );
1202        }
1203    }
1204
1205    /// Sets the timeout to use if -1 (specifying default timeout) is
1206    /// passed as @timeout_msec in the g_dbus_proxy_call() and
1207    /// g_dbus_proxy_call_sync() functions.
1208    ///
1209    /// See the #GDBusProxy:g-default-timeout property for more details.
1210    /// ## `timeout_msec`
1211    /// Timeout in milliseconds.
1212    #[doc(alias = "g_dbus_proxy_set_default_timeout")]
1213    fn set_default_timeout(&self, timeout_msec: i32) {
1214        unsafe {
1215            ffi::g_dbus_proxy_set_default_timeout(self.as_ref().to_glib_none().0, timeout_msec);
1216        }
1217    }
1218
1219    /// Ensure that interactions with @self conform to the given
1220    /// interface. See the #GDBusProxy:g-interface-info property for more
1221    /// details.
1222    /// ## `info`
1223    /// Minimum interface this proxy conforms to
1224    ///    or [`None`] to unset.
1225    #[doc(alias = "g_dbus_proxy_set_interface_info")]
1226    fn set_interface_info(&self, info: Option<&DBusInterfaceInfo>) {
1227        unsafe {
1228            ffi::g_dbus_proxy_set_interface_info(
1229                self.as_ref().to_glib_none().0,
1230                info.to_glib_none().0,
1231            );
1232        }
1233    }
1234
1235    /// The #GDBusConnection the proxy is for.
1236    #[doc(alias = "g-connection")]
1237    fn g_connection(&self) -> Option<DBusConnection> {
1238        ObjectExt::property(self.as_ref(), "g-connection")
1239    }
1240
1241    /// The timeout to use if -1 (specifying default timeout) is passed
1242    /// as @timeout_msec in the g_dbus_proxy_call() and
1243    /// g_dbus_proxy_call_sync() functions.
1244    ///
1245    /// This allows applications to set a proxy-wide timeout for all
1246    /// remote method invocations on the proxy. If this property is -1,
1247    /// the default timeout (typically 25 seconds) is used. If set to
1248    /// `G_MAXINT`, then no timeout is used.
1249    #[doc(alias = "g-default-timeout")]
1250    fn g_default_timeout(&self) -> i32 {
1251        ObjectExt::property(self.as_ref(), "g-default-timeout")
1252    }
1253
1254    /// The timeout to use if -1 (specifying default timeout) is passed
1255    /// as @timeout_msec in the g_dbus_proxy_call() and
1256    /// g_dbus_proxy_call_sync() functions.
1257    ///
1258    /// This allows applications to set a proxy-wide timeout for all
1259    /// remote method invocations on the proxy. If this property is -1,
1260    /// the default timeout (typically 25 seconds) is used. If set to
1261    /// `G_MAXINT`, then no timeout is used.
1262    #[doc(alias = "g-default-timeout")]
1263    fn set_g_default_timeout(&self, g_default_timeout: i32) {
1264        ObjectExt::set_property(self.as_ref(), "g-default-timeout", g_default_timeout)
1265    }
1266
1267    /// Flags from the #GDBusProxyFlags enumeration.
1268    #[doc(alias = "g-flags")]
1269    fn g_flags(&self) -> DBusProxyFlags {
1270        ObjectExt::property(self.as_ref(), "g-flags")
1271    }
1272
1273    /// Ensure that interactions with this proxy conform to the given
1274    /// interface. This is mainly to ensure that malformed data received
1275    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
1276    /// said to be the "expected interface".
1277    ///
1278    /// The checks performed are:
1279    /// - When completing a method call, if the type signature of
1280    ///   the reply message isn't what's expected, the reply is
1281    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
1282    ///
1283    /// - Received signals that have a type signature mismatch are dropped and
1284    ///   a warning is logged via g_warning().
1285    ///
1286    /// - Properties received via the initial `GetAll()` call or via the
1287    ///   `::PropertiesChanged` signal (on the
1288    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
1289    ///   interface) or set using g_dbus_proxy_set_cached_property()
1290    ///   with a type signature mismatch are ignored and a warning is
1291    ///   logged via g_warning().
1292    ///
1293    /// Note that these checks are never done on methods, signals and
1294    /// properties that are not referenced in the given
1295    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
1296    /// service-side is not considered an ABI break.
1297    #[doc(alias = "g-interface-info")]
1298    fn g_interface_info(&self) -> Option<DBusInterfaceInfo> {
1299        ObjectExt::property(self.as_ref(), "g-interface-info")
1300    }
1301
1302    /// Ensure that interactions with this proxy conform to the given
1303    /// interface. This is mainly to ensure that malformed data received
1304    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
1305    /// said to be the "expected interface".
1306    ///
1307    /// The checks performed are:
1308    /// - When completing a method call, if the type signature of
1309    ///   the reply message isn't what's expected, the reply is
1310    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
1311    ///
1312    /// - Received signals that have a type signature mismatch are dropped and
1313    ///   a warning is logged via g_warning().
1314    ///
1315    /// - Properties received via the initial `GetAll()` call or via the
1316    ///   `::PropertiesChanged` signal (on the
1317    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
1318    ///   interface) or set using g_dbus_proxy_set_cached_property()
1319    ///   with a type signature mismatch are ignored and a warning is
1320    ///   logged via g_warning().
1321    ///
1322    /// Note that these checks are never done on methods, signals and
1323    /// properties that are not referenced in the given
1324    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
1325    /// service-side is not considered an ABI break.
1326    #[doc(alias = "g-interface-info")]
1327    fn set_g_interface_info(&self, g_interface_info: Option<&DBusInterfaceInfo>) {
1328        ObjectExt::set_property(self.as_ref(), "g-interface-info", g_interface_info)
1329    }
1330
1331    /// The D-Bus interface name the proxy is for.
1332    #[doc(alias = "g-interface-name")]
1333    fn g_interface_name(&self) -> Option<glib::GString> {
1334        ObjectExt::property(self.as_ref(), "g-interface-name")
1335    }
1336
1337    /// The well-known or unique name that the proxy is for.
1338    #[doc(alias = "g-name")]
1339    fn g_name(&self) -> Option<glib::GString> {
1340        ObjectExt::property(self.as_ref(), "g-name")
1341    }
1342
1343    /// The unique name that owns #GDBusProxy:g-name or [`None`] if no-one
1344    /// currently owns that name. You may connect to #GObject::notify signal to
1345    /// track changes to this property.
1346    #[doc(alias = "g-name-owner")]
1347    fn g_name_owner(&self) -> Option<glib::GString> {
1348        ObjectExt::property(self.as_ref(), "g-name-owner")
1349    }
1350
1351    /// The object path the proxy is for.
1352    #[doc(alias = "g-object-path")]
1353    fn g_object_path(&self) -> Option<glib::GString> {
1354        ObjectExt::property(self.as_ref(), "g-object-path")
1355    }
1356
1357    #[doc(alias = "g-default-timeout")]
1358    fn connect_g_default_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
1359        &self,
1360        f: F,
1361    ) -> SignalHandlerId {
1362        unsafe extern "C" fn notify_g_default_timeout_trampoline<
1363            P: IsA<DBusProxy>,
1364            F: Fn(&P) + Send + Sync + 'static,
1365        >(
1366            this: *mut ffi::GDBusProxy,
1367            _param_spec: glib::ffi::gpointer,
1368            f: glib::ffi::gpointer,
1369        ) {
1370            let f: &F = &*(f as *const F);
1371            f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
1372        }
1373        unsafe {
1374            let f: Box_<F> = Box_::new(f);
1375            connect_raw(
1376                self.as_ptr() as *mut _,
1377                c"notify::g-default-timeout".as_ptr() as *const _,
1378                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1379                    notify_g_default_timeout_trampoline::<Self, F> as *const (),
1380                )),
1381                Box_::into_raw(f),
1382            )
1383        }
1384    }
1385
1386    #[doc(alias = "g-interface-info")]
1387    fn connect_g_interface_info_notify<F: Fn(&Self) + Send + Sync + 'static>(
1388        &self,
1389        f: F,
1390    ) -> SignalHandlerId {
1391        unsafe extern "C" fn notify_g_interface_info_trampoline<
1392            P: IsA<DBusProxy>,
1393            F: Fn(&P) + Send + Sync + 'static,
1394        >(
1395            this: *mut ffi::GDBusProxy,
1396            _param_spec: glib::ffi::gpointer,
1397            f: glib::ffi::gpointer,
1398        ) {
1399            let f: &F = &*(f as *const F);
1400            f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
1401        }
1402        unsafe {
1403            let f: Box_<F> = Box_::new(f);
1404            connect_raw(
1405                self.as_ptr() as *mut _,
1406                c"notify::g-interface-info".as_ptr() as *const _,
1407                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1408                    notify_g_interface_info_trampoline::<Self, F> as *const (),
1409                )),
1410                Box_::into_raw(f),
1411            )
1412        }
1413    }
1414
1415    #[doc(alias = "g-name-owner")]
1416    fn connect_g_name_owner_notify<F: Fn(&Self) + Send + Sync + 'static>(
1417        &self,
1418        f: F,
1419    ) -> SignalHandlerId {
1420        unsafe extern "C" fn notify_g_name_owner_trampoline<
1421            P: IsA<DBusProxy>,
1422            F: Fn(&P) + Send + Sync + 'static,
1423        >(
1424            this: *mut ffi::GDBusProxy,
1425            _param_spec: glib::ffi::gpointer,
1426            f: glib::ffi::gpointer,
1427        ) {
1428            let f: &F = &*(f as *const F);
1429            f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
1430        }
1431        unsafe {
1432            let f: Box_<F> = Box_::new(f);
1433            connect_raw(
1434                self.as_ptr() as *mut _,
1435                c"notify::g-name-owner".as_ptr() as *const _,
1436                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1437                    notify_g_name_owner_trampoline::<Self, F> as *const (),
1438                )),
1439                Box_::into_raw(f),
1440            )
1441        }
1442    }
1443}
1444
1445impl<O: IsA<DBusProxy>> DBusProxyExt for O {}