gstreamer-rs/gstreamer/src/subclass/child_proxy.rs

184 lines
6.1 KiB
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
2018-11-18 14:36:28 +00:00
use glib::{prelude::*, subclass::prelude::*, translate::*};
2018-11-18 14:36:28 +00:00
use super::prelude::*;
use crate::ChildProxy;
2018-11-18 14:36:28 +00:00
pub trait ChildProxyImpl: GstObjectImpl + Send + Sync {
fn child_by_name(&self, name: &str) -> Option<glib::Object> {
self.parent_child_by_name(name)
2021-03-14 08:29:44 +00:00
}
fn child_by_index(&self, index: u32) -> Option<glib::Object>;
fn children_count(&self) -> u32;
2021-03-14 08:29:44 +00:00
fn child_added(&self, child: &glib::Object, name: &str) {
self.parent_child_added(child, name);
2021-03-14 08:29:44 +00:00
}
fn child_removed(&self, child: &glib::Object, name: &str) {
self.parent_child_removed(child, name);
2021-03-14 08:29:44 +00:00
}
}
pub trait ChildProxyImplExt: ObjectSubclass {
fn parent_child_by_name(&self, name: &str) -> Option<glib::Object>;
2021-03-14 08:29:44 +00:00
fn parent_child_by_index(&self, index: u32) -> Option<glib::Object>;
fn parent_children_count(&self) -> u32;
2021-03-14 08:29:44 +00:00
fn parent_child_added(&self, _child: &glib::Object, _name: &str);
fn parent_child_removed(&self, _child: &glib::Object, _name: &str);
2021-03-14 08:29:44 +00:00
}
impl<T: ChildProxyImpl> ChildProxyImplExt for T {
fn parent_child_by_name(&self, name: &str) -> Option<glib::Object> {
2018-11-18 14:36:28 +00:00
unsafe {
2021-03-14 08:29:44 +00:00
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
2021-03-14 08:29:44 +00:00
as *const ffi::GstChildProxyInterface;
2018-11-18 14:36:28 +00:00
2021-03-14 08:29:44 +00:00
let func = (*parent_iface)
.get_child_by_name
.expect("no parent \"child_by_name\" implementation");
2021-03-14 08:29:44 +00:00
let ret = func(
self.obj().unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
2018-11-18 14:36:28 +00:00
name.to_glib_none().0,
);
2021-03-14 08:29:44 +00:00
from_glib_full(ret)
}
}
2018-11-18 14:36:28 +00:00
fn parent_child_by_index(&self, index: u32) -> Option<glib::Object> {
2021-03-14 08:29:44 +00:00
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
2021-03-14 08:29:44 +00:00
as *const ffi::GstChildProxyInterface;
2018-11-18 14:36:28 +00:00
2021-03-14 08:29:44 +00:00
let func = (*parent_iface)
.get_child_by_index
.expect("no parent \"child_by_index\" implementation");
2021-03-14 08:29:44 +00:00
let ret = func(
self.obj().unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
2021-03-14 08:29:44 +00:00
index,
);
2018-11-18 14:36:28 +00:00
from_glib_full(ret)
}
}
fn parent_children_count(&self) -> u32 {
2021-03-14 08:29:44 +00:00
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
2021-03-14 08:29:44 +00:00
as *const ffi::GstChildProxyInterface;
2018-11-18 14:36:28 +00:00
2021-03-14 08:29:44 +00:00
let func = (*parent_iface)
.get_children_count
.expect("no parent \"children_count\" implementation");
func(self.obj().unsafe_cast_ref::<ChildProxy>().to_glib_none().0)
2021-03-14 08:29:44 +00:00
}
}
fn parent_child_added(&self, child: &glib::Object, name: &str) {
2021-03-14 08:29:44 +00:00
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
2021-03-14 08:29:44 +00:00
as *const ffi::GstChildProxyInterface;
if let Some(func) = (*parent_iface).child_added {
func(
self.obj().unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
2021-03-14 08:29:44 +00:00
child.to_glib_none().0,
name.to_glib_none().0,
);
}
}
}
fn parent_child_removed(&self, child: &glib::Object, name: &str) {
2021-03-14 08:29:44 +00:00
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
2021-03-14 08:29:44 +00:00
as *const ffi::GstChildProxyInterface;
if let Some(func) = (*parent_iface).child_removed {
func(
self.obj().unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
2021-03-14 08:29:44 +00:00
child.to_glib_none().0,
name.to_glib_none().0,
);
}
}
}
2018-11-18 14:36:28 +00:00
}
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
2021-03-14 08:29:44 +00:00
fn interface_init(iface: &mut glib::Interface<Self>) {
2021-03-08 10:06:56 +00:00
let iface = iface.as_mut();
iface.get_child_by_name = Some(child_proxy_get_child_by_name::<T>);
iface.get_child_by_index = Some(child_proxy_get_child_by_index::<T>);
iface.get_children_count = Some(child_proxy_get_children_count::<T>);
iface.child_added = Some(child_proxy_child_added::<T>);
iface.child_removed = Some(child_proxy_child_removed::<T>);
}
}
unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
child_proxy: *mut ffi::GstChildProxy,
2018-11-18 14:36:28 +00:00
name: *const libc::c_char,
) -> *mut glib::gobject_ffi::GObject {
2018-11-18 14:36:28 +00:00
let instance = &*(child_proxy as *mut T::Instance);
2021-12-28 15:50:06 +00:00
let imp = instance.imp();
2018-11-18 14:36:28 +00:00
imp.child_by_name(&glib::GString::from_glib_borrow(name))
.into_glib_ptr()
2018-11-18 14:36:28 +00:00
}
unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
child_proxy: *mut ffi::GstChildProxy,
2018-11-18 14:36:28 +00:00
index: u32,
) -> *mut glib::gobject_ffi::GObject {
2018-11-18 14:36:28 +00:00
let instance = &*(child_proxy as *mut T::Instance);
2021-12-28 15:50:06 +00:00
let imp = instance.imp();
2018-11-18 14:36:28 +00:00
imp.child_by_index(index).into_glib_ptr()
2018-11-18 14:36:28 +00:00
}
unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
child_proxy: *mut ffi::GstChildProxy,
) -> u32 {
2018-11-18 14:36:28 +00:00
let instance = &*(child_proxy as *mut T::Instance);
2021-12-28 15:50:06 +00:00
let imp = instance.imp();
2018-11-18 14:36:28 +00:00
imp.children_count()
2018-11-18 14:36:28 +00:00
}
unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
child_proxy: *mut ffi::GstChildProxy,
child: *mut glib::gobject_ffi::GObject,
2018-11-18 14:36:28 +00:00
name: *const libc::c_char,
) {
2018-11-18 14:36:28 +00:00
let instance = &*(child_proxy as *mut T::Instance);
2021-12-28 15:50:06 +00:00
let imp = instance.imp();
2018-11-18 14:36:28 +00:00
imp.child_added(
&from_glib_borrow(child),
&glib::GString::from_glib_borrow(name),
2018-11-18 14:36:28 +00:00
)
}
unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>(
child_proxy: *mut ffi::GstChildProxy,
child: *mut glib::gobject_ffi::GObject,
2018-11-18 14:36:28 +00:00
name: *const libc::c_char,
) {
2018-11-18 14:36:28 +00:00
let instance = &*(child_proxy as *mut T::Instance);
2021-12-28 15:50:06 +00:00
let imp = instance.imp();
2018-11-18 14:36:28 +00:00
imp.child_removed(
&from_glib_borrow(child),
&glib::GString::from_glib_borrow(name),
2018-11-18 14:36:28 +00:00
)
}