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