1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{
    DBusConnection, DBusInterface, DBusInterfaceInfo, DBusInterfaceSkeletonFlags,
    DBusMethodInvocation,
};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Abstract base class for D-Bus interfaces on the service side.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `g-flags`
    ///  Flags from the #GDBusInterfaceSkeletonFlags enumeration.
    ///
    /// Readable | Writeable
    ///
    /// ## Signals
    ///
    ///
    /// #### `g-authorize-method`
    ///  Emitted when a method is invoked by a remote caller and used to
    /// determine if the method call is authorized.
    ///
    /// Note that this signal is emitted in a thread dedicated to
    /// handling the method call so handlers are allowed to perform
    /// blocking IO. This means that it is appropriate to call e.g.
    /// [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
    /// with the
    /// [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
    /// flag set.
    ///
    /// If [`false`] is returned then no further handlers are run and the
    /// signal handler must take a reference to @invocation and finish
    /// handling the call (e.g. return an error via
    /// g_dbus_method_invocation_return_error()).
    ///
    /// Otherwise, if [`true`] is returned, signal emission continues. If no
    /// handlers return [`false`], then the method is dispatched. If
    /// @interface has an enclosing #GDBusObjectSkeleton, then the
    /// #GDBusObjectSkeleton::authorize-method signal handlers run before
    /// the handlers for this signal.
    ///
    /// The default class handler just returns [`true`].
    ///
    /// Please note that the common case is optimized: if no signals
    /// handlers are connected and the default class handler isn't
    /// overridden (for both @interface and the enclosing
    /// #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
    /// not have the
    /// [`DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD`][crate::DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD]
    /// flags set, no dedicated thread is ever used and the call will be
    /// handled in the same thread as the object that @interface belongs
    /// to was exported in.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`DBusInterfaceSkeletonExt`][trait@crate::prelude::DBusInterfaceSkeletonExt], [`trait@glib::ObjectExt`], [`DBusInterfaceExt`][trait@crate::prelude::DBusInterfaceExt]
    #[doc(alias = "GDBusInterfaceSkeleton")]
    pub struct DBusInterfaceSkeleton(Object<ffi::GDBusInterfaceSkeleton, ffi::GDBusInterfaceSkeletonClass>) @implements DBusInterface;

    match fn {
        type_ => || ffi::g_dbus_interface_skeleton_get_type(),
    }
}

impl DBusInterfaceSkeleton {
    pub const NONE: Option<&'static DBusInterfaceSkeleton> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::DBusInterfaceSkeleton>> Sealed for T {}
}

