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
87mod sealed {
88 pub trait Sealed {}
89 impl<T: super::IsA<super::DBusObjectManagerServer>> Sealed for T {}
90}
91
92/// Trait containing all [`struct@DBusObjectManagerServer`] methods.
93///
94/// # Implementors
95///
96/// [`DBusObjectManagerServer`][struct@crate::DBusObjectManagerServer]
97pub trait DBusObjectManagerServerExt:
98 IsA<DBusObjectManagerServer> + sealed::Sealed + 'static
99{
100 /// Exports @object on @self.
101 ///
102 /// If there is already a #GDBusObject exported at the object path,
103 /// then the old object is removed.
104 ///
105 /// The object path for @object must be in the hierarchy rooted by the
106 /// object path for @self.
107 ///
108 /// Note that @self will take a reference on @object for as long as
109 /// it is exported.
110 /// ## `object`
111 /// A #GDBusObjectSkeleton.
112 #[doc(alias = "g_dbus_object_manager_server_export")]
113 fn export(&self, object: &impl IsA<DBusObjectSkeleton>) {
114 unsafe {
115 ffi::g_dbus_object_manager_server_export(
116 self.as_ref().to_glib_none().0,
117 object.as_ref().to_glib_none().0,
118 );
119 }
120 }
121
122 /// Like g_dbus_object_manager_server_export() but appends a string of
123 /// the form _N (with N being a natural number) to @object's object path
124 /// if an object with the given path already exists. As such, the
125 /// #GDBusObjectProxy:g-object-path property of @object may be modified.
126 /// ## `object`
127 /// An object.
128 #[doc(alias = "g_dbus_object_manager_server_export_uniquely")]
129 fn export_uniquely(&self, object: &impl IsA<DBusObjectSkeleton>) {
130 unsafe {
131 ffi::g_dbus_object_manager_server_export_uniquely(
132 self.as_ref().to_glib_none().0,
133 object.as_ref().to_glib_none().0,
134 );
135 }
136 }
137
138 /// Gets the #GDBusConnection used by @self.
139 ///
140 /// # Returns
141 ///
142 /// A #GDBusConnection object or [`None`] if
143 /// @self isn't exported on a connection. The returned object should
144 /// be freed with g_object_unref().
145 #[doc(alias = "g_dbus_object_manager_server_get_connection")]
146 #[doc(alias = "get_connection")]
147 fn connection(&self) -> Option<DBusConnection> {
148 unsafe {
149 from_glib_full(ffi::g_dbus_object_manager_server_get_connection(
150 self.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 /// Returns whether @object is currently exported on @self.
156 /// ## `object`
157 /// An object.
158 ///
159 /// # Returns
160 ///
161 /// [`true`] if @object is exported
162 #[doc(alias = "g_dbus_object_manager_server_is_exported")]
163 fn is_exported(&self, object: &impl IsA<DBusObjectSkeleton>) -> bool {
164 unsafe {
165 from_glib(ffi::g_dbus_object_manager_server_is_exported(
166 self.as_ref().to_glib_none().0,
167 object.as_ref().to_glib_none().0,
168 ))
169 }
170 }
171
172 /// Exports all objects managed by @self on @connection. If
173 /// @connection is [`None`], stops exporting objects.
174 /// ## `connection`
175 /// A #GDBusConnection or [`None`].
176 #[doc(alias = "g_dbus_object_manager_server_set_connection")]
177 #[doc(alias = "connection")]
178 fn set_connection(&self, connection: Option<&DBusConnection>) {
179 unsafe {
180 ffi::g_dbus_object_manager_server_set_connection(
181 self.as_ref().to_glib_none().0,
182 connection.to_glib_none().0,
183 );
184 }
185 }
186
187 /// If @self has an object at @path, removes the object. Otherwise
188 /// does nothing.
189 ///
190 /// Note that @object_path must be in the hierarchy rooted by the
191 /// object path for @self.
192 /// ## `object_path`
193 /// An object path.
194 ///
195 /// # Returns
196 ///
197 /// [`true`] if object at @object_path was removed, [`false`] otherwise.
198 #[doc(alias = "g_dbus_object_manager_server_unexport")]
199 fn unexport(&self, object_path: &str) -> bool {
200 unsafe {
201 from_glib(ffi::g_dbus_object_manager_server_unexport(
202 self.as_ref().to_glib_none().0,
203 object_path.to_glib_none().0,
204 ))
205 }
206 }
207
208 #[doc(alias = "connection")]
209 fn connect_connection_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
210 unsafe extern "C" fn notify_connection_trampoline<
211 P: IsA<DBusObjectManagerServer>,
212 F: Fn(&P) + 'static,
213 >(
214 this: *mut ffi::GDBusObjectManagerServer,
215 _param_spec: glib::ffi::gpointer,
216 f: glib::ffi::gpointer,
217 ) {
218 let f: &F = &*(f as *const F);
219 f(DBusObjectManagerServer::from_glib_borrow(this).unsafe_cast_ref())
220 }
221 unsafe {
222 let f: Box_<F> = Box_::new(f);
223 connect_raw(
224 self.as_ptr() as *mut _,
225 b"notify::connection\0".as_ptr() as *const _,
226 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
227 notify_connection_trampoline::<Self, F> as *const (),
228 )),
229 Box_::into_raw(f),
230 )
231 }
232 }
233}
234
235impl<O: IsA<DBusObjectManagerServer>> DBusObjectManagerServerExt for O {}