forked from mirrors/gstreamer-rs
gstreamer: subclassing: move parent fn in dedicated trait (!231)
This commit is contained in:
parent
e2d448f002
commit
fb99f1abad
4 changed files with 70 additions and 30 deletions
|
@ -20,7 +20,7 @@ use Element;
|
|||
use LoggableError;
|
||||
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> {
|
||||
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) {
|
||||
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> {
|
||||
unsafe {
|
||||
let data = self.get_type_data();
|
||||
|
|
|
@ -28,7 +28,7 @@ use StateChangeError;
|
|||
use StateChangeReturn;
|
||||
use StateChangeSuccess;
|
||||
|
||||
pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
|
||||
pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync + 'static {
|
||||
fn change_state(
|
||||
&self,
|
||||
element: &::Element,
|
||||
|
@ -62,7 +62,54 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
|
|||
fn set_context(&self, element: &::Element, context: &::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(
|
||||
&self,
|
||||
element: &::Element,
|
||||
|
@ -152,32 +199,7 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
|
|||
.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<
|
||||
R,
|
||||
F: FnOnce(&Self) -> R,
|
||||
|
|
|
@ -22,11 +22,11 @@ pub mod pipeline;
|
|||
pub mod uri_handler;
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::bin::BinImpl;
|
||||
pub use super::bin::{BinImpl, BinImplExt};
|
||||
pub use super::child_proxy::ChildProxyImpl;
|
||||
pub use super::element::{ElementClassSubclassExt, ElementImpl, ElementImplExt};
|
||||
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::uri_handler::URIHandlerImpl;
|
||||
pub use super::PanicPoison;
|
||||
|
|
|
@ -16,7 +16,7 @@ use glib::subclass::prelude::*;
|
|||
use Pad;
|
||||
use PadClass;
|
||||
|
||||
pub trait PadImpl: ObjectImpl + Send + Sync + 'static {
|
||||
pub trait PadImpl: PadImplExt + ObjectImpl + Send + Sync + 'static {
|
||||
fn linked(&self, pad: &Pad, peer: &Pad) {
|
||||
self.parent_linked(pad, peer)
|
||||
}
|
||||
|
@ -24,7 +24,15 @@ pub trait PadImpl: ObjectImpl + Send + Sync + 'static {
|
|||
fn unlinked(&self, pad: &Pad, peer: &Pad) {
|
||||
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) {
|
||||
unsafe {
|
||||
let data = self.get_type_data();
|
||||
|
|
Loading…
Reference in a new issue