mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
Use LoggableError in user defined functions and callbacks
`LoggableError` ensures an error in a user defined function is always logged. This commit changes eligible function signatures accordingly.
This commit is contained in:
parent
c5f0bab614
commit
f59e35d0a3
3 changed files with 47 additions and 30 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
use Bin;
|
||||
use Element;
|
||||
use LoggableError;
|
||||
|
||||
use glib;
|
||||
use glib::object::Cast;
|
||||
|
@ -27,7 +28,7 @@ pub trait GstBinExtManual: 'static {
|
|||
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError>;
|
||||
fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError>;
|
||||
|
||||
fn connect_do_latency<F: Fn(&Self) -> Result<(), glib::BoolError> + Send + Sync + 'static>(
|
||||
fn connect_do_latency<F: Fn(&Self) -> Result<(), LoggableError> + Send + Sync + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> SignalHandlerId;
|
||||
|
@ -82,12 +83,12 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn connect_do_latency<F: Fn(&Self) -> Result<(), glib::BoolError> + Send + Sync + 'static>(
|
||||
fn connect_do_latency<F: Fn(&Self) -> Result<(), LoggableError> + Send + Sync + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> SignalHandlerId {
|
||||
unsafe {
|
||||
let f: Box_<Box_<Fn(&Self) -> Result<(), glib::BoolError> + Send + Sync + 'static>> =
|
||||
let f: Box_<Box_<Fn(&Self) -> Result<(), LoggableError> + Send + Sync + 'static>> =
|
||||
Box_::new(Box_::new(f));
|
||||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
|
@ -163,11 +164,11 @@ unsafe extern "C" fn do_latency_trampoline<P>(
|
|||
where
|
||||
P: IsA<Bin>,
|
||||
{
|
||||
let f: &&(Fn(&P) -> Result<(), glib::BoolError> + Send + Sync + 'static) = transmute(f);
|
||||
let f: &&(Fn(&P) -> Result<(), LoggableError> + Send + Sync + 'static) = transmute(f);
|
||||
match f(&Bin::from_glib_borrow(this).unsafe_cast()) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &Bin::from_glib_borrow(this), "{}", err);
|
||||
err.log_with_object(&Bin::from_glib_borrow(this));
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use FlowSuccess;
|
|||
use Format;
|
||||
use FormattedValue;
|
||||
use GenericFormattedValue;
|
||||
use LoggableError;
|
||||
use Pad;
|
||||
use PadLinkCheck;
|
||||
use PadLinkError;
|
||||
|
@ -164,11 +165,11 @@ pub trait PadExtManual: 'static {
|
|||
|
||||
fn set_activate_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError> + Send + Sync + 'static;
|
||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static;
|
||||
|
||||
fn set_activatemode_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), glib::BoolError>
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static;
|
||||
|
@ -516,12 +517,12 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
|||
|
||||
fn set_activate_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError> + Send + Sync + 'static,
|
||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
||||
{
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||
unsafe {
|
||||
let func_box: Box<
|
||||
Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError> + Send + Sync + 'static,
|
||||
Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
||||
> = Box::new(func);
|
||||
ffi::gst_pad_set_activate_function_full(
|
||||
self.as_ref().to_glib_none().0,
|
||||
|
@ -534,7 +535,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
|||
|
||||
fn set_activatemode_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), glib::BoolError>
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
|
@ -542,7 +543,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
|||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||
unsafe {
|
||||
let func_box: Box<
|
||||
Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), glib::BoolError>
|
||||
Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
|
@ -1119,7 +1120,7 @@ unsafe extern "C" fn trampoline_activate_function(
|
|||
parent: *mut ffi::GstObject,
|
||||
) -> glib_ffi::gboolean {
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||
let func: &&(Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError>
|
||||
let func: &&(Fn(&Pad, &Option<::Object>) -> Result<(), LoggableError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static) = transmute((*pad).activatedata);
|
||||
|
@ -1128,7 +1129,7 @@ unsafe extern "C" fn trampoline_activate_function(
|
|||
match func(&pad, &from_glib_borrow(parent)) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &pad, "{}", err);
|
||||
err.log_with_object(&pad);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -1142,15 +1143,24 @@ unsafe extern "C" fn trampoline_activatemode_function(
|
|||
active: glib_ffi::gboolean,
|
||||
) -> glib_ffi::gboolean {
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||
let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool + Send + Sync + 'static) =
|
||||
transmute((*pad).activatemodedata);
|
||||
let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), LoggableError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static) = transmute((*pad).activatemodedata);
|
||||
|
||||
func(
|
||||
&from_glib_borrow(pad),
|
||||
let pad: Pad = from_glib_borrow(pad);
|
||||
match func(
|
||||
&pad,
|
||||
&from_glib_borrow(parent),
|
||||
from_glib(mode),
|
||||
from_glib(active),
|
||||
)
|
||||
) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
err.log_with_object(&pad);
|
||||
false
|
||||
}
|
||||
}
|
||||
.to_glib()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,15 @@ use glib::subclass::prelude::*;
|
|||
use Bin;
|
||||
use BinClass;
|
||||
use Element;
|
||||
use LoggableError;
|
||||
use Message;
|
||||
|
||||
pub trait BinImpl: ElementImpl + Send + Sync + 'static {
|
||||
fn add_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
fn add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
|
||||
self.parent_add_element(bin, element)
|
||||
}
|
||||
|
||||
fn remove_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
fn remove_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
|
||||
self.parent_remove_element(bin, element)
|
||||
}
|
||||
|
||||
|
@ -32,29 +33,34 @@ pub trait BinImpl: ElementImpl + Send + Sync + 'static {
|
|||
self.parent_handle_message(bin, message)
|
||||
}
|
||||
|
||||
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
|
||||
unsafe {
|
||||
let data = self.get_type_data();
|
||||
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||
let f = (*parent_class)
|
||||
.add_element
|
||||
.ok_or_else(|| glib_bool_error!("Parent function `add_element` is not defined"))?;
|
||||
glib_result_from_gboolean!(
|
||||
let f = (*parent_class).add_element.ok_or_else(|| {
|
||||
gst_loggable_error!(::CAT_RUST, "Parent function `add_element` is not defined")
|
||||
})?;
|
||||
gst_result_from_gboolean!(
|
||||
f(bin.to_glib_none().0, element.to_glib_none().0),
|
||||
::CAT_RUST,
|
||||
"Failed to add the element using the parent function"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
|
||||
unsafe {
|
||||
let data = self.get_type_data();
|
||||
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||
let f = (*parent_class).remove_element.ok_or_else(|| {
|
||||
glib_bool_error!("Parent function `remove_element` is not defined")
|
||||
gst_loggable_error!(
|
||||
::CAT_RUST,
|
||||
"Parent function `remove_element` is not defined"
|
||||
)
|
||||
})?;
|
||||
glib_result_from_gboolean!(
|
||||
gst_result_from_gboolean!(
|
||||
f(bin.to_glib_none().0, element.to_glib_none().0),
|
||||
::CAT_RUST,
|
||||
"Failed to remove the element using the parent function"
|
||||
)
|
||||
}
|
||||
|
@ -103,7 +109,7 @@ where
|
|||
match imp.add_element(&wrap, &from_glib_borrow(element)) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &wrap, "{}", err);
|
||||
err.log_with_object(&wrap);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +134,7 @@ where
|
|||
match imp.remove_element(&wrap, &from_glib_borrow(element)) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &wrap, "{}", err);
|
||||
err.log_with_object(&wrap);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue