change typedef style, add optional logging
Some checks failed
Rust / build-gnu-apt (pull_request) Failing after 1m24s
Rust / build-size-gnu-unstable (pull_request) Failing after 1m28s

This commit is contained in:
Vinzenz Schroeter 2025-05-16 00:33:27 +02:00
parent 0c6efcee56
commit 389ced492c
6 changed files with 286 additions and 163 deletions

View file

@ -457,7 +457,7 @@ typedef struct ValueGrid_u8 ValueGrid_u8;
* ByteSlice empty = {.start: NULL, .length = 0};
* ```
*/
typedef struct {
typedef struct ByteSlice {
/**
* The start address of the memory.
*/
@ -486,7 +486,7 @@ typedef struct {
* }).unwrap()
* ```
*/
typedef ValueGrid_Brightness BrightnessGrid;
typedef struct ValueGrid_Brightness BrightnessGrid;
/**
* A display brightness value, checked for correct value range
@ -532,7 +532,7 @@ typedef uint8_t Brightness;
* connection.send_command(command).unwrap()
* ```
*/
typedef ValueGrid_char CharGrid;
typedef struct ValueGrid_char CharGrid;
/**
* Type alias for documenting the meaning of the u16 in enum values
@ -544,23 +544,23 @@ typedef size_t Offset;
*
* The encoding is currently not enforced.
*/
typedef ValueGrid_u8 Cp437Grid;
typedef struct ValueGrid_u8 Cp437Grid;
/**
* Pointer to one of the available command structs.
*/
typedef union {
typedef union CommandUnion {
uint8_t *null;
BitmapCommand */*notnull*/ bitmap;
BitVecCommand */*notnull*/ bitvec;
BrightnessGridCommand */*notnull*/ brightness_grid;
CharGridCommand */*notnull*/ char_grid;
Cp437GridCommand */*notnull*/ cp437_grid;
GlobalBrightnessCommand */*notnull*/ global_brightness;
ClearCommand */*notnull*/ clear;
BitmapLegacyCommand */*notnull*/ bitmap_legacy;
HardResetCommand */*notnull*/ hard_reset;
FadeOutCommand */*notnull*/ fade_out;
struct BitmapCommand */*notnull*/ bitmap;
struct BitVecCommand */*notnull*/ bitvec;
struct BrightnessGridCommand */*notnull*/ brightness_grid;
struct CharGridCommand */*notnull*/ char_grid;
struct Cp437GridCommand */*notnull*/ cp437_grid;
struct GlobalBrightnessCommand */*notnull*/ global_brightness;
struct ClearCommand */*notnull*/ clear;
struct BitmapLegacyCommand */*notnull*/ bitmap_legacy;
struct HardResetCommand */*notnull*/ hard_reset;
struct FadeOutCommand */*notnull*/ fade_out;
} CommandUnion;
/**
@ -570,7 +570,7 @@ typedef union {
*
* Rust equivalent: [TypedCommand].
*/
typedef struct {
typedef struct Command {
/**
* Specifies which kind of command struct is contained in `data`
*/
@ -578,7 +578,7 @@ typedef struct {
/**
* The pointer to the command struct
*/
CommandUnion data;
union CommandUnion data;
} Command;
/**
@ -591,7 +591,7 @@ typedef struct {
*
* The contained values are in platform endian-ness and may need to be converted before sending.
*/
typedef struct {
typedef struct Header {
/**
* The first two bytes specify which command this packet represents.
*/
@ -627,10 +627,12 @@ typedef struct {
extern "C" {
#endif // __cplusplus
void init_env_logger(void);
/**
* Clones a [Bitmap].
*/
Bitmap */*notnull*/ sp_bitmap_clone(Bitmap */*notnull*/ bitmap);
struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ bitmap);
/**
* Sets the state of all pixels in the [Bitmap].
@ -640,12 +642,12 @@ Bitmap */*notnull*/ sp_bitmap_clone(Bitmap */*notnull*/ bitmap);
* - `bitmap`: instance to write to
* - `value`: the value to set all pixels to
*/
void sp_bitmap_fill(Bitmap */*notnull*/ bitmap, bool value);
void sp_bitmap_fill(struct Bitmap */*notnull*/ bitmap, bool value);
/**
* Deallocates a [Bitmap].
*/
void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
void sp_bitmap_free(struct Bitmap */*notnull*/ bitmap);
/**
* Tries to convert the BitVec to a Bitmap.
@ -654,7 +656,7 @@ void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
*
* Returns NULL in case of error.
*/
Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
/**
* Gets the current value at the specified position in the [Bitmap].
@ -668,7 +670,7 @@ Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
*
* - when accessing `x` or `y` out of bounds
*/
bool sp_bitmap_get(Bitmap */*notnull*/ bitmap, size_t x, size_t y);
bool sp_bitmap_get(struct Bitmap */*notnull*/ bitmap, size_t x, size_t y);
/**
* Gets the height in pixels of the [Bitmap] instance.
@ -677,12 +679,12 @@ bool sp_bitmap_get(Bitmap */*notnull*/ bitmap, size_t x, size_t y);
*
* - `bitmap`: instance to read from
*/
size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
size_t sp_bitmap_height(struct Bitmap */*notnull*/ bitmap);
/**
* Consumes the Bitmap and returns the contained BitVec
*/
BitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
/**
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
@ -691,10 +693,10 @@ BitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
*
* Returns NULL in case of an error.
*/
Packet *sp_bitmap_into_packet(Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
CompressionCode compression);
struct Packet *sp_bitmap_into_packet(struct Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
CompressionCode compression);
/**
* Loads a [Bitmap] with the specified dimensions from the provided data.
@ -706,9 +708,9 @@ Packet *sp_bitmap_into_packet(Bitmap */*notnull*/ bitmap,
*
* returns: [Bitmap] that contains a copy of the provided data, or NULL in case of an error.
*/
Bitmap *sp_bitmap_load(size_t width,
size_t height,
ByteSlice data);
struct Bitmap *sp_bitmap_load(size_t width,
size_t height,
struct ByteSlice data);
/**
* Creates a new [Bitmap] with the specified dimensions.
@ -735,14 +737,14 @@ Bitmap *sp_bitmap_load(size_t width,
* sp_bitmap_free(grid);
* ```
*/
Bitmap *sp_bitmap_new(size_t width, size_t height);
struct Bitmap *sp_bitmap_new(size_t width, size_t height);
/**
* Creates a new [Bitmap] with a size matching the screen.
*
* returns: [Bitmap] initialized to all pixels off.
*/
Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
/**
* Sets the value of the specified position in the [Bitmap].
@ -757,14 +759,17 @@ Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
*
* - when accessing `x` or `y` out of bounds
*/
void sp_bitmap_set(Bitmap */*notnull*/ bitmap, size_t x, size_t y, bool value);
void sp_bitmap_set(struct Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
bool value);
/**
* Gets an unsafe reference to the data of the [Bitmap] instance.
*
* The returned memory is valid for the lifetime of the bitmap.
*/
ByteSlice sp_bitmap_unsafe_data_ref(Bitmap */*notnull*/ bitmap);
struct ByteSlice sp_bitmap_unsafe_data_ref(struct Bitmap */*notnull*/ bitmap);
/**
* Gets the width in pixels of the [Bitmap] instance.
@ -783,7 +788,7 @@ ByteSlice sp_bitmap_unsafe_data_ref(Bitmap */*notnull*/ bitmap);
*
* - `bitmap` points to a valid [Bitmap]
*/
size_t sp_bitmap_width(Bitmap */*notnull*/ bitmap);
size_t sp_bitmap_width(struct Bitmap */*notnull*/ bitmap);
/**
* Clones a [DisplayBitVec].
@ -828,10 +833,10 @@ bool sp_bitvec_get(BitVec */*notnull*/ bit_vec, size_t index);
*
* Returns NULL in case of an error.
*/
Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
struct Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Returns true if length is 0.
@ -856,7 +861,7 @@ size_t sp_bitvec_len(BitVec */*notnull*/ bit_vec);
*
* returns: [DisplayBitVec] instance containing data.
*/
BitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
BitVec */*notnull*/ sp_bitvec_load(struct ByteSlice data);
/**
* Creates a new [DisplayBitVec] instance.
@ -897,7 +902,7 @@ void sp_bitvec_set(BitVec */*notnull*/ bit_vec, size_t index, bool value);
*
* - `bit_vec`: instance to write to
*/
ByteSlice sp_bitvec_unsafe_data_ref(BitVec */*notnull*/ bit_vec);
struct ByteSlice sp_bitvec_unsafe_data_ref(BitVec */*notnull*/ bit_vec);
/**
* Clones a [BrightnessGrid].
@ -955,9 +960,9 @@ size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ brightness_grid);
*
* Returns NULL in case of an error.
*/
Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
size_t x,
size_t y);
struct Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [BrightnessGrid] with the specified dimensions from the provided data.
@ -968,7 +973,7 @@ Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
*/
BrightnessGrid *sp_brightness_grid_load(size_t width,
size_t height,
ByteSlice data);
struct ByteSlice data);
/**
* Creates a new [BrightnessGrid] with the specified dimensions.
@ -1022,7 +1027,7 @@ void sp_brightness_grid_set(BrightnessGrid */*notnull*/ brightness_grid,
*
* returns: slice of bytes underlying the `brightness_grid`.
*/
ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid */*notnull*/ brightness_grid);
struct ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid */*notnull*/ brightness_grid);
/**
* Gets the width of the [BrightnessGrid] instance.
@ -1085,16 +1090,16 @@ size_t sp_char_grid_height(CharGrid */*notnull*/ char_grid);
*
* Returns NULL in case of an error.
*/
Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
size_t x,
size_t y);
struct Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [CharGrid] with the specified dimensions from the provided data.
*
* returns: new CharGrid or NULL in case of an error
*/
CharGrid *sp_char_grid_load(size_t width, size_t height, ByteSlice data);
CharGrid *sp_char_grid_load(size_t width, size_t height, struct ByteSlice data);
/**
* Creates a new [CharGrid] with the specified dimensions.
@ -1146,12 +1151,12 @@ size_t sp_char_grid_width(CharGrid */*notnull*/ char_grid);
*
* returns: a new [BitmapCommand] instance.
*/
BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(BitmapCommand */*notnull*/ command);
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(struct BitmapCommand */*notnull*/ command);
/**
* Deallocates a [BitmapCommand] instance.
*/
void sp_cmd_bitmap_free(BitmapCommand */*notnull*/ command);
void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ command);
/**
* Move the provided [Bitmap] into a new [BitmapCommand],
@ -1159,7 +1164,7 @@ void sp_cmd_bitmap_free(BitmapCommand */*notnull*/ command);
*
* Rust equivalent: `BitmapCommand::from(bitmap)`
*/
BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(Bitmap */*notnull*/ bitmap);
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(struct Bitmap */*notnull*/ bitmap);
/**
* Returns a pointer to the provided `BitmapCommand`.
@ -1169,17 +1174,17 @@ BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(Bitmap */*notnull*/ bitmap)
* - The returned bitmap inherits the lifetime of the command in which it is contained.
* - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command.
*/
Bitmap */*notnull*/ sp_cmd_bitmap_get(BitmapCommand */*notnull*/ command);
struct Bitmap */*notnull*/ sp_cmd_bitmap_get(struct BitmapCommand */*notnull*/ command);
/**
* Reads the compression kind of the [BitmapCommand].
*/
CompressionCode sp_cmd_bitmap_get_compression(BitmapCommand */*notnull*/ command);
CompressionCode sp_cmd_bitmap_get_compression(struct BitmapCommand */*notnull*/ command);
/**
* Reads the origin field of the [BitmapCommand].
*/
void sp_cmd_bitmap_get_origin(BitmapCommand */*notnull*/ command,
void sp_cmd_bitmap_get_origin(struct BitmapCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
@ -1190,27 +1195,27 @@ void sp_cmd_bitmap_get_origin(BitmapCommand */*notnull*/ command,
*
* Returns: a new [BitmapCommand] instance.
*/
BitmapCommand */*notnull*/ sp_cmd_bitmap_new(Bitmap */*notnull*/ bitmap,
size_t origin_x,
size_t origin_y,
CompressionCode compression);
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_new(struct Bitmap */*notnull*/ bitmap,
size_t origin_x,
size_t origin_y,
CompressionCode compression);
/**
* Moves the provided [Bitmap] to be contained in the [BitmapCommand].
*/
void sp_cmd_bitmap_set(BitmapCommand */*notnull*/ command,
Bitmap */*notnull*/ bitmap);
void sp_cmd_bitmap_set(struct BitmapCommand */*notnull*/ command,
struct Bitmap */*notnull*/ bitmap);
/**
* Overwrites the compression kind of the [BitmapCommand].
*/
void sp_cmd_bitmap_set_compression(BitmapCommand */*notnull*/ command,
void sp_cmd_bitmap_set_compression(struct BitmapCommand */*notnull*/ command,
CompressionCode compression);
/**
* Overwrites the origin field of the [BitmapCommand].
*/
void sp_cmd_bitmap_set_origin(BitmapCommand */*notnull*/ command,
void sp_cmd_bitmap_set_origin(struct BitmapCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
@ -1219,39 +1224,39 @@ void sp_cmd_bitmap_set_origin(BitmapCommand */*notnull*/ command,
*
* Returns: NULL or a [Packet] containing the command.
*/
Packet *sp_cmd_bitmap_try_into_packet(BitmapCommand */*notnull*/ command);
struct Packet *sp_cmd_bitmap_try_into_packet(struct BitmapCommand */*notnull*/ command);
/**
* Clones an [BitVecCommand] instance.
*
* returns: a new [BitVecCommand] instance.
*/
BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(BitVecCommand */*notnull*/ command);
struct BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(struct BitVecCommand */*notnull*/ command);
/**
* Deallocates a [BitVecCommand].
*/
void sp_cmd_bitvec_free(BitVecCommand */*notnull*/ command);
void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ command);
/**
* Returns a pointer to the [BitVec] contained in the [BitVecCommand].
*/
BitVec *sp_cmd_bitvec_get(BitVecCommand */*notnull*/ command);
BitVec *sp_cmd_bitvec_get(struct BitVecCommand */*notnull*/ command);
/**
* Reads the compression kind of the [BitVecCommand].
*/
CompressionCode sp_cmd_bitvec_get_compression(BitVecCommand */*notnull*/ command);
CompressionCode sp_cmd_bitvec_get_compression(struct BitVecCommand */*notnull*/ command);
/**
* Reads the offset field of the [BitVecCommand].
*/
Offset sp_cmd_bitvec_get_offset(BitVecCommand */*notnull*/ command);
Offset sp_cmd_bitvec_get_offset(struct BitVecCommand */*notnull*/ command);
/**
* Returns the [BinaryOperation] of the command.
*/
BinaryOperation sp_cmd_bitvec_get_operation(BitVecCommand */*notnull*/ command);
BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ command);
/**
* Set pixel data starting at the pixel offset on screen.
@ -1267,33 +1272,33 @@ BinaryOperation sp_cmd_bitvec_get_operation(BitVecCommand */*notnull*/ command);
*
* The contained [`DisplayBitVec`] is always uncompressed.
*/
BitVecCommand */*notnull*/ sp_cmd_bitvec_new(BitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
struct BitVecCommand */*notnull*/ sp_cmd_bitvec_new(BitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Moves the provided [BitVec] to be contained in the [BitVecCommand].
*/
void sp_cmd_bitvec_set(BitVecCommand */*notnull*/ command,
void sp_cmd_bitvec_set(struct BitVecCommand */*notnull*/ command,
BitVec */*notnull*/ bitvec);
/**
* Overwrites the compression kind of the [BitVecCommand].
*/
void sp_cmd_bitvec_set_compression(BitVecCommand */*notnull*/ command,
void sp_cmd_bitvec_set_compression(struct BitVecCommand */*notnull*/ command,
CompressionCode compression);
/**
* Overwrites the offset field of the [BitVecCommand].
*/
void sp_cmd_bitvec_set_offset(BitVecCommand */*notnull*/ command,
void sp_cmd_bitvec_set_offset(struct BitVecCommand */*notnull*/ command,
Offset offset);
/**
* Overwrites the [BinaryOperation] of the command.
*/
void sp_cmd_bitvec_set_operation(BitVecCommand */*notnull*/ command,
void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ command,
BinaryOperation operation);
/**
@ -1301,32 +1306,32 @@ void sp_cmd_bitvec_set_operation(BitVecCommand */*notnull*/ command,
*
* Returns: NULL or a [Packet] containing the command.
*/
Packet *sp_cmd_bitvec_try_into_packet(BitVecCommand */*notnull*/ command);
struct Packet *sp_cmd_bitvec_try_into_packet(struct BitVecCommand */*notnull*/ command);
/**
* Clones an [GlobalBrightnessCommand] instance.
*
* returns: a new [GlobalBrightnessCommand] instance.
*/
GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(GlobalBrightnessCommand */*notnull*/ command);
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struct GlobalBrightnessCommand */*notnull*/ command);
void sp_cmd_brightness_global_free(BitmapCommand */*notnull*/ command);
void sp_cmd_brightness_global_free(struct BitmapCommand */*notnull*/ command);
Brightness *sp_cmd_brightness_global_get(GlobalBrightnessCommand */*notnull*/ command);
Brightness *sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
Packet */*notnull*/ sp_cmd_brightness_global_into_packet(GlobalBrightnessCommand */*notnull*/ command);
struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
/**
* Set the brightness of all tiles to the same value.
*
* Returns: a new [GlobalBrightnessCommand] instance.
*/
GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness);
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness);
/**
* Moves the provided bitmap to be contained in the command.
*/
void sp_cmd_brightness_global_set(GlobalBrightnessCommand */*notnull*/ command,
void sp_cmd_brightness_global_set(struct GlobalBrightnessCommand */*notnull*/ command,
Brightness brightness);
/**
@ -1334,28 +1339,28 @@ void sp_cmd_brightness_global_set(GlobalBrightnessCommand */*notnull*/ command,
*
* returns: a new [BrightnessGridCommand] instance.
*/
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(BrightnessGridCommand */*notnull*/ command);
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(struct BrightnessGridCommand */*notnull*/ command);
/**
* Deallocates a [BitmapCommand].
*/
void sp_cmd_brightness_grid_free(BitmapCommand */*notnull*/ command);
void sp_cmd_brightness_grid_free(struct BitmapCommand */*notnull*/ command);
/**
* Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
* leaving other fields as their default values.
*/
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_from_grid(BrightnessGrid */*notnull*/ grid);
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_from_grid(BrightnessGrid */*notnull*/ grid);
/**
* Returns a pointer to the [BrightnessGrid] contained in the [BrightnessGridCommand].
*/
BrightnessGrid *sp_cmd_brightness_grid_get(BrightnessGridCommand */*notnull*/ command);
BrightnessGrid *sp_cmd_brightness_grid_get(struct BrightnessGridCommand */*notnull*/ command);
/**
* Overwrites the origin field of the [BrightnessGridCommand].
*/
void sp_cmd_brightness_grid_get_origin(BrightnessGridCommand */*notnull*/ command,
void sp_cmd_brightness_grid_get_origin(struct BrightnessGridCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
@ -1364,7 +1369,7 @@ void sp_cmd_brightness_grid_get_origin(BrightnessGridCommand */*notnull*/ comman
*
* Returns: NULL or a [Packet] containing the command.
*/
Packet *sp_cmd_brightness_grid_into_packet(BrightnessGridCommand */*notnull*/ command);
struct Packet *sp_cmd_brightness_grid_into_packet(struct BrightnessGridCommand */*notnull*/ command);
/**
* Set the brightness of individual tiles in a rectangular area of the display.
@ -1373,20 +1378,20 @@ Packet *sp_cmd_brightness_grid_into_packet(BrightnessGridCommand */*notnull*/ co
*
* Returns: a new [BrightnessGridCommand] instance.
*/
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_new(BrightnessGrid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_new(BrightnessGrid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
/**
* Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
*/
void sp_cmd_brightness_grid_set(BrightnessGridCommand */*notnull*/ command,
void sp_cmd_brightness_grid_set(struct BrightnessGridCommand */*notnull*/ command,
BrightnessGrid */*notnull*/ grid);
/**
* Reads the origin field of the [BrightnessGridCommand].
*/
void sp_cmd_brightness_grid_set_origin(BrightnessGridCommand */*notnull*/ command,
void sp_cmd_brightness_grid_set_origin(struct BrightnessGridCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
@ -1395,28 +1400,28 @@ void sp_cmd_brightness_grid_set_origin(BrightnessGridCommand */*notnull*/ comman
*
* returns: a new [CharGridCommand] instance.
*/
CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(CharGridCommand */*notnull*/ command);
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(struct CharGridCommand */*notnull*/ command);
/**
* Deallocates a [BitmapCommand].
*/
void sp_cmd_char_grid_free(BitmapCommand */*notnull*/ command);
void sp_cmd_char_grid_free(struct BitmapCommand */*notnull*/ command);
/**
* Moves the provided [CharGrid] into a new [CharGridCommand],
* leaving other fields as their default values.
*/
CharGridCommand */*notnull*/ sp_cmd_char_grid_from_grid(CharGrid */*notnull*/ grid);
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_from_grid(CharGrid */*notnull*/ grid);
/**
* Returns a pointer to the [CharGrid] contained in the [CharGridCommand].
*/
CharGrid *sp_cmd_char_grid_get(CharGridCommand */*notnull*/ command);
CharGrid *sp_cmd_char_grid_get(struct CharGridCommand */*notnull*/ command);
/**
* Reads the origin field of the [CharGridCommand].
*/
void sp_cmd_char_grid_get_origin(CharGridCommand */*notnull*/ command,
void sp_cmd_char_grid_get_origin(struct CharGridCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
@ -1427,20 +1432,20 @@ void sp_cmd_char_grid_get_origin(CharGridCommand */*notnull*/ command,
*
* Returns: a new [CharGridCommand] instance.
*/
CharGridCommand */*notnull*/ sp_cmd_char_grid_new(CharGrid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_new(CharGrid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
/**
* Moves the provided [CharGrid] to be contained in the [CharGridCommand].
*/
void sp_cmd_char_grid_set(CharGridCommand */*notnull*/ command,
void sp_cmd_char_grid_set(struct CharGridCommand */*notnull*/ command,
CharGrid */*notnull*/ grid);
/**
* Overwrites the origin field of the [CharGridCommand].
*/
void sp_cmd_char_grid_set_origin(CharGridCommand */*notnull*/ command,
void sp_cmd_char_grid_set_origin(struct CharGridCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
@ -1449,12 +1454,12 @@ void sp_cmd_char_grid_set_origin(CharGridCommand */*notnull*/ command,
*
* Returns: NULL or a [Packet] containing the command.
*/
Packet *sp_cmd_char_grid_try_into_packet(CharGridCommand */*notnull*/ command);
struct Packet *sp_cmd_char_grid_try_into_packet(struct CharGridCommand */*notnull*/ command);
/**
* Deallocates a [ClearCommand].
*/
void sp_cmd_clear_free(ClearCommand */*notnull*/ command);
void sp_cmd_clear_free(struct ClearCommand */*notnull*/ command);
/**
* Set all pixels to the off state.
@ -1463,25 +1468,25 @@ void sp_cmd_clear_free(ClearCommand */*notnull*/ command);
*
* Returns: a new [ClearCommand] instance.
*/
ClearCommand */*notnull*/ sp_cmd_clear_new(void);
struct ClearCommand */*notnull*/ sp_cmd_clear_new(void);
/**
* Clones an [Cp437GridCommand] instance.
*
* returns: a new [Cp437GridCommand] instance.
*/
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(Cp437GridCommand */*notnull*/ command);
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(struct Cp437GridCommand */*notnull*/ command);
/**
* Deallocates a [Cp437GridCommand].
*/
void sp_cmd_cp437_grid_free(BitmapCommand */*notnull*/ command);
void sp_cmd_cp437_grid_free(struct BitmapCommand */*notnull*/ command);
/**
* Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
* leaving other fields as their default values.
*/
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*notnull*/ grid);
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*notnull*/ grid);
/**
* Show text on the screen.
@ -1491,14 +1496,14 @@ Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*notnull*/
*
* [CP-437]: https://en.wikipedia.org/wiki/Code_page_437
*/
Cp437Grid *sp_cmd_cp437_grid_get(Cp437GridCommand */*notnull*/ command);
Cp437Grid *sp_cmd_cp437_grid_get(struct Cp437GridCommand */*notnull*/ command);
/**
* Gets the origin field of the [Cp437GridCommand].
*
* Rust equivalent: `cp437_command.origin`
*/
void sp_cmd_cp437_grid_get_origin(Cp437GridCommand */*notnull*/ command,
void sp_cmd_cp437_grid_get_origin(struct Cp437GridCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
@ -1509,16 +1514,16 @@ void sp_cmd_cp437_grid_get_origin(Cp437GridCommand */*notnull*/ command,
*
* The origin is relative to the top-left of the display.
*/
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_new(Cp437Grid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_new(Cp437Grid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
/**
* Moves the provided bitmap into the provided command.
*
* This drops the previously contained [Cp437Grid].
*/
void sp_cmd_cp437_grid_set(Cp437GridCommand */*notnull*/ command,
void sp_cmd_cp437_grid_set(struct Cp437GridCommand */*notnull*/ command,
Cp437Grid */*notnull*/ grid);
/**
@ -1526,7 +1531,7 @@ void sp_cmd_cp437_grid_set(Cp437GridCommand */*notnull*/ command,
*
* Rust equivalent: `cp437_command.origin = Origin::new(origin_x, origin_y)`
*/
void sp_cmd_cp437_grid_set_origin(Cp437GridCommand */*notnull*/ command,
void sp_cmd_cp437_grid_set_origin(struct Cp437GridCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
@ -1535,26 +1540,26 @@ void sp_cmd_cp437_grid_set_origin(Cp437GridCommand */*notnull*/ command,
*
* Returns: NULL or a [Packet] containing the command.
*/
Packet *sp_cmd_cp437_grid_try_into_packet(Cp437GridCommand */*notnull*/ command);
struct Packet *sp_cmd_cp437_grid_try_into_packet(struct Cp437GridCommand */*notnull*/ command);
/**
* Deallocates a [FadeOutCommand].
*/
void sp_cmd_fade_out_free(ClearCommand */*notnull*/ command);
void sp_cmd_fade_out_free(struct ClearCommand */*notnull*/ command);
/**
* A yet-to-be-tested command.
*
* Returns: a new [FadeOutCommand] instance.
*/
FadeOutCommand */*notnull*/ sp_cmd_fade_out_new(void);
struct FadeOutCommand */*notnull*/ sp_cmd_fade_out_new(void);
/**
* Clones an [SPCommand] instance.
*
* returns: a new [SPCommand] instance.
*/
Command sp_cmd_generic_clone(Command command);
struct Command sp_cmd_generic_clone(struct Command command);
/**
* Deallocates an [SPCommand].
@ -1566,7 +1571,7 @@ Command sp_cmd_generic_clone(Command command);
* sp_command_free(c);
* ```
*/
void sp_cmd_generic_free(Command command);
void sp_cmd_generic_free(struct Command command);
/**
* Tries to turn a [SPCommand] into a [Packet].
@ -1574,7 +1579,7 @@ void sp_cmd_generic_free(Command command);
*
* Returns tag [CommandTag::Invalid] in case of an error.
*/
Packet *sp_cmd_generic_into_packet(Command command);
struct Packet *sp_cmd_generic_into_packet(struct Command command);
/**
* Tries to turn a [Packet] into a [SPCommand].
@ -1583,12 +1588,12 @@ Packet *sp_cmd_generic_into_packet(Command command);
*
* Returns: pointer to new [SPCommand] instance or NULL if parsing failed.
*/
Command *sp_cmd_generic_try_from_packet(Packet */*notnull*/ packet);
struct Command *sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
/**
* Deallocates a [HardResetCommand].
*/
void sp_cmd_hard_reset_free(ClearCommand */*notnull*/ command);
void sp_cmd_hard_reset_free(struct ClearCommand */*notnull*/ command);
/**
* Kills the udp daemon on the display, which usually results in a restart.
@ -1597,7 +1602,7 @@ void sp_cmd_hard_reset_free(ClearCommand */*notnull*/ command);
*
* Returns: a new [HardResetCommand] instance.
*/
HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
struct HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
/**
* Clones a [Cp437Grid].
@ -1651,14 +1656,16 @@ size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ cp437_grid);
*
* Returns NULL in case of an error.
*/
Packet *sp_cp437_grid_into_packet(Cp437Grid */*notnull*/ grid,
size_t x,
size_t y);
struct Packet *sp_cp437_grid_into_packet(Cp437Grid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [Cp437Grid] with the specified dimensions from the provided data.
*/
Cp437Grid *sp_cp437_grid_load(size_t width, size_t height, ByteSlice data);
Cp437Grid *sp_cp437_grid_load(size_t width,
size_t height,
struct ByteSlice data);
/**
* Creates a new [Cp437Grid] with the specified dimensions.
@ -1692,7 +1699,7 @@ void sp_cp437_grid_set(Cp437Grid */*notnull*/ cp437_grid,
*
* The returned memory is valid for the lifetime of the grid.
*/
ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid */*notnull*/ cp437_grid);
struct ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid */*notnull*/ cp437_grid);
/**
* Gets the width of the [Cp437Grid] instance.
@ -1708,26 +1715,27 @@ size_t sp_cp437_grid_width(Cp437Grid */*notnull*/ cp437_grid);
*
* returns: a new [Packet] instance.
*/
Packet */*notnull*/ sp_packet_clone(Packet */*notnull*/ packet);
struct Packet */*notnull*/ sp_packet_clone(struct Packet */*notnull*/ packet);
/**
* Deallocates a [Packet].
*/
void sp_packet_free(Packet */*notnull*/ packet);
void sp_packet_free(struct Packet */*notnull*/ packet);
/**
* Creates a raw [Packet] from parts.
*
* returns: new instance. Will never return null.
*/
Packet */*notnull*/ sp_packet_from_parts(Header header, ByteSlice payload);
struct Packet */*notnull*/ sp_packet_from_parts(struct Header header,
struct ByteSlice payload);
/**
* Returns a pointer to the header field of the provided packet.
*
* The returned header can be changed and will be valid for the lifetime of the packet.
*/
Header */*notnull*/ sp_packet_get_header(Packet */*notnull*/ packet);
struct Header */*notnull*/ sp_packet_get_header(struct Packet */*notnull*/ packet);
/**
* Returns a pointer to the current payload of the provided packet.
@ -1736,7 +1744,7 @@ Header */*notnull*/ sp_packet_get_header(Packet */*notnull*/ packet);
*
* The returned memory can be changed and will be valid until a new payload is set.
*/
ByteSlice sp_packet_get_payload(Packet */*notnull*/ packet);
struct ByteSlice sp_packet_get_payload(struct Packet */*notnull*/ packet);
/**
* Serialize the packet into the provided buffer.
@ -1745,21 +1753,23 @@ ByteSlice sp_packet_get_payload(Packet */*notnull*/ packet);
*
* - if the buffer is not big enough to hold header+payload.
*/
void sp_packet_serialize_to(Packet */*notnull*/ packet, ByteSlice buffer);
void sp_packet_serialize_to(struct Packet */*notnull*/ packet,
struct ByteSlice buffer);
/**
* Sets the payload of the provided packet to the provided data.
*
* This makes previous payload pointers invalid.
*/
void sp_packet_set_payload(Packet */*notnull*/ packet, ByteSlice data);
void sp_packet_set_payload(struct Packet */*notnull*/ packet,
struct ByteSlice data);
/**
* Tries to load a [Packet] from the passed array with the specified length.
*
* returns: NULL in case of an error, pointer to the allocated packet otherwise
*/
Packet *sp_packet_try_load(ByteSlice data);
struct Packet *sp_packet_try_load(struct ByteSlice data);
/**
* Converts u16 into [CommandCode].
@ -1772,7 +1782,7 @@ bool sp_u16_to_command_code(uint16_t code,
/**
* Closes and deallocates a [UdpSocket].
*/
void sp_udp_free(UdpSocket */*notnull*/ connection);
void sp_udp_free(struct UdpSocket */*notnull*/ connection);
/**
* Creates a new instance of [UdpSocket].
@ -1787,7 +1797,7 @@ void sp_udp_free(UdpSocket */*notnull*/ connection);
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
UdpSocket *sp_udp_open(char */*notnull*/ host);
struct UdpSocket *sp_udp_open(char */*notnull*/ host);
/**
* Creates a new instance of [UdpSocket].
@ -1802,11 +1812,11 @@ UdpSocket *sp_udp_open(char */*notnull*/ host);
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
uint8_t ip2,
uint8_t ip3,
uint8_t ip4,
uint16_t port);
struct UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
uint8_t ip2,
uint8_t ip3,
uint8_t ip4,
uint16_t port);
/**
* Sends a [SPCommand] to the display using the [UdpSocket].
@ -1821,7 +1831,8 @@ UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
* sp_udp_send_command(connection, sp_command_brightness(5));
* ```
*/
bool sp_udp_send_command(UdpSocket */*notnull*/ connection, Command command);
bool sp_udp_send_command(struct UdpSocket */*notnull*/ connection,
struct Command command);
/**
* Sends a [Header] to the display using the [UdpSocket].
@ -1834,7 +1845,8 @@ bool sp_udp_send_command(UdpSocket */*notnull*/ connection, Command command);
* sp_udp_send_header(connection, sp_command_brightness(5));
* ```
*/
bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header);
bool sp_udp_send_header(struct UdpSocket */*notnull*/ udp_connection,
struct Header header);
/**
* Sends a [Packet] to the display using the [UdpSocket].
@ -1843,8 +1855,8 @@ bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header);
*
* returns: true in case of success
*/
bool sp_udp_send_packet(UdpSocket */*notnull*/ connection,
Packet */*notnull*/ packet);
bool sp_udp_send_packet(struct UdpSocket */*notnull*/ connection,
struct Packet */*notnull*/ packet);
#ifdef __cplusplus
} // extern "C"