2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-09-09 11:12:49 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{borrow::Cow, ffi::CStr, fmt, ptr};
|
2019-07-14 15:15:15 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use glib::{ffi::gpointer, prelude::*, translate::*, IntoGStr};
|
2017-09-09 11:12:49 +00:00
|
|
|
use libc::c_char;
|
2020-01-22 17:38:13 +00:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use crate::DebugLevel;
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstDebugMessage")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct DebugMessage(ptr::NonNull<ffi::GstDebugMessage>);
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
impl fmt::Debug for DebugMessage {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_tuple("DebugMessage").field(&self.get()).finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DebugMessage {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_message_get")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-12-10 16:22:15 +00:00
|
|
|
pub fn get(&self) -> Option<Cow<glib::GStr>> {
|
2019-07-14 15:15:15 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let message = ffi::gst_debug_message_get(self.0.as_ptr());
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
if message.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2022-12-10 16:22:15 +00:00
|
|
|
Some(glib::GStr::from_ptr_lossy(message))
|
2019-07-14 15:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-06 08:04:44 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-12-06 08:04:44 +00:00
|
|
|
#[doc(alias = "gst_debug_message_get_id")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-12-10 16:22:15 +00:00
|
|
|
pub fn id(&self) -> Option<&glib::GStr> {
|
2022-12-06 08:04:44 +00:00
|
|
|
unsafe {
|
2022-12-10 16:22:15 +00:00
|
|
|
let id = ffi::gst_debug_message_get_id(self.0.as_ptr());
|
2022-12-06 08:04:44 +00:00
|
|
|
|
2022-12-10 16:22:15 +00:00
|
|
|
if id.is_null() {
|
2022-12-06 08:04:44 +00:00
|
|
|
None
|
|
|
|
} else {
|
2022-12-10 16:22:15 +00:00
|
|
|
Some(glib::GStr::from_ptr(id))
|
2022-12-06 08:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-14 15:15:15 +00:00
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstDebugCategory")]
|
2021-01-31 10:21:30 +00:00
|
|
|
pub struct DebugCategory(Option<ptr::NonNull<ffi::GstDebugCategory>>);
|
2017-09-09 11:12:49 +00:00
|
|
|
|
|
|
|
impl DebugCategory {
|
2021-11-06 17:37:13 +00:00
|
|
|
#[doc(alias = "gst_debug_category_new")]
|
|
|
|
#[doc(alias = "GST_DEBUG_CATEGORY")]
|
|
|
|
#[doc(alias = "GST_DEBUG_CATEGORY_INIT")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(
|
|
|
|
name: &str,
|
|
|
|
color: crate::DebugColorFlags,
|
|
|
|
description: Option<&str>,
|
|
|
|
) -> DebugCategory {
|
2020-07-09 14:06:01 +00:00
|
|
|
skip_assert_initialized!();
|
2017-09-09 11:12:49 +00:00
|
|
|
extern "C" {
|
|
|
|
fn _gst_debug_category_new(
|
|
|
|
name: *const c_char,
|
2020-11-21 13:46:48 +00:00
|
|
|
color: ffi::GstDebugColorFlags,
|
2017-09-09 11:12:49 +00:00
|
|
|
description: *const c_char,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> *mut ffi::GstDebugCategory;
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
2017-12-16 15:56:23 +00:00
|
|
|
|
2017-09-09 11:12:49 +00:00
|
|
|
// Gets the category if it exists already
|
|
|
|
unsafe {
|
2018-04-01 08:29:15 +00:00
|
|
|
let ptr = _gst_debug_category_new(
|
2017-09-09 11:12:49 +00:00
|
|
|
name.to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
color.into_glib(),
|
2017-09-09 11:12:49 +00:00
|
|
|
description.to_glib_none().0,
|
2018-04-01 08:29:15 +00:00
|
|
|
);
|
2021-01-31 10:21:30 +00:00
|
|
|
// Can be NULL if the debug system is compiled out
|
|
|
|
DebugCategory(ptr::NonNull::new(ptr))
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-06 17:37:13 +00:00
|
|
|
#[doc(alias = "gst_debug_get_category")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-09-09 11:12:49 +00:00
|
|
|
pub fn get(name: &str) -> Option<DebugCategory> {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-09-09 11:12:49 +00:00
|
|
|
unsafe {
|
|
|
|
extern "C" {
|
2020-11-21 13:46:48 +00:00
|
|
|
fn _gst_debug_get_category(name: *const c_char) -> *mut ffi::GstDebugCategory;
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let cat = _gst_debug_get_category(name.to_glib_none().0);
|
|
|
|
|
|
|
|
if cat.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2021-01-31 10:21:30 +00:00
|
|
|
Some(DebugCategory(Some(ptr::NonNull::new_unchecked(cat))))
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_threshold")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_category_get_threshold")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn threshold(self) -> crate::DebugLevel {
|
2021-01-31 10:21:30 +00:00
|
|
|
match self.0 {
|
2022-12-06 08:06:59 +00:00
|
|
|
Some(cat) => unsafe { from_glib(cat.as_ref().threshold) },
|
2021-01-31 10:21:30 +00:00
|
|
|
None => crate::DebugLevel::None,
|
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_category_set_threshold")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set_threshold(self, threshold: crate::DebugLevel) {
|
2021-01-31 10:21:30 +00:00
|
|
|
if let Some(cat) = self.0 {
|
2021-04-27 15:15:46 +00:00
|
|
|
unsafe { ffi::gst_debug_category_set_threshold(cat.as_ptr(), threshold.into_glib()) }
|
2021-01-31 10:21:30 +00:00
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_category_reset_threshold")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2019-02-28 08:54:32 +00:00
|
|
|
pub fn reset_threshold(self) {
|
2021-01-31 10:21:30 +00:00
|
|
|
if let Some(cat) = self.0 {
|
|
|
|
unsafe { ffi::gst_debug_category_reset_threshold(cat.as_ptr()) }
|
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-10 17:56:05 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn above_threshold(self, level: crate::DebugLevel) -> bool {
|
|
|
|
match self.0 {
|
|
|
|
Some(cat) => unsafe { cat.as_ref().threshold >= level.into_glib() },
|
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_color")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_category_get_color")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn color(self) -> crate::DebugColorFlags {
|
2021-01-31 10:21:30 +00:00
|
|
|
match self.0 {
|
2022-12-06 08:06:59 +00:00
|
|
|
Some(cat) => unsafe { from_glib(cat.as_ref().color) },
|
2021-01-31 10:21:30 +00:00
|
|
|
None => crate::DebugColorFlags::empty(),
|
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_name")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_category_get_name")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn name<'a>(self) -> &'a str {
|
2021-01-31 10:21:30 +00:00
|
|
|
match self.0 {
|
2022-12-06 08:06:59 +00:00
|
|
|
Some(cat) => unsafe { CStr::from_ptr(cat.as_ref().name).to_str().unwrap() },
|
2021-01-31 10:21:30 +00:00
|
|
|
None => "",
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_description")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_category_get_description")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn description<'a>(self) -> Option<&'a str> {
|
2022-01-24 12:48:36 +00:00
|
|
|
let cat = self.0?;
|
2017-12-16 15:56:23 +00:00
|
|
|
|
2022-01-24 12:48:36 +00:00
|
|
|
unsafe {
|
2022-12-06 08:06:59 +00:00
|
|
|
let ptr = cat.as_ref().description;
|
2022-01-24 12:48:36 +00:00
|
|
|
|
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(CStr::from_ptr(ptr).to_str().unwrap())
|
|
|
|
}
|
2017-12-16 15:56:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 10:27:36 +00:00
|
|
|
#[inline]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_log")]
|
2021-11-16 16:19:03 +00:00
|
|
|
#[doc(alias = "gst_debug_log_literal")]
|
2022-12-10 18:01:03 +00:00
|
|
|
pub fn log(
|
2019-02-28 08:54:32 +00:00
|
|
|
self,
|
2022-12-10 18:01:03 +00:00
|
|
|
obj: Option<&impl IsA<glib::Object>>,
|
2020-11-21 13:46:48 +00:00
|
|
|
level: crate::DebugLevel,
|
2022-12-10 14:59:43 +00:00
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
2017-09-09 11:12:49 +00:00
|
|
|
line: u32,
|
|
|
|
args: fmt::Arguments,
|
|
|
|
) {
|
2022-12-10 17:56:05 +00:00
|
|
|
if !self.above_threshold(level) {
|
|
|
|
return;
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
self.log_unfiltered_internal(
|
|
|
|
obj.map(|obj| obj.as_ref()),
|
|
|
|
level,
|
|
|
|
file,
|
|
|
|
function,
|
|
|
|
line,
|
|
|
|
args,
|
|
|
|
)
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log_literal")]
|
2022-12-10 18:01:03 +00:00
|
|
|
pub fn log_literal(
|
2022-12-10 15:13:04 +00:00
|
|
|
self,
|
2022-12-10 18:01:03 +00:00
|
|
|
obj: Option<&impl IsA<glib::Object>>,
|
2022-12-10 15:13:04 +00:00
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
2022-12-10 15:13:04 +00:00
|
|
|
line: u32,
|
|
|
|
msg: &glib::GStr,
|
|
|
|
) {
|
2022-12-10 17:56:05 +00:00
|
|
|
if !self.above_threshold(level) {
|
|
|
|
return;
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
self.log_literal_unfiltered_internal(
|
|
|
|
obj.map(|obj| obj.as_ref()),
|
|
|
|
level,
|
|
|
|
file,
|
|
|
|
function,
|
|
|
|
line,
|
|
|
|
msg,
|
|
|
|
)
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
2021-11-06 17:37:13 +00:00
|
|
|
|
2022-09-13 17:25:14 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Logs without checking the log level.
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log")]
|
2022-12-10 18:01:03 +00:00
|
|
|
pub fn log_unfiltered(
|
2022-09-13 17:25:14 +00:00
|
|
|
self,
|
2022-12-10 18:01:03 +00:00
|
|
|
obj: Option<&impl IsA<glib::Object>>,
|
2022-09-13 17:25:14 +00:00
|
|
|
level: crate::DebugLevel,
|
2022-12-10 14:59:43 +00:00
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
|
|
|
line: u32,
|
|
|
|
args: fmt::Arguments,
|
|
|
|
) {
|
|
|
|
self.log_unfiltered_internal(
|
|
|
|
obj.map(|obj| obj.as_ref()),
|
|
|
|
level,
|
|
|
|
file,
|
|
|
|
function,
|
|
|
|
line,
|
|
|
|
args,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Logs without checking the log level.
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log_literal")]
|
|
|
|
pub fn log_literal_unfiltered(
|
|
|
|
self,
|
|
|
|
obj: Option<&impl IsA<glib::Object>>,
|
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
|
|
|
function: &str,
|
|
|
|
line: u32,
|
|
|
|
msg: &glib::GStr,
|
|
|
|
) {
|
|
|
|
self.log_literal_unfiltered_internal(
|
|
|
|
obj.map(|obj| obj.as_ref()),
|
|
|
|
level,
|
|
|
|
file,
|
|
|
|
function,
|
|
|
|
line,
|
|
|
|
msg,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
fn log_unfiltered_internal(
|
|
|
|
self,
|
|
|
|
obj: Option<&glib::Object>,
|
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
|
|
|
function: &str,
|
2022-09-13 17:25:14 +00:00
|
|
|
line: u32,
|
|
|
|
args: fmt::Arguments,
|
2022-12-10 15:13:04 +00:00
|
|
|
) {
|
2022-12-31 18:45:16 +00:00
|
|
|
let mut w = smallvec::SmallVec::<[u8; 256]>::new();
|
2022-12-10 15:13:04 +00:00
|
|
|
|
|
|
|
// Can't really happen but better safe than sorry
|
2022-12-31 18:45:16 +00:00
|
|
|
if std::io::Write::write_fmt(&mut w, args).is_err() {
|
2022-12-10 15:13:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-12-31 18:45:16 +00:00
|
|
|
w.push(0);
|
2022-12-10 15:13:04 +00:00
|
|
|
|
2022-12-31 18:45:16 +00:00
|
|
|
self.log_literal_unfiltered_internal(obj, level, file, function, line, unsafe {
|
|
|
|
glib::GStr::from_utf8_with_nul_unchecked(&w)
|
|
|
|
});
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
#[inline(never)]
|
|
|
|
fn log_literal_unfiltered_internal(
|
2022-12-10 15:13:04 +00:00
|
|
|
self,
|
2022-12-27 10:22:37 +00:00
|
|
|
obj: Option<&glib::Object>,
|
2022-12-10 15:13:04 +00:00
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
2022-12-10 15:13:04 +00:00
|
|
|
line: u32,
|
|
|
|
msg: &glib::GStr,
|
2022-09-13 17:25:14 +00:00
|
|
|
) {
|
|
|
|
let cat = match self.0 {
|
|
|
|
Some(cat) => cat,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
let obj_ptr = match obj {
|
2022-12-27 10:22:37 +00:00
|
|
|
Some(obj) => obj.as_ptr(),
|
2022-09-13 17:25:14 +00:00
|
|
|
None => ptr::null_mut(),
|
|
|
|
};
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
function.run_with_gstr(|function| {
|
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_debug_log_literal(
|
|
|
|
cat.as_ptr(),
|
|
|
|
level.into_glib(),
|
|
|
|
file.as_ptr(),
|
|
|
|
function.as_ptr(),
|
|
|
|
line as i32,
|
|
|
|
obj_ptr,
|
|
|
|
msg.as_ptr(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "v1_20"))]
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_debug_log(
|
|
|
|
cat.as_ptr(),
|
|
|
|
level.into_glib(),
|
|
|
|
file.as_ptr(),
|
|
|
|
function.as_ptr(),
|
|
|
|
line as i32,
|
|
|
|
obj_ptr,
|
|
|
|
b"%s\0".as_ptr() as *const _,
|
|
|
|
msg.as_ptr(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2022-09-13 17:25:14 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-12-06 08:04:44 +00:00
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log_id")]
|
|
|
|
pub fn log_id(
|
|
|
|
self,
|
2022-12-27 10:22:37 +00:00
|
|
|
id: impl AsRef<glib::GStr>,
|
2022-12-06 08:04:44 +00:00
|
|
|
level: crate::DebugLevel,
|
2022-12-10 14:59:43 +00:00
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
2022-12-06 08:04:44 +00:00
|
|
|
line: u32,
|
|
|
|
args: fmt::Arguments,
|
|
|
|
) {
|
2022-12-10 17:56:05 +00:00
|
|
|
if !self.above_threshold(level) {
|
|
|
|
return;
|
2022-12-06 08:04:44 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
self.log_id_unfiltered_internal(id.as_ref(), level, file, function, line, args);
|
2022-12-06 08:04:44 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-12-06 08:04:44 +00:00
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log_id_literal")]
|
2022-12-10 15:13:04 +00:00
|
|
|
pub fn log_id_literal(
|
2022-12-06 08:04:44 +00:00
|
|
|
self,
|
2022-12-27 10:22:37 +00:00
|
|
|
id: impl AsRef<glib::GStr>,
|
2022-12-06 08:04:44 +00:00
|
|
|
level: crate::DebugLevel,
|
2022-12-10 14:59:43 +00:00
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
2022-12-06 08:04:44 +00:00
|
|
|
line: u32,
|
2022-12-10 15:13:04 +00:00
|
|
|
msg: &glib::GStr,
|
2022-12-06 08:04:44 +00:00
|
|
|
) {
|
2022-12-10 17:56:05 +00:00
|
|
|
if !self.above_threshold(level) {
|
|
|
|
return;
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
self.log_id_literal_unfiltered_internal(id.as_ref(), level, file, function, line, msg);
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-12-10 15:13:04 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Logs without checking the log level.
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log_id")]
|
|
|
|
pub fn log_id_unfiltered(
|
|
|
|
self,
|
2022-12-27 10:22:37 +00:00
|
|
|
id: impl AsRef<glib::GStr>,
|
2022-12-10 15:13:04 +00:00
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
|
|
|
line: u32,
|
|
|
|
args: fmt::Arguments,
|
|
|
|
) {
|
|
|
|
self.log_id_unfiltered_internal(id.as_ref(), level, file, function, line, args)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-12-27 10:22:37 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Logs without checking the log level.
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_debug_log_id_literal")]
|
|
|
|
pub fn log_id_literal_unfiltered(
|
|
|
|
self,
|
|
|
|
id: impl AsRef<glib::GStr>,
|
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
|
|
|
function: &str,
|
|
|
|
line: u32,
|
|
|
|
msg: &glib::GStr,
|
|
|
|
) {
|
|
|
|
self.log_id_literal_unfiltered_internal(id.as_ref(), level, file, function, line, msg)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
2022-12-27 10:22:37 +00:00
|
|
|
#[inline(never)]
|
|
|
|
fn log_id_unfiltered_internal(
|
|
|
|
self,
|
|
|
|
id: &glib::GStr,
|
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
|
|
|
function: &str,
|
2022-12-10 15:13:04 +00:00
|
|
|
line: u32,
|
|
|
|
args: fmt::Arguments,
|
|
|
|
) {
|
2022-12-31 18:45:16 +00:00
|
|
|
let mut w = smallvec::SmallVec::<[u8; 256]>::new();
|
2022-12-06 08:04:44 +00:00
|
|
|
|
|
|
|
// Can't really happen but better safe than sorry
|
2022-12-31 18:45:16 +00:00
|
|
|
if std::io::Write::write_fmt(&mut w, args).is_err() {
|
2022-12-06 08:04:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-31 18:45:16 +00:00
|
|
|
self.log_id_literal_unfiltered_internal(id, level, file, function, line, unsafe {
|
|
|
|
glib::GStr::from_utf8_with_nul_unchecked(&w)
|
|
|
|
});
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
2022-12-27 10:22:37 +00:00
|
|
|
#[inline(never)]
|
|
|
|
fn log_id_literal_unfiltered_internal(
|
2022-12-10 15:13:04 +00:00
|
|
|
self,
|
2022-12-27 10:22:37 +00:00
|
|
|
id: &glib::GStr,
|
2022-12-10 15:13:04 +00:00
|
|
|
level: crate::DebugLevel,
|
|
|
|
file: &glib::GStr,
|
2022-12-27 10:22:37 +00:00
|
|
|
function: &str,
|
2022-12-10 15:13:04 +00:00
|
|
|
line: u32,
|
|
|
|
msg: &glib::GStr,
|
|
|
|
) {
|
|
|
|
let cat = match self.0 {
|
|
|
|
Some(cat) => cat,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
2022-12-27 10:22:37 +00:00
|
|
|
function.run_with_gstr(|function| unsafe {
|
2022-12-06 08:04:44 +00:00
|
|
|
ffi::gst_debug_log_id_literal(
|
|
|
|
cat.as_ptr(),
|
|
|
|
level.into_glib(),
|
2022-12-10 14:59:43 +00:00
|
|
|
file.as_ptr(),
|
2022-12-10 15:13:04 +00:00
|
|
|
function.as_ptr(),
|
2022-12-06 08:04:44 +00:00
|
|
|
line as i32,
|
2022-12-27 10:22:37 +00:00
|
|
|
id.as_ptr(),
|
2022-12-10 15:13:04 +00:00
|
|
|
msg.as_ptr(),
|
2022-12-06 08:04:44 +00:00
|
|
|
);
|
2022-12-27 10:22:37 +00:00
|
|
|
});
|
2022-12-06 08:04:44 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 17:37:13 +00:00
|
|
|
#[doc(alias = "get_all_categories")]
|
|
|
|
#[doc(alias = "gst_debug_get_all_categories")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-16 17:45:12 +00:00
|
|
|
pub fn all_categories() -> glib::SList<DebugCategory> {
|
2023-01-02 17:03:08 +00:00
|
|
|
unsafe { glib::SList::from_glib_container(ffi::gst_debug_get_all_categories()) }
|
2021-11-06 17:37:13 +00:00
|
|
|
}
|
2022-01-24 12:48:21 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2022-01-24 12:48:21 +00:00
|
|
|
#[doc(alias = "gst_debug_log_get_line")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-01-24 12:48:21 +00:00
|
|
|
pub fn get_line(
|
|
|
|
&self,
|
|
|
|
level: crate::DebugLevel,
|
2022-12-10 15:22:27 +00:00
|
|
|
file: &glib::GStr,
|
|
|
|
function: &glib::GStr,
|
2022-01-24 12:48:21 +00:00
|
|
|
line: u32,
|
|
|
|
object: Option<&LoggedObject>,
|
|
|
|
message: &DebugMessage,
|
|
|
|
) -> Option<glib::GString> {
|
|
|
|
let cat = self.0?;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_debug_log_get_line(
|
|
|
|
cat.as_ptr(),
|
|
|
|
level.into_glib(),
|
2022-12-10 15:22:27 +00:00
|
|
|
file.as_ptr(),
|
|
|
|
function.as_ptr(),
|
2022-01-24 12:48:21 +00:00
|
|
|
line as i32,
|
|
|
|
object.map(|o| o.as_ptr()).unwrap_or(ptr::null_mut()),
|
|
|
|
message.0.as_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Sync for DebugCategory {}
|
|
|
|
unsafe impl Send for DebugCategory {}
|
|
|
|
|
2021-11-16 17:45:12 +00:00
|
|
|
impl fmt::Debug for DebugCategory {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_tuple("DebugCategory").field(&self.name()).finish()
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 17:37:13 +00:00
|
|
|
|
2021-11-16 17:45:12 +00:00
|
|
|
impl GlibPtrDefault for DebugCategory {
|
|
|
|
type GlibType = *mut ffi::GstDebugCategory;
|
|
|
|
}
|
2021-11-06 17:37:13 +00:00
|
|
|
|
2023-01-02 17:03:08 +00:00
|
|
|
unsafe impl TransparentPtrType for DebugCategory {}
|
|
|
|
|
2021-11-16 17:45:12 +00:00
|
|
|
impl FromGlibPtrNone<*mut ffi::GstDebugCategory> for DebugCategory {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-16 17:45:12 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *mut ffi::GstDebugCategory) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert!(!ptr.is_null());
|
2021-11-16 17:45:12 +00:00
|
|
|
DebugCategory(Some(ptr::NonNull::new_unchecked(ptr)))
|
2021-11-06 17:37:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 17:45:12 +00:00
|
|
|
impl FromGlibPtrFull<*mut ffi::GstDebugCategory> for DebugCategory {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-16 17:45:12 +00:00
|
|
|
unsafe fn from_glib_full(ptr: *mut ffi::GstDebugCategory) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert!(!ptr.is_null());
|
2021-11-16 17:45:12 +00:00
|
|
|
DebugCategory(Some(ptr::NonNull::new_unchecked(ptr)))
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 17:38:13 +00:00
|
|
|
pub static CAT_RUST: Lazy<DebugCategory> = Lazy::new(|| {
|
|
|
|
DebugCategory::new(
|
2019-01-15 22:20:44 +00:00
|
|
|
"GST_RUST",
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::DebugColorFlags::UNDERLINE,
|
2019-05-23 18:19:24 +00:00
|
|
|
Some("GStreamer's Rust binding core"),
|
2020-01-22 17:38:13 +00:00
|
|
|
)
|
|
|
|
});
|
2019-01-15 22:20:44 +00:00
|
|
|
|
|
|
|
macro_rules! declare_debug_category_from_name(
|
|
|
|
($cat:ident, $cat_name:expr) => (
|
2020-01-22 17:38:13 +00:00
|
|
|
pub static $cat: Lazy<DebugCategory> = Lazy::new(|| DebugCategory::get($cat_name)
|
|
|
|
.expect(&format!("Unable to find `DebugCategory` with name {}", $cat_name)));
|
2019-01-15 22:20:44 +00:00
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
declare_debug_category_from_name!(CAT_DEFAULT, "default");
|
|
|
|
declare_debug_category_from_name!(CAT_GST_INIT, "GST_INIT");
|
|
|
|
declare_debug_category_from_name!(CAT_MEMORY, "GST_MEMORY");
|
|
|
|
declare_debug_category_from_name!(CAT_PARENTAGE, "GST_PARENTAGE");
|
|
|
|
declare_debug_category_from_name!(CAT_STATES, "GST_STATES");
|
|
|
|
declare_debug_category_from_name!(CAT_SCHEDULING, "GST_SCHEDULING");
|
|
|
|
declare_debug_category_from_name!(CAT_BUFFER, "GST_BUFFER");
|
|
|
|
declare_debug_category_from_name!(CAT_BUFFER_LIST, "GST_BUFFER_LIST");
|
|
|
|
declare_debug_category_from_name!(CAT_BUS, "GST_BUS");
|
|
|
|
declare_debug_category_from_name!(CAT_CAPS, "GST_CAPS");
|
|
|
|
declare_debug_category_from_name!(CAT_CLOCK, "GST_CLOCK");
|
|
|
|
declare_debug_category_from_name!(CAT_ELEMENT_PADS, "GST_ELEMENT_PADS");
|
|
|
|
declare_debug_category_from_name!(CAT_PADS, "GST_PADS");
|
|
|
|
declare_debug_category_from_name!(CAT_PERFORMANCE, "GST_PERFORMANCE");
|
|
|
|
declare_debug_category_from_name!(CAT_PIPELINE, "GST_PIPELINE");
|
|
|
|
declare_debug_category_from_name!(CAT_PLUGIN_LOADING, "GST_PLUGIN_LOADING");
|
|
|
|
declare_debug_category_from_name!(CAT_PLUGIN_INFO, "GST_PLUGIN_INFO");
|
|
|
|
declare_debug_category_from_name!(CAT_PROPERTIES, "GST_PROPERTIES");
|
|
|
|
declare_debug_category_from_name!(CAT_NEGOTIATION, "GST_NEGOTIATION");
|
|
|
|
declare_debug_category_from_name!(CAT_REFCOUNTING, "GST_REFCOUNTING");
|
|
|
|
declare_debug_category_from_name!(CAT_ERROR_SYSTEM, "GST_ERROR_SYSTEM");
|
|
|
|
declare_debug_category_from_name!(CAT_EVENT, "GST_EVENT");
|
|
|
|
declare_debug_category_from_name!(CAT_MESSAGE, "GST_MESSAGE");
|
|
|
|
declare_debug_category_from_name!(CAT_PARAMS, "GST_PARAMS");
|
|
|
|
declare_debug_category_from_name!(CAT_CALL_TRACE, "GST_CALL_TRACE");
|
|
|
|
declare_debug_category_from_name!(CAT_SIGNAL, "GST_SIGNAL");
|
|
|
|
declare_debug_category_from_name!(CAT_PROBE, "GST_PROBE");
|
|
|
|
declare_debug_category_from_name!(CAT_REGISTRY, "GST_REGISTRY");
|
|
|
|
declare_debug_category_from_name!(CAT_QOS, "GST_QOS");
|
|
|
|
declare_debug_category_from_name!(CAT_META, "GST_META");
|
|
|
|
declare_debug_category_from_name!(CAT_LOCKING, "GST_LOCKING");
|
|
|
|
declare_debug_category_from_name!(CAT_CONTEXT, "GST_CONTEXT");
|
|
|
|
|
2017-09-09 11:12:49 +00:00
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! error(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Error, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! warning(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Warning, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! fixme(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Fixme, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! info(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Info, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! debug(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Debug, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! log(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Log, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! trace(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Trace, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! memdump(
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, obj: $obj, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($cat:expr, imp: $imp:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, imp: $imp, $($args)*)
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, id: $id, $($args)*)
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, $($args:tt)*) => { {
|
2022-02-21 17:56:06 +00:00
|
|
|
$crate::log_with_level!($cat.clone(), level: $crate::DebugLevel::Memdump, $($args)*)
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-02-21 17:56:06 +00:00
|
|
|
macro_rules! log_with_level(
|
2022-12-10 15:13:04 +00:00
|
|
|
($cat:expr, level: $level:expr, obj: $obj:expr, $msg:literal) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
|
|
|
#[allow(unused_unsafe)]
|
2022-12-11 09:16:27 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 15:13:04 +00:00
|
|
|
use $crate::glib::Cast;
|
|
|
|
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-12-10 15:13:04 +00:00
|
|
|
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
2023-05-10 08:14:21 +00:00
|
|
|
let function_name = $crate::glib::function_name!();
|
2022-12-11 09:16:27 +00:00
|
|
|
|
|
|
|
// Check if formatting is necessary or not
|
|
|
|
// FIXME: This needs to be a closure because the return value of format_args!() can't
|
|
|
|
// be assigned to a variable
|
|
|
|
(|args: std::fmt::Arguments| {
|
|
|
|
if args.as_str().is_some() {
|
|
|
|
$crate::DebugCategory::log_literal_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
Some(obj),
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
$crate::glib::gstr!($msg),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
$crate::DebugCategory::log_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
Some(obj),
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
args,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})(format_args!($msg))
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, level: $level:expr, obj: $obj:expr, $($args:tt)*) => { {
|
2022-09-13 17:25:14 +00:00
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
2022-12-10 14:59:43 +00:00
|
|
|
#[allow(unused_unsafe)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-10-23 18:44:38 +00:00
|
|
|
use $crate::glib::Cast;
|
|
|
|
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-10-23 18:44:38 +00:00
|
|
|
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
2022-12-10 14:59:43 +00:00
|
|
|
$crate::DebugCategory::log_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
Some(obj),
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::function_name!(),
|
2022-12-10 14:59:43 +00:00
|
|
|
line!(),
|
|
|
|
format_args!($($args)*),
|
|
|
|
)
|
2022-09-13 17:25:14 +00:00
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
2022-12-10 15:13:04 +00:00
|
|
|
($cat:expr, level: $level:expr, imp: $imp:expr, $msg:literal) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
|
|
|
#[allow(unused_unsafe)]
|
2022-12-11 09:16:27 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 15:13:04 +00:00
|
|
|
use $crate::glib::Cast;
|
|
|
|
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-12-10 15:13:04 +00:00
|
|
|
let obj = $imp.obj();
|
|
|
|
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
2023-05-10 08:14:21 +00:00
|
|
|
let function_name = $crate::glib::function_name!();
|
2022-12-11 09:16:27 +00:00
|
|
|
|
|
|
|
// Check if formatting is necessary or not
|
|
|
|
// FIXME: This needs to be a closure because the return value of format_args!() can't
|
|
|
|
// be assigned to a variable
|
|
|
|
(|args: std::fmt::Arguments| {
|
|
|
|
if args.as_str().is_some() {
|
|
|
|
$crate::DebugCategory::log_literal_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
Some(obj),
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
$crate::glib::gstr!($msg),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
$crate::DebugCategory::log_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
Some(obj),
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
args,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})(format_args!($msg))
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
}};
|
2022-10-09 08:49:28 +00:00
|
|
|
($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.
|
2022-12-10 14:59:43 +00:00
|
|
|
#[allow(unused_unsafe)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-10-09 08:49:28 +00:00
|
|
|
use $crate::glib::Cast;
|
|
|
|
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-10-23 19:59:23 +00:00
|
|
|
let obj = $imp.obj();
|
2022-10-09 08:49:28 +00:00
|
|
|
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
2022-12-10 14:59:43 +00:00
|
|
|
$crate::DebugCategory::log_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
Some(obj),
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::function_name!(),
|
2022-12-10 14:59:43 +00:00
|
|
|
line!(),
|
|
|
|
format_args!($($args)*),
|
|
|
|
)
|
2022-10-09 08:49:28 +00:00
|
|
|
}
|
|
|
|
}};
|
2022-12-10 15:18:25 +00:00
|
|
|
($cat:expr, level: $level:expr, id: $id:literal, $msg:literal) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
|
|
|
#[allow(unused_unsafe)]
|
2022-12-11 09:16:27 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2023-05-10 08:14:21 +00:00
|
|
|
let function_name = $crate::glib::function_name!();
|
|
|
|
|
2022-12-11 09:16:27 +00:00
|
|
|
// Check if formatting is necessary or not
|
|
|
|
// FIXME: This needs to be a closure because the return value of format_args!() can't
|
|
|
|
// be assigned to a variable
|
|
|
|
(|args: std::fmt::Arguments| {
|
|
|
|
if args.as_str().is_some() {
|
|
|
|
$crate::DebugCategory::log_id_literal_unfiltered(
|
|
|
|
$cat.clone(),
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::gstr!($id),
|
2022-12-11 09:16:27 +00:00
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
$crate::glib::gstr!($msg),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
$crate::DebugCategory::log_id_unfiltered(
|
|
|
|
$cat.clone(),
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::gstr!($id),
|
2022-12-11 09:16:27 +00:00
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
args,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})(format_args!($msg))
|
2022-12-10 15:18:25 +00:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
($cat:expr, level: $level:expr, id: $id:literal, $($args:tt)*) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
|
|
|
#[allow(unused_unsafe)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-12-10 15:18:25 +00:00
|
|
|
$crate::DebugCategory::log_id_unfiltered(
|
|
|
|
$cat.clone(),
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::gstr!($id),
|
2022-12-10 15:18:25 +00:00
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::function_name!(),
|
2022-12-10 15:18:25 +00:00
|
|
|
line!(),
|
|
|
|
format_args!($($args)*),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}};
|
2022-12-10 15:13:04 +00:00
|
|
|
($cat:expr, level: $level:expr, id: $id:expr, $msg:literal) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
|
|
|
#[allow(unused_unsafe)]
|
2022-12-11 09:16:27 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2023-05-10 08:14:21 +00:00
|
|
|
let function_name = $crate::glib::function_name!();
|
|
|
|
|
2022-12-11 09:16:27 +00:00
|
|
|
// Check if formatting is necessary or not
|
|
|
|
// FIXME: This needs to be a closure because the return value of format_args!() can't
|
|
|
|
// be assigned to a variable
|
|
|
|
(|args: std::fmt::Arguments| {
|
|
|
|
if args.as_str().is_some() {
|
|
|
|
$crate::DebugCategory::log_id_literal_unfiltered(
|
|
|
|
$cat.clone(),
|
2022-12-27 10:22:37 +00:00
|
|
|
$id,
|
2022-12-11 09:16:27 +00:00
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
$crate::glib::gstr!($msg),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
$crate::DebugCategory::log_id_unfiltered(
|
|
|
|
$cat.clone(),
|
2022-12-27 10:22:37 +00:00
|
|
|
$id,
|
2022-12-11 09:16:27 +00:00
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
args,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})(format_args!($msg))
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
}};
|
2022-12-06 08:04:44 +00:00
|
|
|
($cat:expr, level: $level:expr, id: $id:expr, $($args:tt)*) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
2022-12-10 14:59:43 +00:00
|
|
|
#[allow(unused_unsafe)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-12-10 14:59:43 +00:00
|
|
|
$crate::DebugCategory::log_id_unfiltered(
|
|
|
|
$cat.clone(),
|
2022-12-27 10:22:37 +00:00
|
|
|
$id,
|
2022-12-10 14:59:43 +00:00
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::function_name!(),
|
2022-12-10 14:59:43 +00:00
|
|
|
line!(),
|
|
|
|
format_args!($($args)*),
|
|
|
|
)
|
2022-12-06 08:04:44 +00:00
|
|
|
}
|
|
|
|
}};
|
2022-12-10 15:13:04 +00:00
|
|
|
($cat:expr, level: $level:expr, $msg:literal) => { {
|
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
|
|
|
#[allow(unused_unsafe)]
|
2022-12-11 09:16:27 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2023-05-10 08:14:21 +00:00
|
|
|
let function_name = $crate::glib::function_name!();
|
|
|
|
|
2022-12-11 09:16:27 +00:00
|
|
|
// Check if formatting is necessary or not
|
|
|
|
// FIXME: This needs to be a closure because the return value of format_args!() can't
|
|
|
|
// be assigned to a variable
|
|
|
|
(|args: std::fmt::Arguments| {
|
|
|
|
if args.as_str().is_some() {
|
|
|
|
$crate::DebugCategory::log_literal_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
None as Option<&$crate::glib::Object>,
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
$crate::glib::gstr!($msg),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
$crate::DebugCategory::log_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
None as Option<&$crate::glib::Object>,
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2023-05-10 08:14:21 +00:00
|
|
|
function_name,
|
2022-12-11 09:16:27 +00:00
|
|
|
line!(),
|
|
|
|
args,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})(format_args!($msg))
|
2022-12-10 15:13:04 +00:00
|
|
|
}
|
|
|
|
}};
|
2017-09-09 11:12:49 +00:00
|
|
|
($cat:expr, level: $level:expr, $($args:tt)*) => { {
|
2022-09-13 17:25:14 +00:00
|
|
|
// Check the log level before using `format_args!` otherwise
|
|
|
|
// formatted arguments are evaluated even if we end up not logging.
|
2022-12-10 14:59:43 +00:00
|
|
|
#[allow(unused_unsafe)]
|
2022-12-10 17:56:05 +00:00
|
|
|
if $cat.above_threshold($level) {
|
2022-12-10 17:57:22 +00:00
|
|
|
// FIXME: Once there's a function_name! macro that returns a string literal we can
|
2022-12-27 10:22:37 +00:00
|
|
|
// directly pass it as `&GStr` forward
|
2022-12-10 17:57:22 +00:00
|
|
|
|
2022-12-10 14:59:43 +00:00
|
|
|
$crate::DebugCategory::log_unfiltered(
|
|
|
|
$cat.clone(),
|
|
|
|
None as Option<&$crate::glib::Object>,
|
|
|
|
$level,
|
2022-12-24 22:25:18 +00:00
|
|
|
unsafe { $crate::glib::GStr::from_utf8_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
2022-12-27 10:22:37 +00:00
|
|
|
$crate::glib::function_name!(),
|
2022-12-10 14:59:43 +00:00
|
|
|
line!(),
|
|
|
|
format_args!($($args)*),
|
|
|
|
)
|
2022-09-13 17:25:14 +00:00
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}};
|
|
|
|
);
|
|
|
|
|
2019-07-14 15:15:15 +00:00
|
|
|
unsafe extern "C" fn log_handler<T>(
|
2020-11-21 13:46:48 +00:00
|
|
|
category: *mut ffi::GstDebugCategory,
|
|
|
|
level: ffi::GstDebugLevel,
|
2019-07-14 15:15:15 +00:00
|
|
|
file: *const c_char,
|
|
|
|
function: *const c_char,
|
|
|
|
line: i32,
|
2020-11-21 13:46:48 +00:00
|
|
|
object: *mut glib::gobject_ffi::GObject,
|
|
|
|
message: *mut ffi::GstDebugMessage,
|
2019-07-14 15:15:15 +00:00
|
|
|
user_data: gpointer,
|
|
|
|
) where
|
2022-12-10 15:22:27 +00:00
|
|
|
T: Fn(
|
|
|
|
DebugCategory,
|
|
|
|
DebugLevel,
|
|
|
|
&glib::GStr,
|
|
|
|
&glib::GStr,
|
|
|
|
u32,
|
|
|
|
Option<&LoggedObject>,
|
|
|
|
&DebugMessage,
|
|
|
|
) + Send
|
2019-07-14 15:15:15 +00:00
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
2021-01-31 10:21:30 +00:00
|
|
|
if category.is_null() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let category = DebugCategory(Some(ptr::NonNull::new_unchecked(category)));
|
2019-07-14 15:15:15 +00:00
|
|
|
let level = from_glib(level);
|
2022-12-10 15:22:27 +00:00
|
|
|
let file = glib::GStr::from_ptr(file);
|
|
|
|
let function = glib::GStr::from_ptr(function);
|
2019-07-14 15:15:15 +00:00
|
|
|
let line = line as u32;
|
2020-10-26 08:42:33 +00:00
|
|
|
let object = ptr::NonNull::new(object).map(LoggedObject);
|
2019-07-14 15:15:15 +00:00
|
|
|
let message = DebugMessage(ptr::NonNull::new_unchecked(message));
|
|
|
|
let handler = &*(user_data as *mut T);
|
|
|
|
(handler)(
|
|
|
|
category,
|
|
|
|
level,
|
2022-12-10 15:22:27 +00:00
|
|
|
file,
|
|
|
|
function,
|
2019-07-14 15:15:15 +00:00
|
|
|
line,
|
2020-10-26 08:42:33 +00:00
|
|
|
object.as_ref(),
|
2019-07-14 15:15:15 +00:00
|
|
|
&message,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn log_handler_data_free<T>(data: gpointer) {
|
|
|
|
let data = Box::from_raw(data as *mut T);
|
|
|
|
drop(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct DebugLogFunction(ptr::NonNull<std::os::raw::c_void>);
|
|
|
|
|
|
|
|
// The contained pointer is never dereferenced and has no thread affinity.
|
|
|
|
// It may be convenient to send it or share it between threads to allow cleaning
|
|
|
|
// up log functions from other threads than the one that created it.
|
|
|
|
unsafe impl Send for DebugLogFunction {}
|
|
|
|
unsafe impl Sync for DebugLogFunction {}
|
|
|
|
|
2020-10-26 08:42:33 +00:00
|
|
|
#[derive(Debug)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GObject")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct LoggedObject(ptr::NonNull<glib::gobject_ffi::GObject>);
|
2020-10-26 08:42:33 +00:00
|
|
|
|
|
|
|
impl LoggedObject {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn as_ptr(&self) -> *mut glib::gobject_ffi::GObject {
|
2020-10-26 08:42:33 +00:00
|
|
|
self.0.as_ptr()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for LoggedObject {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
unsafe {
|
|
|
|
let ptr = self.0.as_ptr();
|
2020-11-09 09:33:52 +00:00
|
|
|
let g_type_instance = &mut (*ptr).g_type_instance;
|
2020-11-21 13:46:48 +00:00
|
|
|
if glib::gobject_ffi::g_type_check_instance_is_fundamentally_a(
|
2020-11-09 09:33:52 +00:00
|
|
|
g_type_instance,
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::gobject_ffi::g_object_get_type(),
|
|
|
|
) != glib::ffi::GFALSE
|
2020-11-09 09:33:52 +00:00
|
|
|
{
|
|
|
|
let type_ = (*g_type_instance.g_class).g_type;
|
2020-10-26 08:42:33 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
if glib::gobject_ffi::g_type_is_a(type_, ffi::gst_pad_get_type())
|
|
|
|
!= glib::ffi::GFALSE
|
2020-10-26 08:42:33 +00:00
|
|
|
{
|
2020-11-21 13:46:48 +00:00
|
|
|
let name_ptr = (*(ptr as *mut ffi::GstObject)).name;
|
2020-10-26 08:42:33 +00:00
|
|
|
let name = if name_ptr.is_null() {
|
|
|
|
"<null>"
|
|
|
|
} else {
|
|
|
|
CStr::from_ptr(name_ptr)
|
|
|
|
.to_str()
|
|
|
|
.unwrap_or("<invalid name>")
|
|
|
|
};
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let parent_ptr = (*(ptr as *mut ffi::GstObject)).parent;
|
2020-10-26 08:42:33 +00:00
|
|
|
let parent_name = if parent_ptr.is_null() {
|
|
|
|
"<null>"
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
let name_ptr = (*(parent_ptr as *mut ffi::GstObject)).name;
|
2020-10-26 08:42:33 +00:00
|
|
|
if name_ptr.is_null() {
|
|
|
|
"<null>"
|
|
|
|
} else {
|
|
|
|
CStr::from_ptr(name_ptr)
|
|
|
|
.to_str()
|
|
|
|
.unwrap_or("<invalid name>")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-25 08:09:45 +00:00
|
|
|
write!(f, "{parent_name}:{name}")
|
2020-11-21 13:46:48 +00:00
|
|
|
} else if glib::gobject_ffi::g_type_is_a(type_, ffi::gst_object_get_type())
|
|
|
|
!= glib::ffi::GFALSE
|
2020-10-26 08:42:33 +00:00
|
|
|
{
|
2020-11-21 13:46:48 +00:00
|
|
|
let name_ptr = (*(ptr as *mut ffi::GstObject)).name;
|
2020-10-26 08:42:33 +00:00
|
|
|
let name = if name_ptr.is_null() {
|
|
|
|
"<null>"
|
|
|
|
} else {
|
|
|
|
CStr::from_ptr(name_ptr)
|
|
|
|
.to_str()
|
|
|
|
.unwrap_or("<invalid name>")
|
|
|
|
};
|
2023-01-25 08:09:45 +00:00
|
|
|
write!(f, "{name}")
|
2020-10-26 08:42:33 +00:00
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
let type_name = CStr::from_ptr(glib::gobject_ffi::g_type_name(type_));
|
2020-10-26 08:42:33 +00:00
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"{}:{:?}",
|
|
|
|
type_name.to_str().unwrap_or("<invalid type>"),
|
|
|
|
ptr
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
2023-01-25 08:09:45 +00:00
|
|
|
write!(f, "{ptr:?}")
|
2020-10-26 08:42:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_add_log_function")]
|
2019-07-14 15:15:15 +00:00
|
|
|
pub fn debug_add_log_function<T>(function: T) -> DebugLogFunction
|
|
|
|
where
|
2022-12-10 15:22:27 +00:00
|
|
|
T: Fn(
|
|
|
|
DebugCategory,
|
|
|
|
DebugLevel,
|
|
|
|
&glib::GStr,
|
|
|
|
&glib::GStr,
|
|
|
|
u32,
|
|
|
|
Option<&LoggedObject>,
|
|
|
|
&DebugMessage,
|
|
|
|
) + Send
|
2019-07-14 15:15:15 +00:00
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-07-14 15:15:15 +00:00
|
|
|
unsafe {
|
|
|
|
let user_data = Box::new(function);
|
|
|
|
let user_data_ptr = Box::into_raw(user_data) as gpointer;
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_debug_add_log_function(
|
2019-07-14 15:15:15 +00:00
|
|
|
Some(log_handler::<T>),
|
|
|
|
user_data_ptr,
|
|
|
|
Some(log_handler_data_free::<T>),
|
|
|
|
);
|
|
|
|
DebugLogFunction(ptr::NonNull::new_unchecked(user_data_ptr))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn debug_remove_default_log_function() {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-07-14 15:15:15 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_debug_remove_log_function(None);
|
2019-07-14 15:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_debug_remove_log_function_by_data")]
|
2019-07-14 15:15:15 +00:00
|
|
|
pub fn debug_remove_log_function(log_fn: DebugLogFunction) {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-07-14 15:15:15 +00:00
|
|
|
unsafe {
|
2021-01-31 10:21:30 +00:00
|
|
|
ffi::gst_debug_remove_log_function_by_data(log_fn.0.as_ptr());
|
2019-07-14 15:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-09 11:12:49 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::sync::{mpsc, Arc, Mutex};
|
|
|
|
|
2017-09-09 11:12:49 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_existing")]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn existing() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-09-09 11:12:49 +00:00
|
|
|
|
2019-01-15 22:20:44 +00:00
|
|
|
let perf_cat = DebugCategory::get("GST_PERFORMANCE")
|
|
|
|
.expect("Unable to find `DebugCategory` with name \"GST_PERFORMANCE\"");
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(perf_cat.name(), CAT_PERFORMANCE.name());
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 17:37:13 +00:00
|
|
|
#[test]
|
|
|
|
fn all() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
2023-01-02 17:03:08 +00:00
|
|
|
assert!(DebugCategory::all_categories()
|
|
|
|
.iter()
|
|
|
|
.any(|c| c.name() == "GST_PERFORMANCE"));
|
2021-11-06 17:37:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-09 11:12:49 +00:00
|
|
|
#[test]
|
|
|
|
fn new_and_log() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-09-09 11:12:49 +00:00
|
|
|
|
|
|
|
let cat = DebugCategory::new(
|
|
|
|
"test-cat",
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::DebugColorFlags::empty(),
|
2019-05-23 18:19:24 +00:00
|
|
|
Some("some debug category"),
|
2017-09-09 11:12:49 +00:00
|
|
|
);
|
|
|
|
|
2022-02-21 17:56:06 +00:00
|
|
|
error!(cat, "meh");
|
|
|
|
warning!(cat, "meh");
|
|
|
|
fixme!(cat, "meh");
|
|
|
|
info!(cat, "meh");
|
|
|
|
debug!(cat, "meh");
|
|
|
|
log!(cat, "meh");
|
|
|
|
trace!(cat, "meh");
|
|
|
|
memdump!(cat, "meh");
|
2017-09-09 11:12:49 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let obj = crate::Bin::new(Some("meh"));
|
2022-10-23 18:44:38 +00:00
|
|
|
|
2022-02-21 17:56:06 +00:00
|
|
|
error!(cat, obj: &obj, "meh");
|
|
|
|
warning!(cat, obj: &obj, "meh");
|
|
|
|
fixme!(cat, obj: &obj, "meh");
|
|
|
|
info!(cat, obj: &obj, "meh");
|
|
|
|
debug!(cat, obj: &obj, "meh");
|
|
|
|
log!(cat, obj: &obj, "meh");
|
|
|
|
trace!(cat, obj: &obj, "meh");
|
|
|
|
memdump!(cat, obj: &obj, "meh");
|
2022-10-23 18:44:38 +00:00
|
|
|
|
|
|
|
error!(cat, obj: obj, "meh");
|
|
|
|
warning!(cat, obj: obj, "meh");
|
|
|
|
fixme!(cat, obj: obj, "meh");
|
|
|
|
info!(cat, obj: obj, "meh");
|
|
|
|
debug!(cat, obj: obj, "meh");
|
|
|
|
log!(cat, obj: obj, "meh");
|
|
|
|
trace!(cat, obj: obj, "meh");
|
|
|
|
memdump!(cat, obj: obj, "meh");
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn log_handler() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
let cat = DebugCategory::new(
|
|
|
|
"test-cat-log",
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::DebugColorFlags::empty(),
|
2019-07-14 15:15:15 +00:00
|
|
|
Some("some debug category"),
|
|
|
|
);
|
|
|
|
cat.set_threshold(DebugLevel::Info);
|
2020-11-21 13:46:48 +00:00
|
|
|
let obj = crate::Bin::new(Some("meh"));
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
let (sender, receiver) = mpsc::channel();
|
|
|
|
|
|
|
|
let sender = Arc::new(Mutex::new(sender));
|
|
|
|
|
|
|
|
let handler = move |category: DebugCategory,
|
|
|
|
level: DebugLevel,
|
2022-12-10 15:22:27 +00:00
|
|
|
_file: &glib::GStr,
|
|
|
|
_function: &glib::GStr,
|
2019-07-14 15:15:15 +00:00
|
|
|
_line: u32,
|
2020-10-26 08:42:33 +00:00
|
|
|
_object: Option<&LoggedObject>,
|
2019-07-14 15:15:15 +00:00
|
|
|
message: &DebugMessage| {
|
|
|
|
let cat = DebugCategory::get("test-cat-log").unwrap();
|
2019-09-04 12:02:55 +00:00
|
|
|
|
|
|
|
if category != cat {
|
|
|
|
// This test can run in parallel with other tests, including new_and_log above.
|
|
|
|
// We cannot be certain we only see our own messages.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-14 15:15:15 +00:00
|
|
|
assert_eq!(level, DebugLevel::Info);
|
2022-12-10 16:22:15 +00:00
|
|
|
assert_eq!(message.get().unwrap().as_ref(), "meh");
|
2019-07-14 15:15:15 +00:00
|
|
|
let _ = sender.lock().unwrap().send(());
|
|
|
|
};
|
|
|
|
|
|
|
|
debug_remove_default_log_function();
|
|
|
|
let log_fn = debug_add_log_function(handler);
|
2022-02-21 17:56:06 +00:00
|
|
|
info!(cat, obj: &obj, "meh");
|
2019-07-14 15:15:15 +00:00
|
|
|
|
2019-12-22 07:59:23 +00:00
|
|
|
receiver.recv().unwrap();
|
2019-07-14 15:15:15 +00:00
|
|
|
|
|
|
|
debug_remove_log_function(log_fn);
|
|
|
|
|
2022-02-21 17:56:06 +00:00
|
|
|
info!(cat, obj: &obj, "meh2");
|
2019-07-14 15:15:15 +00:00
|
|
|
assert!(receiver.recv().is_err());
|
|
|
|
}
|
2022-09-18 15:12:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_argument_evaluation() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let cat = DebugCategory::new(
|
|
|
|
"no_argument_evaluation",
|
|
|
|
crate::DebugColorFlags::empty(),
|
|
|
|
Some("No Argument Evaluation debug category"),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut arg_evaluated = false;
|
|
|
|
trace!(cat, "{}", {
|
|
|
|
arg_evaluated = true;
|
|
|
|
"trace log"
|
|
|
|
});
|
|
|
|
|
|
|
|
assert!(!arg_evaluated);
|
|
|
|
}
|
2022-12-06 08:04:44 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[test]
|
|
|
|
fn id_logging() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let cat = DebugCategory::new(
|
|
|
|
"log_with_id_test_category",
|
|
|
|
crate::DebugColorFlags::empty(),
|
|
|
|
Some("Blablabla"),
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(cat, id: "123", "test");
|
2022-12-10 15:18:25 +00:00
|
|
|
trace!(cat, id: glib::GString::from("123"), "test");
|
|
|
|
trace!(cat, id: &glib::GString::from("123"), "test");
|
2022-12-06 08:04:44 +00:00
|
|
|
}
|
2017-09-09 11:12:49 +00:00
|
|
|
}
|