1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::num::NonZeroU32;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{Caps, DeviceMonitor};
8
9#[derive(Debug, PartialEq, Eq)]
10pub struct DeviceMonitorFilterId(NonZeroU32);
11
12impl IntoGlib for DeviceMonitorFilterId {
13 type GlibType = libc::c_uint;
14
15 #[inline]
16 fn into_glib(self) -> libc::c_uint {
17 self.0.get()
18 }
19}
20
21impl FromGlib<libc::c_uint> for DeviceMonitorFilterId {
22 #[inline]
23 unsafe fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId {
24 skip_assert_initialized!();
25 debug_assert_ne!(val, 0);
26 DeviceMonitorFilterId(NonZeroU32::new_unchecked(val))
27 }
28}
29mod sealed {
30 pub trait Sealed {}
31 impl<T: super::IsA<super::DeviceMonitor>> Sealed for T {}
32}
33
34pub trait DeviceMonitorExtManual: sealed::Sealed + IsA<DeviceMonitor> + 'static {
35 #[doc(alias = "gst_device_monitor_add_filter")]
36 fn add_filter(
37 &self,
38 classes: Option<&str>,
39 caps: Option<&Caps>,
40 ) -> Option<DeviceMonitorFilterId> {
41 let id = unsafe {
42 ffi::gst_device_monitor_add_filter(
43 self.as_ref().to_glib_none().0,
44 classes.to_glib_none().0,
45 caps.to_glib_none().0,
46 )
47 };
48
49 if id == 0 {
50 None
51 } else {
52 Some(unsafe { from_glib(id) })
53 }
54 }
55
56 #[doc(alias = "gst_device_monitor_remove_filter")]
57 fn remove_filter(
58 &self,
59 filter_id: DeviceMonitorFilterId,
60 ) -> Result<(), glib::error::BoolError> {
61 unsafe {
62 glib::result_from_gboolean!(
63 ffi::gst_device_monitor_remove_filter(
64 self.as_ref().to_glib_none().0,
65 filter_id.into_glib()
66 ),
67 "Failed to remove the filter"
68 )
69 }
70 }
71
72 #[doc(alias = "gst_device_monitor_get_devices")]
73 #[doc(alias = "get_devices")]
74 fn devices(&self) -> glib::List<crate::Device> {
75 unsafe {
76 FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_devices(
77 self.as_ref().to_glib_none().0,
78 ))
79 }
80 }
81}
82
83impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {}
84