gstreamer: subclassing: move parent fn in dedicated trait (!231)

This commit is contained in:
François Laignel 2019-02-13 10:57:04 +01:00 committed by Sebastian Dröge
parent e2d448f002
commit fb99f1abad
4 changed files with 70 additions and 30 deletions

View file

@ -20,7 +20,7 @@ use Element;
use LoggableError; use LoggableError;
use Message; use Message;
pub trait BinImpl: ElementImpl + Send + Sync + 'static { pub trait BinImpl: BinImplExt + ElementImpl + Send + Sync + 'static {
fn add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> { fn add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
self.parent_add_element(bin, element) self.parent_add_element(bin, element)
} }
@ -32,7 +32,17 @@ pub trait BinImpl: ElementImpl + Send + Sync + 'static {
fn handle_message(&self, bin: &Bin, message: Message) { fn handle_message(&self, bin: &Bin, message: Message) {
self.parent_handle_message(bin, message) self.parent_handle_message(bin, message)
} }
}
pub trait BinImplExt {
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError>;
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError>;
fn parent_handle_message(&self, bin: &Bin, message: Message);
}
impl<T: BinImpl + ObjectImpl> BinImplExt for T {
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> { fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();

View file

@ -28,7 +28,7 @@ use StateChangeError;
use StateChangeReturn; use StateChangeReturn;
use StateChangeSuccess; use StateChangeSuccess;
pub trait ElementImpl: ObjectImpl + Send + Sync + 'static { pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync + 'static {
fn change_state( fn change_state(
&self, &self,
element: &::Element, element: &::Element,
@ -62,7 +62,54 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
fn set_context(&self, element: &::Element, context: &::Context) { fn set_context(&self, element: &::Element, context: &::Context) {
self.parent_set_context(element, context) self.parent_set_context(element, context)
} }
}
pub trait ElementImplExt {
fn parent_change_state(
&self,
element: &::Element,
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError>;
fn parent_request_new_pad(
&self,
element: &::Element,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::CapsRef>,
) -> Option<::Pad>;
fn parent_release_pad(&self, element: &::Element, pad: &::Pad);
fn parent_send_event(&self, element: &::Element, event: Event) -> bool;
fn parent_query(&self, element: &::Element, query: &mut QueryRef) -> bool;
fn parent_set_context(&self, element: &::Element, context: &::Context);
fn catch_panic<
R,
F: FnOnce(&Self) -> R,
G: FnOnce() -> R,
P: IsA<::Element> + IsA<glib::Object> + glib::value::SetValue,
>(
&self,
element: &P,
fallback: G,
f: F,
) -> R;
fn catch_panic_pad_function<R, F: FnOnce(&Self, &::Element) -> R, G: FnOnce() -> R>(
parent: &Option<::Object>,
fallback: G,
f: F,
) -> R;
}
impl<T: ElementImpl + ObjectSubclass> ElementImplExt for T
where
T::Instance: PanicPoison,
{
fn parent_change_state( fn parent_change_state(
&self, &self,
element: &::Element, element: &::Element,
@ -152,32 +199,7 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
.unwrap_or(()) .unwrap_or(())
} }
} }
}
pub trait ElementImplExt {
fn catch_panic<
R,
F: FnOnce(&Self) -> R,
G: FnOnce() -> R,
P: IsA<::Element> + IsA<glib::Object> + glib::value::SetValue,
>(
&self,
element: &P,
fallback: G,
f: F,
) -> R;
fn catch_panic_pad_function<R, F: FnOnce(&Self, &::Element) -> R, G: FnOnce() -> R>(
parent: &Option<::Object>,
fallback: G,
f: F,
) -> R;
}
impl<T: ElementImpl + ObjectSubclass> ElementImplExt for T
where
T::Instance: PanicPoison,
{
fn catch_panic< fn catch_panic<
R, R,
F: FnOnce(&Self) -> R, F: FnOnce(&Self) -> R,

View file

@ -22,11 +22,11 @@ pub mod pipeline;
pub mod uri_handler; pub mod uri_handler;
pub mod prelude { pub mod prelude {
pub use super::bin::BinImpl; pub use super::bin::{BinImpl, BinImplExt};
pub use super::child_proxy::ChildProxyImpl; pub use super::child_proxy::ChildProxyImpl;
pub use super::element::{ElementClassSubclassExt, ElementImpl, ElementImplExt}; pub use super::element::{ElementClassSubclassExt, ElementImpl, ElementImplExt};
pub use super::ghost_pad::GhostPadImpl; pub use super::ghost_pad::GhostPadImpl;
pub use super::pad::PadImpl; pub use super::pad::{PadImpl, PadImplExt};
pub use super::pipeline::PipelineImpl; pub use super::pipeline::PipelineImpl;
pub use super::uri_handler::URIHandlerImpl; pub use super::uri_handler::URIHandlerImpl;
pub use super::PanicPoison; pub use super::PanicPoison;

View file

@ -16,7 +16,7 @@ use glib::subclass::prelude::*;
use Pad; use Pad;
use PadClass; use PadClass;
pub trait PadImpl: ObjectImpl + Send + Sync + 'static { pub trait PadImpl: PadImplExt + ObjectImpl + Send + Sync + 'static {
fn linked(&self, pad: &Pad, peer: &Pad) { fn linked(&self, pad: &Pad, peer: &Pad) {
self.parent_linked(pad, peer) self.parent_linked(pad, peer)
} }
@ -24,7 +24,15 @@ pub trait PadImpl: ObjectImpl + Send + Sync + 'static {
fn unlinked(&self, pad: &Pad, peer: &Pad) { fn unlinked(&self, pad: &Pad, peer: &Pad) {
self.parent_unlinked(pad, peer) self.parent_unlinked(pad, peer)
} }
}
pub trait PadImplExt {
fn parent_linked(&self, pad: &Pad, peer: &Pad);
fn parent_unlinked(&self, pad: &Pad, peer: &Pad);
}
impl<T: PadImpl + ObjectImpl> PadImplExt for T {
fn parent_linked(&self, pad: &Pad, peer: &Pad) { fn parent_linked(&self, pad: &Pad, peer: &Pad) {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();