2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-07-03 10:56:26 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
#[macro_export]
|
2021-01-06 09:57:51 +00:00
|
|
|
macro_rules! mini_object_wrapper (
|
|
|
|
($name:ident, $ref_name:ident, $ffi_name:path) => {
|
2020-06-29 21:12:46 +00:00
|
|
|
pub struct $name {
|
2021-04-03 14:43:50 +00:00
|
|
|
obj: std::ptr::NonNull<$ffi_name>,
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct $ref_name($ffi_name);
|
2017-07-03 10:56:26 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl $name {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
|
2020-06-29 21:12:46 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
assert!(!ptr.is_null());
|
2017-07-03 10:56:26 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::ffi::gst_mini_object_ref(ptr as *mut $crate::ffi::GstMiniObject);
|
2020-03-06 22:31:30 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
$name {
|
2021-04-03 14:43:50 +00:00
|
|
|
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name),
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
|
2020-06-29 21:12:46 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
assert!(!ptr.is_null());
|
2017-08-02 17:46:22 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
$name {
|
2021-04-03 14:43:50 +00:00
|
|
|
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name),
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
|
2020-06-29 21:12:46 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
assert!(!ptr.is_null());
|
2017-08-02 17:46:22 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
$crate::glib::translate::Borrowed::new($name {
|
2021-04-03 14:43:50 +00:00
|
|
|
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name),
|
2020-06-29 21:12:46 +00:00
|
|
|
})
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn replace_ptr(&mut self, ptr: *mut $ffi_name) {
|
2020-06-29 21:12:46 +00:00
|
|
|
assert!(!ptr.is_null());
|
2021-04-03 14:43:50 +00:00
|
|
|
self.obj = std::ptr::NonNull::new_unchecked(ptr);
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
pub fn make_mut(&mut self) -> &mut $ref_name {
|
|
|
|
unsafe {
|
|
|
|
if self.is_writable() {
|
2021-04-03 14:43:50 +00:00
|
|
|
return &mut *(self.obj.as_mut() as *mut $ffi_name as *mut $ref_name);
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = $crate::ffi::gst_mini_object_make_writable(
|
|
|
|
self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject
|
2020-06-29 21:12:46 +00:00
|
|
|
);
|
2020-11-21 13:46:48 +00:00
|
|
|
self.replace_ptr(ptr as *mut $ffi_name);
|
2020-06-29 21:12:46 +00:00
|
|
|
assert!(self.is_writable());
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2021-04-03 14:43:50 +00:00
|
|
|
&mut *(self.obj.as_mut() as *mut $ffi_name as *mut $ref_name)
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
pub fn get_mut(&mut self) -> Option<&mut $ref_name> {
|
|
|
|
if self.is_writable() {
|
2021-04-03 14:43:50 +00:00
|
|
|
Some(unsafe { &mut *(self.obj.as_mut() as *mut $ffi_name as *mut $ref_name) })
|
2020-06-29 21:12:46 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
pub fn is_writable(&self) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::glib::translate::from_glib($crate::ffi::gst_mini_object_is_writable(
|
|
|
|
self.as_ptr() as *const $crate::ffi::GstMiniObject
|
2020-06-29 21:12:46 +00:00
|
|
|
))
|
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn into_ptr(self) -> *mut $ffi_name {
|
|
|
|
let s = std::mem::ManuallyDrop::new(self);
|
2020-06-29 21:12:46 +00:00
|
|
|
s.as_mut_ptr()
|
2018-10-05 13:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl Clone for $name {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
unsafe { $name::from_glib_none(self.as_ptr()) }
|
2018-09-28 15:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl Drop for $name {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::ffi::gst_mini_object_unref(self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject);
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
2018-09-28 15:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl std::ops::Deref for $name {
|
2020-06-29 21:12:46 +00:00
|
|
|
type Target = $ref_name;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
2021-04-03 14:43:50 +00:00
|
|
|
unsafe { &*(self.obj.as_ref() as *const $ffi_name as *const $ref_name) }
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<$ref_name> for $name {
|
|
|
|
fn as_ref(&self) -> &$ref_name {
|
2020-06-29 21:12:46 +00:00
|
|
|
&*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl std::borrow::Borrow<$ref_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
fn borrow(&self) -> &$ref_name {
|
2020-06-29 21:12:46 +00:00
|
|
|
&*self
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *const $ffi_name> for $name {
|
2020-06-29 21:12:46 +00:00
|
|
|
type Storage = &'a Self;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *const $ffi_name, Self> {
|
2020-06-29 21:12:46 +00:00
|
|
|
$crate::glib::translate::Stash(unsafe { self.as_ptr() }, self)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_full(&self) -> *const $ffi_name {
|
2020-06-29 21:12:46 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::ffi::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject);
|
2020-06-29 21:12:46 +00:00
|
|
|
self.as_ptr()
|
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *mut $ffi_name> for $name {
|
2020-06-29 21:12:46 +00:00
|
|
|
type Storage = &'a Self;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *mut $ffi_name, Self> {
|
2020-06-29 21:12:46 +00:00
|
|
|
$crate::glib::translate::Stash(unsafe { self.as_mut_ptr() }, self)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_full(&self) -> *mut $ffi_name {
|
2020-06-29 21:12:46 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::ffi::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject);
|
2020-06-29 21:12:46 +00:00
|
|
|
self.as_mut_ptr()
|
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibPtrMut<'a, *mut $ffi_name> for $name {
|
2020-06-29 21:12:46 +00:00
|
|
|
type Storage = &'a mut Self;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none_mut(&'a mut self) -> $crate::glib::translate::StashMut<*mut $ffi_name, Self> {
|
2020-06-29 21:12:46 +00:00
|
|
|
self.make_mut();
|
|
|
|
$crate::glib::translate::StashMut(unsafe { self.as_mut_ptr() }, self)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *mut *mut $ffi_name> for $name {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2018-09-28 14:36:19 +00:00
|
|
|
type Storage = (
|
2020-11-21 13:46:48 +00:00
|
|
|
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, Self>>,
|
|
|
|
Option<Vec<*mut $ffi_name>>,
|
2018-09-28 14:36:19 +00:00
|
|
|
);
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
2018-09-28 14:36:19 +00:00
|
|
|
skip_assert_initialized!();
|
2018-12-08 10:45:21 +00:00
|
|
|
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect();
|
2018-09-28 14:36:19 +00:00
|
|
|
let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
|
2020-11-21 13:46:48 +00:00
|
|
|
v_ptr.push(std::ptr::null_mut() as *mut $ffi_name);
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
(v_ptr.as_ptr() as *mut *mut $ffi_name, (v, Some(v_ptr)))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_container_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
2018-09-28 14:36:19 +00:00
|
|
|
skip_assert_initialized!();
|
2018-12-08 10:45:21 +00:00
|
|
|
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect();
|
2018-09-28 14:36:19 +00:00
|
|
|
|
|
|
|
let v_ptr = unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
|
|
|
|
as *mut *mut $ffi_name;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
|
|
|
for (i, s) in v.iter().enumerate() {
|
2020-11-21 13:46:48 +00:00
|
|
|
std::ptr::write(v_ptr.add(i), s.0);
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v_ptr
|
|
|
|
};
|
|
|
|
|
|
|
|
(v_ptr, (v, None))
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name {
|
2018-09-28 14:36:19 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
|
|
|
|
as *mut *mut $ffi_name;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
|
|
|
for (i, s) in t.iter().enumerate() {
|
2020-11-21 13:46:48 +00:00
|
|
|
std::ptr::write(v_ptr.add(i), $crate::glib::translate::ToGlibPtr::to_glib_full(s));
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v_ptr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *const *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2018-09-28 14:36:19 +00:00
|
|
|
type Storage = (
|
2020-11-21 13:46:48 +00:00
|
|
|
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, $name>>,
|
|
|
|
Option<Vec<*mut $ffi_name>>,
|
2018-09-28 14:36:19 +00:00
|
|
|
);
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none_from_slice(t: &'a [$name]) -> (*const *mut $ffi_name, Self::Storage) {
|
2018-09-28 14:36:19 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
let (ptr, stash) =
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::glib::translate::ToGlibContainerFromSlice::<'a, *mut *mut $ffi_name>::to_glib_none_from_slice(t);
|
|
|
|
(ptr as *const *mut $ffi_name, stash)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_container_from_slice(_: &'a [$name]) -> (*const *mut $ffi_name, Self::Storage) {
|
2018-09-28 14:36:19 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
// Can't have consumer free a *const pointer
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_full_from_slice(_: &[$name]) -> *const *mut $ffi_name {
|
2018-09-28 14:36:19 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
// Can't have consumer free a *const pointer
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrNone<*const $ffi_name> for $name {
|
|
|
|
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
|
2018-09-28 14:36:19 +00:00
|
|
|
Self::from_glib_none(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrNone<*mut $ffi_name> for $name {
|
|
|
|
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
|
2018-09-28 14:36:19 +00:00
|
|
|
Self::from_glib_none(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrFull<*const $ffi_name> for $name {
|
|
|
|
unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
|
2018-09-28 14:36:19 +00:00
|
|
|
Self::from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrFull<*mut $ffi_name> for $name {
|
|
|
|
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
|
2018-09-28 14:36:19 +00:00
|
|
|
Self::from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
|
|
|
|
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
Self::from_glib_borrow(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name {
|
|
|
|
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
Self::from_glib_borrow(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
if num == 0 || ptr.is_null() {
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(num);
|
|
|
|
for i in 0..num {
|
2020-11-21 13:46:48 +00:00
|
|
|
res.push($crate::glib::translate::from_glib_none(std::ptr::read(ptr.add(i))));
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
let res = $crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::glib::ffi::g_free(ptr as *mut _);
|
2018-09-28 14:36:19 +00:00
|
|
|
res
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
if num == 0 || ptr.is_null() {
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(num);
|
|
|
|
for i in 0..num {
|
2020-11-21 13:46:48 +00:00
|
|
|
res.push($crate::glib::translate::from_glib_full(std::ptr::read(ptr.add(i))));
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::glib::ffi::g_free(ptr as *mut _);
|
2018-09-28 14:36:19 +00:00
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_none_as_vec(ptr: *mut *mut $ffi_name) -> Vec<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_container_as_vec(ptr: *mut *mut $ffi_name) -> Vec<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_full_as_vec(ptr: *mut *mut $ffi_name) -> Vec<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::FromGlibContainerAsVec::from_glib_full_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibContainerAsVec<*mut $ffi_name, *const *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_none_num_as_vec(ptr: *const *mut $ffi_name, num: usize) -> Vec<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr as *mut *mut _, num)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_container_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_full_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *const *mut $ffi_name> for $name
|
2018-09-28 14:36:19 +00:00
|
|
|
{
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_none_as_vec(ptr: *const *mut $ffi_name) -> Vec<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::FromGlibPtrArrayContainerAsVec::from_glib_none_as_vec(ptr as *mut *mut _)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_container_as_vec(_: *const *mut $ffi_name) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_full_as_vec(_: *const *mut $ffi_name) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::GlibPtrDefault for $name {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GlibType = *mut $ffi_name;
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl $ref_name {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn as_ptr(&self) -> *const $ffi_name {
|
|
|
|
self as *const Self as *const $ffi_name
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn as_mut_ptr(&self) -> *mut $ffi_name {
|
|
|
|
self as *const Self as *mut $ffi_name
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn from_ptr<'a>(ptr: *const $ffi_name) -> &'a Self {
|
2020-06-29 21:12:46 +00:00
|
|
|
assert!(!ptr.is_null());
|
|
|
|
&*(ptr as *const Self)
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub unsafe fn from_mut_ptr<'a>(ptr: *mut $ffi_name) -> &'a mut Self {
|
2020-06-29 21:12:46 +00:00
|
|
|
assert!(!ptr.is_null());
|
|
|
|
assert_ne!(
|
2020-11-21 13:46:48 +00:00
|
|
|
$crate::ffi::gst_mini_object_is_writable(ptr as *mut $crate::ffi::GstMiniObject),
|
|
|
|
$crate::glib::ffi::GFALSE
|
2020-06-29 21:12:46 +00:00
|
|
|
);
|
|
|
|
&mut *(ptr as *mut Self)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn copy(&self) -> $name {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
$name::from_glib_full($crate::ffi::gst_mini_object_copy(
|
|
|
|
self.as_ptr() as *const $crate::ffi::GstMiniObject
|
|
|
|
) as *const $ffi_name)
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 09:57:51 +00:00
|
|
|
impl $crate::glib::translate::GlibPtrDefault for $ref_name {
|
|
|
|
type GlibType = *mut $ffi_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToOwned for $ref_name {
|
|
|
|
type Owned = $name;
|
|
|
|
|
|
|
|
fn to_owned(&self) -> $name {
|
|
|
|
self.copy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Sync for $ref_name {}
|
|
|
|
unsafe impl Send for $ref_name {}
|
|
|
|
unsafe impl Sync for $name {}
|
|
|
|
unsafe impl Send for $name {}
|
|
|
|
};
|
|
|
|
($name:ident, $ref_name:ident, $ffi_name:path, $get_type:expr) => {
|
|
|
|
$crate::mini_object_wrapper!($name, $ref_name, $ffi_name);
|
|
|
|
|
|
|
|
impl $crate::glib::types::StaticType for $name {
|
|
|
|
fn static_type() -> $crate::glib::types::Type {
|
|
|
|
$ref_name::static_type()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::types::StaticType for $ref_name {
|
|
|
|
fn static_type() -> $crate::glib::types::Type {
|
2021-04-20 13:12:36 +00:00
|
|
|
unsafe { $crate::glib::translate::from_glib($get_type()) }
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for $name {
|
|
|
|
type Type = Self;
|
2021-01-06 09:57:51 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe impl<'a> $crate::glib::value::FromValue<'a> for $name {
|
|
|
|
type Checker = $crate::glib::value::GenericValueTypeOrNoneChecker<Self>;
|
|
|
|
|
|
|
|
unsafe fn from_value(value: &'a $crate::glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
$crate::glib::translate::from_glib_none(
|
|
|
|
$crate::glib::gobject_ffi::g_value_get_boxed($crate::glib::translate::ToGlibPtr::to_glib_none(value).0) as *mut $ffi_name
|
|
|
|
)
|
2021-01-06 09:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl $crate::glib::value::ToValue for $name {
|
|
|
|
fn to_value(&self) -> $crate::glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = $crate::glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
$crate::glib::gobject_ffi::g_value_set_boxed(
|
|
|
|
$crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(&mut value).0,
|
|
|
|
$crate::glib::translate::ToGlibPtr::<*const $ffi_name>::to_glib_none(self).0 as *mut _,
|
|
|
|
)
|
2021-01-06 09:57:51 +00:00
|
|
|
}
|
2021-04-20 07:19:02 +00:00
|
|
|
value
|
|
|
|
}
|
|
|
|
|
|
|
|
fn value_type(&self) -> $crate::glib::Type {
|
|
|
|
<Self as $crate::glib::StaticType>::static_type()
|
2021-01-06 09:57:51 +00:00
|
|
|
}
|
2020-06-29 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl $crate::glib::value::ToValueOptional for $name {
|
|
|
|
fn to_value_optional(s: Option<&Self>) -> $crate::glib::Value {
|
|
|
|
skip_assert_initialized!();
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = $crate::glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
$crate::glib::gobject_ffi::g_value_set_boxed(
|
|
|
|
$crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(&mut value).0,
|
|
|
|
$crate::glib::translate::ToGlibPtr::<*const $ffi_name>::to_glib_none(&s).0 as *mut _,
|
|
|
|
)
|
2020-05-27 10:07:32 +00:00
|
|
|
}
|
2021-04-20 07:19:02 +00:00
|
|
|
value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> $crate::glib::value::FromValue<'a> for &'a $ref_name {
|
|
|
|
type Checker = $crate::glib::value::GenericValueTypeOrNoneChecker<Self>;
|
|
|
|
|
|
|
|
unsafe fn from_value(value: &'a $crate::glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
&*($crate::glib::gobject_ffi::g_value_get_boxed($crate::glib::translate::ToGlibPtr::to_glib_none(value).0) as *const $ref_name)
|
2020-05-27 10:07:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't have SetValue/SetValueOptional impls as otherwise one could use it to get
|
|
|
|
// immutable references from a mutable reference without borrowing via the value
|
2021-01-06 09:57:51 +00:00
|
|
|
};
|
2018-09-28 14:36:19 +00:00
|
|
|
);
|