remove all the wrappers, update servicepoint #1
					 9 changed files with 149 additions and 102 deletions
				
			
		| 
						 | 
					@ -3,7 +3,7 @@
 | 
				
			||||||
//! prefix `sp_bitmap_`
 | 
					//! prefix `sp_bitmap_`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use servicepoint::{DataRef, Grid};
 | 
					use servicepoint::{DataRef, Grid};
 | 
				
			||||||
use std::ptr::{NonNull};
 | 
					use std::ptr::NonNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::byte_slice::SPByteSlice;
 | 
					use crate::byte_slice::SPByteSlice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -82,7 +82,7 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
 | 
				
			||||||
    let data = unsafe { std::slice::from_raw_parts(data, data_length) };
 | 
					    let data = unsafe { std::slice::from_raw_parts(data, data_length) };
 | 
				
			||||||
    let grid = match servicepoint::ByteGrid::load(width, height, data) {
 | 
					    let grid = match servicepoint::ByteGrid::load(width, height, data) {
 | 
				
			||||||
        None => return std::ptr::null_mut(),
 | 
					        None => return std::ptr::null_mut(),
 | 
				
			||||||
        Some(grid) => grid
 | 
					        Some(grid) => grid,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    if let Ok(grid) = servicepoint::BrightnessGrid::try_from(grid) {
 | 
					    if let Ok(grid) = servicepoint::BrightnessGrid::try_from(grid) {
 | 
				
			||||||
        Box::leak(Box::new(SPBrightnessGrid(grid)))
 | 
					        Box::leak(Box::new(SPBrightnessGrid(grid)))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,7 +164,8 @@ pub unsafe extern "C" fn sp_command_brightness(
 | 
				
			||||||
) -> NonNull<SPCommand> {
 | 
					) -> NonNull<SPCommand> {
 | 
				
			||||||
    let brightness = servicepoint::Brightness::try_from(brightness)
 | 
					    let brightness = servicepoint::Brightness::try_from(brightness)
 | 
				
			||||||
        .expect("invalid brightness");
 | 
					        .expect("invalid brightness");
 | 
				
			||||||
    let result = Box::new(SPCommand(GlobalBrightnessCommand::from(brightness).into()));
 | 
					    let result =
 | 
				
			||||||
 | 
					        Box::new(SPCommand(GlobalBrightnessCommand::from(brightness).into()));
 | 
				
			||||||
    NonNull::from(Box::leak(result))
 | 
					    NonNull::from(Box::leak(result))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -194,10 +195,13 @@ pub unsafe extern "C" fn sp_command_char_brightness(
 | 
				
			||||||
) -> NonNull<SPCommand> {
 | 
					) -> NonNull<SPCommand> {
 | 
				
			||||||
    assert!(!grid.is_null());
 | 
					    assert!(!grid.is_null());
 | 
				
			||||||
    let byte_grid = unsafe { *Box::from_raw(grid) };
 | 
					    let byte_grid = unsafe { *Box::from_raw(grid) };
 | 
				
			||||||
    let result = Box::new(SPCommand(servicepoint::BrightnessGridCommand {
 | 
					    let result = Box::new(SPCommand(
 | 
				
			||||||
 | 
					        servicepoint::BrightnessGridCommand {
 | 
				
			||||||
            origin: servicepoint::Origin::new(x, y),
 | 
					            origin: servicepoint::Origin::new(x, y),
 | 
				
			||||||
            grid: byte_grid.0,
 | 
					            grid: byte_grid.0,
 | 
				
			||||||
    }.into()));
 | 
					        }
 | 
				
			||||||
 | 
					        .into(),
 | 
				
			||||||
 | 
					    ));
 | 
				
			||||||
    NonNull::from(Box::leak(result))
 | 
					    NonNull::from(Box::leak(result))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -232,7 +236,14 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
 | 
				
			||||||
    bit_vec: *mut SPBitVec,
 | 
					    bit_vec: *mut SPBitVec,
 | 
				
			||||||
    compression: SPCompressionCode,
 | 
					    compression: SPCompressionCode,
 | 
				
			||||||
) -> *mut SPCommand {
 | 
					) -> *mut SPCommand {
 | 
				
			||||||
    unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Overwrite)}
 | 
					    unsafe {
 | 
				
			||||||
 | 
					        sp_command_bitmap_linear_internal(
 | 
				
			||||||
 | 
					            offset,
 | 
				
			||||||
 | 
					            bit_vec,
 | 
				
			||||||
 | 
					            compression,
 | 
				
			||||||
 | 
					            BinaryOperation::Overwrite,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Set pixel data according to an and-mask starting at the offset.
 | 
					/// Set pixel data according to an and-mask starting at the offset.
 | 
				
			||||||
| 
						 | 
					@ -266,7 +277,14 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
 | 
				
			||||||
    bit_vec: *mut SPBitVec,
 | 
					    bit_vec: *mut SPBitVec,
 | 
				
			||||||
    compression: SPCompressionCode,
 | 
					    compression: SPCompressionCode,
 | 
				
			||||||
) -> *mut SPCommand {
 | 
					) -> *mut SPCommand {
 | 
				
			||||||
    unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Xor)}
 | 
					    unsafe {
 | 
				
			||||||
 | 
					        sp_command_bitmap_linear_internal(
 | 
				
			||||||
 | 
					            offset,
 | 
				
			||||||
 | 
					            bit_vec,
 | 
				
			||||||
 | 
					            compression,
 | 
				
			||||||
 | 
					            BinaryOperation::Xor,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Set pixel data according to an or-mask starting at the offset.
 | 
					/// Set pixel data according to an or-mask starting at the offset.
 | 
				
			||||||
| 
						 | 
					@ -300,7 +318,14 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
 | 
				
			||||||
    bit_vec: *mut SPBitVec,
 | 
					    bit_vec: *mut SPBitVec,
 | 
				
			||||||
    compression: SPCompressionCode,
 | 
					    compression: SPCompressionCode,
 | 
				
			||||||
) -> *mut SPCommand {
 | 
					) -> *mut SPCommand {
 | 
				
			||||||
    unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Or)}
 | 
					    unsafe {
 | 
				
			||||||
 | 
					        sp_command_bitmap_linear_internal(
 | 
				
			||||||
 | 
					            offset,
 | 
				
			||||||
 | 
					            bit_vec,
 | 
				
			||||||
 | 
					            compression,
 | 
				
			||||||
 | 
					            BinaryOperation::Or,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Set pixel data according to a xor-mask starting at the offset.
 | 
					/// Set pixel data according to a xor-mask starting at the offset.
 | 
				
			||||||
| 
						 | 
					@ -334,7 +359,14 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
 | 
				
			||||||
    bit_vec: *mut SPBitVec,
 | 
					    bit_vec: *mut SPBitVec,
 | 
				
			||||||
    compression: SPCompressionCode,
 | 
					    compression: SPCompressionCode,
 | 
				
			||||||
) -> *mut SPCommand {
 | 
					) -> *mut SPCommand {
 | 
				
			||||||
    unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Xor)}
 | 
					    unsafe {
 | 
				
			||||||
 | 
					        sp_command_bitmap_linear_internal(
 | 
				
			||||||
 | 
					            offset,
 | 
				
			||||||
 | 
					            bit_vec,
 | 
				
			||||||
 | 
					            compression,
 | 
				
			||||||
 | 
					            BinaryOperation::Xor,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[inline]
 | 
					#[inline]
 | 
				
			||||||
| 
						 | 
					@ -342,7 +374,7 @@ unsafe fn sp_command_bitmap_linear_internal(
 | 
				
			||||||
    offset: usize,
 | 
					    offset: usize,
 | 
				
			||||||
    bit_vec: *mut SPBitVec,
 | 
					    bit_vec: *mut SPBitVec,
 | 
				
			||||||
    compression: SPCompressionCode,
 | 
					    compression: SPCompressionCode,
 | 
				
			||||||
    operation: BinaryOperation
 | 
					    operation: BinaryOperation,
 | 
				
			||||||
) -> *mut SPCommand {
 | 
					) -> *mut SPCommand {
 | 
				
			||||||
    assert!(!bit_vec.is_null());
 | 
					    assert!(!bit_vec.is_null());
 | 
				
			||||||
    let bit_vec = unsafe { *Box::from_raw(bit_vec) };
 | 
					    let bit_vec = unsafe { *Box::from_raw(bit_vec) };
 | 
				
			||||||
| 
						 | 
					@ -350,12 +382,15 @@ unsafe fn sp_command_bitmap_linear_internal(
 | 
				
			||||||
        Ok(compression) => compression,
 | 
					        Ok(compression) => compression,
 | 
				
			||||||
        Err(_) => return std::ptr::null_mut(),
 | 
					        Err(_) => return std::ptr::null_mut(),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    let command = SPCommand(servicepoint::BitVecCommand {
 | 
					    let command = SPCommand(
 | 
				
			||||||
 | 
					        servicepoint::BitVecCommand {
 | 
				
			||||||
            offset,
 | 
					            offset,
 | 
				
			||||||
            operation,
 | 
					            operation,
 | 
				
			||||||
            bitvec: bit_vec.into(),
 | 
					            bitvec: bit_vec.into(),
 | 
				
			||||||
            compression,
 | 
					            compression,
 | 
				
			||||||
    }.into());
 | 
					        }
 | 
				
			||||||
 | 
					        .into(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
    Box::leak(Box::new(command))
 | 
					    Box::leak(Box::new(command))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -385,11 +420,13 @@ pub unsafe extern "C" fn sp_command_cp437_data(
 | 
				
			||||||
) -> NonNull<SPCommand> {
 | 
					) -> NonNull<SPCommand> {
 | 
				
			||||||
    assert!(!grid.is_null());
 | 
					    assert!(!grid.is_null());
 | 
				
			||||||
    let grid = *unsafe { Box::from_raw(grid) };
 | 
					    let grid = *unsafe { Box::from_raw(grid) };
 | 
				
			||||||
    let result = Box::new(SPCommand(servicepoint::Cp437GridCommand {
 | 
					    let result = Box::new(SPCommand(
 | 
				
			||||||
        origin: servicepoint::Origin::new(x,
 | 
					        servicepoint::Cp437GridCommand {
 | 
				
			||||||
                                          y),
 | 
					            origin: servicepoint::Origin::new(x, y),
 | 
				
			||||||
            grid: grid.0,
 | 
					            grid: grid.0,
 | 
				
			||||||
    }.into()));
 | 
					        }
 | 
				
			||||||
 | 
					        .into(),
 | 
				
			||||||
 | 
					    ));
 | 
				
			||||||
    NonNull::from(Box::leak(result))
 | 
					    NonNull::from(Box::leak(result))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -419,11 +456,13 @@ pub unsafe extern "C" fn sp_command_utf8_data(
 | 
				
			||||||
) -> NonNull<SPCommand> {
 | 
					) -> NonNull<SPCommand> {
 | 
				
			||||||
    assert!(!grid.is_null());
 | 
					    assert!(!grid.is_null());
 | 
				
			||||||
    let grid = unsafe { *Box::from_raw(grid) };
 | 
					    let grid = unsafe { *Box::from_raw(grid) };
 | 
				
			||||||
    let result = Box::new(SPCommand(servicepoint::CharGridCommand {
 | 
					    let result = Box::new(SPCommand(
 | 
				
			||||||
        origin: servicepoint::Origin::new(x,
 | 
					        servicepoint::CharGridCommand {
 | 
				
			||||||
                                          y),
 | 
					            origin: servicepoint::Origin::new(x, y),
 | 
				
			||||||
            grid: grid.0,
 | 
					            grid: grid.0,
 | 
				
			||||||
    }.into()));
 | 
					        }
 | 
				
			||||||
 | 
					        .into(),
 | 
				
			||||||
 | 
					    ));
 | 
				
			||||||
    NonNull::from(Box::leak(result))
 | 
					    NonNull::from(Box::leak(result))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -460,11 +499,14 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
 | 
				
			||||||
        Ok(compression) => compression,
 | 
					        Ok(compression) => compression,
 | 
				
			||||||
        Err(_) => return std::ptr::null_mut(),
 | 
					        Err(_) => return std::ptr::null_mut(),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    let command = SPCommand(servicepoint::BitmapCommand {
 | 
					    let command = SPCommand(
 | 
				
			||||||
 | 
					        servicepoint::BitmapCommand {
 | 
				
			||||||
            origin: servicepoint::Origin::new(x, y),
 | 
					            origin: servicepoint::Origin::new(x, y),
 | 
				
			||||||
            bitmap,
 | 
					            bitmap,
 | 
				
			||||||
            compression,
 | 
					            compression,
 | 
				
			||||||
    }.into());
 | 
					        }
 | 
				
			||||||
 | 
					        .into(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
    Box::leak(Box::new(command))
 | 
					    Box::leak(Box::new(command))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,9 +2,9 @@
 | 
				
			||||||
//!
 | 
					//!
 | 
				
			||||||
//! prefix `sp_connection_`
 | 
					//! prefix `sp_connection_`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::ffi::{c_char, CStr};
 | 
					 | 
				
			||||||
use servicepoint::Connection;
 | 
					 | 
				
			||||||
use crate::{SPCommand, SPPacket};
 | 
					use crate::{SPCommand, SPPacket};
 | 
				
			||||||
 | 
					use servicepoint::Connection;
 | 
				
			||||||
 | 
					use std::ffi::{c_char, CStr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// A connection to the display.
 | 
					/// A connection to the display.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
| 
						 | 
					@ -36,7 +36,9 @@ pub unsafe extern "C" fn sp_connection_open(
 | 
				
			||||||
    host: *const c_char,
 | 
					    host: *const c_char,
 | 
				
			||||||
) -> *mut SPConnection {
 | 
					) -> *mut SPConnection {
 | 
				
			||||||
    assert!(!host.is_null());
 | 
					    assert!(!host.is_null());
 | 
				
			||||||
    let host = unsafe {CStr::from_ptr(host)}.to_str().expect("Bad encoding");
 | 
					    let host = unsafe { CStr::from_ptr(host) }
 | 
				
			||||||
 | 
					        .to_str()
 | 
				
			||||||
 | 
					        .expect("Bad encoding");
 | 
				
			||||||
    let connection = match servicepoint::UdpConnection::open(host) {
 | 
					    let connection = match servicepoint::UdpConnection::open(host) {
 | 
				
			||||||
        Err(_) => return std::ptr::null_mut(),
 | 
					        Err(_) => return std::ptr::null_mut(),
 | 
				
			||||||
        Ok(value) => value,
 | 
					        Ok(value) => value,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,7 +72,7 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
 | 
				
			||||||
) -> *mut SPCp437Grid {
 | 
					) -> *mut SPCp437Grid {
 | 
				
			||||||
    assert!(data.is_null());
 | 
					    assert!(data.is_null());
 | 
				
			||||||
    let data = unsafe { std::slice::from_raw_parts(data, data_length) };
 | 
					    let data = unsafe { std::slice::from_raw_parts(data, data_length) };
 | 
				
			||||||
    let grid = servicepoint::Cp437Grid::load(        width, height, data,    );
 | 
					    let grid = servicepoint::Cp437Grid::load(width, height, data);
 | 
				
			||||||
    if let Some(grid) = grid {
 | 
					    if let Some(grid) = grid {
 | 
				
			||||||
        Box::leak(Box::new(SPCp437Grid(grid)))
 | 
					        Box::leak(Box::new(SPCp437Grid(grid)))
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
//!
 | 
					//!
 | 
				
			||||||
//! prefix `sp_packet_`
 | 
					//! prefix `sp_packet_`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::ptr::{NonNull};
 | 
					use std::ptr::NonNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::SPCommand;
 | 
					use crate::SPCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,9 @@ pub unsafe extern "C" fn sp_packet_from_command(
 | 
				
			||||||
    let command = unsafe { *Box::from_raw(command) };
 | 
					    let command = unsafe { *Box::from_raw(command) };
 | 
				
			||||||
    if let Ok(packet) = command.0.try_into() {
 | 
					    if let Ok(packet) = command.0.try_into() {
 | 
				
			||||||
        Box::leak(Box::new(SPPacket(packet)))
 | 
					        Box::leak(Box::new(SPPacket(packet)))
 | 
				
			||||||
    } else { std::ptr::null_mut() }
 | 
					    } else {
 | 
				
			||||||
 | 
					        std::ptr::null_mut()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Tries to load a [SPPacket] from the passed array with the specified length.
 | 
					/// Tries to load a [SPPacket] from the passed array with the specified length.
 | 
				
			||||||
| 
						 | 
					@ -105,7 +107,8 @@ pub unsafe extern "C" fn sp_packet_from_parts(
 | 
				
			||||||
    let payload = if payload.is_null() {
 | 
					    let payload = if payload.is_null() {
 | 
				
			||||||
        vec![]
 | 
					        vec![]
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        let payload = unsafe {std::slice::from_raw_parts(payload, payload_len) };
 | 
					        let payload =
 | 
				
			||||||
 | 
					            unsafe { std::slice::from_raw_parts(payload, payload_len) };
 | 
				
			||||||
        Vec::from(payload)
 | 
					        Vec::from(payload)
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue