Description of debug categories is optional

Also add a getter for the description of a debug category
This commit is contained in:
Sebastian Dröge 2017-12-16 17:56:23 +02:00
parent f7c971874d
commit c2f075ed8d

View file

@ -22,7 +22,11 @@ use glib::translate::{from_glib, ToGlib, ToGlibPtr};
pub struct DebugCategory(*mut ffi::GstDebugCategory);
impl DebugCategory {
pub fn new(name: &str, color: ::DebugColorFlags, description: &str) -> DebugCategory {
pub fn new<'a, P: Into<Option<&'a str>>>(
name: &str,
color: ::DebugColorFlags,
description: P,
) -> DebugCategory {
extern "C" {
fn _gst_debug_category_new(
name: *const c_char,
@ -30,6 +34,8 @@ impl DebugCategory {
description: *const c_char,
) -> *mut ffi::GstDebugCategory;
}
let description = description.into();
// Gets the category if it exists already
unsafe {
DebugCategory(_gst_debug_category_new(
@ -84,6 +90,18 @@ impl DebugCategory {
}
}
pub fn get_description(&self) -> Option<&str> {
unsafe {
let ptr = ffi::gst_debug_category_get_name(self.0);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
pub fn log<O: IsA<::Object>>(
&self,
obj: Option<&O>,