Commit ec2a0635 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

Port Pad subclassing

parent 97211e86
......@@ -577,6 +577,7 @@ trait_name = "GstObjectExt"
[[object]]
name = "Gst.Pad"
subclassing = true
status = "generate"
[[object.function]]
name = "link_maybe_ghosting"
......
......@@ -8,6 +8,7 @@ use Event;
use EventType;
use FlowReturn;
use Object;
use PadClass;
use PadDirection;
use PadLinkCheck;
use PadLinkReturn;
......@@ -34,7 +35,7 @@ use std::mem::transmute;
use std::ptr;
glib_wrapper! {
pub struct Pad(Object<ffi::GstPad, ffi::GstPadClass>): Object;
pub struct Pad(Object<ffi::GstPad, ffi::GstPadClass, PadClass>): Object;
match fn {
get_type => || ffi::gst_pad_get_type(),
......
......@@ -184,6 +184,7 @@ mod gobject;
mod iterator;
mod object;
mod pad;
pub use pad::PadClass;
mod parse_context;
mod proxy_pad;
mod tag_setter;
......
......@@ -26,6 +26,7 @@ use StaticPadTemplate;
use std::cell::RefCell;
use std::mem;
use std::mem::transmute;
use std::ops;
use std::ptr;
use glib;
......@@ -34,7 +35,7 @@ use glib::translate::{
ToGlibPtr,
};
use glib::Object;
use glib::{IsA, StaticType};
use glib::{IsA, IsClassFor, StaticType};
use glib_ffi;
use glib_ffi::gpointer;
......@@ -912,6 +913,30 @@ impl<O: IsA<Pad>> PadExtManual for O {
}
}
#[repr(C)]
pub struct PadClass(ffi::GstPadClass);
unsafe impl IsClassFor for PadClass {
type Instance = Pad;
}
unsafe impl Send for PadClass {}
unsafe impl Sync for PadClass {}
impl ops::Deref for PadClass {
type Target = glib::ObjectClass;
fn deref(&self) -> &Self::Target {
self.upcast_ref()
}
}
impl ops::DerefMut for PadClass {
fn deref_mut(&mut self) -> &mut Self::Target {
self.upcast_ref_mut()
}
}
unsafe extern "C" fn trampoline_pad_probe(
pad: *mut ffi::GstPad,
info: *mut ffi::GstPadProbeInfo,
......
......@@ -16,6 +16,7 @@ pub mod plugin;
pub mod bin;
pub mod child_proxy;
pub mod element;
pub mod pad;
pub mod pipeline;
pub mod uri_handler;
......@@ -23,6 +24,7 @@ pub mod prelude {
pub use super::bin::BinImpl;
pub use super::child_proxy::ChildProxyImpl;
pub use super::element::{ElementClassSubclassExt, ElementImpl, ElementImplExt};
pub use super::pad::PadImpl;
pub use super::pipeline::PipelineImpl;
pub use super::uri_handler::URIHandlerImpl;
pub use super::PanicPoison;
......
// Copyright (C) 2018 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.
use ffi;
use glib;
use glib::translate::*;
use glib::subclass::prelude::*;
use Pad;
use PadClass;
pub trait PadImpl: ObjectImpl + Send + Sync + 'static {
fn linked(&self, pad: &Pad, peer: &Pad) {
self.parent_linked(pad, peer)
}
fn unlinked(&self, pad: &Pad, peer: &Pad) {
self.parent_unlinked(pad, peer)
}
fn parent_linked(&self, pad: &Pad, peer: &Pad) {
unsafe {
let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstPadClass;
(*parent_class)
.linked
.map(|f| f(pad.to_glib_none().0, peer.to_glib_none().0))
.unwrap_or(())
}
}
fn parent_unlinked(&self, pad: &Pad, peer: &Pad) {
unsafe {
let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstPadClass;
(*parent_class)
.unlinked
.map(|f| f(pad.to_glib_none().0, peer.to_glib_none().0))
.unwrap_or(())
}
}
}
unsafe impl<T: ObjectSubclass + PadImpl> IsSubclassable<T> for PadClass {
fn override_vfuncs(&mut self) {
<glib::ObjectClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe {
let klass = &mut *(self as *const Self as *mut ffi::GstPadClass);
klass.linked = Some(pad_linked::<T>);
klass.unlinked = Some(pad_unlinked::<T>);
}
}
}
unsafe extern "C" fn pad_linked<T: ObjectSubclass>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad)
where
T: PadImpl,
{
glib_floating_reference_guard!(ptr);
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Pad = from_glib_borrow(ptr);
imp.linked(&wrap, &from_glib_borrow(peer))
}
unsafe extern "C" fn pad_unlinked<T: ObjectSubclass>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad)
where
T: PadImpl,
{
glib_floating_reference_guard!(ptr);
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Pad = from_glib_borrow(ptr);
imp.unlinked(&wrap, &from_glib_borrow(peer))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment