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
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use glib::{prelude::*, subclass::prelude::*, translate::*};
|
2018-11-18 14:36:28 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use super::prelude::*;
|
2024-06-02 08:48:53 +00:00
|
|
|
use crate::{ffi, ChildProxy};
|
2018-11-18 14:36:28 +00:00
|
|
|
|
2021-08-24 06:12:27 +00:00
|
|
|
pub trait ChildProxyImpl: GstObjectImpl + Send + Sync {
|
2022-10-08 18:50:06 +00:00
|
|
|
fn child_by_name(&self, name: &str) -> Option<glib::Object> {
|
|
|
|
self.parent_child_by_name(name)
|
2021-03-14 08:29:44 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +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
|
|
|
|
2022-10-08 18:50:06 +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
|
|
|
}
|
2022-10-08 18:50:06 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
mod sealed {
|
|
|
|
pub trait Sealed {}
|
|
|
|
impl<T: super::ChildProxyImplExt> Sealed for T {}
|
2021-03-14 08:29:44 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
pub trait ChildProxyImplExt: sealed::Sealed + ObjectSubclass {
|
2022-10-08 18:50:06 +00:00
|
|
|
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();
|
2021-04-14 20:30:38 +00:00
|
|
|
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
|
2021-04-14 20:30:38 +00:00
|
|
|
.expect("no parent \"child_by_name\" implementation");
|
2021-03-14 08:29:44 +00:00
|
|
|
let ret = func(
|
2022-10-23 19:59:23 +00:00
|
|
|
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
|
|
|
|
2022-10-08 18:50:06 +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();
|
2021-04-14 20:30:38 +00:00
|
|
|
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
|
2021-04-14 20:30:38 +00:00
|
|
|
.expect("no parent \"child_by_index\" implementation");
|
2021-03-14 08:29:44 +00:00
|
|
|
let ret = func(
|
2022-10-23 19:59:23 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_children_count(&self) -> u32 {
|
2021-03-14 08:29:44 +00:00
|
|
|
unsafe {
|
|
|
|
let type_data = Self::type_data();
|
2021-04-14 20:30:38 +00:00
|
|
|
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
|
2021-04-14 20:30:38 +00:00
|
|
|
.expect("no parent \"children_count\" implementation");
|
2022-10-23 19:59:23 +00:00
|
|
|
func(self.obj().unsafe_cast_ref::<ChildProxy>().to_glib_none().0)
|
2021-03-14 08:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +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();
|
2021-04-14 20:30:38 +00:00
|
|
|
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(
|
2022-10-23 19:59:23 +00:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
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();
|
2021-04-14 20:30:38 +00:00
|
|
|
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(
|
2022-10-23 19:59:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
impl<T: ChildProxyImpl> ChildProxyImplExt for T {}
|
|
|
|
|
2020-07-25 08:02:04 +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>);
|
2018-12-18 23:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
|
2020-11-21 13:46:48 +00:00
|
|
|
child_proxy: *mut ffi::GstChildProxy,
|
2018-11-18 14:36:28 +00:00
|
|
|
name: *const libc::c_char,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> *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
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.child_by_name(&glib::GString::from_glib_borrow(name))
|
2023-01-04 16:11:27 +00:00
|
|
|
.into_glib_ptr()
|
2018-11-18 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
|
2020-11-21 13:46:48 +00:00
|
|
|
child_proxy: *mut ffi::GstChildProxy,
|
2018-11-18 14:36:28 +00:00
|
|
|
index: u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> *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
|
|
|
|
2023-01-04 16:11:27 +00:00
|
|
|
imp.child_by_index(index).into_glib_ptr()
|
2018-11-18 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
|
2020-11-21 13:46:48 +00:00
|
|
|
child_proxy: *mut ffi::GstChildProxy,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> 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
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.children_count()
|
2018-11-18 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
|
2020-11-21 13:46:48 +00:00
|
|
|
child_proxy: *mut ffi::GstChildProxy,
|
|
|
|
child: *mut glib::gobject_ffi::GObject,
|
2018-11-18 14:36:28 +00:00
|
|
|
name: *const libc::c_char,
|
2020-07-25 08:02:04 +00:00
|
|
|
) {
|
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),
|
2020-04-05 14:52:56 +00:00
|
|
|
&glib::GString::from_glib_borrow(name),
|
2018-11-18 14:36:28 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>(
|
2020-11-21 13:46:48 +00:00
|
|
|
child_proxy: *mut ffi::GstChildProxy,
|
|
|
|
child: *mut glib::gobject_ffi::GObject,
|
2018-11-18 14:36:28 +00:00
|
|
|
name: *const libc::c_char,
|
2020-07-25 08:02:04 +00:00
|
|
|
) {
|
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),
|
2020-04-05 14:52:56 +00:00
|
|
|
&glib::GString::from_glib_borrow(name),
|
2018-11-18 14:36:28 +00:00
|
|
|
)
|
|
|
|
}
|