type per command, binding generation macros, nix package #4
					 11 changed files with 55 additions and 50 deletions
				
			
		|  | @ -845,15 +845,15 @@ BrightnessGrid *sp_brightness_grid_load(size_t width, | |||
|  * | ||||
|  * # Examples | ||||
|  * ```C | ||||
|  * UdpConnection connection = sp_udp_open("127.0.0.1:2342"); | ||||
|  * UdpSocket *connection = sp_udp_open("127.0.0.1:2342"); | ||||
|  * if (connection == NULL) | ||||
|  *     return 1; | ||||
|  * | ||||
|  * BrightnessGrid grid = sp_brightness_grid_new(2, 2); | ||||
|  * BrightnessGrid *grid = sp_brightness_grid_new(2, 2); | ||||
|  * sp_brightness_grid_set(grid, 0, 0, 0); | ||||
|  * sp_brightness_grid_set(grid, 1, 1, 10); | ||||
|  * | ||||
|  * TypedCommand command = sp_command_char_brightness(grid); | ||||
|  * TypedCommand *command = sp_command_char_brightness(grid); | ||||
|  * sp_udp_free(connection); | ||||
|  * ``` | ||||
|  */ | ||||
|  | @ -1013,6 +1013,12 @@ BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(BitmapCommand */*notnull*/ comman | |||
| 
 | ||||
| void sp_cmd_bitmap_free(BitmapCommand */*notnull*/ command); | ||||
| 
 | ||||
| /**
 | ||||
|  * Move the provided [Bitmap] into a new [BitmapCommand], | ||||
|  * leaving other fields as their default values. | ||||
|  * | ||||
|  * Rust equivalent: [`<BitmapCommand as From<Bitmap>>::from`] | ||||
|  */ | ||||
| BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(Bitmap */*notnull*/ bitmap); | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -1475,19 +1481,19 @@ bool sp_u16_to_command_code(uint16_t code, | |||
|                             CommandCode *result); | ||||
| 
 | ||||
| /**
 | ||||
|  * Closes and deallocates a [UdpConnection]. | ||||
|  * Closes and deallocates a [UdpSocket]. | ||||
|  */ | ||||
| void sp_udp_free(UdpSocket */*notnull*/ connection); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new instance of [UdpConnection]. | ||||
|  * Creates a new instance of [UdpSocket]. | ||||
|  * | ||||
|  * returns: NULL if connection fails, or connected instance | ||||
|  * | ||||
|  * # Examples | ||||
|  * | ||||
|  * ```C | ||||
|  * UdpConnection connection = sp_udp_open("172.23.42.29:2342"); | ||||
|  * UdpSocket connection = sp_udp_open("172.23.42.29:2342"); | ||||
|  * if (connection != NULL) | ||||
|  *     sp_udp_send_command(connection, sp_command_clear()); | ||||
|  * ``` | ||||
|  | @ -1495,14 +1501,14 @@ void sp_udp_free(UdpSocket */*notnull*/ connection); | |||
| UdpSocket *sp_udp_open(char */*notnull*/ host); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new instance of [UdpConnection]. | ||||
|  * Creates a new instance of [UdpSocket]. | ||||
|  * | ||||
|  * returns: NULL if connection fails, or connected instance | ||||
|  * | ||||
|  * # Examples | ||||
|  * | ||||
|  * ```C | ||||
|  * UdpConnection connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); | ||||
|  * UdpSocket connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); | ||||
|  * if (connection != NULL) | ||||
|  *     sp_udp_send_command(connection, sp_command_clear()); | ||||
|  * ``` | ||||
|  | @ -1514,7 +1520,7 @@ UdpSocket *sp_udp_open_ipv4(uint8_t ip1, | |||
|                             uint16_t port); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sends a [TypedCommand] to the display using the [UdpConnection]. | ||||
|  * Sends a [TypedCommand] to the display using the [UdpSocket]. | ||||
|  * | ||||
|  * The passed `command` gets consumed. | ||||
|  * | ||||
|  | @ -1530,7 +1536,7 @@ bool sp_udp_send_command(UdpSocket */*notnull*/ connection, | |||
|                          TypedCommand */*notnull*/ command); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sends a [Header] to the display using the [UdpConnection]. | ||||
|  * Sends a [Header] to the display using the [UdpSocket]. | ||||
|  * | ||||
|  * returns: true in case of success | ||||
|  * | ||||
|  | @ -1543,7 +1549,7 @@ bool sp_udp_send_command(UdpSocket */*notnull*/ connection, | |||
| bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sends a [Packet] to the display using the [UdpConnection]. | ||||
|  * Sends a [Packet] to the display using the [UdpSocket]. | ||||
|  * | ||||
|  * The passed `packet` gets consumed. | ||||
|  * | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| use crate::byte_slice::ByteSlice; | ||||
| use crate::{ | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove, | ||||
|     SPBitVec, | ||||
|     byte_slice::ByteSlice, bitvec::SPBitVec, | ||||
| }; | ||||
| use servicepoint::{ | ||||
|     Bitmap, BitmapCommand, CompressionCode, DataRef, Grid, Origin, Packet, | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| use crate::{ | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice, | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, byte_slice::ByteSlice, | ||||
| }; | ||||
| use servicepoint::{ | ||||
|     BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet, | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| use crate::{ | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove, | ||||
|     ByteSlice, | ||||
|     byte_slice::ByteSlice, | ||||
| }; | ||||
| use servicepoint::{ | ||||
|     Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid, | ||||
|  | @ -15,15 +15,15 @@ use std::ptr::NonNull; | |||
| ///
 | ||||
| /// # Examples
 | ||||
| /// ```C
 | ||||
| /// UdpConnection connection = sp_udp_open("127.0.0.1:2342");
 | ||||
| /// UdpSocket *connection = sp_udp_open("127.0.0.1:2342");
 | ||||
| /// if (connection == NULL)
 | ||||
| ///     return 1;
 | ||||
| ///
 | ||||
| /// BrightnessGrid grid = sp_brightness_grid_new(2, 2);
 | ||||
| /// BrightnessGrid *grid = sp_brightness_grid_new(2, 2);
 | ||||
| /// sp_brightness_grid_set(grid, 0, 0, 0);
 | ||||
| /// sp_brightness_grid_set(grid, 1, 1, 10);
 | ||||
| ///
 | ||||
| /// TypedCommand command = sp_command_char_brightness(grid);
 | ||||
| /// TypedCommand *command = sp_command_char_brightness(grid);
 | ||||
| /// sp_udp_free(connection);
 | ||||
| /// ```
 | ||||
| #[no_mangle] | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| use crate::{ | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice, | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, byte_slice::ByteSlice, | ||||
| }; | ||||
| use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet}; | ||||
| use std::ptr::NonNull; | ||||
|  |  | |||
|  | @ -23,6 +23,10 @@ pub unsafe extern "C" fn sp_cmd_bitmap_new( | |||
|     }) | ||||
| } | ||||
| 
 | ||||
| /// Move the provided [Bitmap] into a new [BitmapCommand],
 | ||||
| /// leaving other fields as their default values.
 | ||||
| ///
 | ||||
| /// Rust equivalent: [`<BitmapCommand as From<Bitmap>>::from`]
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_cmd_bitmap_from_bitmap( | ||||
|     bitmap: NonNull<Bitmap>, | ||||
|  |  | |||
|  | @ -3,3 +3,9 @@ mod bitvec_command; | |||
| mod brightness_grid_command; | ||||
| mod char_grid_command; | ||||
| mod cp437_grid_command; | ||||
| 
 | ||||
| pub use bitmap_command::*; | ||||
| pub use bitvec_command::*; | ||||
| pub use brightness_grid_command::*; | ||||
| pub use char_grid_command::*; | ||||
| pub use cp437_grid_command::*; | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| use crate::{ | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove, | ||||
|     ByteSlice, | ||||
|     byte_slice::ByteSlice, | ||||
| }; | ||||
| use servicepoint::{ | ||||
|     Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet, | ||||
|  |  | |||
							
								
								
									
										32
									
								
								src/lib.rs
									
										
									
									
									
								
							
							
						
						
									
										32
									
								
								src/lib.rs
									
										
									
									
									
								
							|  | @ -9,7 +9,7 @@ | |||
| //! #include "servicepoint.h"
 | ||||
| //!
 | ||||
| //! int main(void) {
 | ||||
| //!     UdpConnection *connection = sp_udp_open("172.23.42.29:2342");
 | ||||
| //!     UdpSocket *connection = sp_udp_open("172.23.42.29:2342");
 | ||||
| //!     if (connection == NULL)
 | ||||
| //!         return 1;
 | ||||
| //!
 | ||||
|  | @ -25,28 +25,18 @@ | |||
| //! }
 | ||||
|  | ||||
| //! ```
 | ||||
| 
 | ||||
| pub use crate::bitmap::*; | ||||
| pub use crate::bitvec::*; | ||||
| pub use crate::brightness_grid::*; | ||||
| pub use crate::byte_slice::*; | ||||
| pub use crate::char_grid::*; | ||||
| pub use crate::cp437_grid::*; | ||||
| pub use crate::packet::*; | ||||
| pub use crate::typed_command::*; | ||||
| pub use crate::udp::*; | ||||
| pub use servicepoint::CommandCode; | ||||
| use std::ptr::NonNull; | ||||
| 
 | ||||
| mod bitmap; | ||||
| mod bitvec; | ||||
| mod brightness_grid; | ||||
| mod byte_slice; | ||||
| mod char_grid; | ||||
| mod commands; | ||||
| mod cp437_grid; | ||||
| mod packet; | ||||
| mod typed_command; | ||||
| mod udp; | ||||
| pub mod bitmap; | ||||
| pub mod bitvec; | ||||
| pub mod brightness_grid; | ||||
| pub mod byte_slice; | ||||
| pub mod char_grid; | ||||
| pub mod commands; | ||||
| pub mod cp437_grid; | ||||
| pub mod packet; | ||||
| pub mod typed_command; | ||||
| pub mod udp; | ||||
| 
 | ||||
| use std::time::Duration; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| use crate::{ | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, ByteSlice, | ||||
|     heap_drop, heap_move_nonnull, heap_move_ok, heap_remove, byte_slice::ByteSlice, | ||||
| }; | ||||
| use servicepoint::{CommandCode, Header, Packet, TypedCommand}; | ||||
| use std::ptr::NonNull; | ||||
|  |  | |||
							
								
								
									
										16
									
								
								src/udp.rs
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/udp.rs
									
										
									
									
									
								
							|  | @ -4,14 +4,14 @@ use std::ffi::{c_char, CStr}; | |||
| use std::net::{Ipv4Addr, SocketAddrV4, UdpSocket}; | ||||
| use std::ptr::NonNull; | ||||
| 
 | ||||
| /// Creates a new instance of [UdpConnection].
 | ||||
| /// Creates a new instance of [UdpSocket].
 | ||||
| ///
 | ||||
| /// returns: NULL if connection fails, or connected instance
 | ||||
| ///
 | ||||
| /// # Examples
 | ||||
| ///
 | ||||
| /// ```C
 | ||||
| /// UdpConnection connection = sp_udp_open("172.23.42.29:2342");
 | ||||
| /// UdpSocket connection = sp_udp_open("172.23.42.29:2342");
 | ||||
| /// if (connection != NULL)
 | ||||
| ///     sp_udp_send_command(connection, sp_command_clear());
 | ||||
| /// ```
 | ||||
|  | @ -24,14 +24,14 @@ pub unsafe extern "C" fn sp_udp_open(host: NonNull<c_char>) -> *mut UdpSocket { | |||
|     heap_move_ok(UdpSocket::bind_connect(host)) | ||||
| } | ||||
| 
 | ||||
| /// Creates a new instance of [UdpConnection].
 | ||||
| /// Creates a new instance of [UdpSocket].
 | ||||
| ///
 | ||||
| /// returns: NULL if connection fails, or connected instance
 | ||||
| ///
 | ||||
| /// # Examples
 | ||||
| ///
 | ||||
| /// ```C
 | ||||
| /// UdpConnection connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
 | ||||
| /// UdpSocket connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
 | ||||
| /// if (connection != NULL)
 | ||||
| ///     sp_udp_send_command(connection, sp_command_clear());
 | ||||
| /// ```
 | ||||
|  | @ -47,7 +47,7 @@ pub unsafe extern "C" fn sp_udp_open_ipv4( | |||
|     heap_move_ok(UdpSocket::bind_connect(addr)) | ||||
| } | ||||
| 
 | ||||
| /// Sends a [Packet] to the display using the [UdpConnection].
 | ||||
| /// Sends a [Packet] to the display using the [UdpSocket].
 | ||||
| ///
 | ||||
| /// The passed `packet` gets consumed.
 | ||||
| ///
 | ||||
|  | @ -61,7 +61,7 @@ pub unsafe extern "C" fn sp_udp_send_packet( | |||
|     unsafe { connection.as_ref().send(&Vec::from(packet)) }.is_ok() | ||||
| } | ||||
| 
 | ||||
| /// Sends a [TypedCommand] to the display using the [UdpConnection].
 | ||||
| /// Sends a [TypedCommand] to the display using the [UdpSocket].
 | ||||
| ///
 | ||||
| /// The passed `command` gets consumed.
 | ||||
| ///
 | ||||
|  | @ -81,7 +81,7 @@ pub unsafe extern "C" fn sp_udp_send_command( | |||
|     unsafe { connection.as_ref().send_command(command) }.is_some() | ||||
| } | ||||
| 
 | ||||
| /// Sends a [Header] to the display using the [UdpConnection].
 | ||||
| /// Sends a [Header] to the display using the [UdpSocket].
 | ||||
| ///
 | ||||
| /// returns: true in case of success
 | ||||
| ///
 | ||||
|  | @ -104,7 +104,7 @@ pub unsafe extern "C" fn sp_udp_send_header( | |||
|         .is_ok() | ||||
| } | ||||
| 
 | ||||
| /// Closes and deallocates a [UdpConnection].
 | ||||
| /// Closes and deallocates a [UdpSocket].
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_udp_free(connection: NonNull<UdpSocket>) { | ||||
|     unsafe { heap_drop(connection) } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	
update example