Merge gihub patch

2-bindgen
Pierre Réveillon 2021-12-05 23:57:54 +01:00
commit 31db9558af
1 changed files with 17 additions and 3 deletions

View File

@ -324,21 +324,35 @@ pub struct EventManager<'a> {
}
impl<'a> EventManager<'a> {
pub fn attach<F>(&self, event_type: EventType, callback: F) -> Result<(), ()>
pub fn detach(&self, event_type: EventType, registered_callback: *mut c_void) -> Result<(),()> {
let result = unsafe {
sys::libvlc_event_detach(self.ptr, event_type as i32, event_manager_callback, registered_callback)
};
if result == 0 {
Ok(())
} else {
Err(())
}
}
pub fn attach<F>(&self, event_type: EventType, callback: F) -> Result<*mut c_void, ()>
where F: Fn(Event, VLCObject) + Send + 'static
{
// Explicit type annotation is needed
let callback: Box<Box<dyn Fn(Event, VLCObject) + Send + 'static>> =
Box::new(Box::new(callback));
let raw = Box::into_raw(callback) as *mut c_void;
let result = unsafe{
sys::libvlc_event_attach(
self.ptr, event_type as i32, Some(event_manager_callback),
Box::into_raw(callback) as *mut c_void)
raw)
};
if result == 0 {
Ok(())
Ok(raw)
}else{
Err(())
}