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 // DO NOT EDIT
4 
5 use glib;
6 use glib::object::IsA;
7 use glib::object::ObjectType as ObjectType_;
8 use glib::signal::connect_raw;
9 use glib::signal::SignalHandlerId;
10 use glib::translate::*;
11 use glib::GString;
12 use glib::StaticType;
13 use glib::Value;
14 use glib_sys;
15 use gobject_sys;
16 use gst_sys;
17 use std::boxed::Box as Box_;
18 use std::mem::transmute;
19 use Caps;
20 use Object;
21 use Pad;
22 use PadDirection;
23 use PadPresence;
24 
25 glib_wrapper! {
26     pub struct PadTemplate(Object<gst_sys::GstPadTemplate, gst_sys::GstPadTemplateClass, PadTemplateClass>) @extends Object;
27 
28     match fn {
29         get_type => || gst_sys::gst_pad_template_get_type(),
30     }
31 }
32 
33 impl PadTemplate {
new( name_template: &str, direction: PadDirection, presence: PadPresence, caps: &Caps, ) -> Result<PadTemplate, glib::BoolError>34     pub fn new(
35         name_template: &str,
36         direction: PadDirection,
37         presence: PadPresence,
38         caps: &Caps,
39     ) -> Result<PadTemplate, glib::BoolError> {
40         assert_initialized_main_thread!();
41         unsafe {
42             Option::<_>::from_glib_none(gst_sys::gst_pad_template_new(
43                 name_template.to_glib_none().0,
44                 direction.to_glib(),
45                 presence.to_glib(),
46                 caps.to_glib_none().0,
47             ))
48             .ok_or_else(|| glib_bool_error!("Failed to create pad template"))
49         }
50     }
51 
52     #[cfg(any(feature = "v1_14", feature = "dox"))]
new_with_gtype( name_template: &str, direction: PadDirection, presence: PadPresence, caps: &Caps, pad_type: glib::types::Type, ) -> Result<PadTemplate, glib::BoolError>53     pub fn new_with_gtype(
54         name_template: &str,
55         direction: PadDirection,
56         presence: PadPresence,
57         caps: &Caps,
58         pad_type: glib::types::Type,
59     ) -> Result<PadTemplate, glib::BoolError> {
60         assert_initialized_main_thread!();
61         unsafe {
62             Option::<_>::from_glib_none(gst_sys::gst_pad_template_new_with_gtype(
63                 name_template.to_glib_none().0,
64                 direction.to_glib(),
65                 presence.to_glib(),
66                 caps.to_glib_none().0,
67                 pad_type.to_glib(),
68             ))
69             .ok_or_else(|| glib_bool_error!("Failed to create pad template"))
70         }
71     }
72 
get_caps(&self) -> Option<Caps>73     pub fn get_caps(&self) -> Option<Caps> {
74         unsafe { from_glib_full(gst_sys::gst_pad_template_get_caps(self.to_glib_none().0)) }
75     }
76 
pad_created<P: IsA<Pad>>(&self, pad: &P)77     pub fn pad_created<P: IsA<Pad>>(&self, pad: &P) {
78         unsafe {
79             gst_sys::gst_pad_template_pad_created(
80                 self.to_glib_none().0,
81                 pad.as_ref().to_glib_none().0,
82             );
83         }
84     }
85 
get_property_direction(&self) -> PadDirection86     pub fn get_property_direction(&self) -> PadDirection {
87         unsafe {
88             let mut value = Value::from_type(<PadDirection as StaticType>::static_type());
89             gobject_sys::g_object_get_property(
90                 self.as_ptr() as *mut gobject_sys::GObject,
91                 b"direction\0".as_ptr() as *const _,
92                 value.to_glib_none_mut().0,
93             );
94             value
95                 .get()
96                 .expect("Return Value for property `direction` getter")
97                 .unwrap()
98         }
99     }
100 
101     #[cfg(any(feature = "v1_14", feature = "dox"))]
get_property_gtype(&self) -> glib::types::Type102     pub fn get_property_gtype(&self) -> glib::types::Type {
103         unsafe {
104             let mut value = Value::from_type(<glib::types::Type as StaticType>::static_type());
105             gobject_sys::g_object_get_property(
106                 self.as_ptr() as *mut gobject_sys::GObject,
107                 b"gtype\0".as_ptr() as *const _,
108                 value.to_glib_none_mut().0,
109             );
110             value
111                 .get()
112                 .expect("Return Value for property `gtype` getter")
113                 .unwrap()
114         }
115     }
116 
get_property_name_template(&self) -> Option<GString>117     pub fn get_property_name_template(&self) -> Option<GString> {
118         unsafe {
119             let mut value = Value::from_type(<GString as StaticType>::static_type());
120             gobject_sys::g_object_get_property(
121                 self.as_ptr() as *mut gobject_sys::GObject,
122                 b"name-template\0".as_ptr() as *const _,
123                 value.to_glib_none_mut().0,
124             );
125             value
126                 .get()
127                 .expect("Return Value for property `name-template` getter")
128         }
129     }
130 
get_property_presence(&self) -> PadPresence131     pub fn get_property_presence(&self) -> PadPresence {
132         unsafe {
133             let mut value = Value::from_type(<PadPresence as StaticType>::static_type());
134             gobject_sys::g_object_get_property(
135                 self.as_ptr() as *mut gobject_sys::GObject,
136                 b"presence\0".as_ptr() as *const _,
137                 value.to_glib_none_mut().0,
138             );
139             value
140                 .get()
141                 .expect("Return Value for property `presence` getter")
142                 .unwrap()
143         }
144     }
145 
connect_pad_created<F: Fn(&PadTemplate, &Pad) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId146     pub fn connect_pad_created<F: Fn(&PadTemplate, &Pad) + Send + Sync + 'static>(
147         &self,
148         f: F,
149     ) -> SignalHandlerId {
150         unsafe extern "C" fn pad_created_trampoline<
151             F: Fn(&PadTemplate, &Pad) + Send + Sync + 'static,
152         >(
153             this: *mut gst_sys::GstPadTemplate,
154             pad: *mut gst_sys::GstPad,
155             f: glib_sys::gpointer,
156         ) {
157             let f: &F = &*(f as *const F);
158             f(&from_glib_borrow(this), &from_glib_borrow(pad))
159         }
160         unsafe {
161             let f: Box_<F> = Box_::new(f);
162             connect_raw(
163                 self.as_ptr() as *mut _,
164                 b"pad-created\0".as_ptr() as *const _,
165                 Some(transmute(pad_created_trampoline::<F> as usize)),
166                 Box_::into_raw(f),
167             )
168         }
169     }
170 }
171 
172 unsafe impl Send for PadTemplate {}
173 unsafe impl Sync for PadTemplate {}
174