#7 Merge github patch
commit
b3e704eeae
23
src/core.rs
23
src/core.rs
|
@ -364,7 +364,22 @@ pub struct EventManager<'a> {
|
|||
}
|
||||
|
||||
impl<'a> EventManager<'a> {
|
||||
pub fn attach<F>(&self, event_type: EventType, callback: F) -> Result<(), InternalError>
|
||||
pub fn detach(&self, event_type: EventType, registered_callback: *mut c_void) {
|
||||
unsafe {
|
||||
sys::libvlc_event_detach(
|
||||
self.ptr,
|
||||
event_type as i32,
|
||||
Some(event_manager_callback),
|
||||
registered_callback
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attach<F>(
|
||||
&self,
|
||||
event_type: EventType,
|
||||
callback: F,
|
||||
) -> Result<*mut c_void, InternalError>
|
||||
where
|
||||
F: Fn(Event, VLCObject) + Send + 'static,
|
||||
{
|
||||
|
@ -372,17 +387,19 @@ impl<'a> EventManager<'a> {
|
|||
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(InternalError)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue