pub struct PtrWrapper<T> { /* private fields */ }Implementations§
Source§impl<T> PtrWrapper<T>
impl<T> PtrWrapper<T>
Sourcepub unsafe fn new(
ptr: *mut T,
destroy_fn: unsafe extern "C" fn(ptr: *mut T) -> Status,
) -> PtrWrapper<T>
pub unsafe fn new( ptr: *mut T, destroy_fn: unsafe extern "C" fn(ptr: *mut T) -> Status, ) -> PtrWrapper<T>
Examples found in repository?
examples/log_gaze.rs (line 34)
23fn run_demo() -> Result<(), TobiiError> {
24 unsafe{
25 let custom_log = CustomLog {
26 log_context: ptr::null_mut(),
27 log_func: Some(custom_log_fn)
28 };
29
30 println!("Initializing API!");
31 let mut api_ptr: *mut Api = mem::zeroed();
32 let status = tobii_api_create( &mut api_ptr as *mut *mut Api, ptr::null_mut(), &custom_log as *const _);
33 status_to_result(status)?;
34 let api = PtrWrapper::new(api_ptr, tobii_api_destroy);
35
36 let devices = helpers::list_devices(api.ptr())?;
37 println!("{:?}", devices);
38
39 if devices.len() < 1 {
40 println!("No devices");
41 return Ok(());
42 }
43
44 let url_c_string = CString::new(devices[0].clone()).unwrap();
45 let url_c = url_c_string.as_c_str();
46 let mut device_ptr: *mut Device = mem::zeroed();
47 let status = tobii_device_create(api.ptr(), url_c.as_ptr(), &mut device_ptr as *mut *mut Device);
48 status_to_result(status)?;
49 let device = PtrWrapper::new(device_ptr, tobii_device_destroy);
50
51 let status = tobii_gaze_point_subscribe(device.ptr(), Some(gaze_callback), ptr::null_mut());
52 let _subscription = PtrWrapper::new(device.ptr(), tobii_gaze_point_unsubscribe);
53 status_to_result(status)?;
54 for _i in 1..1000 {
55 let status = helpers::wait_for_device_callbacks(device.ptr());
56 match status_to_result(status) {
57 Err(TobiiError::TimedOut) => continue,
58 Err(TobiiError::ConnectionFailed) => {
59 status_to_result(helpers::reconnect(device.ptr()))?;
60 continue;
61 },
62 Err(e) => return Err(e),
63 Ok(()) => (),
64 }
65
66 let status = tobii_device_process_callbacks(device.ptr());
67 if status == TOBII_ERROR_CONNECTION_FAILED {
68 status_to_result(helpers::reconnect(device.ptr()))?;
69 continue;
70 }
71 status_to_result(status)?;
72 }
73 }
74 Ok(())
75}Sourcepub fn ptr(&self) -> *mut T
pub fn ptr(&self) -> *mut T
Examples found in repository?
examples/log_gaze.rs (line 36)
23fn run_demo() -> Result<(), TobiiError> {
24 unsafe{
25 let custom_log = CustomLog {
26 log_context: ptr::null_mut(),
27 log_func: Some(custom_log_fn)
28 };
29
30 println!("Initializing API!");
31 let mut api_ptr: *mut Api = mem::zeroed();
32 let status = tobii_api_create( &mut api_ptr as *mut *mut Api, ptr::null_mut(), &custom_log as *const _);
33 status_to_result(status)?;
34 let api = PtrWrapper::new(api_ptr, tobii_api_destroy);
35
36 let devices = helpers::list_devices(api.ptr())?;
37 println!("{:?}", devices);
38
39 if devices.len() < 1 {
40 println!("No devices");
41 return Ok(());
42 }
43
44 let url_c_string = CString::new(devices[0].clone()).unwrap();
45 let url_c = url_c_string.as_c_str();
46 let mut device_ptr: *mut Device = mem::zeroed();
47 let status = tobii_device_create(api.ptr(), url_c.as_ptr(), &mut device_ptr as *mut *mut Device);
48 status_to_result(status)?;
49 let device = PtrWrapper::new(device_ptr, tobii_device_destroy);
50
51 let status = tobii_gaze_point_subscribe(device.ptr(), Some(gaze_callback), ptr::null_mut());
52 let _subscription = PtrWrapper::new(device.ptr(), tobii_gaze_point_unsubscribe);
53 status_to_result(status)?;
54 for _i in 1..1000 {
55 let status = helpers::wait_for_device_callbacks(device.ptr());
56 match status_to_result(status) {
57 Err(TobiiError::TimedOut) => continue,
58 Err(TobiiError::ConnectionFailed) => {
59 status_to_result(helpers::reconnect(device.ptr()))?;
60 continue;
61 },
62 Err(e) => return Err(e),
63 Ok(()) => (),
64 }
65
66 let status = tobii_device_process_callbacks(device.ptr());
67 if status == TOBII_ERROR_CONNECTION_FAILED {
68 status_to_result(helpers::reconnect(device.ptr()))?;
69 continue;
70 }
71 status_to_result(status)?;
72 }
73 }
74 Ok(())
75}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for PtrWrapper<T>
impl<T> RefUnwindSafe for PtrWrapper<T>where
T: RefUnwindSafe,
impl<T> !Send for PtrWrapper<T>
impl<T> !Sync for PtrWrapper<T>
impl<T> Unpin for PtrWrapper<T>
impl<T> UnwindSafe for PtrWrapper<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more