gstreamer/auto/
device_monitor.rs1use crate::{ffi, Bus, Object};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GstDeviceMonitor")]
16 pub struct DeviceMonitor(Object<ffi::GstDeviceMonitor, ffi::GstDeviceMonitorClass>) @extends Object;
17
18 match fn {
19 type_ => || ffi::gst_device_monitor_get_type(),
20 }
21}
22
23impl DeviceMonitor {
24 pub const NONE: Option<&'static DeviceMonitor> = None;
25
26 #[doc(alias = "gst_device_monitor_new")]
27 pub fn new() -> DeviceMonitor {
28 assert_initialized_main_thread!();
29 unsafe { from_glib_full(ffi::gst_device_monitor_new()) }
30 }
31}
32
33impl Default for DeviceMonitor {
34 fn default() -> Self {
35 Self::new()
36 }
37}
38
39unsafe impl Send for DeviceMonitor {}
40unsafe impl Sync for DeviceMonitor {}
41
42pub trait DeviceMonitorExt: IsA<DeviceMonitor> + 'static {
43 #[doc(alias = "gst_device_monitor_get_bus")]
44 #[doc(alias = "get_bus")]
45 fn bus(&self) -> Bus {
46 unsafe {
47 from_glib_full(ffi::gst_device_monitor_get_bus(
48 self.as_ref().to_glib_none().0,
49 ))
50 }
51 }
52
53 #[doc(alias = "gst_device_monitor_get_providers")]
54 #[doc(alias = "get_providers")]
55 fn providers(&self) -> Vec<glib::GString> {
56 unsafe {
57 FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_providers(
58 self.as_ref().to_glib_none().0,
59 ))
60 }
61 }
62
63 #[doc(alias = "gst_device_monitor_get_show_all_devices")]
64 #[doc(alias = "get_show_all_devices")]
65 fn shows_all_devices(&self) -> bool {
66 unsafe {
67 from_glib(ffi::gst_device_monitor_get_show_all_devices(
68 self.as_ref().to_glib_none().0,
69 ))
70 }
71 }
72
73 #[doc(alias = "gst_device_monitor_set_show_all_devices")]
74 fn set_show_all_devices(&self, show_all: bool) {
75 unsafe {
76 ffi::gst_device_monitor_set_show_all_devices(
77 self.as_ref().to_glib_none().0,
78 show_all.into_glib(),
79 );
80 }
81 }
82
83 #[doc(alias = "gst_device_monitor_start")]
84 fn start(&self) -> Result<(), glib::error::BoolError> {
85 unsafe {
86 glib::result_from_gboolean!(
87 ffi::gst_device_monitor_start(self.as_ref().to_glib_none().0),
88 "Failed to start"
89 )
90 }
91 }
92
93 #[doc(alias = "gst_device_monitor_stop")]
94 fn stop(&self) {
95 unsafe {
96 ffi::gst_device_monitor_stop(self.as_ref().to_glib_none().0);
97 }
98 }
99
100 #[doc(alias = "show-all")]
101 fn shows_all(&self) -> bool {
102 ObjectExt::property(self.as_ref(), "show-all")
103 }
104
105 #[doc(alias = "show-all")]
106 fn set_show_all(&self, show_all: bool) {
107 ObjectExt::set_property(self.as_ref(), "show-all", show_all)
108 }
109
110 #[doc(alias = "show-all")]
111 fn connect_show_all_notify<F: Fn(&Self) + Send + Sync + 'static>(
112 &self,
113 f: F,
114 ) -> SignalHandlerId {
115 unsafe extern "C" fn notify_show_all_trampoline<
116 P: IsA<DeviceMonitor>,
117 F: Fn(&P) + Send + Sync + 'static,
118 >(
119 this: *mut ffi::GstDeviceMonitor,
120 _param_spec: glib::ffi::gpointer,
121 f: glib::ffi::gpointer,
122 ) {
123 let f: &F = &*(f as *const F);
124 f(DeviceMonitor::from_glib_borrow(this).unsafe_cast_ref())
125 }
126 unsafe {
127 let f: Box_<F> = Box_::new(f);
128 connect_raw(
129 self.as_ptr() as *mut _,
130 c"notify::show-all".as_ptr() as *const _,
131 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
132 notify_show_all_trampoline::<Self, F> as *const (),
133 )),
134 Box_::into_raw(f),
135 )
136 }
137 }
138}
139
140impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O {}