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
66mod sealed {
67 pub trait Sealed {}
68 impl<T: super::IsA<super::DeviceProvider>> Sealed for T {}
69}
70
71/// Trait containing all [`struct@DeviceProvider`] methods.
72///
73/// # Implementors
74///
75/// [`DeviceProvider`][struct@crate::DeviceProvider]
76pub trait DeviceProviderExt: IsA<DeviceProvider> + sealed::Sealed + 'static {
77 #[doc(alias = "gst_device_provider_can_monitor")]
78 fn can_monitor(&self) -> bool {
79 unsafe {
80 from_glib(ffi::gst_device_provider_can_monitor(
81 self.as_ref().to_glib_none().0,
82 ))
83 }
84 }
85
86 /// Posts a message on the provider's [`Bus`][crate::Bus] to inform applications that
87 /// a new device has been added.
88 ///
89 /// This is for use by subclasses.
90 ///
91 /// `device`'s reference count will be incremented, and any floating reference
92 /// will be removed (see `gst_object_ref_sink()`).
93 /// ## `device`
94 /// a [`Device`][crate::Device] that has been added
95 #[doc(alias = "gst_device_provider_device_add")]
96 fn device_add(&self, device: &impl IsA<Device>) {
97 unsafe {
98 ffi::gst_device_provider_device_add(
99 self.as_ref().to_glib_none().0,
100 device.as_ref().to_glib_none().0,
101 );
102 }
103 }
104
105 /// This function is used when `changed_device` was modified into its new form
106 /// `device`. This will post a `DEVICE_CHANGED` message on the bus to let
107 /// the application know that the device was modified. [`Device`][crate::Device] is immutable
108 /// for MT. safety purposes so this is an "atomic" way of letting the application
109 /// know when a device was modified.
110 /// ## `device`
111 /// the new version of `changed_device`
112 /// ## `changed_device`
113 /// the old version of the device that has been updated
114 #[cfg(feature = "v1_16")]
115 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
116 #[doc(alias = "gst_device_provider_device_changed")]
117 fn device_changed(&self, device: &impl IsA<Device>, changed_device: &impl IsA<Device>) {
118 unsafe {
119 ffi::gst_device_provider_device_changed(
120 self.as_ref().to_glib_none().0,
121 device.as_ref().to_glib_none().0,
122 changed_device.as_ref().to_glib_none().0,
123 );
124 }
125 }
126
127 /// Posts a message on the provider's [`Bus`][crate::Bus] to inform applications that
128 /// a device has been removed.
129 ///
130 /// This is for use by subclasses.
131 /// ## `device`
132 /// a [`Device`][crate::Device] that has been removed
133 #[doc(alias = "gst_device_provider_device_remove")]
134 fn device_remove(&self, device: &impl IsA<Device>) {
135 unsafe {
136 ffi::gst_device_provider_device_remove(
137 self.as_ref().to_glib_none().0,
138 device.as_ref().to_glib_none().0,
139 );
140 }
141 }
142
143 /// Gets the [`Bus`][crate::Bus] of this [`DeviceProvider`][crate::DeviceProvider]
144 ///
145 /// # Returns
146 ///
147 /// a [`Bus`][crate::Bus]
148 #[doc(alias = "gst_device_provider_get_bus")]
149 #[doc(alias = "get_bus")]
150 fn bus(&self) -> Bus {
151 unsafe {
152 from_glib_full(ffi::gst_device_provider_get_bus(
153 self.as_ref().to_glib_none().0,
154 ))
155 }
156 }
157
158 /// Retrieves the factory that was used to create this device provider.
159 ///
160 /// # Returns
161 ///
162 /// the [`DeviceProviderFactory`][crate::DeviceProviderFactory] used for
163 /// creating this device provider. no refcounting is needed.
164 #[doc(alias = "gst_device_provider_get_factory")]
165 #[doc(alias = "get_factory")]
166 fn factory(&self) -> Option<DeviceProviderFactory> {
167 unsafe {
168 from_glib_none(ffi::gst_device_provider_get_factory(
169 self.as_ref().to_glib_none().0,
170 ))
171 }
172 }
173
174 /// Get the provider factory names of the [`DeviceProvider`][crate::DeviceProvider] instances that
175 /// are hidden by `self`.
176 ///
177 /// # Returns
178 ///
179 ///
180 /// a list of hidden providers factory names or [`None`] when
181 /// nothing is hidden by `self`. Free with g_strfreev.
182 #[doc(alias = "gst_device_provider_get_hidden_providers")]
183 #[doc(alias = "get_hidden_providers")]
184 fn hidden_providers(&self) -> Vec<glib::GString> {
185 unsafe {
186 FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_hidden_providers(
187 self.as_ref().to_glib_none().0,
188 ))
189 }
190 }
191
192 /// Make `self` hide the devices from the factory with `name`.
193 ///
194 /// This function is used when `self` will also provide the devices reported
195 /// by provider factory `name`. A monitor should stop monitoring the
196 /// device provider with `name` to avoid duplicate devices.
197 /// ## `name`
198 /// a provider factory name
199 #[doc(alias = "gst_device_provider_hide_provider")]
200 fn hide_provider(&self, name: &str) {
201 unsafe {
202 ffi::gst_device_provider_hide_provider(
203 self.as_ref().to_glib_none().0,
204 name.to_glib_none().0,
205 );
206 }
207 }
208
209 /// This function can be used to know if the `self` was successfully started.
210 #[cfg(feature = "v1_20")]
211 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
212 #[doc(alias = "gst_device_provider_is_started")]
213 fn is_started(&self) -> bool {
214 unsafe {
215 from_glib(ffi::gst_device_provider_is_started(
216 self.as_ref().to_glib_none().0,
217 ))
218 }
219 }
220
221 /// Starts providering the devices. This will cause `GST_MESSAGE_DEVICE_ADDED`
222 /// and `GST_MESSAGE_DEVICE_REMOVED` messages to be posted on the provider's bus
223 /// when devices are added or removed from the system.
224 ///
225 /// Since the [`DeviceProvider`][crate::DeviceProvider] is a singleton,
226 /// [`start()`][Self::start()] may already have been called by another
227 /// user of the object, [`stop()`][Self::stop()] needs to be called the same
228 /// number of times.
229 ///
230 /// After this function has been called, [`DeviceProviderExtManual::devices()`][crate::prelude::DeviceProviderExtManual::devices()] will
231 /// return the same objects that have been received from the
232 /// `GST_MESSAGE_DEVICE_ADDED` messages and will no longer probe.
233 ///
234 /// # Returns
235 ///
236 /// [`true`] if the device providering could be started
237 #[doc(alias = "gst_device_provider_start")]
238 fn start(&self) -> Result<(), glib::error::BoolError> {
239 unsafe {
240 glib::result_from_gboolean!(
241 ffi::gst_device_provider_start(self.as_ref().to_glib_none().0),
242 "Failed to start"
243 )
244 }
245 }
246
247 /// Decreases the use-count by one. If the use count reaches zero, this
248 /// [`DeviceProvider`][crate::DeviceProvider] will stop providering the devices. This needs to be
249 /// called the same number of times that [`start()`][Self::start()] was called.
250 #[doc(alias = "gst_device_provider_stop")]
251 fn stop(&self) {
252 unsafe {
253 ffi::gst_device_provider_stop(self.as_ref().to_glib_none().0);
254 }
255 }
256
257 /// Make `self` unhide the devices from factory `name`.
258 ///
259 /// This function is used when `self` will no longer provide the devices
260 /// reported by provider factory `name`. A monitor should start
261 /// monitoring the devices from provider factory `name` in order to see
262 /// all devices again.
263 /// ## `name`
264 /// a provider factory name
265 #[doc(alias = "gst_device_provider_unhide_provider")]
266 fn unhide_provider(&self, name: &str) {
267 unsafe {
268 ffi::gst_device_provider_unhide_provider(
269 self.as_ref().to_glib_none().0,
270 name.to_glib_none().0,
271 );
272 }
273 }
274
275 #[doc(alias = "provider-hidden")]
276 fn connect_provider_hidden<F: Fn(&Self, &str) + Send + Sync + 'static>(
277 &self,
278 f: F,
279 ) -> SignalHandlerId {
280 unsafe extern "C" fn provider_hidden_trampoline<
281 P: IsA<DeviceProvider>,
282 F: Fn(&P, &str) + Send + Sync + 'static,
283 >(
284 this: *mut ffi::GstDeviceProvider,
285 object: *mut std::ffi::c_char,
286 f: glib::ffi::gpointer,
287 ) {
288 let f: &F = &*(f as *const F);
289 f(
290 DeviceProvider::from_glib_borrow(this).unsafe_cast_ref(),
291 &glib::GString::from_glib_borrow(object),
292 )
293 }
294 unsafe {
295 let f: Box_<F> = Box_::new(f);
296 connect_raw(
297 self.as_ptr() as *mut _,
298 b"provider-hidden\0".as_ptr() as *const _,
299 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
300 provider_hidden_trampoline::<Self, F> as *const (),
301 )),
302 Box_::into_raw(f),
303 )
304 }
305 }
306
307 #[doc(alias = "provider-unhidden")]
308 fn connect_provider_unhidden<F: Fn(&Self, &str) + Send + Sync + 'static>(
309 &self,
310 f: F,
311 ) -> SignalHandlerId {
312 unsafe extern "C" fn provider_unhidden_trampoline<
313 P: IsA<DeviceProvider>,
314 F: Fn(&P, &str) + Send + Sync + 'static,
315 >(
316 this: *mut ffi::GstDeviceProvider,
317 object: *mut std::ffi::c_char,
318 f: glib::ffi::gpointer,
319 ) {
320 let f: &F = &*(f as *const F);
321 f(
322 DeviceProvider::from_glib_borrow(this).unsafe_cast_ref(),
323 &glib::GString::from_glib_borrow(object),
324 )
325 }
326 unsafe {
327 let f: Box_<F> = Box_::new(f);
328 connect_raw(
329 self.as_ptr() as *mut _,
330 b"provider-unhidden\0".as_ptr() as *const _,
331 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
332 provider_unhidden_trampoline::<Self, F> as *const (),
333 )),
334 Box_::into_raw(f),
335 )
336 }
337 }
338}
339
340impl<O: IsA<DeviceProvider>> DeviceProviderExt for O {}