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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::{Bus, Device, DeviceProviderFactory, Object};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// A [`DeviceProvider`][crate::DeviceProvider] subclass is provided by a plugin that handles devices
    /// if there is a way to programmatically list connected devices. It can also
    /// optionally provide updates to the list of connected devices.
    ///
    /// Each [`DeviceProvider`][crate::DeviceProvider] subclass is a singleton, a plugin should
    /// normally provide a single subclass for all devices.
    ///
    /// Applications would normally use a [`DeviceMonitor`][crate::DeviceMonitor] to monitor devices
    /// from all relevant providers.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Signals
    ///
    ///
    /// #### `provider-hidden`
    ///
    ///
    ///
    /// #### `provider-unhidden`
    ///
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `deep-notify`
    ///  The deep notify signal is used to be notified of property changes. It is
    /// typically attached to the toplevel bin to receive notifications from all
    /// the elements contained in that bin.
    ///
    /// Detailed
    /// </details>
    ///
    /// # Implements
    ///
    /// [`DeviceProviderExt`][trait@crate::prelude::DeviceProviderExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`DeviceProviderExtManual`][trait@crate::prelude::DeviceProviderExtManual]
    #[doc(alias = "GstDeviceProvider")]
    pub struct DeviceProvider(Object<ffi::GstDeviceProvider, ffi::GstDeviceProviderClass>) @extends Object;

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

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

unsafe impl Send for DeviceProvider {}
unsafe impl Sync for DeviceProvider {}

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

