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