gstreamer: Implement new logging variants that work ObjectSubclass values

This commit is contained in:
Sebastian Dröge 2022-10-09 11:49:28 +03:00
parent 274a5bd020
commit 25c53c4276
3 changed files with 60 additions and 1 deletions

View file

@ -145,6 +145,19 @@ impl LoggableError {
); );
} }
pub fn log_with_imp<I: glib::subclass::prelude::ObjectSubclass>(&self, imp: &I) {
use glib::subclass::prelude::*;
self.category.log(
Some(unsafe { imp.instance().unsafe_cast_ref::<glib::Object>() }),
crate::DebugLevel::Error,
self.bool_error.filename,
self.bool_error.function,
self.bool_error.line,
format_args!("{}", self.bool_error.message),
);
}
pub fn category(&self) -> crate::DebugCategory { pub fn category(&self) -> crate::DebugCategory {
self.category self.category
} }

View file

@ -176,7 +176,7 @@ impl DebugCategory {
} }
let obj_ptr = match obj { let obj_ptr = match obj {
Some(obj) => obj.to_glib_none().0 as *mut glib::gobject_ffi::GObject, Some(obj) => obj.as_ptr() as *mut glib::gobject_ffi::GObject,
None => ptr::null_mut(), None => ptr::null_mut(),
}; };
@ -386,6 +386,9 @@ macro_rules! error(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, $($args)*)
}}; }};
@ -396,6 +399,9 @@ macro_rules! warning(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, $($args)*)
}}; }};
@ -406,6 +412,9 @@ macro_rules! fixme(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, $($args)*)
}}; }};
@ -416,6 +425,9 @@ macro_rules! info(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, $($args)*)
}}; }};
@ -426,6 +438,9 @@ macro_rules! debug(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, $($args)*)
}}; }};
@ -436,6 +451,9 @@ macro_rules! log(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, $($args)*)
}}; }};
@ -446,6 +464,9 @@ macro_rules! trace(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, $($args)*)
}}; }};
@ -456,6 +477,9 @@ macro_rules! memdump(
($cat:expr, obj: $obj:expr, $($args:tt)*) => { { ($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, obj: $obj, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, obj: $obj, $($args)*)
}}; }};
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, imp: $imp, $($args)*)
}};
($cat:expr, $($args:tt)*) => { { ($cat:expr, $($args:tt)*) => { {
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, $($args)*) $crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, $($args)*)
}}; }};
@ -471,6 +495,18 @@ macro_rules! log_with_level(
$level, file!(), module_path!(), line!(), format_args!($($args)*)) $level, file!(), module_path!(), line!(), format_args!($($args)*))
} }
}}; }};
($cat:expr, level: $level:expr, imp: $imp:expr, $($args:tt)*) => { {
// Check the log level before using `format_args!` otherwise
// formatted arguments are evaluated even if we end up not logging.
if $level <= $cat.threshold() {
use $crate::glib::Cast;
let obj = $imp.instance();
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
$crate::DebugCategory::log_unfiltered($cat.clone(), Some(&*obj),
$level, file!(), module_path!(), line!(), format_args!($($args)*))
}
}};
($cat:expr, level: $level:expr, $($args:tt)*) => { { ($cat:expr, level: $level:expr, $($args:tt)*) => { {
// Check the log level before using `format_args!` otherwise // Check the log level before using `format_args!` otherwise
// formatted arguments are evaluated even if we end up not logging. // formatted arguments are evaluated even if we end up not logging.

View file

@ -173,6 +173,8 @@ pub trait ElementImplExt: ObjectSubclass {
fallback: G, fallback: G,
f: F, f: F,
) -> R; ) -> R;
fn post_error_message(&self, msg: crate::ErrorMessage);
} }
impl<T: ElementImpl> ElementImplExt for T { impl<T: ElementImpl> ElementImplExt for T {
@ -371,6 +373,14 @@ impl<T: ElementImpl> ElementImplExt for T {
}) })
} }
} }
fn post_error_message(&self, msg: crate::ErrorMessage) {
unsafe {
self.instance()
.unsafe_cast_ref::<Element>()
.post_error_message(msg)
}
}
} }
unsafe impl<T: ElementImpl> IsSubclassable<T> for Element { unsafe impl<T: ElementImpl> IsSubclassable<T> for Element {