/// Trait containing all [`struct@DeviceProvider`] methods.
///
/// # Implementors
///
/// [`DeviceProvider`][struct@crate::DeviceProvider]
pub trait DeviceProviderExt: IsA<DeviceProvider> + sealed::Sealed + 'static {
    #[doc(alias = "gst_device_provider_can_monitor")]
    fn can_monitor(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_device_provider_can_monitor(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Posts a message on the provider's [`Bus`][crate::Bus] to inform applications that
    /// a new device has been added.
    ///
    /// This is for use by subclasses.
    ///
    /// `device`'s reference count will be incremented, and any floating reference
    /// will be removed (see `gst_object_ref_sink()`).
    /// ## `device`
    /// a [`Device`][crate::Device] that has been added
    #[doc(alias = "gst_device_provider_device_add")]
    fn device_add(&self, device: &impl IsA<Device>) {
        unsafe {
            ffi::gst_device_provider_device_add(
                self.as_ref().to_glib_none().0,
                device.as_ref().to_glib_none().0,
            );
        }
    }

    /// This function is used when `changed_device` was modified into its new form
    /// `device`. This will post a `DEVICE_CHANGED` message on the bus to let
    /// the application know that the device was modified. [`Device`][crate::Device] is immutable
    /// for MT. safety purposes so this is an "atomic" way of letting the application
    /// know when a device was modified.
    /// ## `device`
    /// the new version of `changed_device`
    /// ## `changed_device`
    /// the old version of the device that has been updated
    #[cfg(feature = "v1_16")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
    #[doc(alias = "gst_device_provider_device_changed")]
    fn device_changed(&self, device: &impl IsA<Device>, changed_device: &impl IsA<Device>) {
        unsafe {
            ffi::gst_device_provider_device_changed(
                self.as_ref().to_glib_none().0,
                device.as_ref().to_glib_none().0,
                changed_device.as_ref().to_glib_none().0,
            );
        }
    }

    /// Posts a message on the provider's [`Bus`][crate::Bus] to inform applications that
    /// a device has been removed.
    ///
    /// This is for use by subclasses.
    /// ## `device`
    /// a [`Device`][crate::Device] that has been removed
    #[doc(alias = "gst_device_provider_device_remove")]
    fn device_remove(&self, device: &impl IsA<Device>) {
        unsafe {
            ffi::gst_device_provider_device_remove(
                self.as_ref().to_glib_none().0,
                device.as_ref().to_glib_none().0,
            );
        }
    }

    /// Gets the [`Bus`][crate::Bus] of this [`DeviceProvider`][crate::DeviceProvider]
    ///
    /// # Returns
    ///
    /// a [`Bus`][crate::Bus]
    #[doc(alias = "gst_device_provider_get_bus")]
    #[doc(alias = "get_bus")]
    fn bus(&self) -> Bus {
        unsafe {
            from_glib_full(ffi::gst_device_provider_get_bus(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Retrieves the factory that was used to create this device provider.
    ///
    /// # Returns
    ///
    /// the [`DeviceProviderFactory`][crate::DeviceProviderFactory] used for
    ///  creating this device provider. no refcounting is needed.
    #[doc(alias = "gst_device_provider_get_factory")]
    #[doc(alias = "get_factory")]
    fn factory(&self) -> Option<DeviceProviderFactory> {
        unsafe {
            from_glib_none(ffi::gst_device_provider_get_factory(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the provider factory names of the [`DeviceProvider`][crate::DeviceProvider] instances that
    /// are hidden by `self`.
    ///
    /// # Returns
    ///
    ///
    ///  a list of hidden providers factory names or [`None`] when
    ///  nothing is hidden by `self`. Free with g_strfreev.
    #[doc(alias = "gst_device_provider_get_hidden_providers")]
    #[doc(alias = "get_hidden_providers")]
    fn hidden_providers(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_hidden_providers(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Make `self` hide the devices from the factory with `name`.
    ///
    /// This function is used when `self` will also provide the devices reported
    /// by provider factory `name`. A monitor should stop monitoring the
    /// device provider with `name` to avoid duplicate devices.
    /// ## `name`
    /// a provider factory name
    #[doc(alias = "gst_device_provider_hide_provider")]
    fn hide_provider(&self, name: &str) {
        unsafe {
            ffi::gst_device_provider_hide_provider(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            );
        }
    }

    /// This function can be used to know if the `self` was successfully started.
    #[cfg(feature = "v1_20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
    #[doc(alias = "gst_device_provider_is_started")]
    fn is_started(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_device_provider_is_started(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Starts providering the devices. This will cause `GST_MESSAGE_DEVICE_ADDED`
    /// and `GST_MESSAGE_DEVICE_REMOVED` messages to be posted on the provider's bus
    /// when devices are added or removed from the system.
    ///
    /// Since the [`DeviceProvider`][crate::DeviceProvider] is a singleton,
    /// [`start()`][Self::start()] may already have been called by another
    /// user of the object, [`stop()`][Self::stop()] needs to be called the same
    /// number of times.
    ///
    /// After this function has been called, [`DeviceProviderExtManual::devices()`][crate::prelude::DeviceProviderExtManual::devices()] will
    /// return the same objects that have been received from the
    /// `GST_MESSAGE_DEVICE_ADDED` messages and will no longer probe.
    ///
    /// # Returns
    ///
    /// [`true`] if the device providering could be started
    #[doc(alias = "gst_device_provider_start")]
    fn start(&self) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::gst_device_provider_start(self.as_ref().to_glib_none().0),
                "Failed to start"
            )
        }
    }

    /// Decreases the use-count by one. If the use count reaches zero, this
    /// [`DeviceProvider`][crate::DeviceProvider] will stop providering the devices. This needs to be
    /// called the same number of times that [`start()`][Self::start()] was called.
    #[doc(alias = "gst_device_provider_stop")]
    fn stop(&self) {
        unsafe {
            ffi::gst_device_provider_stop(self.as_ref().to_glib_none().0);
        }
    }

    /// Make `self` unhide the devices from factory `name`.
    ///
    /// This function is used when `self` will no longer provide the devices
    /// reported by provider factory `name`. A monitor should start
    /// monitoring the devices from provider factory `name` in order to see
    /// all devices again.
    /// ## `name`
    /// a provider factory name
    #[doc(alias = "gst_device_provider_unhide_provider")]
    fn unhide_provider(&self, name: &str) {
        unsafe {
            ffi::gst_device_provider_unhide_provider(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "provider-hidden")]
    fn connect_provider_hidden<F: Fn(&Self, &str) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn provider_hidden_trampoline<
            P: IsA<DeviceProvider>,
            F: Fn(&P, &str) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstDeviceProvider,
            object: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                DeviceProvider::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(object),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"provider-hidden\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    provider_hidden_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "provider-unhidden")]
    fn connect_provider_unhidden<F: Fn(&Self, &str) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn provider_unhidden_trampoline<
            P: IsA<DeviceProvider>,
            F: Fn(&P, &str) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstDeviceProvider,
            object: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                DeviceProvider::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(object),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"provider-unhidden\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    provider_unhidden_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<DeviceProvider>> DeviceProviderExt for O {}