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 | |
6 | use crate::{Caps, Element, Object, Structure}; |
7 | use glib::{ |
8 | prelude::*, |
9 | signal::{connect_raw, SignalHandlerId}, |
10 | translate::*, |
11 | }; |
12 | use std::{boxed::Box as Box_, mem::transmute}; |
13 | |
14 | glib::wrapper! { |
15 | #[doc (alias = "GstDevice" )] |
16 | pub struct Device(Object<ffi::GstDevice, ffi::GstDeviceClass>) @extends Object; |
17 | |
18 | match fn { |
19 | type_ => || ffi::gst_device_get_type(), |
20 | } |
21 | } |
22 | |
23 | impl Device { |
24 | pub const NONE: Option<&'static Device> = None; |
25 | } |
26 | |
27 | unsafe impl Send for Device {} |
28 | unsafe impl Sync for Device {} |
29 | |
30 | mod sealed { |
31 | pub trait Sealed {} |
32 | impl<T: super::IsA<super::Device>> Sealed for T {} |
33 | } |
34 | |
35 | pub trait DeviceExt: IsA<Device> + sealed::Sealed + 'static { |
36 | #[doc (alias = "gst_device_create_element" )] |
37 | fn create_element(&self, name: Option<&str>) -> Result<Element, glib::BoolError> { |
38 | unsafe { |
39 | Option::<_>::from_glib_none(ffi::gst_device_create_element( |
40 | self.as_ref().to_glib_none().0, |
41 | name.to_glib_none().0, |
42 | )) |
43 | .ok_or_else(|| glib::bool_error!("Failed to create element for device" )) |
44 | } |
45 | } |
46 | |
47 | #[doc (alias = "gst_device_get_caps" )] |
48 | #[doc (alias = "get_caps" )] |
49 | fn caps(&self) -> Option<Caps> { |
50 | unsafe { from_glib_full(ffi::gst_device_get_caps(self.as_ref().to_glib_none().0)) } |
51 | } |
52 | |
53 | #[doc (alias = "gst_device_get_device_class" )] |
54 | #[doc (alias = "get_device_class" )] |
55 | fn device_class(&self) -> glib::GString { |
56 | unsafe { |
57 | from_glib_full(ffi::gst_device_get_device_class( |
58 | self.as_ref().to_glib_none().0, |
59 | )) |
60 | } |
61 | } |
62 | |
63 | #[doc (alias = "gst_device_get_display_name" )] |
64 | #[doc (alias = "get_display_name" )] |
65 | fn display_name(&self) -> glib::GString { |
66 | unsafe { |
67 | from_glib_full(ffi::gst_device_get_display_name( |
68 | self.as_ref().to_glib_none().0, |
69 | )) |
70 | } |
71 | } |
72 | |
73 | #[doc (alias = "gst_device_get_properties" )] |
74 | #[doc (alias = "get_properties" )] |
75 | fn properties(&self) -> Option<Structure> { |
76 | unsafe { |
77 | from_glib_full(ffi::gst_device_get_properties( |
78 | self.as_ref().to_glib_none().0, |
79 | )) |
80 | } |
81 | } |
82 | |
83 | #[doc (alias = "gst_device_has_classes" )] |
84 | fn has_classes(&self, classes: &str) -> bool { |
85 | unsafe { |
86 | from_glib(ffi::gst_device_has_classes( |
87 | self.as_ref().to_glib_none().0, |
88 | classes.to_glib_none().0, |
89 | )) |
90 | } |
91 | } |
92 | |
93 | #[doc (alias = "gst_device_has_classesv" )] |
94 | fn has_classesv(&self, classes: &[&str]) -> bool { |
95 | unsafe { |
96 | from_glib(ffi::gst_device_has_classesv( |
97 | self.as_ref().to_glib_none().0, |
98 | classes.to_glib_none().0, |
99 | )) |
100 | } |
101 | } |
102 | |
103 | #[doc (alias = "gst_device_reconfigure_element" )] |
104 | fn reconfigure_element( |
105 | &self, |
106 | element: &impl IsA<Element>, |
107 | ) -> Result<(), glib::error::BoolError> { |
108 | unsafe { |
109 | glib::result_from_gboolean!( |
110 | ffi::gst_device_reconfigure_element( |
111 | self.as_ref().to_glib_none().0, |
112 | element.as_ref().to_glib_none().0 |
113 | ), |
114 | "Failed to reconfigure the element to use this device" |
115 | ) |
116 | } |
117 | } |
118 | |
119 | #[doc (alias = "removed" )] |
120 | fn connect_removed<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { |
121 | unsafe extern "C" fn removed_trampoline< |
122 | P: IsA<Device>, |
123 | F: Fn(&P) + Send + Sync + 'static, |
124 | >( |
125 | this: *mut ffi::GstDevice, |
126 | f: glib::ffi::gpointer, |
127 | ) { |
128 | let f: &F = &*(f as *const F); |
129 | f(Device::from_glib_borrow(this).unsafe_cast_ref()) |
130 | } |
131 | unsafe { |
132 | let f: Box_<F> = Box_::new(f); |
133 | connect_raw( |
134 | self.as_ptr() as *mut _, |
135 | b"removed \0" .as_ptr() as *const _, |
136 | Some(transmute::<_, unsafe extern "C" fn()>( |
137 | removed_trampoline::<Self, F> as *const (), |
138 | )), |
139 | Box_::into_raw(f), |
140 | ) |
141 | } |
142 | } |
143 | } |
144 | |
145 | impl<O: IsA<Device>> DeviceExt for O {} |
146 | |