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