Return () instead of bool for some functions

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/171
This commit is contained in:
François Laignel 2019-01-17 23:10:58 +01:00
parent 333d71f92b
commit b20e4454f1
4 changed files with 23 additions and 20 deletions

View file

@ -867,6 +867,11 @@ trait = false
# Work-around for 1.14 switch from transfer-floating to transfer-full # Work-around for 1.14 switch from transfer-floating to transfer-full
ignore = true ignore = true
[[object.function]]
name = "add_stream"
# Ignore return value which is always `true`
ignore = true
[[object]] [[object]]
name = "Gst.Plugin" name = "Gst.Plugin"
status = "generate" status = "generate"

View file

@ -9,7 +9,6 @@ use ffi;
use glib::GString; use glib::GString;
use glib::StaticType; use glib::StaticType;
use glib::Value; use glib::Value;
use glib::object::IsA;
use glib::object::ObjectType; use glib::object::ObjectType;
use glib::signal::SignalHandlerId; use glib::signal::SignalHandlerId;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -28,13 +27,6 @@ glib_wrapper! {
} }
impl StreamCollection { impl StreamCollection {
#[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn add_stream<P: IsA<Stream>>(&self, stream: &P) -> bool {
unsafe {
from_glib(ffi::gst_stream_collection_add_stream(self.to_glib_none().0, stream.as_ref().to_glib_full()))
}
}
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_size(&self) -> u32 { pub fn get_size(&self) -> u32 {
unsafe { unsafe {

View file

@ -39,25 +39,22 @@ unsafe extern "C" fn trampoline_wait_async(
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static) = transmute(func); let f: &&(Fn(&Clock, ClockTime, &ClockId) + Send + 'static) = transmute(func);
f( f(
&from_glib_borrow(clock), &from_glib_borrow(clock),
from_glib(time), from_glib(time),
&from_glib_borrow(id), &from_glib_borrow(id),
) );
.to_glib() glib_ffi::GTRUE
} }
unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) { unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) {
Box::<Box<Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static>>::from_raw(ptr as *mut _); Box::<Box<Fn(&Clock, ClockTime, &ClockId) + Send + 'static>>::from_raw(ptr as *mut _);
} }
fn into_raw_wait_async<F: Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static>( fn into_raw_wait_async<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(func: F) -> gpointer {
func: F,
) -> gpointer {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
let func: Box<Box<Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static>> = let func: Box<Box<Fn(&Clock, ClockTime, &ClockId) + Send + 'static>> = Box::new(Box::new(func));
Box::new(Box::new(func));
Box::into_raw(func) as gpointer Box::into_raw(func) as gpointer
} }
@ -81,7 +78,7 @@ impl ClockId {
pub fn wait_async<F>(&self, func: F) -> Result<ClockSuccess, ClockError> pub fn wait_async<F>(&self, func: F) -> Result<ClockSuccess, ClockError>
where where
F: Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static, F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static,
{ {
let ret: ClockReturn = unsafe { let ret: ClockReturn = unsafe {
from_glib(ffi::gst_clock_id_wait_async( from_glib(ffi::gst_clock_id_wait_async(
@ -269,8 +266,6 @@ mod tests {
let id = clock.new_single_shot_id(now + 20 * ::MSECOND).unwrap(); let id = clock.new_single_shot_id(now + 20 * ::MSECOND).unwrap();
let res = id.wait_async(move |_, _, _| { let res = id.wait_async(move |_, _, _| {
sender.send(()).unwrap(); sender.send(()).unwrap();
true
}); });
assert!(res == Ok(ClockSuccess::Ok)); assert!(res == Ok(ClockSuccess::Ok));

View file

@ -7,6 +7,7 @@
// except according to those terms. // except according to those terms.
use ffi; use ffi;
use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use Stream; use Stream;
use StreamCollection; use StreamCollection;
@ -80,6 +81,16 @@ impl StreamCollection {
} }
} }
#[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn add_stream<P: IsA<Stream>>(&self, stream: &P) {
unsafe {
ffi::gst_stream_collection_add_stream(
self.to_glib_none().0,
stream.as_ref().to_glib_full(),
);
}
}
pub fn iter(&self) -> Iter { pub fn iter(&self) -> Iter {
Iter::new(self) Iter::new(self)
} }