1// Take a look at the license at the top of the repository in the LICENSE file.
23use std::ffi::CStr;
45use glib::{prelude::*, translate::*};
67use crate::{ffi, DeviceProvider, Plugin, Rank};
89impl DeviceProvider {
10/// Create a new device providerfactory capable of instantiating objects of the
11 /// `type_` and add the factory to `plugin`.
12 /// ## `plugin`
13 /// [`Plugin`][crate::Plugin] to register the device provider with, or [`None`] for
14 /// a static device provider.
15 /// ## `name`
16 /// name of device providers of this type
17 /// ## `rank`
18 /// rank of device provider (higher rank means more importance when autoplugging)
19 /// ## `type_`
20 /// GType of device provider to register
21 ///
22 /// # Returns
23 ///
24 /// [`true`], if the registering succeeded, [`false`] on error
25#[doc(alias = "gst_device_provider_register")]
26pub fn register(
27 plugin: Option<&Plugin>,
28 name: &str,
29 rank: Rank,
30 type_: glib::types::Type,
31 ) -> Result<(), glib::error::BoolError> {
32skip_assert_initialized!();
33unsafe {
34glib::result_from_gboolean!(
35 ffi::gst_device_provider_register(
36 plugin.to_glib_none().0,
37 name.to_glib_none().0,
38 rank.into_glib() as u32,
39 type_.into_glib()
40 ),
41"Failed to register device provider factory"
42)
43 }
44 }
45}
4647mod sealed {
48pub trait Sealed {}
49impl<T: super::IsA<super::DeviceProvider>> Sealed for T {}
50}
5152pub trait DeviceProviderExtManual: sealed::Sealed + IsA<DeviceProvider> + 'static {
53/// Get metadata with `key` in `self`.
54 /// ## `key`
55 /// the key to get
56 ///
57 /// # Returns
58 ///
59 /// the metadata for `key`.
60#[doc(alias = "get_metadata")]
61 #[doc(alias = "gst_device_provider_class_get_metadata")]
62fn metadata<'a>(&self, key: &str) -> Option<&'a str> {
63unsafe {
64self.unsafe_cast_ref::<DeviceProvider>()
65 .class()
66 .metadata(key)
67 }
68 }
6970/// Gets a list of devices that this provider understands. This may actually
71 /// probe the hardware if the provider is not currently started.
72 ///
73 /// If the provider has been started, this will returned the same [`Device`][crate::Device]
74 /// objedcts that have been returned by the `GST_MESSAGE_DEVICE_ADDED` messages.
75 ///
76 /// # Returns
77 ///
78 /// a `GList` of
79 /// [`Device`][crate::Device]
80#[doc(alias = "gst_device_provider_get_devices")]
81 #[doc(alias = "get_devices")]
82fn devices(&self) -> glib::List<crate::Device> {
83unsafe {
84 FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_devices(
85self.as_ref().to_glib_none().0,
86 ))
87 }
88 }
89}
9091impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O {}
9293pub unsafe trait DeviceProviderClassExt {
94/// Get metadata with `key` in `self`.
95 /// ## `key`
96 /// the key to get
97 ///
98 /// # Returns
99 ///
100 /// the metadata for `key`.
101#[doc(alias = "get_metadata")]
102 #[doc(alias = "gst_device_provider_class_get_metadata")]
103fn metadata<'a>(&self, key: &str) -> Option<&'a str> {
104unsafe {
105let klass = self as *const _ as *const ffi::GstDeviceProviderClass;
106107let ptr = ffi::gst_device_provider_class_get_metadata(
108 mut_override(klass),
109 key.to_glib_none().0,
110 );
111112if ptr.is_null() {
113None
114} else {
115Some(CStr::from_ptr(ptr).to_str().unwrap())
116 }
117 }
118 }
119}
120121unsafe impl<T: IsA<DeviceProvider> + glib::object::IsClass> DeviceProviderClassExt
122for glib::object::Class<T>
123{
124}