1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ffi::CStr;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{DeviceProvider, Plugin, Rank};
8
9impl DeviceProvider {
10 #[doc(alias = "gst_device_provider_register")]
11 pub fn register(
12 plugin: Option<&Plugin>,
13 name: &str,
14 rank: Rank,
15 type_: glib::types::Type,
16 ) -> Result<(), glib::error::BoolError> {
17 skip_assert_initialized!();
18 unsafe {
19 glib::result_from_gboolean!(
20 ffi::gst_device_provider_register(
21 plugin.to_glib_none().0,
22 name.to_glib_none().0,
23 rank.into_glib() as u32,
24 type_.into_glib()
25 ),
26 "Failed to register device provider factory"
27 )
28 }
29 }
30}
31
32mod sealed {
33 pub trait Sealed {}
34 impl<T: super::IsA<super::DeviceProvider>> Sealed for T {}
35}
36
37pub trait DeviceProviderExtManual: sealed::Sealed + IsA<DeviceProvider> + 'static {
38 #[doc(alias = "get_metadata")]
39 #[doc(alias = "gst_device_provider_class_get_metadata")]
40 fn metadata<'a>(&self, key: &str) -> Option<&'a str> {
41 unsafe {
42 self.unsafe_cast_ref::<DeviceProvider>()
43 .class()
44 .metadata(key)
45 }
46 }
47
48 #[doc(alias = "gst_device_provider_get_devices")]
49 #[doc(alias = "get_devices")]
50 fn devices(&self) -> glib::List<crate::Device> {
51 unsafe {
52 FromGlibPtrContainer::from_glib_full(ptr:ffi::gst_device_provider_get_devices(
53 self.as_ref().to_glib_none().0,
54 ))
55 }
56 }
57}
58
59impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O {}
60
61pub unsafe trait DeviceProviderClassExt {
62 #[doc(alias = "get_metadata")]
63 #[doc(alias = "gst_device_provider_class_get_metadata")]
64 fn metadata<'a>(&self, key: &str) -> Option<&'a str> {
65 unsafe {
66 let klass: *const GstDeviceProviderClass = self as *const _ as *const ffi::GstDeviceProviderClass;
67
68 let ptr: *const i8 = ffi::gst_device_provider_class_get_metadata(
69 klass:mut_override(klass),
70 key:key.to_glib_none().0,
71 );
72
73 if ptr.is_null() {
74 None
75 } else {
76 Some(CStr::from_ptr(ptr).to_str().unwrap())
77 }
78 }
79 }
80}
81
82unsafe impl<T: IsA<DeviceProvider> + glib::object::IsClass> DeviceProviderClassExt
83 for glib::object::Class<T>
84{
85}
86