2017-07-03 10:56:26 +00:00
|
|
|
// Copyright (C) 2016-2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::marker::PhantomData;
|
2017-07-03 10:56:26 +00:00
|
|
|
use std::mem;
|
2017-08-02 17:46:22 +00:00
|
|
|
use std::ptr;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::{borrow, fmt, ops};
|
2017-07-03 10:56:26 +00:00
|
|
|
|
|
|
|
use ffi;
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib;
|
2018-07-27 10:36:40 +00:00
|
|
|
use glib::translate::{
|
2018-09-28 14:36:19 +00:00
|
|
|
from_glib, from_glib_full, from_glib_none, FromGlibContainerAsVec,
|
2018-07-27 10:36:40 +00:00
|
|
|
FromGlibPtrArrayContainerAsVec, FromGlibPtrBorrow, FromGlibPtrFull, FromGlibPtrNone,
|
|
|
|
GlibPtrDefault, Stash, StashMut, ToGlibContainerFromSlice, ToGlibPtr, ToGlibPtrMut,
|
|
|
|
};
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib_ffi;
|
|
|
|
use glib_ffi::gpointer;
|
|
|
|
use gobject_ffi;
|
2017-07-03 10:56:26 +00:00
|
|
|
|
|
|
|
pub struct GstRc<T: MiniObject> {
|
2018-04-01 08:29:15 +00:00
|
|
|
obj: ptr::NonNull<T>,
|
2017-07-03 10:56:26 +00:00
|
|
|
borrowed: bool,
|
|
|
|
phantom: PhantomData<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject> GstRc<T> {
|
|
|
|
pub unsafe fn from_glib_none(ptr: *const T::GstType) -> Self {
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
|
|
|
|
ffi::gst_mini_object_ref(ptr as *mut ffi::GstMiniObject);
|
|
|
|
|
|
|
|
GstRc {
|
2018-07-06 08:22:29 +00:00
|
|
|
obj: ptr::NonNull::new_unchecked(ptr as *mut T::GstType as *mut T),
|
2017-07-03 10:56:26 +00:00
|
|
|
borrowed: false,
|
|
|
|
phantom: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn from_glib_full(ptr: *const T::GstType) -> Self {
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
|
|
|
|
GstRc {
|
2018-07-06 08:22:29 +00:00
|
|
|
obj: ptr::NonNull::new_unchecked(ptr as *mut T::GstType as *mut T),
|
2017-07-03 10:56:26 +00:00
|
|
|
borrowed: false,
|
|
|
|
phantom: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn from_glib_borrow(ptr: *const T::GstType) -> Self {
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
|
|
|
|
GstRc {
|
2018-07-06 08:22:29 +00:00
|
|
|
obj: ptr::NonNull::new_unchecked(ptr as *mut T::GstType as *mut T),
|
2017-07-03 10:56:26 +00:00
|
|
|
borrowed: true,
|
|
|
|
phantom: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn make_mut(&mut self) -> &mut T {
|
|
|
|
unsafe {
|
|
|
|
if self.is_writable() {
|
2018-04-01 08:29:15 +00:00
|
|
|
return self.obj.as_mut();
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 10:36:40 +00:00
|
|
|
let ptr = T::from_mut_ptr(ffi::gst_mini_object_make_writable(
|
|
|
|
self.as_mut_ptr() as *mut ffi::GstMiniObject
|
|
|
|
) as *mut T::GstType);
|
2018-04-01 08:29:15 +00:00
|
|
|
self.obj = ptr::NonNull::new_unchecked(ptr);
|
2017-07-03 10:56:26 +00:00
|
|
|
assert!(self.is_writable());
|
|
|
|
|
2018-04-01 08:29:15 +00:00
|
|
|
self.obj.as_mut()
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:30:55 +00:00
|
|
|
pub fn get_mut(&mut self) -> Option<&mut T> {
|
2017-07-03 10:56:26 +00:00
|
|
|
if self.is_writable() {
|
2018-04-01 08:29:15 +00:00
|
|
|
Some(unsafe { self.obj.as_mut() })
|
2017-07-03 10:56:26 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_writable(&self) -> bool {
|
|
|
|
unsafe {
|
2018-07-27 10:36:40 +00:00
|
|
|
from_glib(ffi::gst_mini_object_is_writable(
|
|
|
|
self.as_ptr() as *const ffi::GstMiniObject
|
|
|
|
))
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn into_ptr(self) -> *mut T::GstType {
|
|
|
|
let ptr = self.as_mut_ptr();
|
|
|
|
mem::forget(self);
|
|
|
|
|
|
|
|
ptr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject> ops::Deref for GstRc<T> {
|
|
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
self.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject> AsRef<T> for GstRc<T> {
|
|
|
|
fn as_ref(&self) -> &T {
|
2018-04-01 08:29:15 +00:00
|
|
|
unsafe { self.obj.as_ref() }
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject> borrow::Borrow<T> for GstRc<T> {
|
|
|
|
fn borrow(&self) -> &T {
|
|
|
|
self.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Not generally possible because neither T nor ToOwned are defined here...
|
|
|
|
//impl<T: MiniObject> ToOwned for T {
|
|
|
|
// type Owned = GstRc<T>;
|
|
|
|
//
|
|
|
|
// fn to_owned(&self) -> GstRc<T> {
|
|
|
|
// unsafe { GstRc::from_unowned_ptr(self.as_ptr()) }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
impl<T: MiniObject> Clone for GstRc<T> {
|
|
|
|
fn clone(&self) -> GstRc<T> {
|
|
|
|
unsafe { GstRc::from_glib_none(self.as_ptr()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject> Drop for GstRc<T> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
if !self.borrowed {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_mini_object_unref(self.as_mut_ptr() as *mut ffi::GstMiniObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 12:01:24 +00:00
|
|
|
unsafe impl<T: MiniObject + Sync + Send> Sync for GstRc<T> {}
|
|
|
|
unsafe impl<T: MiniObject + Sync + Send> Send for GstRc<T> {}
|
2017-07-03 10:56:26 +00:00
|
|
|
|
2017-08-09 17:05:31 +00:00
|
|
|
impl<T: MiniObject + PartialEq> PartialEq for GstRc<T> {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.as_ref().eq(other.as_ref())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 11:55:29 +00:00
|
|
|
impl<T: MiniObject + Eq> Eq for GstRc<T> {}
|
2017-08-09 17:05:31 +00:00
|
|
|
|
|
|
|
impl<T: MiniObject + fmt::Debug> fmt::Debug for GstRc<T> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-08-09 17:06:27 +00:00
|
|
|
self.as_ref().fmt(f)
|
2017-08-09 17:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 10:56:26 +00:00
|
|
|
impl<T: MiniObject + fmt::Display> fmt::Display for GstRc<T> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-08-09 17:06:27 +00:00
|
|
|
self.as_ref().fmt(f)
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe trait MiniObject
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
type GstType;
|
|
|
|
|
|
|
|
unsafe fn as_ptr(&self) -> *const Self::GstType {
|
|
|
|
self as *const Self as *const Self::GstType
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn as_mut_ptr(&self) -> *mut Self::GstType {
|
|
|
|
self as *const Self as *mut Self::GstType
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_ptr<'a>(ptr: *const Self::GstType) -> &'a Self {
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
&*(ptr as *const Self)
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_mut_ptr<'a>(ptr: *mut Self::GstType) -> &'a mut Self {
|
|
|
|
assert!(!ptr.is_null());
|
2018-07-27 10:36:40 +00:00
|
|
|
assert_ne!(
|
|
|
|
ffi::gst_mini_object_is_writable(ptr as *mut ffi::GstMiniObject),
|
|
|
|
glib_ffi::GFALSE
|
|
|
|
);
|
2017-07-03 10:56:26 +00:00
|
|
|
&mut *(ptr as *mut Self)
|
|
|
|
}
|
2017-10-12 14:58:46 +00:00
|
|
|
|
|
|
|
fn copy(&self) -> GstRc<Self> {
|
|
|
|
unsafe {
|
2018-07-27 10:36:40 +00:00
|
|
|
GstRc::from_glib_full(ffi::gst_mini_object_copy(
|
|
|
|
self.as_ptr() as *const ffi::GstMiniObject
|
|
|
|
) as *const Self::GstType)
|
2017-10-12 14:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 10:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: MiniObject + 'static> ToGlibPtr<'a, *const T::GstType> for GstRc<T> {
|
|
|
|
type Storage = &'a Self;
|
|
|
|
|
|
|
|
fn to_glib_none(&'a self) -> Stash<'a, *const T::GstType, Self> {
|
|
|
|
Stash(unsafe { self.as_ptr() }, self)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full(&self) -> *const T::GstType {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_mini_object_ref(self.as_mut_ptr() as *mut ffi::GstMiniObject);
|
|
|
|
self.as_ptr()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: MiniObject + 'static> ToGlibPtr<'a, *mut T::GstType> for GstRc<T> {
|
|
|
|
type Storage = &'a Self;
|
|
|
|
|
|
|
|
fn to_glib_none(&'a self) -> Stash<'a, *mut T::GstType, Self> {
|
|
|
|
Stash(unsafe { self.as_mut_ptr() }, self)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full(&self) -> *mut T::GstType {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_mini_object_ref(self.as_mut_ptr() as *mut ffi::GstMiniObject);
|
|
|
|
self.as_mut_ptr()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: MiniObject + 'static> ToGlibPtrMut<'a, *mut T::GstType> for GstRc<T> {
|
|
|
|
type Storage = &'a mut Self;
|
|
|
|
|
|
|
|
fn to_glib_none_mut(&'a mut self) -> StashMut<*mut T::GstType, Self> {
|
|
|
|
self.make_mut();
|
|
|
|
StashMut(unsafe { self.as_mut_ptr() }, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 17:46:22 +00:00
|
|
|
impl<'a, T: MiniObject + 'static> ToGlibContainerFromSlice<'a, *mut *mut T::GstType> for GstRc<T> {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2017-09-10 11:55:29 +00:00
|
|
|
type Storage = (
|
|
|
|
Vec<Stash<'a, *mut T::GstType, GstRc<T>>>,
|
|
|
|
Option<Vec<*mut T::GstType>>,
|
|
|
|
);
|
2017-08-02 17:46:22 +00:00
|
|
|
|
|
|
|
fn to_glib_none_from_slice(t: &'a [GstRc<T>]) -> (*mut *mut T::GstType, Self::Storage) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-02 17:46:22 +00:00
|
|
|
let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
|
|
|
|
let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
|
|
|
|
v_ptr.push(ptr::null_mut() as *mut T::GstType);
|
|
|
|
|
|
|
|
(v_ptr.as_ptr() as *mut *mut T::GstType, (v, Some(v_ptr)))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_container_from_slice(t: &'a [GstRc<T>]) -> (*mut *mut T::GstType, Self::Storage) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-02 17:46:22 +00:00
|
|
|
let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
|
|
|
|
|
|
|
|
let v_ptr = unsafe {
|
2017-10-17 09:06:51 +00:00
|
|
|
let v_ptr = glib_ffi::g_malloc0(mem::size_of::<*mut T::GstType>() * t.len() + 1)
|
|
|
|
as *mut *mut T::GstType;
|
2017-08-02 17:46:22 +00:00
|
|
|
|
|
|
|
for (i, s) in v.iter().enumerate() {
|
2018-10-11 08:21:45 +00:00
|
|
|
ptr::write(v_ptr.add(i), s.0);
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v_ptr
|
|
|
|
};
|
|
|
|
|
|
|
|
(v_ptr, (v, None))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full_from_slice(t: &[GstRc<T>]) -> *mut *mut T::GstType {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-02 17:46:22 +00:00
|
|
|
unsafe {
|
2017-10-17 09:06:51 +00:00
|
|
|
let v_ptr = glib_ffi::g_malloc0(mem::size_of::<*mut T::GstType>() * t.len() + 1)
|
|
|
|
as *mut *mut T::GstType;
|
2017-08-02 17:46:22 +00:00
|
|
|
|
|
|
|
for (i, s) in t.iter().enumerate() {
|
2018-10-11 08:21:45 +00:00
|
|
|
ptr::write(v_ptr.add(i), s.to_glib_full());
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v_ptr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 11:55:29 +00:00
|
|
|
impl<'a, T: MiniObject + 'static> ToGlibContainerFromSlice<'a, *const *mut T::GstType>
|
2018-02-22 10:18:37 +00:00
|
|
|
for GstRc<T>
|
|
|
|
{
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2017-09-10 11:55:29 +00:00
|
|
|
type Storage = (
|
|
|
|
Vec<Stash<'a, *mut T::GstType, GstRc<T>>>,
|
|
|
|
Option<Vec<*mut T::GstType>>,
|
|
|
|
);
|
2017-08-02 17:46:22 +00:00
|
|
|
|
|
|
|
fn to_glib_none_from_slice(t: &'a [GstRc<T>]) -> (*const *mut T::GstType, Self::Storage) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-09-10 11:55:29 +00:00
|
|
|
let (ptr, stash) =
|
|
|
|
ToGlibContainerFromSlice::<'a, *mut *mut T::GstType>::to_glib_none_from_slice(t);
|
2017-08-02 17:46:22 +00:00
|
|
|
(ptr as *const *mut T::GstType, stash)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_container_from_slice(_: &'a [GstRc<T>]) -> (*const *mut T::GstType, Self::Storage) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-02 17:46:22 +00:00
|
|
|
// Can't have consumer free a *const pointer
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full_from_slice(_: &[GstRc<T>]) -> *const *mut T::GstType {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-02 17:46:22 +00:00
|
|
|
// Can't have consumer free a *const pointer
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 10:56:26 +00:00
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrNone<*const T::GstType> for GstRc<T> {
|
|
|
|
unsafe fn from_glib_none(ptr: *const T::GstType) -> Self {
|
|
|
|
Self::from_glib_none(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrNone<*mut T::GstType> for GstRc<T> {
|
|
|
|
unsafe fn from_glib_none(ptr: *mut T::GstType) -> Self {
|
|
|
|
Self::from_glib_none(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrFull<*const T::GstType> for GstRc<T> {
|
|
|
|
unsafe fn from_glib_full(ptr: *const T::GstType) -> Self {
|
|
|
|
Self::from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrFull<*mut T::GstType> for GstRc<T> {
|
|
|
|
unsafe fn from_glib_full(ptr: *mut T::GstType) -> Self {
|
|
|
|
Self::from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrBorrow<*const T::GstType> for GstRc<T> {
|
|
|
|
unsafe fn from_glib_borrow(ptr: *const T::GstType) -> Self {
|
|
|
|
Self::from_glib_borrow(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrBorrow<*mut T::GstType> for GstRc<T> {
|
|
|
|
unsafe fn from_glib_borrow(ptr: *mut T::GstType) -> Self {
|
|
|
|
Self::from_glib_borrow(ptr)
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 10:09:34 +00:00
|
|
|
|
2017-09-10 11:55:29 +00:00
|
|
|
impl<T: MiniObject + 'static> FromGlibContainerAsVec<*mut T::GstType, *mut *mut T::GstType>
|
2018-02-22 10:18:37 +00:00
|
|
|
for GstRc<T>
|
|
|
|
{
|
2017-08-02 17:46:22 +00:00
|
|
|
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut T::GstType, num: usize) -> Vec<Self> {
|
|
|
|
if num == 0 || ptr.is_null() {
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(num);
|
|
|
|
for i in 0..num {
|
2018-10-11 08:21:45 +00:00
|
|
|
res.push(from_glib_none(ptr::read(ptr.add(i))));
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut T::GstType, num: usize) -> Vec<Self> {
|
|
|
|
let res = FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
|
|
|
|
glib_ffi::g_free(ptr as *mut _);
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut T::GstType, num: usize) -> Vec<Self> {
|
|
|
|
if num == 0 || ptr.is_null() {
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(num);
|
|
|
|
for i in 0..num {
|
2018-10-11 08:21:45 +00:00
|
|
|
res.push(from_glib_full(ptr::read(ptr.add(i))));
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
glib_ffi::g_free(ptr as *mut _);
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 11:55:29 +00:00
|
|
|
impl<T: MiniObject + 'static> FromGlibPtrArrayContainerAsVec<*mut T::GstType, *mut *mut T::GstType>
|
2018-02-22 10:18:37 +00:00
|
|
|
for GstRc<T>
|
|
|
|
{
|
2017-08-02 17:46:22 +00:00
|
|
|
unsafe fn from_glib_none_as_vec(ptr: *mut *mut T::GstType) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
FromGlibContainerAsVec::from_glib_none_num_as_vec(
|
|
|
|
ptr,
|
|
|
|
glib::translate::c_ptr_array_len(ptr),
|
|
|
|
)
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_container_as_vec(ptr: *mut *mut T::GstType) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
FromGlibContainerAsVec::from_glib_container_num_as_vec(
|
|
|
|
ptr,
|
|
|
|
glib::translate::c_ptr_array_len(ptr),
|
|
|
|
)
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_as_vec(ptr: *mut *mut T::GstType) -> Vec<Self> {
|
2018-09-28 14:36:19 +00:00
|
|
|
FromGlibContainerAsVec::from_glib_full_num_as_vec(
|
|
|
|
ptr,
|
|
|
|
glib::translate::c_ptr_array_len(ptr),
|
|
|
|
)
|
2017-08-02 17:46:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 11:55:29 +00:00
|
|
|
impl<T: MiniObject + 'static> FromGlibContainerAsVec<*mut T::GstType, *const *mut T::GstType>
|
2018-02-22 10:18:37 +00:00
|
|
|
for GstRc<T>
|
|
|
|
{
|
2017-08-02 17:46:22 +00:00
|
|
|
unsafe fn from_glib_none_num_as_vec(ptr: *const *mut T::GstType, num: usize) -> Vec<Self> {
|
|
|
|
FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr as *mut *mut _, num)
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_container_num_as_vec(_: *const *mut T::GstType, _: usize) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_num_as_vec(_: *const *mut T::GstType, _: usize) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 08:30:03 +00:00
|
|
|
impl<T: MiniObject + 'static>
|
|
|
|
FromGlibPtrArrayContainerAsVec<*mut T::GstType, *const *mut T::GstType> for GstRc<T>
|
2018-02-22 10:18:37 +00:00
|
|
|
{
|
2017-08-02 17:46:22 +00:00
|
|
|
unsafe fn from_glib_none_as_vec(ptr: *const *mut T::GstType) -> Vec<Self> {
|
|
|
|
FromGlibPtrArrayContainerAsVec::from_glib_none_as_vec(ptr as *mut *mut _)
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_container_as_vec(_: *const *mut T::GstType) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_as_vec(_: *const *mut T::GstType) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 10:09:34 +00:00
|
|
|
impl<T: MiniObject + glib::StaticType> glib::StaticType for GstRc<T> {
|
|
|
|
fn static_type() -> glib::types::Type {
|
|
|
|
T::static_type()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
impl<'a, T: MiniObject + glib::StaticType + 'static> glib::value::FromValueOptional<'a>
|
2018-02-22 10:18:37 +00:00
|
|
|
for GstRc<T>
|
|
|
|
{
|
2017-07-28 10:09:34 +00:00
|
|
|
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
|
|
|
|
let ptr = gobject_ffi::g_value_get_boxed(v.to_glib_none().0);
|
|
|
|
from_glib_none(ptr as *const T::GstType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: MiniObject + glib::StaticType> glib::value::SetValue for GstRc<T> {
|
|
|
|
unsafe fn set_value(v: &mut glib::Value, s: &Self) {
|
|
|
|
gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 17:46:22 +00:00
|
|
|
|
2017-08-18 12:38:51 +00:00
|
|
|
impl<T: MiniObject + glib::StaticType> glib::value::SetValueOptional for GstRc<T> {
|
|
|
|
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
|
|
|
|
if let Some(s) = s {
|
|
|
|
gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
|
|
|
|
} else {
|
|
|
|
gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 17:46:22 +00:00
|
|
|
impl<T: MiniObject + 'static> GlibPtrDefault for GstRc<T> {
|
|
|
|
type GlibType = *mut T::GstType;
|
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gst_define_mini_object_wrapper(
|
|
|
|
($name:ident, $ref_name:ident, $ffi_name:path, [$($derives:ident,)*], $get_type:expr) => {
|
|
|
|
#[derive($($derives,)*)]
|
2018-09-28 14:41:07 +00:00
|
|
|
#[derive(Clone)]
|
2018-09-28 14:36:19 +00:00
|
|
|
pub struct $name($crate::GstRc<$ref_name>);
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct $ref_name($ffi_name);
|
|
|
|
|
|
|
|
impl $name {
|
|
|
|
pub unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
|
2018-12-08 10:45:21 +00:00
|
|
|
$name($crate::glib::translate::from_glib_none(ptr))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
|
2018-12-08 10:45:21 +00:00
|
|
|
$name($crate::glib::translate::from_glib_full(ptr))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
|
2018-12-08 10:45:21 +00:00
|
|
|
$name($crate::glib::translate::from_glib_borrow(ptr))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn into_ptr(self) -> *mut $ffi_name {
|
|
|
|
self.0.into_ptr()
|
|
|
|
}
|
2018-10-03 13:54:00 +00:00
|
|
|
|
|
|
|
pub fn copy(&self) -> Self {
|
2018-10-05 13:36:15 +00:00
|
|
|
self.0.copy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl $ref_name {
|
|
|
|
fn copy(&self) -> $name {
|
|
|
|
$name(<$ref_name as $crate::MiniObject>::copy(self))
|
2018-10-03 13:54:00 +00:00
|
|
|
}
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 15:11:46 +00:00
|
|
|
impl From<$crate::GstRc<$ref_name>> for $name {
|
|
|
|
fn from(rc: $crate::GstRc<$ref_name>) -> $name {
|
|
|
|
$name(rc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<$crate::GstRc<$ref_name>> for $name {
|
|
|
|
fn into(self) -> $crate::GstRc<$ref_name> {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 14:36:19 +00:00
|
|
|
impl ::std::ops::Deref for $name {
|
|
|
|
type Target = $crate::GstRc<$ref_name>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ::std::ops::DerefMut for $name {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<$ref_name> for $name {
|
|
|
|
fn as_ref(&self) -> &$ref_name {
|
|
|
|
self.0.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ::std::borrow::Borrow<$ref_name> for $name {
|
|
|
|
fn borrow(&self) -> &$ref_name {
|
|
|
|
self.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::types::StaticType for $name {
|
|
|
|
fn static_type() -> $crate::glib::types::Type {
|
2018-09-28 14:36:19 +00:00
|
|
|
$ref_name::static_type()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *const $ffi_name> for $name {
|
|
|
|
type Storage = $crate::glib::translate::Stash<'a, *const $ffi_name, $crate::GstRc<$ref_name>>;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *const $ffi_name, Self> {
|
|
|
|
let stash = $crate::glib::translate::ToGlibPtr::to_glib_none(&self.0);
|
|
|
|
$crate::glib::translate::Stash(stash.0, stash)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full(&self) -> *const $ffi_name {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::ToGlibPtr::to_glib_full(&self.0)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *mut $ffi_name> for $name {
|
|
|
|
type Storage = $crate::glib::translate::Stash<'a, *mut $ffi_name, $crate::GstRc<$ref_name>>;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *mut $ffi_name, Self> {
|
|
|
|
let stash = $crate::glib::translate::ToGlibPtr::to_glib_none(&self.0);
|
|
|
|
$crate::glib::translate::Stash(stash.0, stash)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full(&self) -> *mut $ffi_name {
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::ToGlibPtr::to_glib_full(&self.0)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl<'a> $crate::glib::translate::ToGlibPtrMut<'a, *mut $ffi_name> for $name {
|
|
|
|
type Storage = $crate::glib::translate::StashMut<'a, *mut $ffi_name, $crate::GstRc<$ref_name>>;
|
2018-09-28 14:36:19 +00:00
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
fn to_glib_none_mut(&'a mut self) -> $crate::glib::translate::StashMut<*mut $ffi_name, Self> {
|
|
|
|
let stash = $crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(&mut self.0);
|
|
|
|
$crate::glib::translate::StashMut(stash.0, stash)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +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 = (
|
2018-12-08 10:45:21 +00:00
|
|
|
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, $name>>,
|
2018-09-28 14:36:19 +00:00
|
|
|
Option<Vec<*mut $ffi_name>>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fn to_glib_none_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
|
|
|
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();
|
2018-09-28 15:11:46 +00:00
|
|
|
v_ptr.push(::std::ptr::null_mut() as *mut $ffi_name);
|
2018-09-28 14:36:19 +00:00
|
|
|
|
|
|
|
(v_ptr.as_ptr() as *mut *mut $ffi_name, (v, Some(v_ptr)))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_container_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
|
|
|
|
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 {
|
2018-12-08 10:45:21 +00:00
|
|
|
let v_ptr = $crate::glib_ffi::g_malloc0(::std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
|
2018-09-28 14:36:19 +00:00
|
|
|
as *mut *mut $ffi_name;
|
|
|
|
|
|
|
|
for (i, s) in v.iter().enumerate() {
|
2018-10-11 08:21:45 +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))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
2018-12-08 10:45:21 +00:00
|
|
|
let v_ptr = $crate::glib_ffi::g_malloc0(::std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
|
2018-09-28 14:36:19 +00:00
|
|
|
as *mut *mut $ffi_name;
|
|
|
|
|
|
|
|
for (i, s) in t.iter().enumerate() {
|
2018-12-08 10:45:21 +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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +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 = (
|
2018-12-08 10:45:21 +00:00
|
|
|
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, $name>>,
|
2018-09-28 14:36:19 +00:00
|
|
|
Option<Vec<*mut $ffi_name>>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fn to_glib_none_from_slice(t: &'a [$name]) -> (*const *mut $ffi_name, Self::Storage) {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let (ptr, stash) =
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib::translate::ToGlibContainerFromSlice::<'a, *mut *mut $ffi_name>::to_glib_none_from_slice(t);
|
2018-09-28 14:36:19 +00:00
|
|
|
(ptr as *const *mut $ffi_name, stash)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_container_from_slice(_: &'a [$name]) -> (*const *mut $ffi_name, Self::Storage) {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
// Can't have consumer free a *const pointer
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_glib_full_from_slice(_: &[$name]) -> *const *mut $ffi_name {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
// Can't have consumer free a *const pointer
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrNone<*const $ffi_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
|
|
|
|
Self::from_glib_none(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrNone<*mut $ffi_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
|
|
|
|
Self::from_glib_none(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrFull<*const $ffi_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
|
|
|
|
Self::from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrFull<*mut $ffi_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
|
|
|
|
Self::from_glib_full(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
|
|
|
|
Self::from_glib_borrow(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> Self {
|
|
|
|
Self::from_glib_borrow(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
|
|
|
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
|
|
|
|
if num == 0 || ptr.is_null() {
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(num);
|
|
|
|
for i in 0..num {
|
2018-12-08 10:45:21 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
$crate::glib_ffi::g_free(ptr as *mut _);
|
2018-09-28 14:36:19 +00:00
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
|
|
|
|
if num == 0 || ptr.is_null() {
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut res = Vec::with_capacity(num);
|
|
|
|
for i in 0..num {
|
2018-12-08 10:45:21 +00:00
|
|
|
res.push($crate::glib::translate::from_glib_full(::std::ptr::read(ptr.add(i))));
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
2018-12-08 10:45:21 +00:00
|
|
|
$crate::glib_ffi::g_free(ptr as *mut _);
|
2018-09-28 14:36:19 +00:00
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibContainerAsVec<*mut $ffi_name, *const *mut $ffi_name>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_container_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *const *mut $ffi_name> for $name
|
2018-09-28 14:36:19 +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
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_container_as_vec(_: *const *mut $ffi_name) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_glib_full_as_vec(_: *const *mut $ffi_name) -> Vec<Self> {
|
|
|
|
// Can't free a *const
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl<'a> $crate::glib::value::FromValueOptional<'a>
|
2018-09-28 14:36:19 +00:00
|
|
|
for $name
|
|
|
|
{
|
|
|
|
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
|
2018-12-08 10:45:21 +00:00
|
|
|
<$crate::GstRc<$ref_name> as $crate::glib::value::FromValueOptional>::from_value_optional(v).map($name)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::value::SetValue for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn set_value(v: &mut glib::Value, s: &Self) {
|
2018-12-08 10:45:21 +00:00
|
|
|
<$crate::GstRc<$ref_name> as $crate::glib::value::SetValue>::set_value(v, &s.0)
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::value::SetValueOptional for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
|
2018-12-08 10:45:21 +00:00
|
|
|
<$crate::GstRc<$ref_name> as $crate::glib::value::SetValueOptional>::set_value_optional(v, s.map(|s| &s.0))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::translate::GlibPtrDefault for $name {
|
2018-09-28 14:36:19 +00:00
|
|
|
type GlibType = *mut $ffi_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl $crate::MiniObject for $ref_name {
|
|
|
|
type GstType = $ffi_name;
|
|
|
|
}
|
|
|
|
|
2018-12-08 10:45:21 +00:00
|
|
|
impl $crate::glib::types::StaticType for $ref_name {
|
|
|
|
fn static_type() -> $crate::glib::types::Type {
|
|
|
|
unsafe { $crate::glib::translate::from_glib($get_type()) }
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToOwned for $ref_name {
|
|
|
|
type Owned = $name;
|
|
|
|
|
|
|
|
fn to_owned(&self) -> $name {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2018-09-28 14:36:19 +00:00
|
|
|
unsafe {
|
2018-12-08 10:45:21 +00:00
|
|
|
$name($crate::glib::translate::from_glib_none($crate::miniobject::MiniObject::as_ptr(self)))
|
2018-09-28 14:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Sync for $ref_name {}
|
|
|
|
unsafe impl Send for $ref_name {}
|
|
|
|
}
|
|
|
|
);
|