gstreamer/auto/
device_provider.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// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, Bus, Device, DeviceProviderFactory, Object};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// A [`DeviceProvider`][crate::DeviceProvider] subclass is provided by a plugin that handles devices
17    /// if there is a way to programmatically list connected devices. It can also
18    /// optionally provide updates to the list of connected devices.
19    ///
20    /// Each [`DeviceProvider`][crate::DeviceProvider] subclass is a singleton, a plugin should
21    /// normally provide a single subclass for all devices.
22    ///
23    /// Applications would normally use a [`DeviceMonitor`][crate::DeviceMonitor] to monitor devices
24    /// from all relevant providers.
25    ///
26    /// This is an Abstract Base Class, you cannot instantiate it.
27    ///
28    /// ## Signals
29    ///
30    ///
31    /// #### `provider-hidden`
32    ///
33    ///
34    ///
35    /// #### `provider-unhidden`
36    ///
37    /// <details><summary><h4>Object</h4></summary>
38    ///
39    ///
40    /// #### `deep-notify`
41    ///  The deep notify signal is used to be notified of property changes. It is
42    /// typically attached to the toplevel bin to receive notifications from all
43    /// the elements contained in that bin.
44    ///
45    /// Detailed
46    /// </details>
47    ///
48    /// # Implements
49    ///
50    /// [`DeviceProviderExt`][trait@crate::prelude::DeviceProviderExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`DeviceProviderExtManual`][trait@crate::prelude::DeviceProviderExtManual]
51    #[doc(alias = "GstDeviceProvider")]
52    pub struct DeviceProvider(Object<ffi::GstDeviceProvider, ffi::GstDeviceProviderClass>) @extends Object;
53
54    match fn {
55        type_ => || ffi::gst_device_provider_get_type(),
56    }
57}
58
59impl DeviceProvider {
60    pub const NONE: Option<&'static DeviceProvider> = None;
61}
62
63unsafe impl Send for DeviceProvider {}
64unsafe impl Sync for DeviceProvider {}
65
66/// Trait containing all [`struct@DeviceProvider`] methods.
67///
68/// # Implementors
69///
70/// [`DeviceProvider`][struct@crate::DeviceProvider]
71pub trait DeviceProviderExt: IsA<DeviceProvider> + 'static {
72    #[doc(alias = "gst_device_provider_can_monitor")]
73    fn can_monitor(&self) -> bool {
74        unsafe {
75            from_glib(ffi::gst_device_provider_can_monitor(
76                self.as_ref().to_glib_none().0,
77            ))
78        }
79    }
80
81    /// Posts a message on the provider's [`Bus`][crate::Bus] to inform applications that
82    /// a new device has been added.
83    ///
84    /// This is for use by subclasses.
85    ///
86    /// `device`'s reference count will be incremented, and any floating reference
87    /// will be removed (see `gst_object_ref_sink()`).
88    /// ## `device`
89    /// a [`Device`][crate::Device] that has been added
90    #[doc(alias = "gst_device_provider_device_add")]
91    fn device_add(&self, device: &impl IsA<Device>) {
92        unsafe {
93            ffi::gst_device_provider_device_add(
94                self.as_ref().to_glib_none().0,
95                device.as_ref().to_glib_none().0,
96            );
97        }
98    }
99
100    /// This function is used when `changed_device` was modified into its new form
101    /// `device`. This will post a `DEVICE_CHANGED` message on the bus to let
102    /// the application know that the device was modified. [`Device`][crate::Device] is immutable
103    /// for MT. safety purposes so this is an "atomic" way of letting the application
104    /// know when a device was modified.
105    /// ## `device`
106    /// the new version of `changed_device`
107    /// ## `changed_device`
108    /// the old version of the device that has been updated
109    #[cfg(feature = "v1_16")]
110    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
111    #[doc(alias = "gst_device_provider_device_changed")]
112    fn device_changed(&self, device: &impl IsA<Device>, changed_device: &impl IsA<Device>) {
113        unsafe {
114            ffi::gst_device_provider_device_changed(
115                self.as_ref().to_glib_none().0,
116                device.as_ref().to_glib_none().0,
117                changed_device.as_ref().to_glib_none().0,
118            );
119        }
120    }
121
122    /// Posts a message on the provider's [`Bus`][crate::Bus] to inform applications that
123    /// a device has been removed.
124    ///
125    /// This is for use by subclasses.
126    /// ## `device`
127    /// a [`Device`][crate::Device] that has been removed
128    #[doc(alias = "gst_device_provider_device_remove")]
129    fn device_remove(&self, device: &impl IsA<Device>) {
130        unsafe {
131            ffi::gst_device_provider_device_remove(
132                self.as_ref().to_glib_none().0,
133                device.as_ref().to_glib_none().0,
134            );
135        }
136    }
137
138    /// Gets the [`Bus`][crate::Bus] of this [`DeviceProvider`][crate::DeviceProvider]
139    ///
140    /// # Returns
141    ///
142    /// a [`Bus`][crate::Bus]
143    #[doc(alias = "gst_device_provider_get_bus")]
144    #[doc(alias = "get_bus")]
145    fn bus(&self) -> Bus {
146        unsafe {
147            from_glib_full(ffi::gst_device_provider_get_bus(
148                self.as_ref().to_glib_none().0,
149            ))
150        }
151    }
152
153    /// Retrieves the factory that was used to create this device provider.
154    ///
155    /// # Returns
156    ///
157    /// the [`DeviceProviderFactory`][crate::DeviceProviderFactory] used for
158    ///  creating this device provider. no refcounting is needed.
159    #[doc(alias = "gst_device_provider_get_factory")]
160    #[doc(alias = "get_factory")]
161    fn factory(&self) -> Option<DeviceProviderFactory> {
162        unsafe {
163            from_glib_none(ffi::gst_device_provider_get_factory(
164                self.as_ref().to_glib_none().0,
165            ))
166        }
167    }
168
169    /// Get the provider factory names of the [`DeviceProvider`][crate::DeviceProvider] instances that
170    /// are hidden by `self`.
171    ///
172    /// # Returns
173    ///
174    ///
175    ///  a list of hidden providers factory names or [`None`] when
176    ///  nothing is hidden by `self`. Free with g_strfreev.
177    #[doc(alias = "gst_device_provider_get_hidden_providers")]
178    #[doc(alias = "get_hidden_providers")]
179    fn hidden_providers(&self) -> Vec<glib::GString> {
180        unsafe {
181            FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_hidden_providers(
182                self.as_ref().to_glib_none().0,
183            ))
184        }
185    }
186
187    /// Make `self` hide the devices from the factory with `name`.
188    ///
189    /// This function is used when `self` will also provide the devices reported
190    /// by provider factory `name`. A monitor should stop monitoring the
191    /// device provider with `name` to avoid duplicate devices.
192    /// ## `name`
193    /// a provider factory name
194    #[doc(alias = "gst_device_provider_hide_provider")]
195    fn hide_provider(&self, name: &str) {
196        unsafe {
197            ffi::gst_device_provider_hide_provider(
198                self.as_ref().to_glib_none().0,
199                name.to_glib_none().0,
200            );
201        }
202    }
203
204    /// This function can be used to know if the `self` was successfully started.
205    #[cfg(feature = "v1_20")]
206    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
207    #[doc(alias = "gst_device_provider_is_started")]
208    fn is_started(&self) -> bool {
209        unsafe {
210            from_glib(ffi::gst_device_provider_is_started(
211                self.as_ref().to_glib_none().0,
212            ))
213        }
214    }
215
216    /// Starts providering the devices. This will cause `GST_MESSAGE_DEVICE_ADDED`
217    /// and `GST_MESSAGE_DEVICE_REMOVED` messages to be posted on the provider's bus
218    /// when devices are added or removed from the system.
219    ///
220    /// Since the [`DeviceProvider`][crate::DeviceProvider] is a singleton,
221    /// [`start()`][Self::start()] may already have been called by another
222    /// user of the object, [`stop()`][Self::stop()] needs to be called the same
223    /// number of times.
224    ///
225    /// After this function has been called, [`DeviceProviderExtManual::devices()`][crate::prelude::DeviceProviderExtManual::devices()] will
226    /// return the same objects that have been received from the
227    /// `GST_MESSAGE_DEVICE_ADDED` messages and will no longer probe.
228    ///
229    /// # Returns
230    ///
231    /// [`true`] if the device providering could be started
232    #[doc(alias = "gst_device_provider_start")]
233    fn start(&self) -> Result<(), glib::error::BoolError> {
234        unsafe {
235            glib::result_from_gboolean!(
236                ffi::gst_device_provider_start(self.as_ref().to_glib_none().0),
237                "Failed to start"
238            )
239        }
240    }
241
242    /// Decreases the use-count by one. If the use count reaches zero, this
243    /// [`DeviceProvider`][crate::DeviceProvider] will stop providering the devices. This needs to be
244    /// called the same number of times that [`start()`][Self::start()] was called.
245    #[doc(alias = "gst_device_provider_stop")]
246    fn stop(&self) {
247        unsafe {
248            ffi::gst_device_provider_stop(self.as_ref().to_glib_none().0);
249        }
250    }
251
252    /// Make `self` unhide the devices from factory `name`.
253    ///
254    /// This function is used when `self` will no longer provide the devices
255    /// reported by provider factory `name`. A monitor should start
256    /// monitoring the devices from provider factory `name` in order to see
257    /// all devices again.
258    /// ## `name`
259    /// a provider factory name
260    #[doc(alias = "gst_device_provider_unhide_provider")]
261    fn unhide_provider(&self, name: &str) {
262        unsafe {
263            ffi::gst_device_provider_unhide_provider(
264                self.as_ref().to_glib_none().0,
265                name.to_glib_none().0,
266            );
267        }
268    }
269
270    #[doc(alias = "provider-hidden")]
271    fn connect_provider_hidden<F: Fn(&Self, &str) + Send + Sync + 'static>(
272        &self,
273        f: F,
274    ) -> SignalHandlerId {
275        unsafe extern "C" fn provider_hidden_trampoline<
276            P: IsA<DeviceProvider>,
277            F: Fn(&P, &str) + Send + Sync + 'static,
278        >(
279            this: *mut ffi::GstDeviceProvider,
280            object: *mut std::ffi::c_char,
281            f: glib::ffi::gpointer,
282        ) {
283            let f: &F = &*(f as *const F);
284            f(
285                DeviceProvider::from_glib_borrow(this).unsafe_cast_ref(),
286                &glib::GString::from_glib_borrow(object),
287            )
288        }
289        unsafe {
290            let f: Box_<F> = Box_::new(f);
291            connect_raw(
292                self.as_ptr() as *mut _,
293                c"provider-hidden".as_ptr() as *const _,
294                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
295                    provider_hidden_trampoline::<Self, F> as *const (),
296                )),
297                Box_::into_raw(f),
298            )
299        }
300    }
301
302    #[doc(alias = "provider-unhidden")]
303    fn connect_provider_unhidden<F: Fn(&Self, &str) + Send + Sync + 'static>(
304        &self,
305        f: F,
306    ) -> SignalHandlerId {
307        unsafe extern "C" fn provider_unhidden_trampoline<
308            P: IsA<DeviceProvider>,
309            F: Fn(&P, &str) + Send + Sync + 'static,
310        >(
311            this: *mut ffi::GstDeviceProvider,
312            object: *mut std::ffi::c_char,
313            f: glib::ffi::gpointer,
314        ) {
315            let f: &F = &*(f as *const F);
316            f(
317                DeviceProvider::from_glib_borrow(this).unsafe_cast_ref(),
318                &glib::GString::from_glib_borrow(object),
319            )
320        }
321        unsafe {
322            let f: Box_<F> = Box_::new(f);
323            connect_raw(
324                self.as_ptr() as *mut _,
325                c"provider-unhidden".as_ptr() as *const _,
326                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
327                    provider_unhidden_trampoline::<Self, F> as *const (),
328                )),
329                Box_::into_raw(f),
330            )
331        }
332    }
333}
334
335impl<O: IsA<DeviceProvider>> DeviceProviderExt for O {}