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::{ffi, Caps, Object, Pad, PadDirection, PadPresence}; |
7 | use glib::{ |
8 | object::ObjectType as _, |
9 | prelude::*, |
10 | signal::{connect_raw, SignalHandlerId}, |
11 | translate::*, |
12 | }; |
13 | use std::boxed::Box as Box_; |
14 | |
15 | glib::wrapper! { |
16 | #[doc (alias = "GstPadTemplate" )] |
17 | pub struct PadTemplate(Object<ffi::GstPadTemplate, ffi::GstPadTemplateClass>) @extends Object; |
18 | |
19 | match fn { |
20 | type_ => || ffi::gst_pad_template_get_type(), |
21 | } |
22 | } |
23 | |
24 | impl PadTemplate { |
25 | #[doc (alias = "gst_pad_template_new" )] |
26 | pub fn new( |
27 | name_template: &str, |
28 | direction: PadDirection, |
29 | presence: PadPresence, |
30 | caps: &Caps, |
31 | ) -> Result<PadTemplate, glib::BoolError> { |
32 | assert_initialized_main_thread!(); |
33 | unsafe { |
34 | Option::<_>::from_glib_none(ffi::gst_pad_template_new( |
35 | name_template.to_glib_none().0, |
36 | direction.into_glib(), |
37 | presence.into_glib(), |
38 | caps.to_glib_none().0, |
39 | )) |
40 | .ok_or_else(|| glib::bool_error!("Failed to create pad template" )) |
41 | } |
42 | } |
43 | |
44 | #[doc (alias = "gst_pad_template_new_with_gtype" )] |
45 | #[doc (alias = "new_with_gtype" )] |
46 | pub fn with_gtype( |
47 | name_template: &str, |
48 | direction: PadDirection, |
49 | presence: PadPresence, |
50 | caps: &Caps, |
51 | pad_type: glib::types::Type, |
52 | ) -> Result<PadTemplate, glib::BoolError> { |
53 | assert_initialized_main_thread!(); |
54 | unsafe { |
55 | Option::<_>::from_glib_none(ffi::gst_pad_template_new_with_gtype( |
56 | name_template.to_glib_none().0, |
57 | direction.into_glib(), |
58 | presence.into_glib(), |
59 | caps.to_glib_none().0, |
60 | pad_type.into_glib(), |
61 | )) |
62 | .ok_or_else(|| glib::bool_error!("Failed to create pad template" )) |
63 | } |
64 | } |
65 | |
66 | #[doc (alias = "gst_pad_template_pad_created" )] |
67 | pub fn pad_created(&self, pad: &impl IsA<Pad>) { |
68 | unsafe { |
69 | ffi::gst_pad_template_pad_created(self.to_glib_none().0, pad.as_ref().to_glib_none().0); |
70 | } |
71 | } |
72 | |
73 | #[doc (alias = "pad-created" )] |
74 | pub fn connect_pad_created<F: Fn(&Self, &Pad) + Send + Sync + 'static>( |
75 | &self, |
76 | f: F, |
77 | ) -> SignalHandlerId { |
78 | unsafe extern "C" fn pad_created_trampoline< |
79 | F: Fn(&PadTemplate, &Pad) + Send + Sync + 'static, |
80 | >( |
81 | this: *mut ffi::GstPadTemplate, |
82 | pad: *mut ffi::GstPad, |
83 | f: glib::ffi::gpointer, |
84 | ) { |
85 | let f: &F = &*(f as *const F); |
86 | f(&from_glib_borrow(this), &from_glib_borrow(pad)) |
87 | } |
88 | unsafe { |
89 | let f: Box_<F> = Box_::new(f); |
90 | connect_raw( |
91 | self.as_ptr() as *mut _, |
92 | b"pad-created \0" .as_ptr() as *const _, |
93 | Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( |
94 | pad_created_trampoline::<F> as *const (), |
95 | )), |
96 | Box_::into_raw(f), |
97 | ) |
98 | } |
99 | } |
100 | } |
101 | |
102 | unsafe impl Send for PadTemplate {} |
103 | unsafe impl Sync for PadTemplate {} |
104 | |