Skip to main content

gio/auto/
dbus_object_manager_client.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
5use crate::{
6    AsyncInitable, AsyncResult, BusType, Cancellable, DBusConnection, DBusObjectManager,
7    DBusObjectManagerClientFlags, DBusObjectProxy, DBusProxy, Initable, ffi,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    ///  problem cannot happen.
19    ///
20    /// To avoid having the application connect to signals on the returned
21    /// [`DBusObjectProxy`][crate::DBusObjectProxy] and [`DBusProxy`][crate::DBusProxy] objects, the
22    /// [`interface-added`][struct@crate::DBusObject#interface-added],
23    /// [`interface-removed`][struct@crate::DBusObject#interface-removed],
24    /// [`g-properties-changed`][struct@crate::DBusProxy#g-properties-changed] and
25    /// [`g-signal`][struct@crate::DBusProxy#g-signal] signals
26    /// are also emitted on the `GDBusObjectManagerClient` instance managing these
27    /// objects. The signals emitted are
28    /// [`interface-added`][struct@crate::DBusObjectManager#interface-added],
29    /// [`interface-removed`][struct@crate::DBusObjectManager#interface-removed],
30    /// [`interface-proxy-properties-changed`][struct@crate::DBusObjectManagerClient#interface-proxy-properties-changed] and
31    /// [`interface-proxy-signal`][struct@crate::DBusObjectManagerClient#interface-proxy-signal].
32    ///
33    /// Note that all callbacks and signals are emitted in the
34    /// thread-default main context (see
35    /// [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()]) that the
36    /// `GDBusObjectManagerClient` object was constructed in. Additionally, the
37    /// [`DBusObjectProxy`][crate::DBusObjectProxy] and [`DBusProxy`][crate::DBusProxy] objects
38    /// originating from the `GDBusObjectManagerClient` object will be created in
39    /// the same context and, consequently, will deliver signals in the
40    /// same main loop.
41    ///
42    /// ## Properties
43    ///
44    ///
45    /// #### `bus-type`
46    ///  If this property is not [`BusType::None`][crate::BusType::None], then
47    /// #GDBusObjectManagerClient:connection must be [`None`] and will be set to the
48    /// #GDBusConnection obtained by calling g_bus_get() with the value
49    /// of this property.
50    ///
51    /// Writable | Construct Only
52    ///
53    ///
54    /// #### `connection`
55    ///  The #GDBusConnection to use.
56    ///
57    /// Readable | Writable | Construct Only
58    ///
59    ///
60    /// #### `flags`
61    ///  Flags from the #GDBusObjectManagerClientFlags enumeration.
62    ///
63    /// Readable | Writable | Construct Only
64    ///
65    ///
66    /// #### `get-proxy-type-destroy-notify`
67    ///  A #GDestroyNotify for the #gpointer user_data in #GDBusObjectManagerClient:get-proxy-type-user-data.
68    ///
69    /// Readable | Writable | Construct Only
70    ///
71    ///
72    /// #### `get-proxy-type-func`
73    ///  The #GDBusProxyTypeFunc to use when determining what #GType to
74    /// use for interface proxies or [`None`].
75    ///
76    /// Readable | Writable | Construct Only
77    ///
78    ///
79    /// #### `get-proxy-type-user-data`
80    ///  The #gpointer user_data to pass to #GDBusObjectManagerClient:get-proxy-type-func.
81    ///
82    /// Readable | Writable | Construct Only
83    ///
84    ///
85    /// #### `name`
86    ///  The well-known name or unique name that the manager is for.
87    ///
88    /// Readable | Writable | Construct Only
89    ///
90    ///
91    /// #### `name-owner`
92    ///  The unique name that owns #GDBusObjectManagerClient:name or [`None`] if
93    /// no-one is currently owning the name. Connect to the
94    /// #GObject::notify signal to track changes to this property.
95    ///
96    /// Readable
97    ///
98    ///
99    /// #### `object-path`
100    ///  The object path the manager is for.
101    ///
102    /// Readable | Writable | Construct Only
103    ///
104    /// ## Signals
105    ///
106    ///
107    /// #### `interface-proxy-properties-changed`
108    ///  Emitted when one or more D-Bus properties on proxy changes. The
109    /// local cache has already been updated when this signal fires. Note
110    /// that both @changed_properties and @invalidated_properties are
111    /// guaranteed to never be [`None`] (either may be empty though).
112    ///
113    /// This signal exists purely as a convenience to avoid having to
114    /// connect signals to all interface proxies managed by @manager.
115    ///
116    /// This signal is emitted in the thread-default main context
117    /// (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()])
118    /// that @manager was constructed in.
119    ///
120    ///
121    ///
122    ///
123    /// #### `interface-proxy-signal`
124    ///  Emitted when a D-Bus signal is received on @interface_proxy.
125    ///
126    /// This signal exists purely as a convenience to avoid having to
127    /// connect signals to all interface proxies managed by @manager.
128    ///
129    /// This signal is emitted in the thread-default main context
130    /// (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()])
131    /// that @manager was constructed in.
132    ///
133    ///
134    /// <details><summary><h4>DBusObjectManager</h4></summary>
135    ///
136    ///
137    /// #### `interface-added`
138    ///  Emitted when @interface is added to @object.
139    ///
140    /// This signal exists purely as a convenience to avoid having to
141    /// connect signals to all objects managed by @manager.
142    ///
143    ///
144    ///
145    ///
146    /// #### `interface-removed`
147    ///  Emitted when @interface has been removed from @object.
148    ///
149    /// This signal exists purely as a convenience to avoid having to
150    /// connect signals to all objects managed by @manager.
151    ///
152    ///
153    ///
154    ///
155    /// #### `object-added`
156    ///  Emitted when @object is added to @manager.
157    ///
158    ///
159    ///
160    ///
161    /// #### `object-removed`
162    ///  Emitted when @object is removed from @manager.
163    ///
164    ///
165    /// </details>
166    ///
167    /// # Implements
168    ///
169    /// [`DBusObjectManagerClientExt`][trait@crate::prelude::DBusObjectManagerClientExt], [`trait@glib::ObjectExt`], [`AsyncInitableExt`][trait@crate::prelude::AsyncInitableExt], [`DBusObjectManagerExt`][trait@crate::prelude::DBusObjectManagerExt], [`InitableExt`][trait@crate::prelude::InitableExt], [`DBusObjectManagerClientExtManual`][trait@crate::prelude::DBusObjectManagerClientExtManual]
170    #[doc(alias = "GDBusObjectManagerClient")]
171    pub struct DBusObjectManagerClient(Object<ffi::GDBusObjectManagerClient, ffi::GDBusObjectManagerClientClass>) @implements AsyncInitable, DBusObjectManager, Initable;
172
173    match fn {
174        type_ => || ffi::g_dbus_object_manager_client_get_type(),
175    }
176}
177
178impl DBusObjectManagerClient {
179    pub const NONE: Option<&'static DBusObjectManagerClient> = None;
180
181    /// Like g_dbus_object_manager_client_new_sync() but takes a #GBusType instead
182    /// of a #GDBusConnection.
183    ///
184    /// This is a synchronous failable constructor - the calling thread is
185    /// blocked until a reply is received. See g_dbus_object_manager_client_new_for_bus()
186    /// for the asynchronous version.
187    /// ## `bus_type`
188    /// A #GBusType.
189    /// ## `flags`
190    /// Zero or more flags from the #GDBusObjectManagerClientFlags enumeration.
191    /// ## `name`
192    /// The owner of the control object (unique or well-known name).
193    /// ## `object_path`
194    /// The object path of the control object.
195    /// ## `get_proxy_type_func`
196    /// A #GDBusProxyTypeFunc function or [`None`] to always construct #GDBusProxy proxies.
197    /// ## `get_proxy_type_user_data`
198    /// User data to pass to @get_proxy_type_func.
199    /// ## `get_proxy_type_destroy_notify`
200    /// Free function for @get_proxy_type_user_data or [`None`].
201    /// ## `cancellable`
202    /// A #GCancellable or [`None`]
203    ///
204    /// # Returns
205    ///
206    /// A
207    ///   #GDBusObjectManagerClient object or [`None`] if @error is set. Free
208    ///   with g_object_unref().
209    #[doc(alias = "g_dbus_object_manager_client_new_for_bus_sync")]
210    #[doc(alias = "new_for_bus_sync")]
211    #[allow(dead_code)]
212    pub(crate) fn for_bus_sync_impl(
213        bus_type: BusType,
214        flags: DBusObjectManagerClientFlags,
215        name: &str,
216        object_path: &str,
217        get_proxy_type_func: Option<
218            Box_<
219                dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + 'static,
220            >,
221        >,
222        cancellable: Option<&impl IsA<Cancellable>>,
223    ) -> Result<DBusObjectManagerClient, glib::Error> {
224        let get_proxy_type_func_data: Box_<
225            Option<
226                Box_<
227                    dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type
228                        + 'static,
229                >,
230            >,
231        > = Box_::new(get_proxy_type_func);
232        unsafe extern "C" fn get_proxy_type_func_func(
233            manager: *mut ffi::GDBusObjectManagerClient,
234            object_path: *const std::ffi::c_char,
235            interface_name: *const std::ffi::c_char,
236            data: glib::ffi::gpointer,
237        ) -> glib::ffi::GType {
238            unsafe {
239                let manager = from_glib_borrow(manager);
240                let object_path: Borrowed<glib::GString> = from_glib_borrow(object_path);
241                let interface_name: Borrowed<Option<glib::GString>> =
242                    from_glib_borrow(interface_name);
243                let callback = &*(data as *mut Option<
244                    Box_<
245                        dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type
246                            + 'static,
247                    >,
248                >);
249                if let Some(ref callback) = *callback {
250                    callback(
251                        &manager,
252                        object_path.as_str(),
253                        (*interface_name).as_ref().map(|s| s.as_str()),
254                    )
255                } else {
256                    panic!("cannot get closure...")
257                }
258                .into_glib()
259            }
260        }
261        let get_proxy_type_func = if get_proxy_type_func_data.is_some() {
262            Some(get_proxy_type_func_func as _)
263        } else {
264            None
265        };
266        unsafe extern "C" fn get_proxy_type_destroy_notify_func(data: glib::ffi::gpointer) {
267            unsafe {
268                let _callback = Box_::from_raw(
269                    data as *mut Option<
270                        Box_<
271                            dyn Fn(
272                                    &DBusObjectManagerClient,
273                                    &str,
274                                    Option<&str>,
275                                ) -> glib::types::Type
276                                + 'static,
277                        >,
278                    >,
279                );
280            }
281        }
282        let destroy_call6 = Some(get_proxy_type_destroy_notify_func as _);
283        let super_callback0: Box_<
284            Option<
285                Box_<
286                    dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type
287                        + 'static,
288                >,
289            >,
290        > = get_proxy_type_func_data;
291        unsafe {
292            let mut error = std::ptr::null_mut();
293            let ret = ffi::g_dbus_object_manager_client_new_for_bus_sync(
294                bus_type.into_glib(),
295                flags.into_glib(),
296                name.to_glib_none().0,
297                object_path.to_glib_none().0,
298                get_proxy_type_func,
299                Box_::into_raw(super_callback0) as *mut _,
300                destroy_call6,
301                cancellable.map(|p| p.as_ref()).to_glib_none().0,
302                &mut error,
303            );
304            if error.is_null() {
305                Ok(from_glib_full(ret))
306            } else {
307                Err(from_glib_full(error))
308            }
309        }
310    }
311
312    /// Creates a new #GDBusObjectManagerClient object.
313    ///
314    /// This is a synchronous failable constructor - the calling thread is
315    /// blocked until a reply is received. See g_dbus_object_manager_client_new()
316    /// for the asynchronous version.
317    /// ## `connection`
318    /// A #GDBusConnection.
319    /// ## `flags`
320    /// Zero or more flags from the #GDBusObjectManagerClientFlags enumeration.
321    /// ## `name`
322    /// The owner of the control object (unique or well-known name), or [`None`] when not using a message bus connection.
323    /// ## `object_path`
324    /// The object path of the control object.
325    /// ## `get_proxy_type_func`
326    /// A #GDBusProxyTypeFunc function or [`None`] to always construct #GDBusProxy proxies.
327    /// ## `get_proxy_type_user_data`
328    /// User data to pass to @get_proxy_type_func.
329    /// ## `get_proxy_type_destroy_notify`
330    /// Free function for @get_proxy_type_user_data or [`None`].
331    /// ## `cancellable`
332    /// A #GCancellable or [`None`]
333    ///
334    /// # Returns
335    ///
336    /// A
337    ///   #GDBusObjectManagerClient object or [`None`] if @error is set. Free
338    ///   with g_object_unref().
339    #[doc(alias = "g_dbus_object_manager_client_new_sync")]
340    #[doc(alias = "new_sync")]
341    #[allow(dead_code)]
342    pub(crate) fn new_sync_impl(
343        connection: &DBusConnection,
344        flags: DBusObjectManagerClientFlags,
345        name: Option<&str>,
346        object_path: &str,
347        get_proxy_type_func: Option<
348            Box_<
349                dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type + 'static,
350            >,
351        >,
352        cancellable: Option<&impl IsA<Cancellable>>,
353    ) -> Result<DBusObjectManagerClient, glib::Error> {
354        let get_proxy_type_func_data: Box_<
355            Option<
356                Box_<
357                    dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type
358                        + 'static,
359                >,
360            >,
361        > = Box_::new(get_proxy_type_func);
362        unsafe extern "C" fn get_proxy_type_func_func(
363            manager: *mut ffi::GDBusObjectManagerClient,
364            object_path: *const std::ffi::c_char,
365            interface_name: *const std::ffi::c_char,
366            data: glib::ffi::gpointer,
367        ) -> glib::ffi::GType {
368            unsafe {
369                let manager = from_glib_borrow(manager);
370                let object_path: Borrowed<glib::GString> = from_glib_borrow(object_path);
371                let interface_name: Borrowed<Option<glib::GString>> =
372                    from_glib_borrow(interface_name);
373                let callback = &*(data as *mut Option<
374                    Box_<
375                        dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type
376                            + 'static,
377                    >,
378                >);
379                if let Some(ref callback) = *callback {
380                    callback(
381                        &manager,
382                        object_path.as_str(),
383                        (*interface_name).as_ref().map(|s| s.as_str()),
384                    )
385                } else {
386                    panic!("cannot get closure...")
387                }
388                .into_glib()
389            }
390        }
391        let get_proxy_type_func = if get_proxy_type_func_data.is_some() {
392            Some(get_proxy_type_func_func as _)
393        } else {
394            None
395        };
396        unsafe extern "C" fn get_proxy_type_destroy_notify_func(data: glib::ffi::gpointer) {
397            unsafe {
398                let _callback = Box_::from_raw(
399                    data as *mut Option<
400                        Box_<
401                            dyn Fn(
402                                    &DBusObjectManagerClient,
403                                    &str,
404                                    Option<&str>,
405                                ) -> glib::types::Type
406                                + 'static,
407                        >,
408                    >,
409                );
410            }
411        }
412        let destroy_call6 = Some(get_proxy_type_destroy_notify_func as _);
413        let super_callback0: Box_<
414            Option<
415                Box_<
416                    dyn Fn(&DBusObjectManagerClient, &str, Option<&str>) -> glib::types::Type
417                        + 'static,
418                >,
419            >,
420        > = get_proxy_type_func_data;
421        unsafe {
422            let mut error = std::ptr::null_mut();
423            let ret = ffi::g_dbus_object_manager_client_new_sync(
424                connection.to_glib_none().0,
425                flags.into_glib(),
426                name.to_glib_none().0,
427                object_path.to_glib_none().0,
428                get_proxy_type_func,
429                Box_::into_raw(super_callback0) as *mut _,
430                destroy_call6,
431                cancellable.map(|p| p.as_ref()).to_glib_none().0,
432                &mut error,
433            );
434            if error.is_null() {
435                Ok(from_glib_full(ret))
436            } else {
437                Err(from_glib_full(error))
438            }
439        }
440    }
441}
442
443impl std::fmt::Display for DBusObjectManagerClient {
444    #[inline]
445    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
446        f.write_str(&DBusObjectManagerClientExt::name(self))
447    }
448}
449
450unsafe impl Send for DBusObjectManagerClient {}
451unsafe impl Sync for DBusObjectManagerClient {}
452
453/// Trait containing all [`struct@DBusObjectManagerClient`] methods.
454///
455/// # Implementors
456///
457/// [`DBusObjectManagerClient`][struct@crate::DBusObjectManagerClient]
458pub trait DBusObjectManagerClientExt: IsA<DBusObjectManagerClient> + 'static {
459    /// Gets the #GDBusConnection used by @self.
460    ///
461    /// # Returns
462    ///
463    /// A #GDBusConnection object. Do not free,
464    ///   the object belongs to @self.
465    #[doc(alias = "g_dbus_object_manager_client_get_connection")]
466    #[doc(alias = "get_connection")]
467    fn connection(&self) -> DBusConnection {
468        unsafe {
469            from_glib_none(ffi::g_dbus_object_manager_client_get_connection(
470                self.as_ref().to_glib_none().0,
471            ))
472        }
473    }
474
475    /// Gets the flags that @self was constructed with.
476    ///
477    /// # Returns
478    ///
479    /// Zero of more flags from the #GDBusObjectManagerClientFlags
480    /// enumeration.
481    #[doc(alias = "g_dbus_object_manager_client_get_flags")]
482    #[doc(alias = "get_flags")]
483    fn flags(&self) -> DBusObjectManagerClientFlags {
484        unsafe {
485            from_glib(ffi::g_dbus_object_manager_client_get_flags(
486                self.as_ref().to_glib_none().0,
487            ))
488        }
489    }
490
491    /// Gets the name that @self is for, or [`None`] if not a message bus
492    /// connection.
493    ///
494    /// # Returns
495    ///
496    /// A unique or well-known name. Do not free, the string
497    /// belongs to @self.
498    #[doc(alias = "g_dbus_object_manager_client_get_name")]
499    #[doc(alias = "get_name")]
500    fn name(&self) -> glib::GString {
501        unsafe {
502            from_glib_none(ffi::g_dbus_object_manager_client_get_name(
503                self.as_ref().to_glib_none().0,
504            ))
505        }
506    }
507
508    /// The unique name that owns the name that @self is for or [`None`] if
509    /// no-one currently owns that name. You can connect to the
510    /// #GObject::notify signal to track changes to the
511    /// #GDBusObjectManagerClient:name-owner property.
512    ///
513    /// # Returns
514    ///
515    /// The name owner or [`None`] if no name owner
516    /// exists. Free with g_free().
517    #[doc(alias = "g_dbus_object_manager_client_get_name_owner")]
518    #[doc(alias = "get_name_owner")]
519    #[doc(alias = "name-owner")]
520    fn name_owner(&self) -> Option<glib::GString> {
521        unsafe {
522            from_glib_full(ffi::g_dbus_object_manager_client_get_name_owner(
523                self.as_ref().to_glib_none().0,
524            ))
525        }
526    }
527
528    /// Emitted when a D-Bus signal is received on @interface_proxy.
529    ///
530    /// This signal exists purely as a convenience to avoid having to
531    /// connect signals to all interface proxies managed by @manager.
532    ///
533    /// This signal is emitted in the thread-default main context
534    /// (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()])
535    /// that @manager was constructed in.
536    /// ## `object_proxy`
537    /// The #GDBusObjectProxy on which an interface is emitting a D-Bus signal.
538    /// ## `interface_proxy`
539    /// The #GDBusProxy that is emitting a D-Bus signal.
540    /// ## `sender_name`
541    /// The sender of the signal or NULL if the connection is not a bus connection.
542    /// ## `signal_name`
543    /// The signal name.
544    /// ## `parameters`
545    /// A #GVariant tuple with parameters for the signal.
546    #[doc(alias = "interface-proxy-signal")]
547    fn connect_interface_proxy_signal<
548        F: Fn(&Self, &DBusObjectProxy, &DBusProxy, &str, &str, &glib::Variant) + Send + Sync + 'static,
549    >(
550        &self,
551        f: F,
552    ) -> SignalHandlerId {
553        unsafe extern "C" fn interface_proxy_signal_trampoline<
554            P: IsA<DBusObjectManagerClient>,
555            F: Fn(&P, &DBusObjectProxy, &DBusProxy, &str, &str, &glib::Variant)
556                + Send
557                + Sync
558                + 'static,
559        >(
560            this: *mut ffi::GDBusObjectManagerClient,
561            object_proxy: *mut ffi::GDBusObjectProxy,
562            interface_proxy: *mut ffi::GDBusProxy,
563            sender_name: *mut std::ffi::c_char,
564            signal_name: *mut std::ffi::c_char,
565            parameters: *mut glib::ffi::GVariant,
566            f: glib::ffi::gpointer,
567        ) {
568            unsafe {
569                let f: &F = &*(f as *const F);
570                f(
571                    DBusObjectManagerClient::from_glib_borrow(this).unsafe_cast_ref(),
572                    &from_glib_borrow(object_proxy),
573                    &from_glib_borrow(interface_proxy),
574                    &glib::GString::from_glib_borrow(sender_name),
575                    &glib::GString::from_glib_borrow(signal_name),
576                    &from_glib_borrow(parameters),
577                )
578            }
579        }
580        unsafe {
581            let f: Box_<F> = Box_::new(f);
582            connect_raw(
583                self.as_ptr() as *mut _,
584                c"interface-proxy-signal".as_ptr(),
585                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
586                    interface_proxy_signal_trampoline::<Self, F> as *const (),
587                )),
588                Box_::into_raw(f),
589            )
590        }
591    }
592
593    #[doc(alias = "name-owner")]
594    fn connect_name_owner_notify<F: Fn(&Self) + Send + Sync + 'static>(
595        &self,
596        f: F,
597    ) -> SignalHandlerId {
598        unsafe extern "C" fn notify_name_owner_trampoline<
599            P: IsA<DBusObjectManagerClient>,
600            F: Fn(&P) + Send + Sync + 'static,
601        >(
602            this: *mut ffi::GDBusObjectManagerClient,
603            _param_spec: glib::ffi::gpointer,
604            f: glib::ffi::gpointer,
605        ) {
606            unsafe {
607                let f: &F = &*(f as *const F);
608                f(DBusObjectManagerClient::from_glib_borrow(this).unsafe_cast_ref())
609            }
610        }
611        unsafe {
612            let f: Box_<F> = Box_::new(f);
613            connect_raw(
614                self.as_ptr() as *mut _,
615                c"notify::name-owner".as_ptr(),
616                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
617                    notify_name_owner_trampoline::<Self, F> as *const (),
618                )),
619                Box_::into_raw(f),
620            )
621        }
622    }
623}
624
625impl<O: IsA<DBusObjectManagerClient>> DBusObjectManagerClientExt for O {}