/// Trait containing all [`struct@DBusInterfaceSkeleton`] methods.
///
/// # Implementors
///
/// [`DBusInterfaceSkeleton`][struct@crate::DBusInterfaceSkeleton]
pub trait DBusInterfaceSkeletonExt: IsA<DBusInterfaceSkeleton> + sealed::Sealed + 'static {
    /// Exports @self at @object_path on @connection.
    ///
    /// This can be called multiple times to export the same @self
    /// onto multiple connections however the @object_path provided must be
    /// the same for all connections.
    ///
    /// Use g_dbus_interface_skeleton_unexport() to unexport the object.
    /// ## `connection`
    /// A #GDBusConnection to export @self on.
    /// ## `object_path`
    /// The path to export the interface at.
    ///
    /// # Returns
    ///
    /// [`true`] if the interface was exported on @connection, otherwise [`false`] with
    /// @error set.
    #[doc(alias = "g_dbus_interface_skeleton_export")]
    fn export(&self, connection: &DBusConnection, object_path: &str) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::g_dbus_interface_skeleton_export(
                self.as_ref().to_glib_none().0,
                connection.to_glib_none().0,
                object_path.to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// If @self has outstanding changes, request for these changes to be
    /// emitted immediately.
    ///
    /// For example, an exported D-Bus interface may queue up property
    /// changes and emit the
    /// `org.freedesktop.DBus.Properties.PropertiesChanged`
    /// signal later (e.g. in an idle handler). This technique is useful
    /// for collapsing multiple property changes into one.
    #[doc(alias = "g_dbus_interface_skeleton_flush")]
    fn flush(&self) {
        unsafe {
            ffi::g_dbus_interface_skeleton_flush(self.as_ref().to_glib_none().0);
        }
    }

    /// Gets the first connection that @self is exported on, if any.
    ///
    /// # Returns
    ///
    /// A #GDBusConnection or [`None`] if @self is
    /// not exported anywhere. Do not free, the object belongs to @self.
    #[doc(alias = "g_dbus_interface_skeleton_get_connection")]
    #[doc(alias = "get_connection")]
    fn connection(&self) -> Option<DBusConnection> {
        unsafe {
            from_glib_none(ffi::g_dbus_interface_skeleton_get_connection(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets a list of the connections that @self is exported on.
    ///
    /// # Returns
    ///
    /// A list of
    ///   all the connections that @self is exported on. The returned
    ///   list should be freed with g_list_free() after each element has
    ///   been freed with g_object_unref().
    #[doc(alias = "g_dbus_interface_skeleton_get_connections")]
    #[doc(alias = "get_connections")]
    fn connections(&self) -> Vec<DBusConnection> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::g_dbus_interface_skeleton_get_connections(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the #GDBusInterfaceSkeletonFlags that describes what the behavior
    /// of @self
    ///
    /// # Returns
    ///
    /// One or more flags from the #GDBusInterfaceSkeletonFlags enumeration.
    #[doc(alias = "g_dbus_interface_skeleton_get_flags")]
    #[doc(alias = "get_flags")]
    fn flags(&self) -> DBusInterfaceSkeletonFlags {
        unsafe {
            from_glib(ffi::g_dbus_interface_skeleton_get_flags(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets D-Bus introspection information for the D-Bus interface
    /// implemented by @self.
    ///
    /// # Returns
    ///
    /// A #GDBusInterfaceInfo (never [`None`]). Do not free.
    #[doc(alias = "g_dbus_interface_skeleton_get_info")]
    #[doc(alias = "get_info")]
    fn info(&self) -> DBusInterfaceInfo {
        unsafe {
            from_glib_none(ffi::g_dbus_interface_skeleton_get_info(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the object path that @self is exported on, if any.
    ///
    /// # Returns
    ///
    /// A string owned by @self or [`None`] if @self is not exported
    /// anywhere. Do not free, the string belongs to @self.
    #[doc(alias = "g_dbus_interface_skeleton_get_object_path")]
    #[doc(alias = "get_object_path")]
    fn object_path(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::g_dbus_interface_skeleton_get_object_path(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets all D-Bus properties for @self.
    ///
    /// # Returns
    ///
    /// A #GVariant of type
    /// ['a{sv}'][G-VARIANT-TYPE-VARDICT:CAPS].
    /// Free with g_variant_unref().
    #[doc(alias = "g_dbus_interface_skeleton_get_properties")]
    #[doc(alias = "get_properties")]
    fn properties(&self) -> glib::Variant {
        unsafe {
            from_glib_full(ffi::g_dbus_interface_skeleton_get_properties(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //#[doc(alias = "g_dbus_interface_skeleton_get_vtable")]
    //#[doc(alias = "get_vtable")]
    //fn vtable(&self) -> /*Ignored*/DBusInterfaceVTable {
    //    unsafe { TODO: call ffi:g_dbus_interface_skeleton_get_vtable() }
    //}

    /// Checks if @self is exported on @connection.
    /// ## `connection`
    /// A #GDBusConnection.
    ///
    /// # Returns
    ///
    /// [`true`] if @self is exported on @connection, [`false`] otherwise.
    #[doc(alias = "g_dbus_interface_skeleton_has_connection")]
    fn has_connection(&self, connection: &DBusConnection) -> bool {
        unsafe {
            from_glib(ffi::g_dbus_interface_skeleton_has_connection(
                self.as_ref().to_glib_none().0,
                connection.to_glib_none().0,
            ))
        }
    }

    /// Sets flags describing what the behavior of @skeleton should be.
    /// ## `flags`
    /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
    #[doc(alias = "g_dbus_interface_skeleton_set_flags")]
    fn set_flags(&self, flags: DBusInterfaceSkeletonFlags) {
        unsafe {
            ffi::g_dbus_interface_skeleton_set_flags(
                self.as_ref().to_glib_none().0,
                flags.into_glib(),
            );
        }
    }

    /// Stops exporting @self on all connections it is exported on.
    ///
    /// To unexport @self from only a single connection, use
    /// g_dbus_interface_skeleton_unexport_from_connection()
    #[doc(alias = "g_dbus_interface_skeleton_unexport")]
    fn unexport(&self) {
        unsafe {
            ffi::g_dbus_interface_skeleton_unexport(self.as_ref().to_glib_none().0);
        }
    }

    /// Stops exporting @self on @connection.
    ///
    /// To stop exporting on all connections the interface is exported on,
    /// use g_dbus_interface_skeleton_unexport().
    /// ## `connection`
    /// A #GDBusConnection.
    #[doc(alias = "g_dbus_interface_skeleton_unexport_from_connection")]
    fn unexport_from_connection(&self, connection: &DBusConnection) {
        unsafe {
            ffi::g_dbus_interface_skeleton_unexport_from_connection(
                self.as_ref().to_glib_none().0,
                connection.to_glib_none().0,
            );
        }
    }

    /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
    #[doc(alias = "g-flags")]
    fn g_flags(&self) -> DBusInterfaceSkeletonFlags {
        ObjectExt::property(self.as_ref(), "g-flags")
    }

    /// Flags from the #GDBusInterfaceSkeletonFlags enumeration.
    #[doc(alias = "g-flags")]
    fn set_g_flags(&self, g_flags: DBusInterfaceSkeletonFlags) {
        ObjectExt::set_property(self.as_ref(), "g-flags", g_flags)
    }

    /// Emitted when a method is invoked by a remote caller and used to
    /// determine if the method call is authorized.
    ///
    /// Note that this signal is emitted in a thread dedicated to
    /// handling the method call so handlers are allowed to perform
    /// blocking IO. This means that it is appropriate to call e.g.
    /// [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
    /// with the
    /// [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
    /// flag set.
    ///
    /// If [`false`] is returned then no further handlers are run and the
    /// signal handler must take a reference to @invocation and finish
    /// handling the call (e.g. return an error via
    /// g_dbus_method_invocation_return_error()).
    ///
    /// Otherwise, if [`true`] is returned, signal emission continues. If no
    /// handlers return [`false`], then the method is dispatched. If
    /// @interface has an enclosing #GDBusObjectSkeleton, then the
    /// #GDBusObjectSkeleton::authorize-method signal handlers run before
    /// the handlers for this signal.
    ///
    /// The default class handler just returns [`true`].
    ///
    /// Please note that the common case is optimized: if no signals
    /// handlers are connected and the default class handler isn't
    /// overridden (for both @interface and the enclosing
    /// #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
    /// not have the
    /// [`DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD`][crate::DBusInterfaceSkeletonFlags::HANDLE_METHOD_INVOCATIONS_IN_THREAD]
    /// flags set, no dedicated thread is ever used and the call will be
    /// handled in the same thread as the object that @interface belongs
    /// to was exported in.
    /// ## `invocation`
    /// A #GDBusMethodInvocation.
    ///
    /// # Returns
    ///
    /// [`true`] if the call is authorized, [`false`] otherwise.
    #[doc(alias = "g-authorize-method")]
    fn connect_g_authorize_method<F: Fn(&Self, &DBusMethodInvocation) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn g_authorize_method_trampoline<
            P: IsA<DBusInterfaceSkeleton>,
            F: Fn(&P, &DBusMethodInvocation) -> bool + 'static,
        >(
            this: *mut ffi::GDBusInterfaceSkeleton,
            invocation: *mut ffi::GDBusMethodInvocation,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                DBusInterfaceSkeleton::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(invocation),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"g-authorize-method\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    g_authorize_method_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "g-flags")]
    fn connect_g_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_g_flags_trampoline<
            P: IsA<DBusInterfaceSkeleton>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GDBusInterfaceSkeleton,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(DBusInterfaceSkeleton::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::g-flags\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_g_flags_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<DBusInterfaceSkeleton>> DBusInterfaceSkeletonExt for O {}