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
|
|
|
|
2020-11-14 15:34:41 +00:00
|
|
|
use glib::prelude::*;
|
2018-11-18 14:36:28 +00:00
|
|
|
use glib::subclass::prelude::*;
|
|
|
|
use glib::translate::*;
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::ChildProxy;
|
2018-11-18 14:36:28 +00:00
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
|
2020-11-14 15:34:41 +00:00
|
|
|
fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> {
|
2018-11-18 14:36:28 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let type_ = ffi::gst_child_proxy_get_type();
|
|
|
|
let iface = glib::gobject_ffi::g_type_default_interface_ref(type_)
|
|
|
|
as *mut ffi::GstChildProxyInterface;
|
2018-11-18 14:36:28 +00:00
|
|
|
assert!(!iface.is_null());
|
|
|
|
|
|
|
|
let ret = ((*iface).get_child_by_name.as_ref().unwrap())(
|
2020-11-14 15:34:41 +00:00
|
|
|
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
|
2018-11-18 14:36:28 +00:00
|
|
|
name.to_glib_none().0,
|
|
|
|
);
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::gobject_ffi::g_type_default_interface_unref(iface as glib::ffi::gpointer);
|
2018-11-18 14:36:28 +00:00
|
|
|
|
|
|
|
from_glib_full(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 15:34:41 +00:00
|
|
|
fn get_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object>;
|
|
|
|
fn get_children_count(&self, object: &Self::Type) -> u32;
|
2018-11-18 14:36:28 +00:00
|
|
|
|
2020-11-14 15:34:41 +00:00
|
|
|
fn child_added(&self, _object: &Self::Type, _child: &glib::Object, _name: &str) {}
|
|
|
|
fn child_removed(&self, _object: &Self::Type, _child: &glib::Object, _name: &str) {}
|
2018-11-18 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
|
2021-03-08 10:06:56 +00:00
|
|
|
fn interface_init(iface: &mut glib::Class<Self>) {
|
|
|
|
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);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.get_child_by_name(
|
2020-11-14 15:34:41 +00:00
|
|
|
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
|
2020-04-05 14:52:56 +00:00
|
|
|
&glib::GString::from_glib_borrow(name),
|
2018-11-18 14:36:28 +00:00
|
|
|
)
|
|
|
|
.to_glib_full()
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
2020-11-14 15:34:41 +00:00
|
|
|
imp.get_child_by_index(
|
|
|
|
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
|
|
|
|
index,
|
|
|
|
)
|
|
|
|
.to_glib_full()
|
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);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
2020-11-14 15:34:41 +00:00
|
|
|
imp.get_children_count(&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref())
|
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);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.child_added(
|
2020-11-14 15:34:41 +00:00
|
|
|
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
|
2018-11-18 14:36:28 +00:00
|
|
|
&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);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.child_removed(
|
2020-11-14 15:34:41 +00:00
|
|
|
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
|
2018-11-18 14:36:28 +00:00
|
|
|
&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
|
|
|
)
|
|
|
|
}
|