Make pointer fields private and add raw() method

merge-requests/7/merge
T. Okubo 2018-06-03 15:37:41 +09:00
parent 8a4e4acecf
commit faf6fa7323
5 changed files with 61 additions and 10 deletions

View File

@ -25,7 +25,7 @@ pub fn compiler() -> String {
}
pub struct Instance {
pub ptr: *mut sys::libvlc_instance_t,
pub(crate) ptr: *mut sys::libvlc_instance_t,
}
impl Instance {
@ -102,6 +102,11 @@ impl Instance {
sys::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _);
}
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_instance_t {
self.ptr
}
}
impl Drop for Instance {
@ -132,6 +137,13 @@ pub struct ModuleDescriptionList {
ptr: *mut sys::libvlc_module_description_t,
}
impl ModuleDescriptionList {
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_module_description_t {
self.ptr
}
}
impl Drop for ModuleDescriptionList {
fn drop(&mut self) {
unsafe{ sys::libvlc_module_description_list_release(self.ptr) };
@ -273,8 +285,8 @@ pub enum Event {
}
pub struct EventManager<'a> {
pub ptr: *mut sys::libvlc_event_manager_t,
pub _phantomdata: ::std::marker::PhantomData<&'a sys::libvlc_event_manager_t>,
pub(crate) ptr: *mut sys::libvlc_event_manager_t,
pub(crate) _phantomdata: ::std::marker::PhantomData<&'a sys::libvlc_event_manager_t>,
}
impl<'a> EventManager<'a> {
@ -297,12 +309,17 @@ impl<'a> EventManager<'a> {
Err(())
}
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_event_manager_t {
self.ptr
}
}
unsafe extern "C" fn event_manager_callback(pe: *const sys::libvlc_event_t, data: *mut c_void) {
let f: &Box<Fn(Event, VLCObject) + Send + 'static> = ::std::mem::transmute(data);
f(conv_event(pe), VLCObject{_ptr: (*pe).p_obj});
f(conv_event(pe), VLCObject{ ptr: (*pe).p_obj });
}
// Convert c-style libvlc_event_t to Event
@ -479,10 +496,24 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
}
pub struct VLCObject {
_ptr: *mut c_void,
ptr: *mut c_void,
}
impl VLCObject {
/// Returns raw pointer
pub fn raw(&self) -> *mut c_void {
self.ptr
}
}
pub struct Log {
pub ptr: *const sys::libvlc_log_t
pub(crate) ptr: *const sys::libvlc_log_t
}
impl Log {
/// Returns raw pointer
pub fn raw(&self) -> *const sys::libvlc_log_t {
self.ptr
}
}

View File

@ -9,7 +9,7 @@ use ::tools::{to_cstr, from_cstr, path_to_cstr};
use std::path::Path;
pub struct Media {
pub ptr: *mut sys::libvlc_media_t,
pub(crate) ptr: *mut sys::libvlc_media_t,
}
impl Media {
@ -181,6 +181,11 @@ impl Media {
Some(track)
}
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_media_t {
self.ptr
}
}
impl Drop for Media {

View File

@ -6,7 +6,7 @@ use sys;
use ::{Instance, MediaList};
pub struct MediaLibrary {
pub ptr: *mut sys::libvlc_media_library_t,
pub(crate) ptr: *mut sys::libvlc_media_library_t,
}
impl MediaLibrary {
@ -32,6 +32,11 @@ impl MediaLibrary {
if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
}
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_media_library_t {
self.ptr
}
}
impl Drop for MediaLibrary {

View File

@ -6,7 +6,7 @@ use sys;
use ::{Instance, Media, EventManager};
pub struct MediaList {
pub ptr: *mut sys::libvlc_media_list_t,
pub(crate) ptr: *mut sys::libvlc_media_list_t,
}
impl MediaList {
@ -104,6 +104,11 @@ impl MediaList {
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
}
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_media_list_t {
self.ptr
}
}
impl Drop for MediaList {

View File

@ -12,7 +12,7 @@ use std::mem::transmute;
/// A LibVLC media player plays one media (usually in a custom drawable).
pub struct MediaPlayer {
pub ptr: *mut sys::libvlc_media_player_t,
pub(crate) ptr: *mut sys::libvlc_media_player_t,
}
impl MediaPlayer {
@ -311,6 +311,11 @@ impl MediaPlayer {
pub fn set_video_title_display(&self, position: Position, timeout: u32) {
unsafe{ sys::libvlc_media_player_set_video_title_display(self.ptr, position, timeout); }
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_media_player_t {
self.ptr
}
}
impl Drop for MediaPlayer {