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
135mod sealed {
136 pub trait Sealed {}
137 impl<T: super::IsA<super::DeviceMonitor>> Sealed for T {}
138}
139
140/// Trait containing all [`struct@DeviceMonitor`] methods.
141///
142/// # Implementors
143///
144/// [`DeviceMonitor`][struct@crate::DeviceMonitor]
145pub trait DeviceMonitorExt: IsA<DeviceMonitor> + sealed::Sealed + 'static {
146 /// Gets the [`Bus`][crate::Bus] of this [`DeviceMonitor`][crate::DeviceMonitor]
147 ///
148 /// # Returns
149 ///
150 /// a [`Bus`][crate::Bus]
151 #[doc(alias = "gst_device_monitor_get_bus")]
152 #[doc(alias = "get_bus")]
153 fn bus(&self) -> Bus {
154 unsafe {
155 from_glib_full(ffi::gst_device_monitor_get_bus(
156 self.as_ref().to_glib_none().0,
157 ))
158 }
159 }
160
161 /// Get a list of the currently selected device provider factories.
162 ///
163 /// This
164 ///
165 /// # Returns
166 ///
167 ///
168 /// A list of device provider factory names that are currently being
169 /// monitored by `self` or [`None`] when nothing is being monitored.
170 #[doc(alias = "gst_device_monitor_get_providers")]
171 #[doc(alias = "get_providers")]
172 fn providers(&self) -> Vec<glib::GString> {
173 unsafe {
174 FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_providers(
175 self.as_ref().to_glib_none().0,
176 ))
177 }
178 }
179
180 /// Get if `self` is currently showing all devices, even those from hidden
181 /// providers.
182 ///
183 /// # Returns
184 ///
185 /// [`true`] when all devices will be shown.
186 #[doc(alias = "gst_device_monitor_get_show_all_devices")]
187 #[doc(alias = "get_show_all_devices")]
188 fn shows_all_devices(&self) -> bool {
189 unsafe {
190 from_glib(ffi::gst_device_monitor_get_show_all_devices(
191 self.as_ref().to_glib_none().0,
192 ))
193 }
194 }
195
196 /// Set if all devices should be visible, even those devices from hidden
197 /// providers. Setting `show_all` to true might show some devices multiple times.
198 /// ## `show_all`
199 /// show all devices
200 #[doc(alias = "gst_device_monitor_set_show_all_devices")]
201 fn set_show_all_devices(&self, show_all: bool) {
202 unsafe {
203 ffi::gst_device_monitor_set_show_all_devices(
204 self.as_ref().to_glib_none().0,
205 show_all.into_glib(),
206 );
207 }
208 }
209
210 /// Starts monitoring the devices, one this has succeeded, the
211 /// `GST_MESSAGE_DEVICE_ADDED` and `GST_MESSAGE_DEVICE_REMOVED` messages
212 /// will be emitted on the bus when the list of devices changes.
213 ///
214 /// # Returns
215 ///
216 /// [`true`] if the device monitoring could be started, i.e. at least a
217 /// single device provider was started successfully.
218 #[doc(alias = "gst_device_monitor_start")]
219 fn start(&self) -> Result<(), glib::error::BoolError> {
220 unsafe {
221 glib::result_from_gboolean!(
222 ffi::gst_device_monitor_start(self.as_ref().to_glib_none().0),
223 "Failed to start"
224 )
225 }
226 }
227
228 /// Stops monitoring the devices.
229 #[doc(alias = "gst_device_monitor_stop")]
230 fn stop(&self) {
231 unsafe {
232 ffi::gst_device_monitor_stop(self.as_ref().to_glib_none().0);
233 }
234 }
235
236 #[doc(alias = "show-all")]
237 fn shows_all(&self) -> bool {
238 ObjectExt::property(self.as_ref(), "show-all")
239 }
240
241 #[doc(alias = "show-all")]
242 fn set_show_all(&self, show_all: bool) {
243 ObjectExt::set_property(self.as_ref(), "show-all", show_all)
244 }
245
246 #[doc(alias = "show-all")]
247 fn connect_show_all_notify<F: Fn(&Self) + Send + Sync + 'static>(
248 &self,
249 f: F,
250 ) -> SignalHandlerId {
251 unsafe extern "C" fn notify_show_all_trampoline<
252 P: IsA<DeviceMonitor>,
253 F: Fn(&P) + Send + Sync + 'static,
254 >(
255 this: *mut ffi::GstDeviceMonitor,
256 _param_spec: glib::ffi::gpointer,
257 f: glib::ffi::gpointer,
258 ) {
259 let f: &F = &*(f as *const F);
260 f(DeviceMonitor::from_glib_borrow(this).unsafe_cast_ref())
261 }
262 unsafe {
263 let f: Box_<F> = Box_::new(f);
264 connect_raw(
265 self.as_ptr() as *mut _,
266 b"notify::show-all\0".as_ptr() as *const _,
267 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268 notify_show_all_trampoline::<Self, F> as *const (),
269 )),
270 Box_::into_raw(f),
271 )
272 }
273 }
274}
275
276impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O {}