From a5a016557ff6c5aafcd58ecf6d2f3ed91ed2325a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 15 Feb 2019 13:30:05 +0200 Subject: [PATCH] bus: add_watch() can fail as there can only be one watch at a time Return an Option because of that. --- gstreamer/src/bus.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 642ac559a..76252b788 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -111,35 +111,47 @@ impl Bus { } } - pub fn add_watch(&self, func: F) -> SourceId + pub fn add_watch(&self, func: F) -> Option where F: FnMut(&Bus, &Message) -> Continue + Send + 'static, { unsafe { - from_glib(ffi::gst_bus_add_watch_full( + let res = ffi::gst_bus_add_watch_full( self.to_glib_none().0, glib_ffi::G_PRIORITY_DEFAULT, Some(trampoline_watch::), into_raw_watch(func), Some(destroy_closure_watch::), - )) + ); + + if res == 0 { + None + } else { + Some(from_glib(res)) + } } } - pub fn add_watch_local(&self, func: F) -> SourceId + pub fn add_watch_local(&self, func: F) -> Option where F: FnMut(&Bus, &Message) -> Continue + 'static, { unsafe { assert!(glib::MainContext::ref_thread_default().is_owner()); - from_glib(ffi::gst_bus_add_watch_full( + let res = ffi::gst_bus_add_watch_full( self.to_glib_none().0, glib_ffi::G_PRIORITY_DEFAULT, Some(trampoline_watch::), into_raw_watch(func), Some(destroy_closure_watch::), - )) + ); + + if res == 0 { + None + } else { + Some(from_glib(res)) + } } }