gio/auto/dbus_object_manager_server.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::{ffi, DBusConnection, DBusObjectManager, DBusObjectSkeleton};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// `GDBusObjectManagerServer` is used to export [`DBusObject`][crate::DBusObject] instances
15 /// using the standardized
16 /// [`org.freedesktop.DBus.ObjectManager`](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager)
17 /// interface. For example, remote D-Bus clients can get all objects
18 /// and properties in a single call. Additionally, any change in the
19 /// object hierarchy is broadcast using signals. This means that D-Bus
20 /// clients can keep caches up to date by only listening to D-Bus
21 /// signals.
22 ///
23 /// The recommended path to export an object manager at is the path form of the
24 /// well-known name of a D-Bus service, or below. For example, if a D-Bus service
25 /// is available at the well-known name `net.example.ExampleService1`, the object
26 /// manager should typically be exported at `/net/example/ExampleService1`, or
27 /// below (to allow for multiple object managers in a service).
28 ///
29 /// It is supported, but not recommended, to export an object manager at the root
30 /// path, `/`.
31 ///
32 /// See `Gio::DBusObjectManagerClient` for the client-side code that is
33 /// intended to be used with `GDBusObjectManagerServer` or any D-Bus
34 /// object implementing the `org.freedesktop.DBus.ObjectManager` interface.
35 ///
36 /// ## Properties
37 ///
38 ///
39 /// #### `connection`
40 /// The #GDBusConnection to export objects on.
41 ///
42 /// Readable | Writeable
43 ///
44 ///
45 /// #### `object-path`
46 /// The object path to register the manager object at.
47 ///
48 /// Readable | Writeable | Construct Only
49 ///
50 /// # Implements
51 ///
52 /// [`DBusObjectManagerServerExt`][trait@crate::prelude::DBusObjectManagerServerExt], [`trait@glib::ObjectExt`], [`DBusObjectManagerExt`][trait@crate::prelude::DBusObjectManagerExt]
53 #[doc(alias = "GDBusObjectManagerServer")]
54 pub struct DBusObjectManagerServer(Object<ffi::GDBusObjectManagerServer, ffi::GDBusObjectManagerServerClass>) @implements DBusObjectManager;
55
56 match fn {
57 type_ => || ffi::g_dbus_object_manager_server_get_type(),
58 }
59}
60
61impl DBusObjectManagerServer {
62 pub const NONE: Option<&'static DBusObjectManagerServer> = None;
63
64 /// Creates a new #GDBusObjectManagerServer object.
65 ///
66 /// The returned server isn't yet exported on any connection. To do so,
67 /// use g_dbus_object_manager_server_set_connection(). Normally you
68 /// want to export all of your objects before doing so to avoid
69 /// [InterfacesAdded](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager)
70 /// signals being emitted.
71 /// ## `object_path`
72 /// The object path to export the manager object at.
73 ///
74 /// # Returns
75 ///
76 /// A #GDBusObjectManagerServer object. Free with g_object_unref().
77 #[doc(alias = "g_dbus_object_manager_server_new")]
78 pub fn new(object_path: &str) -> DBusObjectManagerServer {
79 unsafe {
80 from_glib_full(ffi::g_dbus_object_manager_server_new(
81 object_path.to_glib_none().0,
82 ))
83 }
84 }
85}
86
87/// Trait containing all [`struct@DBusObjectManagerServer`] methods.
88///
89/// # Implementors
90///
91/// [`DBusObjectManagerServer`][struct@crate::DBusObjectManagerServer]
92pub trait DBusObjectManagerServerExt: IsA<DBusObjectManagerServer> + 'static {
93 /// Exports @object on @self.
94 ///
95 /// If there is already a #GDBusObject exported at the object path,
96 /// then the old object is removed.
97 ///
98 /// The object path for @object must be in the hierarchy rooted by the
99 /// object path for @self.
100 ///
101 /// Note that @self will take a reference on @object for as long as
102 /// it is exported.
103 /// ## `object`
104 /// A #GDBusObjectSkeleton.
105 #[doc(alias = "g_dbus_object_manager_server_export")]
106 fn export(&self, object: &impl IsA<DBusObjectSkeleton>) {
107 unsafe {
108 ffi::g_dbus_object_manager_server_export(
109 self.as_ref().to_glib_none().0,
110 object.as_ref().to_glib_none().0,
111 );
112 }
113 }
114
115 /// Like g_dbus_object_manager_server_export() but appends a string of
116 /// the form _N (with N being a natural number) to @object's object path
117 /// if an object with the given path already exists. As such, the
118 /// #GDBusObjectProxy:g-object-path property of @object may be modified.
119 /// ## `object`
120 /// An object.
121 #[doc(alias = "g_dbus_object_manager_server_export_uniquely")]
122 fn export_uniquely(&self, object: &impl IsA<DBusObjectSkeleton>) {
123 unsafe {
124 ffi::g_dbus_object_manager_server_export_uniquely(
125 self.as_ref().to_glib_none().0,
126 object.as_ref().to_glib_none().0,
127 );
128 }
129 }
130
131 /// Gets the #GDBusConnection used by @self.
132 ///
133 /// # Returns
134 ///
135 /// A #GDBusConnection object or [`None`] if
136 /// @self isn't exported on a connection. The returned object should
137 /// be freed with g_object_unref().
138 #[doc(alias = "g_dbus_object_manager_server_get_connection")]
139 #[doc(alias = "get_connection")]
140 fn connection(&self) -> Option<DBusConnection> {
141 unsafe {
142 from_glib_full(ffi::g_dbus_object_manager_server_get_connection(
143 self.as_ref().to_glib_none().0,
144 ))
145 }
146 }
147
148 /// Returns whether @object is currently exported on @self.
149 /// ## `object`
150 /// An object.
151 ///
152 /// # Returns
153 ///
154 /// [`true`] if @object is exported
155 #[doc(alias = "g_dbus_object_manager_server_is_exported")]
156 fn is_exported(&self, object: &impl IsA<DBusObjectSkeleton>) -> bool {
157 unsafe {
158 from_glib(ffi::g_dbus_object_manager_server_is_exported(
159 self.as_ref().to_glib_none().0,
160 object.as_ref().to_glib_none().0,
161 ))
162 }
163 }
164
165 /// Exports all objects managed by @self on @connection. If
166 /// @connection is [`None`], stops exporting objects.
167 /// ## `connection`
168 /// A #GDBusConnection or [`None`].
169 #[doc(alias = "g_dbus_object_manager_server_set_connection")]
170 #[doc(alias = "connection")]
171 fn set_connection(&self, connection: Option<&DBusConnection>) {
172 unsafe {
173 ffi::g_dbus_object_manager_server_set_connection(
174 self.as_ref().to_glib_none().0,
175 connection.to_glib_none().0,
176 );
177 }
178 }
179
180 /// If @self has an object at @path, removes the object. Otherwise
181 /// does nothing.
182 ///
183 /// Note that @object_path must be in the hierarchy rooted by the
184 /// object path for @self.
185 /// ## `object_path`
186 /// An object path.
187 ///
188 /// # Returns
189 ///
190 /// [`true`] if object at @object_path was removed, [`false`] otherwise.
191 #[doc(alias = "g_dbus_object_manager_server_unexport")]
192 fn unexport(&self, object_path: &str) -> bool {
193 unsafe {
194 from_glib(ffi::g_dbus_object_manager_server_unexport(
195 self.as_ref().to_glib_none().0,
196 object_path.to_glib_none().0,
197 ))
198 }
199 }
200
201 #[doc(alias = "connection")]
202 fn connect_connection_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
203 unsafe extern "C" fn notify_connection_trampoline<
204 P: IsA<DBusObjectManagerServer>,
205 F: Fn(&P) + 'static,
206 >(
207 this: *mut ffi::GDBusObjectManagerServer,
208 _param_spec: glib::ffi::gpointer,
209 f: glib::ffi::gpointer,
210 ) {
211 let f: &F = &*(f as *const F);
212 f(DBusObjectManagerServer::from_glib_borrow(this).unsafe_cast_ref())
213 }
214 unsafe {
215 let f: Box_<F> = Box_::new(f);
216 connect_raw(
217 self.as_ptr() as *mut _,
218 c"notify::connection".as_ptr() as *const _,
219 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
220 notify_connection_trampoline::<Self, F> as *const (),
221 )),
222 Box_::into_raw(f),
223 )
224 }
225 }
226}
227
228impl<O: IsA<DBusObjectManagerServer>> DBusObjectManagerServerExt for O {}