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    AsyncInitable, AsyncResult, BusType, Cancellable, DBusCallFlags, DBusConnection, DBusInterface,
10    DBusInterfaceInfo, DBusProxyFlags, Initable, ffi,
11};
12use glib::{
13    prelude::*,
14    signal::{SignalHandlerId, connect_raw},
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            unsafe {
400                let mut error = std::ptr::null_mut();
401                let ret = ffi::g_dbus_proxy_new_finish(res, &mut error);
402                let result = if error.is_null() {
403                    Ok(from_glib_full(ret))
404                } else {
405                    Err(from_glib_full(error))
406                };
407                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
408                    Box_::from_raw(user_data as *mut _);
409                let callback: P = callback.into_inner();
410                callback(result);
411            }
412        }
413        let callback = new_trampoline::<P>;
414        unsafe {
415            ffi::g_dbus_proxy_new(
416                connection.to_glib_none().0,
417                flags.into_glib(),
418                info.to_glib_none().0,
419                name.to_glib_none().0,
420                object_path.to_glib_none().0,
421                interface_name.to_glib_none().0,
422                cancellable.map(|p| p.as_ref()).to_glib_none().0,
423                Some(callback),
424                Box_::into_raw(user_data) as *mut _,
425            );
426        }
427    }
428
429    pub fn new_future(
430        connection: &DBusConnection,
431        flags: DBusProxyFlags,
432        info: Option<&DBusInterfaceInfo>,
433        name: Option<&str>,
434        object_path: &str,
435        interface_name: &str,
436    ) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusProxy, glib::Error>> + 'static>> {
437        let connection = connection.clone();
438        let info = info.map(ToOwned::to_owned);
439        let name = name.map(ToOwned::to_owned);
440        let object_path = String::from(object_path);
441        let interface_name = String::from(interface_name);
442        Box_::pin(crate::GioFuture::new(
443            &(),
444            move |_obj, cancellable, send| {
445                Self::new(
446                    &connection,
447                    flags,
448                    info.as_ref().map(::std::borrow::Borrow::borrow),
449                    name.as_ref().map(::std::borrow::Borrow::borrow),
450                    &object_path,
451                    &interface_name,
452                    Some(cancellable),
453                    move |res| {
454                        send.resolve(res);
455                    },
456                );
457            },
458        ))
459    }
460
461    /// Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
462    ///
463    /// #GDBusProxy is used in this [example][`DBusProxy`][crate::DBusProxy]#a-watch-proxy-example].
464    /// ## `bus_type`
465    /// A #GBusType.
466    /// ## `flags`
467    /// Flags used when constructing the proxy.
468    /// ## `info`
469    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
470    /// ## `name`
471    /// A bus name (well-known or unique).
472    /// ## `object_path`
473    /// An object path.
474    /// ## `interface_name`
475    /// A D-Bus interface name.
476    /// ## `cancellable`
477    /// A #GCancellable or [`None`].
478    /// ## `callback`
479    /// Callback function to invoke when the proxy is ready.
480    #[doc(alias = "g_dbus_proxy_new_for_bus")]
481    #[doc(alias = "new_for_bus")]
482    pub fn for_bus<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
483        bus_type: BusType,
484        flags: DBusProxyFlags,
485        info: Option<&DBusInterfaceInfo>,
486        name: &str,
487        object_path: &str,
488        interface_name: &str,
489        cancellable: Option<&impl IsA<Cancellable>>,
490        callback: P,
491    ) {
492        let main_context = glib::MainContext::ref_thread_default();
493        let is_main_context_owner = main_context.is_owner();
494        let has_acquired_main_context = (!is_main_context_owner)
495            .then(|| main_context.acquire().ok())
496            .flatten();
497        assert!(
498            is_main_context_owner || has_acquired_main_context.is_some(),
499            "Async operations only allowed if the thread is owning the MainContext"
500        );
501
502        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
503            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
504        unsafe extern "C" fn for_bus_trampoline<
505            P: FnOnce(Result<DBusProxy, glib::Error>) + 'static,
506        >(
507            _source_object: *mut glib::gobject_ffi::GObject,
508            res: *mut crate::ffi::GAsyncResult,
509            user_data: glib::ffi::gpointer,
510        ) {
511            unsafe {
512                let mut error = std::ptr::null_mut();
513                let ret = ffi::g_dbus_proxy_new_for_bus_finish(res, &mut error);
514                let result = if error.is_null() {
515                    Ok(from_glib_full(ret))
516                } else {
517                    Err(from_glib_full(error))
518                };
519                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
520                    Box_::from_raw(user_data as *mut _);
521                let callback: P = callback.into_inner();
522                callback(result);
523            }
524        }
525        let callback = for_bus_trampoline::<P>;
526        unsafe {
527            ffi::g_dbus_proxy_new_for_bus(
528                bus_type.into_glib(),
529                flags.into_glib(),
530                info.to_glib_none().0,
531                name.to_glib_none().0,
532                object_path.to_glib_none().0,
533                interface_name.to_glib_none().0,
534                cancellable.map(|p| p.as_ref()).to_glib_none().0,
535                Some(callback),
536                Box_::into_raw(user_data) as *mut _,
537            );
538        }
539    }
540
541    pub fn for_bus_future(
542        bus_type: BusType,
543        flags: DBusProxyFlags,
544        info: Option<&DBusInterfaceInfo>,
545        name: &str,
546        object_path: &str,
547        interface_name: &str,
548    ) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusProxy, glib::Error>> + 'static>> {
549        let info = info.map(ToOwned::to_owned);
550        let name = String::from(name);
551        let object_path = String::from(object_path);
552        let interface_name = String::from(interface_name);
553        Box_::pin(crate::GioFuture::new(
554            &(),
555            move |_obj, cancellable, send| {
556                Self::for_bus(
557                    bus_type,
558                    flags,
559                    info.as_ref().map(::std::borrow::Borrow::borrow),
560                    &name,
561                    &object_path,
562                    &interface_name,
563                    Some(cancellable),
564                    move |res| {
565                        send.resolve(res);
566                    },
567                );
568            },
569        ))
570    }
571}
572
573unsafe impl Send for DBusProxy {}
574unsafe impl Sync for DBusProxy {}
575
576/// Trait containing all [`struct@DBusProxy`] methods.
577///
578/// # Implementors
579///
580/// [`DBusProxy`][struct@crate::DBusProxy]
581pub trait DBusProxyExt: IsA<DBusProxy> + 'static {
582    /// Asynchronously invokes the @method_name method on @self.
583    ///
584    /// If @method_name contains any dots, then @name is split into interface and
585    /// method name parts. This allows using @self for invoking methods on
586    /// other interfaces.
587    ///
588    /// If the #GDBusConnection associated with @self is closed then
589    /// the operation will fail with [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. If
590    /// @cancellable is canceled, the operation will fail with
591    /// [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled]. If @parameters contains a value not
592    /// compatible with the D-Bus protocol, the operation fails with
593    /// [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
594    ///
595    /// If the @parameters #GVariant is floating, it is consumed. This allows
596    /// convenient 'inline' use of g_variant_new(), e.g.:
597    ///
598    ///
599    /// **⚠️ The following code is in C ⚠️**
600    ///
601    /// ```C
602    ///  g_dbus_proxy_call (proxy,
603    ///                     "TwoStrings",
604    ///                     g_variant_new ("(ss)",
605    ///                                    "Thing One",
606    ///                                    "Thing Two"),
607    ///                     G_DBUS_CALL_FLAGS_NONE,
608    ///                     -1,
609    ///                     NULL,
610    ///                     (GAsyncReadyCallback) two_strings_done,
611    ///                     &data);
612    /// ```
613    ///
614    /// If @self has an expected interface (see
615    /// #GDBusProxy:g-interface-info) and @method_name is referenced by it,
616    /// then the return value is checked against the return type.
617    ///
618    /// This is an asynchronous method. When the operation is finished,
619    /// @callback will be invoked in the thread-default main context
620    /// (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()])
621    /// of the thread you are calling this method from.
622    /// You can then call g_dbus_proxy_call_finish() to get the result of
623    /// the operation. See g_dbus_proxy_call_sync() for the synchronous
624    /// version of this method.
625    ///
626    /// If @callback is [`None`] then the D-Bus method call message will be sent with
627    /// the [`DBusMessageFlags::NO_REPLY_EXPECTED`][crate::DBusMessageFlags::NO_REPLY_EXPECTED] flag set.
628    /// ## `method_name`
629    /// Name of method to invoke.
630    /// ## `parameters`
631    /// A #GVariant tuple with parameters for the signal or [`None`] if not passing parameters.
632    /// ## `flags`
633    /// Flags from the #GDBusCallFlags enumeration.
634    /// ## `timeout_msec`
635    /// The timeout in milliseconds (with `G_MAXINT` meaning
636    ///                "infinite") or -1 to use the proxy default timeout.
637    /// ## `cancellable`
638    /// A #GCancellable or [`None`].
639    /// ## `callback`
640    /// A #GAsyncReadyCallback to call when the request is satisfied or [`None`] if you don't
641    /// care about the result of the method invocation.
642    #[doc(alias = "g_dbus_proxy_call")]
643    fn call<P: FnOnce(Result<glib::Variant, glib::Error>) + 'static>(
644        &self,
645        method_name: &str,
646        parameters: Option<&glib::Variant>,
647        flags: DBusCallFlags,
648        timeout_msec: i32,
649        cancellable: Option<&impl IsA<Cancellable>>,
650        callback: P,
651    ) {
652        let main_context = glib::MainContext::ref_thread_default();
653        let is_main_context_owner = main_context.is_owner();
654        let has_acquired_main_context = (!is_main_context_owner)
655            .then(|| main_context.acquire().ok())
656            .flatten();
657        assert!(
658            is_main_context_owner || has_acquired_main_context.is_some(),
659            "Async operations only allowed if the thread is owning the MainContext"
660        );
661
662        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
663            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
664        unsafe extern "C" fn call_trampoline<
665            P: FnOnce(Result<glib::Variant, glib::Error>) + 'static,
666        >(
667            _source_object: *mut glib::gobject_ffi::GObject,
668            res: *mut crate::ffi::GAsyncResult,
669            user_data: glib::ffi::gpointer,
670        ) {
671            unsafe {
672                let mut error = std::ptr::null_mut();
673                let ret = ffi::g_dbus_proxy_call_finish(_source_object as *mut _, res, &mut error);
674                let result = if error.is_null() {
675                    Ok(from_glib_full(ret))
676                } else {
677                    Err(from_glib_full(error))
678                };
679                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
680                    Box_::from_raw(user_data as *mut _);
681                let callback: P = callback.into_inner();
682                callback(result);
683            }
684        }
685        let callback = call_trampoline::<P>;
686        unsafe {
687            ffi::g_dbus_proxy_call(
688                self.as_ref().to_glib_none().0,
689                method_name.to_glib_none().0,
690                parameters.to_glib_none().0,
691                flags.into_glib(),
692                timeout_msec,
693                cancellable.map(|p| p.as_ref()).to_glib_none().0,
694                Some(callback),
695                Box_::into_raw(user_data) as *mut _,
696            );
697        }
698    }
699
700    fn call_future(
701        &self,
702        method_name: &str,
703        parameters: Option<&glib::Variant>,
704        flags: DBusCallFlags,
705        timeout_msec: i32,
706    ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Variant, glib::Error>> + 'static>>
707    {
708        let method_name = String::from(method_name);
709        let parameters = parameters.map(ToOwned::to_owned);
710        Box_::pin(crate::GioFuture::new(
711            self,
712            move |obj, cancellable, send| {
713                obj.call(
714                    &method_name,
715                    parameters.as_ref().map(::std::borrow::Borrow::borrow),
716                    flags,
717                    timeout_msec,
718                    Some(cancellable),
719                    move |res| {
720                        send.resolve(res);
721                    },
722                );
723            },
724        ))
725    }
726
727    /// Synchronously invokes the @method_name method on @self.
728    ///
729    /// If @method_name contains any dots, then @name is split into interface and
730    /// method name parts. This allows using @self for invoking methods on
731    /// other interfaces.
732    ///
733    /// If the #GDBusConnection associated with @self is disconnected then
734    /// the operation will fail with [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. If
735    /// @cancellable is canceled, the operation will fail with
736    /// [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled]. If @parameters contains a value not
737    /// compatible with the D-Bus protocol, the operation fails with
738    /// [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
739    ///
740    /// If the @parameters #GVariant is floating, it is consumed. This allows
741    /// convenient 'inline' use of g_variant_new(), e.g.:
742    ///
743    ///
744    /// **⚠️ The following code is in C ⚠️**
745    ///
746    /// ```C
747    ///  g_dbus_proxy_call_sync (proxy,
748    ///                          "TwoStrings",
749    ///                          g_variant_new ("(ss)",
750    ///                                         "Thing One",
751    ///                                         "Thing Two"),
752    ///                          G_DBUS_CALL_FLAGS_NONE,
753    ///                          -1,
754    ///                          NULL,
755    ///                          &error);
756    /// ```
757    ///
758    /// The calling thread is blocked until a reply is received. See
759    /// g_dbus_proxy_call() for the asynchronous version of this
760    /// method.
761    ///
762    /// If @self has an expected interface (see
763    /// #GDBusProxy:g-interface-info) and @method_name is referenced by it,
764    /// then the return value is checked against the return type.
765    /// ## `method_name`
766    /// Name of method to invoke.
767    /// ## `parameters`
768    /// A #GVariant tuple with parameters for the signal
769    ///              or [`None`] if not passing parameters.
770    /// ## `flags`
771    /// Flags from the #GDBusCallFlags enumeration.
772    /// ## `timeout_msec`
773    /// The timeout in milliseconds (with `G_MAXINT` meaning
774    ///                "infinite") or -1 to use the proxy default timeout.
775    /// ## `cancellable`
776    /// A #GCancellable or [`None`].
777    ///
778    /// # Returns
779    ///
780    /// [`None`] if @error is set. Otherwise a #GVariant tuple with
781    /// return values. Free with g_variant_unref().
782    #[doc(alias = "g_dbus_proxy_call_sync")]
783    fn call_sync(
784        &self,
785        method_name: &str,
786        parameters: Option<&glib::Variant>,
787        flags: DBusCallFlags,
788        timeout_msec: i32,
789        cancellable: Option<&impl IsA<Cancellable>>,
790    ) -> Result<glib::Variant, glib::Error> {
791        unsafe {
792            let mut error = std::ptr::null_mut();
793            let ret = ffi::g_dbus_proxy_call_sync(
794                self.as_ref().to_glib_none().0,
795                method_name.to_glib_none().0,
796                parameters.to_glib_none().0,
797                flags.into_glib(),
798                timeout_msec,
799                cancellable.map(|p| p.as_ref()).to_glib_none().0,
800                &mut error,
801            );
802            if error.is_null() {
803                Ok(from_glib_full(ret))
804            } else {
805                Err(from_glib_full(error))
806            }
807        }
808    }
809
810    /// Like g_dbus_proxy_call() but also takes a #GUnixFDList object.
811    ///
812    /// This method is only available on UNIX.
813    /// ## `method_name`
814    /// Name of method to invoke.
815    /// ## `parameters`
816    /// A #GVariant tuple with parameters for the signal or [`None`] if not passing parameters.
817    /// ## `flags`
818    /// Flags from the #GDBusCallFlags enumeration.
819    /// ## `timeout_msec`
820    /// The timeout in milliseconds (with `G_MAXINT` meaning
821    ///                "infinite") or -1 to use the proxy default timeout.
822    /// ## `fd_list`
823    /// A #GUnixFDList or [`None`].
824    /// ## `cancellable`
825    /// A #GCancellable or [`None`].
826    /// ## `callback`
827    /// A #GAsyncReadyCallback to call when the request is satisfied or [`None`] if you don't
828    /// care about the result of the method invocation.
829    #[cfg(unix)]
830    #[cfg_attr(docsrs, doc(cfg(unix)))]
831    #[doc(alias = "g_dbus_proxy_call_with_unix_fd_list")]
832    fn call_with_unix_fd_list<
833        P: FnOnce(Result<(glib::Variant, Option<UnixFDList>), glib::Error>) + 'static,
834    >(
835        &self,
836        method_name: &str,
837        parameters: Option<&glib::Variant>,
838        flags: DBusCallFlags,
839        timeout_msec: i32,
840        fd_list: Option<&impl IsA<UnixFDList>>,
841        cancellable: Option<&impl IsA<Cancellable>>,
842        callback: P,
843    ) {
844        let main_context = glib::MainContext::ref_thread_default();
845        let is_main_context_owner = main_context.is_owner();
846        let has_acquired_main_context = (!is_main_context_owner)
847            .then(|| main_context.acquire().ok())
848            .flatten();
849        assert!(
850            is_main_context_owner || has_acquired_main_context.is_some(),
851            "Async operations only allowed if the thread is owning the MainContext"
852        );
853
854        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
855            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
856        unsafe extern "C" fn call_with_unix_fd_list_trampoline<
857            P: FnOnce(Result<(glib::Variant, Option<UnixFDList>), glib::Error>) + 'static,
858        >(
859            _source_object: *mut glib::gobject_ffi::GObject,
860            res: *mut crate::ffi::GAsyncResult,
861            user_data: glib::ffi::gpointer,
862        ) {
863            unsafe {
864                let mut error = std::ptr::null_mut();
865                let mut out_fd_list = std::ptr::null_mut();
866                let ret = ffi::g_dbus_proxy_call_with_unix_fd_list_finish(
867                    _source_object as *mut _,
868                    &mut out_fd_list,
869                    res,
870                    &mut error,
871                );
872                let result = if error.is_null() {
873                    Ok((from_glib_full(ret), from_glib_full(out_fd_list)))
874                } else {
875                    Err(from_glib_full(error))
876                };
877                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
878                    Box_::from_raw(user_data as *mut _);
879                let callback: P = callback.into_inner();
880                callback(result);
881            }
882        }
883        let callback = call_with_unix_fd_list_trampoline::<P>;
884        unsafe {
885            ffi::g_dbus_proxy_call_with_unix_fd_list(
886                self.as_ref().to_glib_none().0,
887                method_name.to_glib_none().0,
888                parameters.to_glib_none().0,
889                flags.into_glib(),
890                timeout_msec,
891                fd_list.map(|p| p.as_ref()).to_glib_none().0,
892                cancellable.map(|p| p.as_ref()).to_glib_none().0,
893                Some(callback),
894                Box_::into_raw(user_data) as *mut _,
895            );
896        }
897    }
898
899    #[cfg(unix)]
900    #[cfg_attr(docsrs, doc(cfg(unix)))]
901    fn call_with_unix_fd_list_future(
902        &self,
903        method_name: &str,
904        parameters: Option<&glib::Variant>,
905        flags: DBusCallFlags,
906        timeout_msec: i32,
907        fd_list: Option<&(impl IsA<UnixFDList> + Clone + 'static)>,
908    ) -> Pin<
909        Box_<
910            dyn std::future::Future<
911                    Output = Result<(glib::Variant, Option<UnixFDList>), glib::Error>,
912                > + 'static,
913        >,
914    > {
915        let method_name = String::from(method_name);
916        let parameters = parameters.map(ToOwned::to_owned);
917        let fd_list = fd_list.map(ToOwned::to_owned);
918        Box_::pin(crate::GioFuture::new(
919            self,
920            move |obj, cancellable, send| {
921                obj.call_with_unix_fd_list(
922                    &method_name,
923                    parameters.as_ref().map(::std::borrow::Borrow::borrow),
924                    flags,
925                    timeout_msec,
926                    fd_list.as_ref().map(::std::borrow::Borrow::borrow),
927                    Some(cancellable),
928                    move |res| {
929                        send.resolve(res);
930                    },
931                );
932            },
933        ))
934    }
935
936    /// Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects.
937    ///
938    /// This method is only available on UNIX.
939    /// ## `method_name`
940    /// Name of method to invoke.
941    /// ## `parameters`
942    /// A #GVariant tuple with parameters for the signal
943    ///              or [`None`] if not passing parameters.
944    /// ## `flags`
945    /// Flags from the #GDBusCallFlags enumeration.
946    /// ## `timeout_msec`
947    /// The timeout in milliseconds (with `G_MAXINT` meaning
948    ///                "infinite") or -1 to use the proxy default timeout.
949    /// ## `fd_list`
950    /// A #GUnixFDList or [`None`].
951    /// ## `cancellable`
952    /// A #GCancellable or [`None`].
953    ///
954    /// # Returns
955    ///
956    /// [`None`] if @error is set. Otherwise a #GVariant tuple with
957    /// return values. Free with g_variant_unref().
958    ///
959    /// ## `out_fd_list`
960    /// Return location for a #GUnixFDList or [`None`].
961    #[cfg(unix)]
962    #[cfg_attr(docsrs, doc(cfg(unix)))]
963    #[doc(alias = "g_dbus_proxy_call_with_unix_fd_list_sync")]
964    fn call_with_unix_fd_list_sync(
965        &self,
966        method_name: &str,
967        parameters: Option<&glib::Variant>,
968        flags: DBusCallFlags,
969        timeout_msec: i32,
970        fd_list: Option<&impl IsA<UnixFDList>>,
971        cancellable: Option<&impl IsA<Cancellable>>,
972    ) -> Result<(glib::Variant, Option<UnixFDList>), glib::Error> {
973        unsafe {
974            let mut out_fd_list = std::ptr::null_mut();
975            let mut error = std::ptr::null_mut();
976            let ret = ffi::g_dbus_proxy_call_with_unix_fd_list_sync(
977                self.as_ref().to_glib_none().0,
978                method_name.to_glib_none().0,
979                parameters.to_glib_none().0,
980                flags.into_glib(),
981                timeout_msec,
982                fd_list.map(|p| p.as_ref()).to_glib_none().0,
983                &mut out_fd_list,
984                cancellable.map(|p| p.as_ref()).to_glib_none().0,
985                &mut error,
986            );
987            if error.is_null() {
988                Ok((from_glib_full(ret), from_glib_full(out_fd_list)))
989            } else {
990                Err(from_glib_full(error))
991            }
992        }
993    }
994
995    /// Looks up the value for a property from the cache. This call does no
996    /// blocking IO.
997    ///
998    /// If @self has an expected interface (see
999    /// #GDBusProxy:g-interface-info) and @property_name is referenced by
1000    /// it, then @value is checked against the type of the property.
1001    /// ## `property_name`
1002    /// Property name.
1003    ///
1004    /// # Returns
1005    ///
1006    /// A reference to the #GVariant instance
1007    ///    that holds the value for @property_name or [`None`] if the value is not in
1008    ///    the cache. The returned reference must be freed with g_variant_unref().
1009    #[doc(alias = "g_dbus_proxy_get_cached_property")]
1010    #[doc(alias = "get_cached_property")]
1011    fn cached_property(&self, property_name: &str) -> Option<glib::Variant> {
1012        unsafe {
1013            from_glib_full(ffi::g_dbus_proxy_get_cached_property(
1014                self.as_ref().to_glib_none().0,
1015                property_name.to_glib_none().0,
1016            ))
1017        }
1018    }
1019
1020    /// Gets the names of all cached properties on @self.
1021    ///
1022    /// # Returns
1023    ///
1024    /// A
1025    ///          [`None`]-terminated array of strings or [`None`] if
1026    ///          @self has no cached properties. Free the returned array with
1027    ///          g_strfreev().
1028    #[doc(alias = "g_dbus_proxy_get_cached_property_names")]
1029    #[doc(alias = "get_cached_property_names")]
1030    fn cached_property_names(&self) -> Vec<glib::GString> {
1031        unsafe {
1032            FromGlibPtrContainer::from_glib_full(ffi::g_dbus_proxy_get_cached_property_names(
1033                self.as_ref().to_glib_none().0,
1034            ))
1035        }
1036    }
1037
1038    /// Gets the connection @self is for.
1039    ///
1040    /// # Returns
1041    ///
1042    /// A #GDBusConnection owned by @self. Do not free.
1043    #[doc(alias = "g_dbus_proxy_get_connection")]
1044    #[doc(alias = "get_connection")]
1045    fn connection(&self) -> DBusConnection {
1046        unsafe {
1047            from_glib_none(ffi::g_dbus_proxy_get_connection(
1048                self.as_ref().to_glib_none().0,
1049            ))
1050        }
1051    }
1052
1053    /// Gets the timeout to use if -1 (specifying default timeout) is
1054    /// passed as @timeout_msec in the g_dbus_proxy_call() and
1055    /// g_dbus_proxy_call_sync() functions.
1056    ///
1057    /// See the #GDBusProxy:g-default-timeout property for more details.
1058    ///
1059    /// # Returns
1060    ///
1061    /// Timeout to use for @self.
1062    #[doc(alias = "g_dbus_proxy_get_default_timeout")]
1063    #[doc(alias = "get_default_timeout")]
1064    fn default_timeout(&self) -> i32 {
1065        unsafe { ffi::g_dbus_proxy_get_default_timeout(self.as_ref().to_glib_none().0) }
1066    }
1067
1068    /// Gets the flags that @self was constructed with.
1069    ///
1070    /// # Returns
1071    ///
1072    /// Flags from the #GDBusProxyFlags enumeration.
1073    #[doc(alias = "g_dbus_proxy_get_flags")]
1074    #[doc(alias = "get_flags")]
1075    fn flags(&self) -> DBusProxyFlags {
1076        unsafe { from_glib(ffi::g_dbus_proxy_get_flags(self.as_ref().to_glib_none().0)) }
1077    }
1078
1079    /// Returns the #GDBusInterfaceInfo, if any, specifying the interface
1080    /// that @self conforms to. See the #GDBusProxy:g-interface-info
1081    /// property for more details.
1082    ///
1083    /// # Returns
1084    ///
1085    /// A #GDBusInterfaceInfo or [`None`].
1086    ///    Do not unref the returned object, it is owned by @self.
1087    #[doc(alias = "g_dbus_proxy_get_interface_info")]
1088    #[doc(alias = "get_interface_info")]
1089    fn interface_info(&self) -> Option<DBusInterfaceInfo> {
1090        unsafe {
1091            from_glib_none(ffi::g_dbus_proxy_get_interface_info(
1092                self.as_ref().to_glib_none().0,
1093            ))
1094        }
1095    }
1096
1097    /// Gets the D-Bus interface name @self is for.
1098    ///
1099    /// # Returns
1100    ///
1101    /// A string owned by @self. Do not free.
1102    #[doc(alias = "g_dbus_proxy_get_interface_name")]
1103    #[doc(alias = "get_interface_name")]
1104    fn interface_name(&self) -> glib::GString {
1105        unsafe {
1106            from_glib_none(ffi::g_dbus_proxy_get_interface_name(
1107                self.as_ref().to_glib_none().0,
1108            ))
1109        }
1110    }
1111
1112    /// Gets the name that @self was constructed for.
1113    ///
1114    /// When connected to a message bus, this will usually be non-[`None`].
1115    /// However, it may be [`None`] for a proxy that communicates using a peer-to-peer
1116    /// pattern.
1117    ///
1118    /// # Returns
1119    ///
1120    /// A string owned by @self. Do not free.
1121    #[doc(alias = "g_dbus_proxy_get_name")]
1122    #[doc(alias = "get_name")]
1123    fn name(&self) -> Option<glib::GString> {
1124        unsafe { from_glib_none(ffi::g_dbus_proxy_get_name(self.as_ref().to_glib_none().0)) }
1125    }
1126
1127    /// The unique name that owns the name that @self is for or [`None`] if
1128    /// no-one currently owns that name. You may connect to the
1129    /// #GObject::notify signal to track changes to the
1130    /// #GDBusProxy:g-name-owner property.
1131    ///
1132    /// # Returns
1133    ///
1134    /// The name owner or [`None`] if no name
1135    ///    owner exists. Free with g_free().
1136    #[doc(alias = "g_dbus_proxy_get_name_owner")]
1137    #[doc(alias = "get_name_owner")]
1138    fn name_owner(&self) -> Option<glib::GString> {
1139        unsafe {
1140            from_glib_full(ffi::g_dbus_proxy_get_name_owner(
1141                self.as_ref().to_glib_none().0,
1142            ))
1143        }
1144    }
1145
1146    /// Gets the object path @self is for.
1147    ///
1148    /// # Returns
1149    ///
1150    /// A string owned by @self. Do not free.
1151    #[doc(alias = "g_dbus_proxy_get_object_path")]
1152    #[doc(alias = "get_object_path")]
1153    fn object_path(&self) -> glib::GString {
1154        unsafe {
1155            from_glib_none(ffi::g_dbus_proxy_get_object_path(
1156                self.as_ref().to_glib_none().0,
1157            ))
1158        }
1159    }
1160
1161    /// If @value is not [`None`], sets the cached value for the property with
1162    /// name @property_name to the value in @value.
1163    ///
1164    /// If @value is [`None`], then the cached value is removed from the
1165    /// property cache.
1166    ///
1167    /// If @self has an expected interface (see
1168    /// #GDBusProxy:g-interface-info) and @property_name is referenced by
1169    /// it, then @value is checked against the type of the property.
1170    ///
1171    /// If the @value #GVariant is floating, it is consumed. This allows
1172    /// convenient 'inline' use of g_variant_new(), e.g.
1173    ///
1174    ///
1175    /// **⚠️ The following code is in C ⚠️**
1176    ///
1177    /// ```C
1178    ///  g_dbus_proxy_set_cached_property (proxy,
1179    ///                                    "SomeProperty",
1180    ///                                    g_variant_new ("(si)",
1181    ///                                                  "A String",
1182    ///                                                  42));
1183    /// ```
1184    ///
1185    /// Normally you will not need to use this method since @self
1186    /// is tracking changes using the
1187    /// `org.freedesktop.DBus.Properties.PropertiesChanged`
1188    /// D-Bus signal. However, for performance reasons an object may
1189    /// decide to not use this signal for some properties and instead
1190    /// use a proprietary out-of-band mechanism to transmit changes.
1191    ///
1192    /// As a concrete example, consider an object with a property
1193    /// `ChatroomParticipants` which is an array of strings. Instead of
1194    /// transmitting the same (long) array every time the property changes,
1195    /// it is more efficient to only transmit the delta using e.g. signals
1196    /// `ChatroomParticipantJoined(String name)` and
1197    /// `ChatroomParticipantParted(String name)`.
1198    /// ## `property_name`
1199    /// Property name.
1200    /// ## `value`
1201    /// Value for the property or [`None`] to remove it from the cache.
1202    #[doc(alias = "g_dbus_proxy_set_cached_property")]
1203    fn set_cached_property(&self, property_name: &str, value: Option<&glib::Variant>) {
1204        unsafe {
1205            ffi::g_dbus_proxy_set_cached_property(
1206                self.as_ref().to_glib_none().0,
1207                property_name.to_glib_none().0,
1208                value.to_glib_none().0,
1209            );
1210        }
1211    }
1212
1213    /// Sets the timeout to use if -1 (specifying default timeout) is
1214    /// passed as @timeout_msec in the g_dbus_proxy_call() and
1215    /// g_dbus_proxy_call_sync() functions.
1216    ///
1217    /// See the #GDBusProxy:g-default-timeout property for more details.
1218    /// ## `timeout_msec`
1219    /// Timeout in milliseconds.
1220    #[doc(alias = "g_dbus_proxy_set_default_timeout")]
1221    fn set_default_timeout(&self, timeout_msec: i32) {
1222        unsafe {
1223            ffi::g_dbus_proxy_set_default_timeout(self.as_ref().to_glib_none().0, timeout_msec);
1224        }
1225    }
1226
1227    /// Ensure that interactions with @self conform to the given
1228    /// interface. See the #GDBusProxy:g-interface-info property for more
1229    /// details.
1230    /// ## `info`
1231    /// Minimum interface this proxy conforms to
1232    ///    or [`None`] to unset.
1233    #[doc(alias = "g_dbus_proxy_set_interface_info")]
1234    fn set_interface_info(&self, info: Option<&DBusInterfaceInfo>) {
1235        unsafe {
1236            ffi::g_dbus_proxy_set_interface_info(
1237                self.as_ref().to_glib_none().0,
1238                info.to_glib_none().0,
1239            );
1240        }
1241    }
1242
1243    /// The #GDBusConnection the proxy is for.
1244    #[doc(alias = "g-connection")]
1245    fn g_connection(&self) -> Option<DBusConnection> {
1246        ObjectExt::property(self.as_ref(), "g-connection")
1247    }
1248
1249    /// The timeout to use if -1 (specifying default timeout) is passed
1250    /// as @timeout_msec in the g_dbus_proxy_call() and
1251    /// g_dbus_proxy_call_sync() functions.
1252    ///
1253    /// This allows applications to set a proxy-wide timeout for all
1254    /// remote method invocations on the proxy. If this property is -1,
1255    /// the default timeout (typically 25 seconds) is used. If set to
1256    /// `G_MAXINT`, then no timeout is used.
1257    #[doc(alias = "g-default-timeout")]
1258    fn g_default_timeout(&self) -> i32 {
1259        ObjectExt::property(self.as_ref(), "g-default-timeout")
1260    }
1261
1262    /// The timeout to use if -1 (specifying default timeout) is passed
1263    /// as @timeout_msec in the g_dbus_proxy_call() and
1264    /// g_dbus_proxy_call_sync() functions.
1265    ///
1266    /// This allows applications to set a proxy-wide timeout for all
1267    /// remote method invocations on the proxy. If this property is -1,
1268    /// the default timeout (typically 25 seconds) is used. If set to
1269    /// `G_MAXINT`, then no timeout is used.
1270    #[doc(alias = "g-default-timeout")]
1271    fn set_g_default_timeout(&self, g_default_timeout: i32) {
1272        ObjectExt::set_property(self.as_ref(), "g-default-timeout", g_default_timeout)
1273    }
1274
1275    /// Flags from the #GDBusProxyFlags enumeration.
1276    #[doc(alias = "g-flags")]
1277    fn g_flags(&self) -> DBusProxyFlags {
1278        ObjectExt::property(self.as_ref(), "g-flags")
1279    }
1280
1281    /// Ensure that interactions with this proxy conform to the given
1282    /// interface. This is mainly to ensure that malformed data received
1283    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
1284    /// said to be the "expected interface".
1285    ///
1286    /// The checks performed are:
1287    /// - When completing a method call, if the type signature of
1288    ///   the reply message isn't what's expected, the reply is
1289    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
1290    ///
1291    /// - Received signals that have a type signature mismatch are dropped and
1292    ///   a warning is logged via g_warning().
1293    ///
1294    /// - Properties received via the initial `GetAll()` call or via the
1295    ///   `::PropertiesChanged` signal (on the
1296    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
1297    ///   interface) or set using g_dbus_proxy_set_cached_property()
1298    ///   with a type signature mismatch are ignored and a warning is
1299    ///   logged via g_warning().
1300    ///
1301    /// Note that these checks are never done on methods, signals and
1302    /// properties that are not referenced in the given
1303    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
1304    /// service-side is not considered an ABI break.
1305    #[doc(alias = "g-interface-info")]
1306    fn g_interface_info(&self) -> Option<DBusInterfaceInfo> {
1307        ObjectExt::property(self.as_ref(), "g-interface-info")
1308    }
1309
1310    /// Ensure that interactions with this proxy conform to the given
1311    /// interface. This is mainly to ensure that malformed data received
1312    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
1313    /// said to be the "expected interface".
1314    ///
1315    /// The checks performed are:
1316    /// - When completing a method call, if the type signature of
1317    ///   the reply message isn't what's expected, the reply is
1318    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
1319    ///
1320    /// - Received signals that have a type signature mismatch are dropped and
1321    ///   a warning is logged via g_warning().
1322    ///
1323    /// - Properties received via the initial `GetAll()` call or via the
1324    ///   `::PropertiesChanged` signal (on the
1325    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
1326    ///   interface) or set using g_dbus_proxy_set_cached_property()
1327    ///   with a type signature mismatch are ignored and a warning is
1328    ///   logged via g_warning().
1329    ///
1330    /// Note that these checks are never done on methods, signals and
1331    /// properties that are not referenced in the given
1332    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
1333    /// service-side is not considered an ABI break.
1334    #[doc(alias = "g-interface-info")]
1335    fn set_g_interface_info(&self, g_interface_info: Option<&DBusInterfaceInfo>) {
1336        ObjectExt::set_property(self.as_ref(), "g-interface-info", g_interface_info)
1337    }
1338
1339    /// The D-Bus interface name the proxy is for.
1340    #[doc(alias = "g-interface-name")]
1341    fn g_interface_name(&self) -> Option<glib::GString> {
1342        ObjectExt::property(self.as_ref(), "g-interface-name")
1343    }
1344
1345    /// The well-known or unique name that the proxy is for.
1346    #[doc(alias = "g-name")]
1347    fn g_name(&self) -> Option<glib::GString> {
1348        ObjectExt::property(self.as_ref(), "g-name")
1349    }
1350
1351    /// The unique name that owns #GDBusProxy:g-name or [`None`] if no-one
1352    /// currently owns that name. You may connect to #GObject::notify signal to
1353    /// track changes to this property.
1354    #[doc(alias = "g-name-owner")]
1355    fn g_name_owner(&self) -> Option<glib::GString> {
1356        ObjectExt::property(self.as_ref(), "g-name-owner")
1357    }
1358
1359    /// The object path the proxy is for.
1360    #[doc(alias = "g-object-path")]
1361    fn g_object_path(&self) -> Option<glib::GString> {
1362        ObjectExt::property(self.as_ref(), "g-object-path")
1363    }
1364
1365    #[doc(alias = "g-default-timeout")]
1366    fn connect_g_default_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
1367        &self,
1368        f: F,
1369    ) -> SignalHandlerId {
1370        unsafe extern "C" fn notify_g_default_timeout_trampoline<
1371            P: IsA<DBusProxy>,
1372            F: Fn(&P) + Send + Sync + 'static,
1373        >(
1374            this: *mut ffi::GDBusProxy,
1375            _param_spec: glib::ffi::gpointer,
1376            f: glib::ffi::gpointer,
1377        ) {
1378            unsafe {
1379                let f: &F = &*(f as *const F);
1380                f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
1381            }
1382        }
1383        unsafe {
1384            let f: Box_<F> = Box_::new(f);
1385            connect_raw(
1386                self.as_ptr() as *mut _,
1387                c"notify::g-default-timeout".as_ptr() as *const _,
1388                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1389                    notify_g_default_timeout_trampoline::<Self, F> as *const (),
1390                )),
1391                Box_::into_raw(f),
1392            )
1393        }
1394    }
1395
1396    #[doc(alias = "g-interface-info")]
1397    fn connect_g_interface_info_notify<F: Fn(&Self) + Send + Sync + 'static>(
1398        &self,
1399        f: F,
1400    ) -> SignalHandlerId {
1401        unsafe extern "C" fn notify_g_interface_info_trampoline<
1402            P: IsA<DBusProxy>,
1403            F: Fn(&P) + Send + Sync + 'static,
1404        >(
1405            this: *mut ffi::GDBusProxy,
1406            _param_spec: glib::ffi::gpointer,
1407            f: glib::ffi::gpointer,
1408        ) {
1409            unsafe {
1410                let f: &F = &*(f as *const F);
1411                f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
1412            }
1413        }
1414        unsafe {
1415            let f: Box_<F> = Box_::new(f);
1416            connect_raw(
1417                self.as_ptr() as *mut _,
1418                c"notify::g-interface-info".as_ptr() as *const _,
1419                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1420                    notify_g_interface_info_trampoline::<Self, F> as *const (),
1421                )),
1422                Box_::into_raw(f),
1423            )
1424        }
1425    }
1426
1427    #[doc(alias = "g-name-owner")]
1428    fn connect_g_name_owner_notify<F: Fn(&Self) + Send + Sync + 'static>(
1429        &self,
1430        f: F,
1431    ) -> SignalHandlerId {
1432        unsafe extern "C" fn notify_g_name_owner_trampoline<
1433            P: IsA<DBusProxy>,
1434            F: Fn(&P) + Send + Sync + 'static,
1435        >(
1436            this: *mut ffi::GDBusProxy,
1437            _param_spec: glib::ffi::gpointer,
1438            f: glib::ffi::gpointer,
1439        ) {
1440            unsafe {
1441                let f: &F = &*(f as *const F);
1442                f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
1443            }
1444        }
1445        unsafe {
1446            let f: Box_<F> = Box_::new(f);
1447            connect_raw(
1448                self.as_ptr() as *mut _,
1449                c"notify::g-name-owner".as_ptr() as *const _,
1450                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1451                    notify_g_name_owner_trampoline::<Self, F> as *const (),
1452                )),
1453                Box_::into_raw(f),
1454            )
1455        }
1456    }
1457}
1458
1459impl<O: IsA<DBusProxy>> DBusProxyExt for O {}