Skip to main content

gstreamer/auto/
device_monitor.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::{Bus, Object, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// device);
16    ///  name = gst_device_get_display_name (device);
17    ///  g_print("Device removed: `s`\n", name);
18    ///  g_free (name);
19    ///  gst_object_unref (device);
20    ///  break;
21    ///  default:
22    ///  break;
23    ///  }
24    ///
25    ///  return G_SOURCE_CONTINUE;
26    ///  }
27    ///
28    ///  GstDeviceMonitor *
29    ///  setup_raw_video_source_device_monitor (void) {
30    ///  GstDeviceMonitor *monitor;
31    ///  GstBus *bus;
32    ///  GstCaps *caps;
33    ///
34    ///  monitor = gst_device_monitor_new ();
35    ///
36    ///  bus = gst_device_monitor_get_bus (monitor);
37    ///  gst_bus_add_watch (bus, my_bus_func, NULL);
38    ///  gst_object_unref (bus);
39    ///
40    ///  caps = gst_caps_new_empty_simple ("video/x-raw");
41    ///  gst_device_monitor_add_filter (monitor, "Video/Source", caps);
42    ///  gst_caps_unref (caps);
43    ///
44    ///  gst_device_monitor_start (monitor);
45    ///
46    ///  return monitor;
47    ///  }
48    /// ]|
49    ///
50    /// ## Properties
51    ///
52    ///
53    /// #### `show-all`
54    ///  Readable | Writable
55    /// <details><summary><h4>Object</h4></summary>
56    ///
57    ///
58    /// #### `name`
59    ///  Readable | Writable | Construct
60    ///
61    ///
62    /// #### `parent`
63    ///  The parent of the object. Please note, that when changing the 'parent'
64    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
65    /// signals due to locking issues. In some cases one can use
66    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
67    /// achieve a similar effect.
68    ///
69    /// Readable | Writable
70    /// </details>
71    ///
72    /// # Implements
73    ///
74    /// [`DeviceMonitorExt`][trait@crate::prelude::DeviceMonitorExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`DeviceMonitorExtManual`][trait@crate::prelude::DeviceMonitorExtManual], [`GstObjectExtManual`][trait@crate::prelude::GstObjectExtManual]
75    #[doc(alias = "GstDeviceMonitor")]
76    pub struct DeviceMonitor(Object<ffi::GstDeviceMonitor, ffi::GstDeviceMonitorClass>) @extends Object;
77
78    match fn {
79        type_ => || ffi::gst_device_monitor_get_type(),
80    }
81}
82
83impl DeviceMonitor {
84    pub const NONE: Option<&'static DeviceMonitor> = None;
85
86    /// Create a new [`DeviceMonitor`][crate::DeviceMonitor]
87    ///
88    /// # Returns
89    ///
90    /// a new device monitor.
91    #[doc(alias = "gst_device_monitor_new")]
92    pub fn new() -> DeviceMonitor {
93        assert_initialized_main_thread!();
94        unsafe { from_glib_full(ffi::gst_device_monitor_new()) }
95    }
96}
97
98impl Default for DeviceMonitor {
99    fn default() -> Self {
100        Self::new()
101    }
102}
103
104unsafe impl Send for DeviceMonitor {}
105unsafe impl Sync for DeviceMonitor {}
106
107/// Trait containing all [`struct@DeviceMonitor`] methods.
108///
109/// # Implementors
110///
111/// [`DeviceMonitor`][struct@crate::DeviceMonitor]
112pub trait DeviceMonitorExt: IsA<DeviceMonitor> + 'static {
113    /// Gets the [`Bus`][crate::Bus] of this [`DeviceMonitor`][crate::DeviceMonitor]
114    ///
115    /// # Returns
116    ///
117    /// a [`Bus`][crate::Bus]
118    #[doc(alias = "gst_device_monitor_get_bus")]
119    #[doc(alias = "get_bus")]
120    fn bus(&self) -> Bus {
121        unsafe {
122            from_glib_full(ffi::gst_device_monitor_get_bus(
123                self.as_ref().to_glib_none().0,
124            ))
125        }
126    }
127
128    /// Get a list of the currently selected device provider factories.
129    ///
130    /// This
131    ///
132    /// # Returns
133    ///
134    ///
135    ///  A list of device provider factory names that are currently being
136    ///  monitored by `self` or [`None`] when nothing is being monitored.
137    #[doc(alias = "gst_device_monitor_get_providers")]
138    #[doc(alias = "get_providers")]
139    fn providers(&self) -> Vec<glib::GString> {
140        unsafe {
141            FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_providers(
142                self.as_ref().to_glib_none().0,
143            ))
144        }
145    }
146
147    /// Get if `self` is currently showing all devices, even those from hidden
148    /// providers.
149    ///
150    /// # Returns
151    ///
152    /// [`true`] when all devices will be shown.
153    #[doc(alias = "gst_device_monitor_get_show_all_devices")]
154    #[doc(alias = "get_show_all_devices")]
155    fn shows_all_devices(&self) -> bool {
156        unsafe {
157            from_glib(ffi::gst_device_monitor_get_show_all_devices(
158                self.as_ref().to_glib_none().0,
159            ))
160        }
161    }
162
163    /// Set if all devices should be visible, even those devices from hidden
164    /// providers. Setting `show_all` to true might show some devices multiple times.
165    /// ## `show_all`
166    /// show all devices
167    #[doc(alias = "gst_device_monitor_set_show_all_devices")]
168    fn set_show_all_devices(&self, show_all: bool) {
169        unsafe {
170            ffi::gst_device_monitor_set_show_all_devices(
171                self.as_ref().to_glib_none().0,
172                show_all.into_glib(),
173            );
174        }
175    }
176
177    /// Starts monitoring the devices, once this has succeeded, the
178    /// `GST_MESSAGE_DEVICE_ADDED` and `GST_MESSAGE_DEVICE_REMOVED` messages
179    /// will be emitted on the bus when the list of devices changes.
180    ///
181    /// Since 1.28, device providers are started asynchronously and
182    /// `GST_MESSAGE_DEVICE_MONITOR_STARTED` will be emitted once the initial list
183    /// of devices has been populated, signalling that monitor startup has
184    /// completed.
185    ///
186    /// The monitor will hold a strong reference to itself while it is populating
187    /// devices asynchronously, so you must call [`stop()`][Self::stop()] before
188    /// unreffing if you want monitoring to stop immediately.
189    ///
190    /// # Returns
191    ///
192    /// [`true`] if the device monitoring could be started, i.e. at least a
193    ///  single device provider was started successfully.
194    #[doc(alias = "gst_device_monitor_start")]
195    fn start(&self) -> Result<(), glib::error::BoolError> {
196        unsafe {
197            glib::result_from_gboolean!(
198                ffi::gst_device_monitor_start(self.as_ref().to_glib_none().0),
199                "Failed to start"
200            )
201        }
202    }
203
204    /// Stops monitoring the devices.
205    #[doc(alias = "gst_device_monitor_stop")]
206    fn stop(&self) {
207        unsafe {
208            ffi::gst_device_monitor_stop(self.as_ref().to_glib_none().0);
209        }
210    }
211
212    #[doc(alias = "show-all")]
213    fn shows_all(&self) -> bool {
214        ObjectExt::property(self.as_ref(), "show-all")
215    }
216
217    #[doc(alias = "show-all")]
218    fn set_show_all(&self, show_all: bool) {
219        ObjectExt::set_property(self.as_ref(), "show-all", show_all)
220    }
221
222    #[doc(alias = "show-all")]
223    fn connect_show_all_notify<F: Fn(&Self) + Send + Sync + 'static>(
224        &self,
225        f: F,
226    ) -> SignalHandlerId {
227        unsafe extern "C" fn notify_show_all_trampoline<
228            P: IsA<DeviceMonitor>,
229            F: Fn(&P) + Send + Sync + 'static,
230        >(
231            this: *mut ffi::GstDeviceMonitor,
232            _param_spec: glib::ffi::gpointer,
233            f: glib::ffi::gpointer,
234        ) {
235            unsafe {
236                let f: &F = &*(f as *const F);
237                f(DeviceMonitor::from_glib_borrow(this).unsafe_cast_ref())
238            }
239        }
240        unsafe {
241            let f: Box_<F> = Box_::new(f);
242            connect_raw(
243                self.as_ptr() as *mut _,
244                c"notify::show-all".as_ptr(),
245                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
246                    notify_show_all_trampoline::<Self, F> as *const (),
247                )),
248                Box_::into_raw(f),
249            )
250        }
251    }
252}
253
254impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O {}