1 // Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com> 2 // 3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your 6 // option. This file may not be copied, modified, or distributed 7 // except according to those terms. 8 9 use Caps; 10 use PadTemplate; 11 12 use glib_sys; 13 use gobject_sys; 14 use gst_sys; 15 16 use glib; 17 use glib::translate::{ 18 from_glib, from_glib_full, from_glib_none, FromGlibPtrNone, ToGlibPtr, ToGlibPtrMut, 19 }; 20 use std::ffi::CStr; 21 22 use std::fmt; 23 use std::ptr; 24 25 #[repr(C)] 26 pub struct StaticPadTemplate(ptr::NonNull<gst_sys::GstStaticPadTemplate>); 27 28 impl StaticPadTemplate { get(&self) -> PadTemplate29 pub fn get(&self) -> PadTemplate { 30 unsafe { from_glib_full(gst_sys::gst_static_pad_template_get(self.0.as_ptr())) } 31 } 32 get_caps(&self) -> Caps33 pub fn get_caps(&self) -> Caps { 34 unsafe { from_glib_full(gst_sys::gst_static_pad_template_get_caps(self.0.as_ptr())) } 35 } 36 name_template<'a>(&self) -> &'a str37 pub fn name_template<'a>(&self) -> &'a str { 38 unsafe { 39 CStr::from_ptr(self.0.as_ref().name_template) 40 .to_str() 41 .unwrap() 42 } 43 } 44 direction(&self) -> ::PadDirection45 pub fn direction(&self) -> ::PadDirection { 46 unsafe { from_glib(self.0.as_ref().direction) } 47 } 48 presence(&self) -> ::PadPresence49 pub fn presence(&self) -> ::PadPresence { 50 unsafe { from_glib(self.0.as_ref().presence) } 51 } 52 } 53 54 unsafe impl Send for StaticPadTemplate {} 55 unsafe impl Sync for StaticPadTemplate {} 56 57 impl fmt::Debug for StaticPadTemplate { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result58 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 59 f.debug_struct("StaticPadTemplate") 60 .field("name_template", &unsafe { 61 CStr::from_ptr(self.0.as_ref().name_template).to_str() 62 }) 63 .field("direction", &unsafe { 64 from_glib::<_, ::PadDirection>(self.0.as_ref().direction) 65 }) 66 .field("presence", &unsafe { 67 from_glib::<_, ::PadPresence>(self.0.as_ref().presence) 68 }) 69 .field("static_caps", &unsafe { 70 from_glib_none::<_, ::StaticCaps>(&self.0.as_ref().static_caps as *const _) 71 }) 72 .finish() 73 } 74 } 75 76 impl glib::types::StaticType for StaticPadTemplate { static_type() -> glib::types::Type77 fn static_type() -> glib::types::Type { 78 unsafe { glib::translate::from_glib(gst_sys::gst_static_pad_template_get_type()) } 79 } 80 } 81 82 #[doc(hidden)] 83 impl<'a> glib::value::FromValueOptional<'a> for StaticPadTemplate { from_value_optional(value: &glib::Value) -> Option<Self>84 unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { 85 Option::<StaticPadTemplate>::from_glib_none(gobject_sys::g_value_get_boxed( 86 value.to_glib_none().0, 87 ) as *mut gst_sys::GstStaticPadTemplate) 88 } 89 } 90 91 #[doc(hidden)] 92 impl glib::value::SetValue for StaticPadTemplate { set_value(value: &mut glib::Value, this: &Self)93 unsafe fn set_value(value: &mut glib::Value, this: &Self) { 94 gobject_sys::g_value_set_boxed( 95 value.to_glib_none_mut().0, 96 glib::translate::ToGlibPtr::<*const gst_sys::GstStaticPadTemplate>::to_glib_none(this).0 97 as glib_sys::gpointer, 98 ) 99 } 100 } 101 102 #[doc(hidden)] 103 impl glib::value::SetValueOptional for StaticPadTemplate { set_value_optional(value: &mut glib::Value, this: Option<&Self>)104 unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { 105 gobject_sys::g_value_set_boxed( 106 value.to_glib_none_mut().0, 107 glib::translate::ToGlibPtr::<*const gst_sys::GstStaticPadTemplate>::to_glib_none(&this) 108 .0 as glib_sys::gpointer, 109 ) 110 } 111 } 112 113 #[doc(hidden)] 114 impl glib::translate::GlibPtrDefault for StaticPadTemplate { 115 type GlibType = *mut gst_sys::GstStaticPadTemplate; 116 } 117 118 #[doc(hidden)] 119 impl<'a> glib::translate::ToGlibPtr<'a, *const gst_sys::GstStaticPadTemplate> 120 for StaticPadTemplate 121 { 122 type Storage = &'a StaticPadTemplate; 123 to_glib_none( &'a self, ) -> glib::translate::Stash<'a, *const gst_sys::GstStaticPadTemplate, Self>124 fn to_glib_none( 125 &'a self, 126 ) -> glib::translate::Stash<'a, *const gst_sys::GstStaticPadTemplate, Self> { 127 glib::translate::Stash(self.0.as_ptr(), self) 128 } 129 to_glib_full(&self) -> *const gst_sys::GstStaticPadTemplate130 fn to_glib_full(&self) -> *const gst_sys::GstStaticPadTemplate { 131 unimplemented!() 132 } 133 } 134 135 #[doc(hidden)] 136 impl glib::translate::FromGlibPtrNone<*const gst_sys::GstStaticPadTemplate> for StaticPadTemplate { 137 #[inline] from_glib_none(ptr: *const gst_sys::GstStaticPadTemplate) -> Self138 unsafe fn from_glib_none(ptr: *const gst_sys::GstStaticPadTemplate) -> Self { 139 assert!(!ptr.is_null()); 140 StaticPadTemplate(ptr::NonNull::new_unchecked(ptr as *mut _)) 141 } 142 } 143 144 #[doc(hidden)] 145 impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate { 146 #[inline] from_glib_none(ptr: *mut gst_sys::GstStaticPadTemplate) -> Self147 unsafe fn from_glib_none(ptr: *mut gst_sys::GstStaticPadTemplate) -> Self { 148 assert!(!ptr.is_null()); 149 StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)) 150 } 151 } 152 153 #[doc(hidden)] 154 impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate { 155 #[inline] from_glib_borrow(ptr: *mut gst_sys::GstStaticPadTemplate) -> Self156 unsafe fn from_glib_borrow(ptr: *mut gst_sys::GstStaticPadTemplate) -> Self { 157 assert!(!ptr.is_null()); 158 StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)) 159 } 160 } 161 162 #[doc(hidden)] 163 impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate { 164 #[inline] from_glib_full(_ptr: *mut gst_sys::GstStaticPadTemplate) -> Self165 unsafe fn from_glib_full(_ptr: *mut gst_sys::GstStaticPadTemplate) -> Self { 166 unimplemented!(); 167 } 168 } 169