Add EventManager::detach method
							parent
							
								
									14dd7928bd
								
							
						
					
					
						commit
						4c015edec4
					
				
							
								
								
									
										20
									
								
								src/core.rs
								
								
								
								
							
							
						
						
									
										20
									
								
								src/core.rs
								
								
								
								
							| 
						 | 
					@ -326,21 +326,35 @@ pub struct EventManager<'a> {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl<'a> 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
 | 
					        where F: Fn(Event, VLCObject) + Send + 'static
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // Explicit type annotation is needed
 | 
					        // Explicit type annotation is needed
 | 
				
			||||||
        let callback: Box<Box<dyn Fn(Event, VLCObject) + Send + 'static>> =
 | 
					        let callback: Box<Box<dyn Fn(Event, VLCObject) + Send + 'static>> =
 | 
				
			||||||
            Box::new(Box::new(callback));
 | 
					            Box::new(Box::new(callback));
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        let raw = Box::into_raw(callback) as *mut c_void;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let result = unsafe{
 | 
					        let result = unsafe{
 | 
				
			||||||
            sys::libvlc_event_attach(
 | 
					            sys::libvlc_event_attach(
 | 
				
			||||||
                self.ptr, event_type as i32, event_manager_callback,
 | 
					                self.ptr, event_type as i32, event_manager_callback,
 | 
				
			||||||
                Box::into_raw(callback) as *mut c_void)
 | 
					                raw)
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if result == 0 {
 | 
					        if result == 0 {
 | 
				
			||||||
            Ok(())
 | 
					            Ok(raw)
 | 
				
			||||||
        }else{
 | 
					        }else{
 | 
				
			||||||
            Err(())
 | 
					            Err(())
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,6 +74,9 @@ extern "C" {
 | 
				
			||||||
    pub fn libvlc_event_attach(
 | 
					    pub fn libvlc_event_attach(
 | 
				
			||||||
        p_event_manager: *mut libvlc_event_manager_t, i_event_type: libvlc_event_type_t,
 | 
					        p_event_manager: *mut libvlc_event_manager_t, i_event_type: libvlc_event_type_t,
 | 
				
			||||||
        f_callback: libvlc_callback_t, user_data: *mut c_void) -> c_int;
 | 
					        f_callback: libvlc_callback_t, user_data: *mut c_void) -> c_int;
 | 
				
			||||||
 | 
					    pub fn libvlc_event_detach(
 | 
				
			||||||
 | 
					            p_event_manager: *mut libvlc_event_manager_t, i_event_type: libvlc_event_type_t,
 | 
				
			||||||
 | 
					            f_callback: libvlc_callback_t, p_user_data: *mut c_void) -> c_int;
 | 
				
			||||||
    pub fn libvlc_event_type_name(event_type: libvlc_event_type_t) -> *const c_char;
 | 
					    pub fn libvlc_event_type_name(event_type: libvlc_event_type_t) -> *const c_char;
 | 
				
			||||||
    pub fn libvlc_log_get_context(
 | 
					    pub fn libvlc_log_get_context(
 | 
				
			||||||
        ctx: *const libvlc_log_t, module: *const *const c_char, file: *const *const c_char,
 | 
					        ctx: *const libvlc_log_t, module: *const *const c_char, file: *const *const c_char,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue