mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-09-25 05:20:18 +00:00
Allow creating Error/Warning/Info messages only from specific kinds of glib::Error domains
This commit is contained in:
parent
96d00c4ecc
commit
de10335167
2 changed files with 51 additions and 26 deletions
|
@ -64,7 +64,7 @@ pub use log::*;
|
||||||
pub mod miniobject;
|
pub mod miniobject;
|
||||||
pub use miniobject::{GstRc, MiniObject};
|
pub use miniobject::{GstRc, MiniObject};
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub use message::{Message, MessageRef, MessageView};
|
pub use message::{Message, MessageErrorDomain, MessageRef, MessageView};
|
||||||
pub mod structure;
|
pub mod structure;
|
||||||
pub use structure::{Structure, StructureRef};
|
pub use structure::{Structure, StructureRef};
|
||||||
pub mod caps;
|
pub mod caps;
|
||||||
|
|
|
@ -109,19 +109,19 @@ impl GstRc<MessageRef> {
|
||||||
EosBuilder::new()
|
EosBuilder::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_error(error: &glib::Error) -> ErrorBuilder {
|
pub fn new_error<T: MessageErrorDomain>(error: T, message: &str) -> ErrorBuilder<T> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
ErrorBuilder::new(error)
|
ErrorBuilder::new(error, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_warning(error: &glib::Error) -> WarningBuilder {
|
pub fn new_warning<T: MessageErrorDomain>(error: T, message: &str) -> WarningBuilder<T> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
WarningBuilder::new(error)
|
WarningBuilder::new(error, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_info(error: &glib::Error) -> InfoBuilder {
|
pub fn new_info<T: MessageErrorDomain>(error: T, message: &str) -> InfoBuilder<T> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
InfoBuilder::new(error)
|
InfoBuilder::new(error, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_tag(tags: &TagList) -> TagBuilder {
|
pub fn new_tag(tags: &TagList) -> TagBuilder {
|
||||||
|
@ -1112,7 +1112,7 @@ impl<'a> Redirect<'a> {
|
||||||
|
|
||||||
macro_rules! message_builder_generic_impl {
|
macro_rules! message_builder_generic_impl {
|
||||||
($new_fn:expr) => {
|
($new_fn:expr) => {
|
||||||
pub fn src<T: IsA<Object> + Cast + Clone>(self, src: Option<&T>) -> Self {
|
pub fn src<O: IsA<Object> + Cast + Clone>(self, src: Option<&O>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
src: src.map(|o| {
|
src: src.map(|o| {
|
||||||
let o = (*o).clone();
|
let o = (*o).clone();
|
||||||
|
@ -1181,22 +1181,31 @@ impl<'a> EosBuilder<'a> {
|
||||||
message_builder_generic_impl!(|_, src| ffi::gst_message_new_eos(src));
|
message_builder_generic_impl!(|_, src| ffi::gst_message_new_eos(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ErrorBuilder<'a> {
|
pub trait MessageErrorDomain: glib::error::ErrorDomain {}
|
||||||
|
|
||||||
|
impl MessageErrorDomain for ::CoreError {}
|
||||||
|
impl MessageErrorDomain for ::ResourceError {}
|
||||||
|
impl MessageErrorDomain for ::StreamError {}
|
||||||
|
impl MessageErrorDomain for ::LibraryError {}
|
||||||
|
|
||||||
|
pub struct ErrorBuilder<'a, T> {
|
||||||
src: Option<Object>,
|
src: Option<Object>,
|
||||||
seqnum: Option<u32>,
|
seqnum: Option<u32>,
|
||||||
other_fields: Vec<(&'a str, &'a ToValue)>,
|
other_fields: Vec<(&'a str, &'a ToValue)>,
|
||||||
error: &'a glib::Error,
|
error: T,
|
||||||
|
message: &'a str,
|
||||||
debug: Option<&'a str>,
|
debug: Option<&'a str>,
|
||||||
#[allow(unused)] details: Option<Structure>,
|
#[allow(unused)] details: Option<Structure>,
|
||||||
}
|
}
|
||||||
impl<'a> ErrorBuilder<'a> {
|
impl<'a, T: MessageErrorDomain> ErrorBuilder<'a, T> {
|
||||||
fn new(error: &'a glib::Error) -> Self {
|
fn new(error: T, message: &'a str) -> Self {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
Self {
|
Self {
|
||||||
src: None,
|
src: None,
|
||||||
seqnum: None,
|
seqnum: None,
|
||||||
other_fields: Vec::new(),
|
other_fields: Vec::new(),
|
||||||
error: error,
|
error: error,
|
||||||
|
message: message,
|
||||||
debug: None,
|
debug: None,
|
||||||
details: None,
|
details: None,
|
||||||
}
|
}
|
||||||
|
@ -1225,40 +1234,46 @@ impl<'a> ErrorBuilder<'a> {
|
||||||
Some(details) => details.into_ptr(),
|
Some(details) => details.into_ptr(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let error = glib::Error::new(s.error, s.message);
|
||||||
|
|
||||||
ffi::gst_message_new_error_with_details(
|
ffi::gst_message_new_error_with_details(
|
||||||
src,
|
src,
|
||||||
mut_override(s.error.to_glib_none().0),
|
mut_override(error.to_glib_none().0),
|
||||||
s.debug.to_glib_none().0,
|
s.debug.to_glib_none().0,
|
||||||
details,
|
details,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "v1_10"))]
|
#[cfg(not(feature = "v1_10"))]
|
||||||
{
|
{
|
||||||
|
let error = glib::Error::new(s.error, s.message);
|
||||||
|
|
||||||
ffi::gst_message_new_error(
|
ffi::gst_message_new_error(
|
||||||
src,
|
src,
|
||||||
mut_override(s.error.to_glib_none().0),
|
mut_override(error.to_glib_none().0),
|
||||||
s.debug.to_glib_none().0,
|
s.debug.to_glib_none().0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WarningBuilder<'a> {
|
pub struct WarningBuilder<'a, T> {
|
||||||
src: Option<Object>,
|
src: Option<Object>,
|
||||||
seqnum: Option<u32>,
|
seqnum: Option<u32>,
|
||||||
other_fields: Vec<(&'a str, &'a ToValue)>,
|
other_fields: Vec<(&'a str, &'a ToValue)>,
|
||||||
error: &'a glib::Error,
|
error: T,
|
||||||
|
message: &'a str,
|
||||||
debug: Option<&'a str>,
|
debug: Option<&'a str>,
|
||||||
#[allow(unused)] details: Option<Structure>,
|
#[allow(unused)] details: Option<Structure>,
|
||||||
}
|
}
|
||||||
impl<'a> WarningBuilder<'a> {
|
impl<'a, T: MessageErrorDomain> WarningBuilder<'a, T> {
|
||||||
fn new(error: &'a glib::Error) -> Self {
|
fn new(error: T, message: &'a str) -> Self {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
Self {
|
Self {
|
||||||
src: None,
|
src: None,
|
||||||
seqnum: None,
|
seqnum: None,
|
||||||
other_fields: Vec::new(),
|
other_fields: Vec::new(),
|
||||||
error: error,
|
error: error,
|
||||||
|
message: message,
|
||||||
debug: None,
|
debug: None,
|
||||||
details: None,
|
details: None,
|
||||||
}
|
}
|
||||||
|
@ -1287,40 +1302,46 @@ impl<'a> WarningBuilder<'a> {
|
||||||
Some(details) => details.into_ptr(),
|
Some(details) => details.into_ptr(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let error = glib::Error::new(s.error, s.message);
|
||||||
|
|
||||||
ffi::gst_message_new_warning_with_details(
|
ffi::gst_message_new_warning_with_details(
|
||||||
src,
|
src,
|
||||||
mut_override(s.error.to_glib_none().0),
|
mut_override(error.to_glib_none().0),
|
||||||
s.debug.to_glib_none().0,
|
s.debug.to_glib_none().0,
|
||||||
details,
|
details,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "v1_10"))]
|
#[cfg(not(feature = "v1_10"))]
|
||||||
{
|
{
|
||||||
|
let error = glib::Error::new(s.error, s.message);
|
||||||
|
|
||||||
ffi::gst_message_new_warning(
|
ffi::gst_message_new_warning(
|
||||||
src,
|
src,
|
||||||
mut_override(s.error.to_glib_none().0),
|
mut_override(error.to_glib_none().0),
|
||||||
s.debug.to_glib_none().0,
|
s.debug.to_glib_none().0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InfoBuilder<'a> {
|
pub struct InfoBuilder<'a, T> {
|
||||||
src: Option<Object>,
|
src: Option<Object>,
|
||||||
seqnum: Option<u32>,
|
seqnum: Option<u32>,
|
||||||
other_fields: Vec<(&'a str, &'a ToValue)>,
|
other_fields: Vec<(&'a str, &'a ToValue)>,
|
||||||
error: &'a glib::Error,
|
error: T,
|
||||||
|
message: &'a str,
|
||||||
debug: Option<&'a str>,
|
debug: Option<&'a str>,
|
||||||
#[allow(unused)] details: Option<Structure>,
|
#[allow(unused)] details: Option<Structure>,
|
||||||
}
|
}
|
||||||
impl<'a> InfoBuilder<'a> {
|
impl<'a, T: MessageErrorDomain> InfoBuilder<'a, T> {
|
||||||
fn new(error: &'a glib::Error) -> Self {
|
fn new(error: T, message: &'a str) -> Self {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
Self {
|
Self {
|
||||||
src: None,
|
src: None,
|
||||||
seqnum: None,
|
seqnum: None,
|
||||||
other_fields: Vec::new(),
|
other_fields: Vec::new(),
|
||||||
error: error,
|
error: error,
|
||||||
|
message: message,
|
||||||
debug: None,
|
debug: None,
|
||||||
details: None,
|
details: None,
|
||||||
}
|
}
|
||||||
|
@ -1349,18 +1370,22 @@ impl<'a> InfoBuilder<'a> {
|
||||||
Some(details) => details.into_ptr(),
|
Some(details) => details.into_ptr(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let error = glib::Error::new(s.error, s.message);
|
||||||
|
|
||||||
ffi::gst_message_new_info_with_details(
|
ffi::gst_message_new_info_with_details(
|
||||||
src,
|
src,
|
||||||
mut_override(s.error.to_glib_none().0),
|
mut_override(error.to_glib_none().0),
|
||||||
s.debug.to_glib_none().0,
|
s.debug.to_glib_none().0,
|
||||||
details,
|
details,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "v1_10"))]
|
#[cfg(not(feature = "v1_10"))]
|
||||||
{
|
{
|
||||||
|
let error = glib::Error::new(s.error, s.message);
|
||||||
|
|
||||||
ffi::gst_message_new_info(
|
ffi::gst_message_new_info(
|
||||||
src,
|
src,
|
||||||
mut_override(s.error.to_glib_none().0),
|
mut_override(error.to_glib_none().0),
|
||||||
s.debug.to_glib_none().0,
|
s.debug.to_glib_none().0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue