CCommand (opaque wrapper around Command for C)
This commit is contained in:
		
							parent
							
								
									d2369446ef
								
							
						
					
					
						commit
						956e5df812
					
				
					 6 changed files with 107 additions and 82 deletions
				
			
		|  | @ -137,6 +137,11 @@ typedef struct sp_CBitVec sp_CBitVec; | ||||||
|  */ |  */ | ||||||
| typedef struct sp_CBrightnessGrid sp_CBrightnessGrid; | typedef struct sp_CBrightnessGrid sp_CBrightnessGrid; | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * Opaque struct needed for correct code generation. | ||||||
|  |  */ | ||||||
|  | typedef struct sp_CCommand sp_CCommand; | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * A C-wrapper for grid containing codepage 437 characters. |  * A C-wrapper for grid containing codepage 437 characters. | ||||||
|  * |  * | ||||||
|  | @ -588,9 +593,9 @@ size_t sp_brightness_grid_width(const struct sp_CBrightnessGrid *this_); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_bitmap_linear(sp_Offset offset, | struct sp_CCommand *sp_command_bitmap_linear(sp_Offset offset, | ||||||
|                                             struct sp_CBitVec *bit_vec, |                                              struct sp_CBitVec *bit_vec, | ||||||
|                                             sp_CompressionCode compression); |                                              sp_CompressionCode compression); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::BitmapLinearAnd` instance. |  * Allocates a new `Command::BitmapLinearAnd` instance. | ||||||
|  | @ -606,9 +611,9 @@ struct sp_Command *sp_command_bitmap_linear(sp_Offset offset, | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_bitmap_linear_and(sp_Offset offset, | struct sp_CCommand *sp_command_bitmap_linear_and(sp_Offset offset, | ||||||
|                                                 struct sp_CBitVec *bit_vec, |                                                  struct sp_CBitVec *bit_vec, | ||||||
|                                                 sp_CompressionCode compression); |                                                  sp_CompressionCode compression); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::BitmapLinearOr` instance. |  * Allocates a new `Command::BitmapLinearOr` instance. | ||||||
|  | @ -624,9 +629,9 @@ struct sp_Command *sp_command_bitmap_linear_and(sp_Offset offset, | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_bitmap_linear_or(sp_Offset offset, | struct sp_CCommand *sp_command_bitmap_linear_or(sp_Offset offset, | ||||||
|                                                struct sp_CBitVec *bit_vec, |                                                 struct sp_CBitVec *bit_vec, | ||||||
|                                                sp_CompressionCode compression); |                                                 sp_CompressionCode compression); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::BitmapLinearWin` instance. |  * Allocates a new `Command::BitmapLinearWin` instance. | ||||||
|  | @ -642,10 +647,10 @@ struct sp_Command *sp_command_bitmap_linear_or(sp_Offset offset, | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_bitmap_linear_win(size_t x, | struct sp_CCommand *sp_command_bitmap_linear_win(size_t x, | ||||||
|                                                 size_t y, |                                                  size_t y, | ||||||
|                                                 struct sp_PixelGrid *pixel_grid, |                                                  struct sp_PixelGrid *pixel_grid, | ||||||
|                                                 sp_CompressionCode compression_code); |                                                  sp_CompressionCode compression_code); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::BitmapLinearXor` instance. |  * Allocates a new `Command::BitmapLinearXor` instance. | ||||||
|  | @ -661,9 +666,9 @@ struct sp_Command *sp_command_bitmap_linear_win(size_t x, | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_bitmap_linear_xor(sp_Offset offset, | struct sp_CCommand *sp_command_bitmap_linear_xor(sp_Offset offset, | ||||||
|                                                 struct sp_CBitVec *bit_vec, |                                                  struct sp_CBitVec *bit_vec, | ||||||
|                                                 sp_CompressionCode compression); |                                                  sp_CompressionCode compression); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the |  * Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the | ||||||
|  | @ -680,7 +685,7 @@ struct sp_Command *sp_command_bitmap_linear_xor(sp_Offset offset, | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_brightness(uint8_t brightness); | struct sp_CCommand *sp_command_brightness(uint8_t brightness); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::CharBrightness` instance. |  * Allocates a new `Command::CharBrightness` instance. | ||||||
|  | @ -695,9 +700,9 @@ struct sp_Command *sp_command_brightness(uint8_t brightness); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_char_brightness(size_t x, | struct sp_CCommand *sp_command_char_brightness(size_t x, | ||||||
|                                               size_t y, |                                                size_t y, | ||||||
|                                               struct sp_CBrightnessGrid *byte_grid); |                                                struct sp_CBrightnessGrid *byte_grid); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::Clear` instance. |  * Allocates a new `Command::Clear` instance. | ||||||
|  | @ -709,7 +714,7 @@ struct sp_Command *sp_command_char_brightness(size_t x, | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_clear(void); | struct sp_CCommand *sp_command_clear(void); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Clones a `Command` instance. |  * Clones a `Command` instance. | ||||||
|  | @ -723,7 +728,7 @@ struct sp_Command *sp_command_clear(void); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_clone(const struct sp_Command *original); | struct sp_CCommand *sp_command_clone(const struct sp_CCommand *original); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::Cp437Data` instance. |  * Allocates a new `Command::Cp437Data` instance. | ||||||
|  | @ -738,9 +743,9 @@ struct sp_Command *sp_command_clone(const struct sp_Command *original); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_cp437_data(size_t x, | struct sp_CCommand *sp_command_cp437_data(size_t x, | ||||||
|                                          size_t y, |                                           size_t y, | ||||||
|                                          struct sp_CCp437Grid *byte_grid); |                                           struct sp_CCp437Grid *byte_grid); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Deallocates a `Command`. |  * Deallocates a `Command`. | ||||||
|  | @ -753,7 +758,7 @@ struct sp_Command *sp_command_cp437_data(size_t x, | ||||||
|  * - `this` is not used concurrently or after this call |  * - `this` is not used concurrently or after this call | ||||||
|  * - `this` was not passed to another consuming function, e.g. to create a `Packet` |  * - `this` was not passed to another consuming function, e.g. to create a `Packet` | ||||||
|  */ |  */ | ||||||
| void sp_command_dealloc(struct sp_Command *ptr); | void sp_command_dealloc(struct sp_CCommand *ptr); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::FadeOut` instance. |  * Allocates a new `Command::FadeOut` instance. | ||||||
|  | @ -765,7 +770,7 @@ void sp_command_dealloc(struct sp_Command *ptr); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_fade_out(void); | struct sp_CCommand *sp_command_fade_out(void); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Allocates a new `Command::HardReset` instance. |  * Allocates a new `Command::HardReset` instance. | ||||||
|  | @ -777,7 +782,7 @@ struct sp_Command *sp_command_fade_out(void); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_hard_reset(void); | struct sp_CCommand *sp_command_hard_reset(void); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Tries to turn a `Packet` into a `Command`. The packet is deallocated in the process. |  * Tries to turn a `Packet` into a `Command`. The packet is deallocated in the process. | ||||||
|  | @ -794,7 +799,7 @@ struct sp_Command *sp_command_hard_reset(void); | ||||||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or |  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||||
|  *   by explicitly calling `sp_command_dealloc`. |  *   by explicitly calling `sp_command_dealloc`. | ||||||
|  */ |  */ | ||||||
| struct sp_Command *sp_command_try_from_packet(struct sp_Packet *packet); | struct sp_CCommand *sp_command_try_from_packet(struct sp_Packet *packet); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Closes and deallocates a `Connection`. |  * Closes and deallocates a `Connection`. | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ int main(void) { | ||||||
|     sp_PixelGrid *pixels = sp_pixel_grid_new(sp_PIXEL_WIDTH, sp_PIXEL_HEIGHT); |     sp_PixelGrid *pixels = sp_pixel_grid_new(sp_PIXEL_WIDTH, sp_PIXEL_HEIGHT); | ||||||
|     sp_pixel_grid_fill(pixels, true); |     sp_pixel_grid_fill(pixels, true); | ||||||
| 
 | 
 | ||||||
|     sp_Command *command = sp_command_bitmap_linear_win(0, 0, pixels, Uncompressed); |     sp_CCommand *command = sp_command_bitmap_linear_win(0, 0, pixels, Uncompressed); | ||||||
|     sp_Packet *packet = sp_packet_from_command(command); |     sp_Packet *packet = sp_packet_from_command(command); | ||||||
|     if (!sp_connection_send(connection, packet)) |     if (!sp_connection_send(connection, packet)) | ||||||
|         return 1; |         return 1; | ||||||
|  |  | ||||||
|  | @ -12,6 +12,15 @@ use crate::bit_vec::CBitVec; | ||||||
| use crate::brightness_grid::CBrightnessGrid; | use crate::brightness_grid::CBrightnessGrid; | ||||||
| use crate::cp437_grid::CCp437Grid; | use crate::cp437_grid::CCp437Grid; | ||||||
| 
 | 
 | ||||||
|  | /// Opaque struct needed for correct code generation.
 | ||||||
|  | pub struct CCommand(pub(crate) Command); | ||||||
|  | 
 | ||||||
|  | impl Clone for CCommand { | ||||||
|  |     fn clone(&self) -> Self { | ||||||
|  |         CCommand(self.0.clone()) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// Tries to turn a `Packet` into a `Command`. The packet is deallocated in the process.
 | /// Tries to turn a `Packet` into a `Command`. The packet is deallocated in the process.
 | ||||||
| ///
 | ///
 | ||||||
| /// Returns: pointer to new `Command` instance or NULL
 | /// Returns: pointer to new `Command` instance or NULL
 | ||||||
|  | @ -28,11 +37,11 @@ use crate::cp437_grid::CCp437Grid; | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_try_from_packet( | pub unsafe extern "C" fn sp_command_try_from_packet( | ||||||
|     packet: *mut Packet, |     packet: *mut Packet, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let packet = *Box::from_raw(packet); |     let packet = *Box::from_raw(packet); | ||||||
|     match Command::try_from(packet) { |     match Command::try_from(packet) { | ||||||
|         Err(_) => null_mut(), |         Err(_) => null_mut(), | ||||||
|         Ok(command) => Box::into_raw(Box::new(command)), |         Ok(command) => Box::into_raw(Box::new(CCommand(command))), | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -48,8 +57,8 @@ pub unsafe extern "C" fn sp_command_try_from_packet( | ||||||
| ///   by explicitly calling `sp_command_dealloc`.
 | ///   by explicitly calling `sp_command_dealloc`.
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_clone( | pub unsafe extern "C" fn sp_command_clone( | ||||||
|     original: *const Command, |     original: *const CCommand, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     Box::into_raw(Box::new((*original).clone())) |     Box::into_raw(Box::new((*original).clone())) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -62,8 +71,8 @@ pub unsafe extern "C" fn sp_command_clone( | ||||||
| /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | ||||||
| ///   by explicitly calling `sp_command_dealloc`.
 | ///   by explicitly calling `sp_command_dealloc`.
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_clear() -> *mut Command { | pub unsafe extern "C" fn sp_command_clear() -> *mut CCommand { | ||||||
|     Box::into_raw(Box::new(Command::Clear)) |     Box::into_raw(Box::new(CCommand(Command::Clear))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::HardReset` instance.
 | /// Allocates a new `Command::HardReset` instance.
 | ||||||
|  | @ -75,8 +84,8 @@ pub unsafe extern "C" fn sp_command_clear() -> *mut Command { | ||||||
| /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | ||||||
| ///   by explicitly calling `sp_command_dealloc`.
 | ///   by explicitly calling `sp_command_dealloc`.
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_hard_reset() -> *mut Command { | pub unsafe extern "C" fn sp_command_hard_reset() -> *mut CCommand { | ||||||
|     Box::into_raw(Box::new(Command::HardReset)) |     Box::into_raw(Box::new(CCommand(Command::HardReset))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::FadeOut` instance.
 | /// Allocates a new `Command::FadeOut` instance.
 | ||||||
|  | @ -88,8 +97,8 @@ pub unsafe extern "C" fn sp_command_hard_reset() -> *mut Command { | ||||||
| /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | ||||||
| ///   by explicitly calling `sp_command_dealloc`.
 | ///   by explicitly calling `sp_command_dealloc`.
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_fade_out() -> *mut Command { | pub unsafe extern "C" fn sp_command_fade_out() -> *mut CCommand { | ||||||
|     Box::into_raw(Box::new(Command::FadeOut)) |     Box::into_raw(Box::new(CCommand(Command::FadeOut))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the
 | /// Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the
 | ||||||
|  | @ -106,10 +115,12 @@ pub unsafe extern "C" fn sp_command_fade_out() -> *mut Command { | ||||||
| /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | /// - the returned `Command` instance is freed in some way, either by using a consuming function or
 | ||||||
| ///   by explicitly calling `sp_command_dealloc`.
 | ///   by explicitly calling `sp_command_dealloc`.
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_brightness(brightness: u8) -> *mut Command { | pub unsafe extern "C" fn sp_command_brightness( | ||||||
|  |     brightness: u8, | ||||||
|  | ) -> *mut CCommand { | ||||||
|     let brightness = |     let brightness = | ||||||
|         Brightness::try_from(brightness).expect("invalid brightness"); |         Brightness::try_from(brightness).expect("invalid brightness"); | ||||||
|     Box::into_raw(Box::new(Command::Brightness(brightness))) |     Box::into_raw(Box::new(CCommand(Command::Brightness(brightness)))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::CharBrightness` instance.
 | /// Allocates a new `Command::CharBrightness` instance.
 | ||||||
|  | @ -128,12 +139,12 @@ pub unsafe extern "C" fn sp_command_char_brightness( | ||||||
|     x: usize, |     x: usize, | ||||||
|     y: usize, |     y: usize, | ||||||
|     byte_grid: *mut CBrightnessGrid, |     byte_grid: *mut CBrightnessGrid, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let byte_grid = *Box::from_raw(byte_grid); |     let byte_grid = *Box::from_raw(byte_grid); | ||||||
|     Box::into_raw(Box::new(Command::CharBrightness( |     Box::into_raw(Box::new(CCommand(Command::CharBrightness( | ||||||
|         Origin::new(x, y), |         Origin::new(x, y), | ||||||
|         byte_grid.0, |         byte_grid.0, | ||||||
|     ))) |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::BitmapLinear` instance.
 | /// Allocates a new `Command::BitmapLinear` instance.
 | ||||||
|  | @ -153,13 +164,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear( | ||||||
|     offset: Offset, |     offset: Offset, | ||||||
|     bit_vec: *mut CBitVec, |     bit_vec: *mut CBitVec, | ||||||
|     compression: CompressionCode, |     compression: CompressionCode, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let bit_vec = *Box::from_raw(bit_vec); |     let bit_vec = *Box::from_raw(bit_vec); | ||||||
|     Box::into_raw(Box::new(Command::BitmapLinear( |     Box::into_raw(Box::new(CCommand(Command::BitmapLinear( | ||||||
|         offset, |         offset, | ||||||
|         bit_vec.into(), |         bit_vec.into(), | ||||||
|         compression, |         compression, | ||||||
|     ))) |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::BitmapLinearAnd` instance.
 | /// Allocates a new `Command::BitmapLinearAnd` instance.
 | ||||||
|  | @ -179,13 +190,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and( | ||||||
|     offset: Offset, |     offset: Offset, | ||||||
|     bit_vec: *mut CBitVec, |     bit_vec: *mut CBitVec, | ||||||
|     compression: CompressionCode, |     compression: CompressionCode, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let bit_vec = *Box::from_raw(bit_vec); |     let bit_vec = *Box::from_raw(bit_vec); | ||||||
|     Box::into_raw(Box::new(Command::BitmapLinearAnd( |     Box::into_raw(Box::new(CCommand(Command::BitmapLinearAnd( | ||||||
|         offset, |         offset, | ||||||
|         bit_vec.into(), |         bit_vec.into(), | ||||||
|         compression, |         compression, | ||||||
|     ))) |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::BitmapLinearOr` instance.
 | /// Allocates a new `Command::BitmapLinearOr` instance.
 | ||||||
|  | @ -205,13 +216,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or( | ||||||
|     offset: Offset, |     offset: Offset, | ||||||
|     bit_vec: *mut CBitVec, |     bit_vec: *mut CBitVec, | ||||||
|     compression: CompressionCode, |     compression: CompressionCode, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let bit_vec = *Box::from_raw(bit_vec); |     let bit_vec = *Box::from_raw(bit_vec); | ||||||
|     Box::into_raw(Box::new(Command::BitmapLinearOr( |     Box::into_raw(Box::new(CCommand(Command::BitmapLinearOr( | ||||||
|         offset, |         offset, | ||||||
|         bit_vec.into(), |         bit_vec.into(), | ||||||
|         compression, |         compression, | ||||||
|     ))) |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::BitmapLinearXor` instance.
 | /// Allocates a new `Command::BitmapLinearXor` instance.
 | ||||||
|  | @ -231,13 +242,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor( | ||||||
|     offset: Offset, |     offset: Offset, | ||||||
|     bit_vec: *mut CBitVec, |     bit_vec: *mut CBitVec, | ||||||
|     compression: CompressionCode, |     compression: CompressionCode, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let bit_vec = *Box::from_raw(bit_vec); |     let bit_vec = *Box::from_raw(bit_vec); | ||||||
|     Box::into_raw(Box::new(Command::BitmapLinearXor( |     Box::into_raw(Box::new(CCommand(Command::BitmapLinearXor( | ||||||
|         offset, |         offset, | ||||||
|         bit_vec.into(), |         bit_vec.into(), | ||||||
|         compression, |         compression, | ||||||
|     ))) |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::Cp437Data` instance.
 | /// Allocates a new `Command::Cp437Data` instance.
 | ||||||
|  | @ -256,9 +267,12 @@ pub unsafe extern "C" fn sp_command_cp437_data( | ||||||
|     x: usize, |     x: usize, | ||||||
|     y: usize, |     y: usize, | ||||||
|     byte_grid: *mut CCp437Grid, |     byte_grid: *mut CCp437Grid, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let byte_grid = *Box::from_raw(byte_grid); |     let byte_grid = *Box::from_raw(byte_grid); | ||||||
|     Box::into_raw(Box::new(Command::Cp437Data(Origin::new(x, y), byte_grid.0))) |     Box::into_raw(Box::new(CCommand(Command::Cp437Data( | ||||||
|  |         Origin::new(x, y), | ||||||
|  |         byte_grid.0, | ||||||
|  |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Allocates a new `Command::BitmapLinearWin` instance.
 | /// Allocates a new `Command::BitmapLinearWin` instance.
 | ||||||
|  | @ -279,13 +293,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win( | ||||||
|     y: usize, |     y: usize, | ||||||
|     pixel_grid: *mut PixelGrid, |     pixel_grid: *mut PixelGrid, | ||||||
|     compression_code: CompressionCode, |     compression_code: CompressionCode, | ||||||
| ) -> *mut Command { | ) -> *mut CCommand { | ||||||
|     let byte_grid = *Box::from_raw(pixel_grid); |     let byte_grid = *Box::from_raw(pixel_grid); | ||||||
|     Box::into_raw(Box::new(Command::BitmapLinearWin( |     Box::into_raw(Box::new(CCommand(Command::BitmapLinearWin( | ||||||
|         Origin::new(x, y), |         Origin::new(x, y), | ||||||
|         byte_grid, |         byte_grid, | ||||||
|         compression_code, |         compression_code, | ||||||
|     ))) |     )))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Deallocates a `Command`.
 | /// Deallocates a `Command`.
 | ||||||
|  | @ -298,6 +312,6 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win( | ||||||
| /// - `this` is not used concurrently or after this call
 | /// - `this` is not used concurrently or after this call
 | ||||||
| /// - `this` was not passed to another consuming function, e.g. to create a `Packet`
 | /// - `this` was not passed to another consuming function, e.g. to create a `Packet`
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_command_dealloc(ptr: *mut Command) { | pub unsafe extern "C" fn sp_command_dealloc(ptr: *mut CCommand) { | ||||||
|     _ = Box::from_raw(ptr); |     _ = Box::from_raw(ptr); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,7 +4,8 @@ | ||||||
| 
 | 
 | ||||||
| use std::ptr::null_mut; | use std::ptr::null_mut; | ||||||
| 
 | 
 | ||||||
| use servicepoint::{Command, Packet}; | use crate::command::CCommand; | ||||||
|  | use servicepoint::Packet; | ||||||
| 
 | 
 | ||||||
| /// Turns a `Command` into a `Packet`.
 | /// Turns a `Command` into a `Packet`.
 | ||||||
| /// The `Command` gets consumed.
 | /// The `Command` gets consumed.
 | ||||||
|  | @ -19,10 +20,10 @@ use servicepoint::{Command, Packet}; | ||||||
| ///   by explicitly calling `sp_packet_dealloc`.
 | ///   by explicitly calling `sp_packet_dealloc`.
 | ||||||
| #[no_mangle] | #[no_mangle] | ||||||
| pub unsafe extern "C" fn sp_packet_from_command( | pub unsafe extern "C" fn sp_packet_from_command( | ||||||
|     command: *mut Command, |     command: *mut CCommand, | ||||||
| ) -> *mut Packet { | ) -> *mut Packet { | ||||||
|     let command = *Box::from_raw(command); |     let command = *Box::from_raw(command); | ||||||
|     let packet = command.into(); |     let packet = command.0.into(); | ||||||
|     Box::into_raw(Box::new(packet)) |     Box::into_raw(Box::new(packet)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -561,7 +561,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_try_from_packet(Packet* packet); |         public static extern CCommand* sp_command_try_from_packet(Packet* packet); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Clones a `Command` instance. |         ///  Clones a `Command` instance. | ||||||
|  | @ -576,7 +576,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_clone(Command* original); |         public static extern CCommand* sp_command_clone(CCommand* original); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::Clear` instance. |         ///  Allocates a new `Command::Clear` instance. | ||||||
|  | @ -589,7 +589,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_clear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_clear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_clear(); |         public static extern CCommand* sp_command_clear(); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::HardReset` instance. |         ///  Allocates a new `Command::HardReset` instance. | ||||||
|  | @ -602,7 +602,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_hard_reset", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_hard_reset", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_hard_reset(); |         public static extern CCommand* sp_command_hard_reset(); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::FadeOut` instance. |         ///  Allocates a new `Command::FadeOut` instance. | ||||||
|  | @ -615,7 +615,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_fade_out", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_fade_out", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_fade_out(); |         public static extern CCommand* sp_command_fade_out(); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the |         ///  Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the | ||||||
|  | @ -633,7 +633,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_brightness(byte brightness); |         public static extern CCommand* sp_command_brightness(byte brightness); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::CharBrightness` instance. |         ///  Allocates a new `Command::CharBrightness` instance. | ||||||
|  | @ -649,7 +649,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_char_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_char_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_char_brightness(nuint x, nuint y, CBrightnessGrid* byte_grid); |         public static extern CCommand* sp_command_char_brightness(nuint x, nuint y, CBrightnessGrid* byte_grid); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::BitmapLinear` instance. |         ///  Allocates a new `Command::BitmapLinear` instance. | ||||||
|  | @ -666,7 +666,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_bitmap_linear(nuint offset, CBitVec* bit_vec, CompressionCode compression); |         public static extern CCommand* sp_command_bitmap_linear(nuint offset, CBitVec* bit_vec, CompressionCode compression); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::BitmapLinearAnd` instance. |         ///  Allocates a new `Command::BitmapLinearAnd` instance. | ||||||
|  | @ -683,7 +683,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_and", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_and", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_bitmap_linear_and(nuint offset, CBitVec* bit_vec, CompressionCode compression); |         public static extern CCommand* sp_command_bitmap_linear_and(nuint offset, CBitVec* bit_vec, CompressionCode compression); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::BitmapLinearOr` instance. |         ///  Allocates a new `Command::BitmapLinearOr` instance. | ||||||
|  | @ -700,7 +700,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_or", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_or", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_bitmap_linear_or(nuint offset, CBitVec* bit_vec, CompressionCode compression); |         public static extern CCommand* sp_command_bitmap_linear_or(nuint offset, CBitVec* bit_vec, CompressionCode compression); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::BitmapLinearXor` instance. |         ///  Allocates a new `Command::BitmapLinearXor` instance. | ||||||
|  | @ -717,7 +717,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_xor", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_xor", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_bitmap_linear_xor(nuint offset, CBitVec* bit_vec, CompressionCode compression); |         public static extern CCommand* sp_command_bitmap_linear_xor(nuint offset, CBitVec* bit_vec, CompressionCode compression); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::Cp437Data` instance. |         ///  Allocates a new `Command::Cp437Data` instance. | ||||||
|  | @ -733,7 +733,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_cp437_data", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_cp437_data", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_cp437_data(nuint x, nuint y, CCp437Grid* byte_grid); |         public static extern CCommand* sp_command_cp437_data(nuint x, nuint y, CCp437Grid* byte_grid); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Allocates a new `Command::BitmapLinearWin` instance. |         ///  Allocates a new `Command::BitmapLinearWin` instance. | ||||||
|  | @ -750,7 +750,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///    by explicitly calling `sp_command_dealloc`. |         ///    by explicitly calling `sp_command_dealloc`. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_win", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_win", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern Command* sp_command_bitmap_linear_win(nuint x, nuint y, PixelGrid* pixel_grid, CompressionCode compression_code); |         public static extern CCommand* sp_command_bitmap_linear_win(nuint x, nuint y, PixelGrid* pixel_grid, CompressionCode compression_code); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Deallocates a `Command`. |         ///  Deallocates a `Command`. | ||||||
|  | @ -764,7 +764,7 @@ namespace ServicePoint.BindGen | ||||||
|         ///  - `this` was not passed to another consuming function, e.g. to create a `Packet` |         ///  - `this` was not passed to another consuming function, e.g. to create a `Packet` | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         [DllImport(__DllName, EntryPoint = "sp_command_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] |         [DllImport(__DllName, EntryPoint = "sp_command_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||||
|         public static extern void sp_command_dealloc(Command* ptr); |         public static extern void sp_command_dealloc(CCommand* ptr); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         ///  Creates a new instance of `Connection`. |         ///  Creates a new instance of `Connection`. | ||||||
|  | @ -1071,6 +1071,11 @@ namespace ServicePoint.BindGen | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     [StructLayout(LayoutKind.Sequential)] | ||||||
|  |     public unsafe partial struct CCommand | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     [StructLayout(LayoutKind.Sequential)] |     [StructLayout(LayoutKind.Sequential)] | ||||||
|     public unsafe partial struct CByteSlice |     public unsafe partial struct CByteSlice | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ using ServicePoint.BindGen; | ||||||
| 
 | 
 | ||||||
| namespace ServicePoint; | namespace ServicePoint; | ||||||
| 
 | 
 | ||||||
| public sealed class Command : SpNativeInstance<BindGen.Command> | public sealed class Command : SpNativeInstance<BindGen.CCommand> | ||||||
| { | { | ||||||
|     public static bool TryFromPacket(Packet packet, [MaybeNullWhen(false)] out Command command) |     public static bool TryFromPacket(Packet packet, [MaybeNullWhen(false)] out Command command) | ||||||
|     { |     { | ||||||
|  | @ -121,7 +121,7 @@ public sealed class Command : SpNativeInstance<BindGen.Command> | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private unsafe Command(BindGen.Command* instance) : base(instance) |     private unsafe Command(BindGen.CCommand* instance) : base(instance) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter