add move fn to dsl, rename SPCommand to GenericCommand, remove DisplayBitVec command

This commit is contained in:
Vinzenz Schroeter 2025-06-23 20:26:07 +02:00
parent e434130784
commit 323ba6128e
13 changed files with 335 additions and 356 deletions

View file

@ -355,7 +355,7 @@ typedef struct Cp437GridCommand Cp437GridCommand;
/**
* This is a type only used by cbindgen to have a type for pointers.
*/
typedef struct BitVec BitVec;
typedef struct DisplayBitVec DisplayBitVec;
/**
* <div class="warning">Untested</div>
@ -578,7 +578,7 @@ typedef union CommandUnion {
*
* Rust equivalent: [TypedCommand].
*/
typedef struct Command {
typedef struct GenericCommand {
/**
* Specifies which kind of command struct is contained in `data`
*/
@ -587,7 +587,7 @@ typedef struct Command {
* The pointer to the command struct
*/
union CommandUnion data;
} Command;
} GenericCommand;
/**
* A raw header.
@ -682,7 +682,8 @@ void sp_bitmap_free(struct Bitmap */*notnull*/ instance);
*
* This function is part of the `bitmap` module.
*/
struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
struct Bitmap *sp_bitmap_from_bitvec(size_t width,
DisplayBitVec */*notnull*/ bitvec);
/**
* Calls method [`servicepoint::Bitmap::get`].
@ -711,11 +712,13 @@ bool sp_bitmap_get(struct Bitmap */*notnull*/ instance, size_t x, size_t y);
size_t sp_bitmap_height(struct Bitmap */*notnull*/ instance);
/**
* Calls method [`servicepoint::Bitmap::into_bitvec`].
*
* Consumes the Bitmap and returns the contained BitVec.
*
* This function is part of the `bitmap` module.
*/
BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
DisplayBitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
/**
* Loads a [Bitmap] with the specified dimensions from the provided data.
@ -793,6 +796,8 @@ void sp_bitmap_set(struct Bitmap */*notnull*/ instance,
bool value);
/**
* Calls method [`servicepoint::Bitmap::try_into_packet`].
*
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
*
* The provided [Bitmap] gets consumed.
@ -906,13 +911,15 @@ void sp_bitmapcommand_set_origin(struct BitmapCommand */*notnull*/ command,
size_t origin_y);
/**
* Calls method [`servicepoint::BitmapCommand::try_into_packet`].
*
*Tries to turn a [`BitmapCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `bitmapcommand` module.
*/
struct Packet *sp_bitmapcommand_try_into_packet(struct BitmapCommand */*notnull*/ command);
struct Packet *sp_bitmapcommand_try_into_packet(struct BitmapCommand */*notnull*/ instance);
/**
*Clones a [`BitVecCommand`] instance.
@ -936,7 +943,7 @@ void sp_bitveccommand_free(struct BitVecCommand */*notnull*/ instance);
*
* This function is part of the `bitveccommand` module.
*/
BitVec */*notnull*/ sp_bitveccommand_get_bitvec_mut(struct BitVecCommand */*notnull*/ instance);
DisplayBitVec */*notnull*/ sp_bitveccommand_get_bitvec_mut(struct BitVecCommand */*notnull*/ instance);
/**
* Gets the value of field `compression` of the [`servicepoint::BitVecCommand`].
@ -975,7 +982,7 @@ BinaryOperation sp_bitveccommand_get_operation(struct BitVecCommand */*notnull*/
*
* This function is part of the `bitveccommand` module.
*/
struct BitVecCommand */*notnull*/ sp_bitveccommand_new(BitVec */*notnull*/ bitvec,
struct BitVecCommand */*notnull*/ sp_bitveccommand_new(DisplayBitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
@ -987,7 +994,7 @@ struct BitVecCommand */*notnull*/ sp_bitveccommand_new(BitVec */*notnull*/ bitve
* This function is part of the `bitveccommand` module.
*/
void sp_bitveccommand_set_bitvec(struct BitVecCommand */*notnull*/ instance,
BitVec */*notnull*/ value);
DisplayBitVec */*notnull*/ value);
/**
* Sets the value of field `compression` of the [`servicepoint::BitVecCommand`].
@ -1014,13 +1021,15 @@ void sp_bitveccommand_set_operation(struct BitVecCommand */*notnull*/ instance,
BinaryOperation value);
/**
* Calls method [`servicepoint::BitVecCommand::try_into_packet`].
*
*Tries to turn a [`BitVecCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `bitveccommand` module.
*/
struct Packet *sp_bitveccommand_try_into_packet(struct BitVecCommand */*notnull*/ command);
struct Packet *sp_bitveccommand_try_into_packet(struct BitVecCommand */*notnull*/ instance);
/**
*Clones a [`BrightnessGrid`] instance.
@ -1147,6 +1156,8 @@ void sp_brightnessgrid_set(BrightnessGrid */*notnull*/ instance,
Brightness value);
/**
* Calls method [`servicepoint::BrightnessGrid::try_into_packet`].
*
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
*
* The provided [BrightnessGrid] gets consumed.
@ -1241,13 +1252,15 @@ void sp_brightnessgridcommand_set_origin(struct BrightnessGridCommand */*notnull
size_t origin_y);
/**
* Calls method [`servicepoint::BrightnessGridCommand::try_into_packet`].
*
*Tries to turn a [`BrightnessGridCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `brightnessgridcommand` module.
*/
struct Packet *sp_brightnessgridcommand_try_into_packet(struct BrightnessGridCommand */*notnull*/ command);
struct Packet *sp_brightnessgridcommand_try_into_packet(struct BrightnessGridCommand */*notnull*/ instance);
/**
*Clones a [`CharGrid`] instance.
@ -1355,6 +1368,8 @@ void sp_chargrid_set(CharGrid */*notnull*/ instance,
uint32_t value);
/**
* Calls method [`servicepoint::CharGrid::try_into_packet`].
*
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
*
* The provided [CharGrid] gets consumed.
@ -1428,13 +1443,15 @@ void sp_chargridcommand_set_origin(struct CharGridCommand */*notnull*/ command,
size_t origin_y);
/**
* Calls method [`servicepoint::CharGridCommand::try_into_packet`].
*
*Tries to turn a [`CharGridCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `chargridcommand` module.
*/
struct Packet *sp_chargridcommand_try_into_packet(struct CharGridCommand */*notnull*/ command);
struct Packet *sp_chargridcommand_try_into_packet(struct CharGridCommand */*notnull*/ instance);
/**
*Clones a [`ClearCommand`] instance.
@ -1462,13 +1479,15 @@ void sp_clearcommand_free(struct ClearCommand */*notnull*/ instance);
struct ClearCommand */*notnull*/ sp_clearcommand_new(void);
/**
* Calls method [`servicepoint::ClearCommand::try_into_packet`].
*
*Tries to turn a [`ClearCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `clearcommand` module.
*/
struct Packet *sp_clearcommand_try_into_packet(struct ClearCommand */*notnull*/ command);
struct Packet *sp_clearcommand_try_into_packet(struct ClearCommand */*notnull*/ instance);
/**
* Moves the provided [CharGrid] into a new [CharGridCommand],
@ -1512,52 +1531,6 @@ struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_new(Cp437Grid */*notnull*/
size_t origin_x,
size_t origin_y);
/**
* Clones an [SPCommand] instance.
*
* returns: a new [SPCommand] instance.
*
* This function is part of the `cmd_generic` module.
*/
struct Command sp_cmd_generic_clone(struct Command command);
/**
* Deallocates an [SPCommand].
*
* Commands with an invalid `tag` do not have to be freed as the `data` pointer should be null.
*
* # Examples
*
* ```C
* SPCommand c = sp_cmd_clear_into_generic(sp_cmd_clear_new());
* sp_command_free(c);
* ```
*
* This function is part of the `cmd_generic` module.
*/
void sp_cmd_generic_free(struct Command command);
/**
* Tries to turn a [SPCommand] into a [Packet].
* The [SPCommand] gets consumed.
*
* Returns tag [CommandTag::Invalid] in case of an error.
*
* This function is part of the `cmd_generic` module.
*/
struct Packet *sp_cmd_generic_into_packet(struct Command command);
/**
* Tries to turn a [Packet] into a [SPCommand].
*
* The packet is dropped in the process.
*
* Returns: pointer to new [SPCommand] instance or NULL if parsing failed.
*
* This function is part of the `cmd_generic` module.
*/
struct Command sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
/**
*Clones a [`Cp437Grid`] instance.
*
@ -1662,6 +1635,8 @@ void sp_cp437grid_set(Cp437Grid */*notnull*/ instance,
uint8_t value);
/**
* Calls method [`servicepoint::Cp437Grid::try_into_packet`].
*
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
*
* The provided [Cp437Grid] gets consumed.
@ -1735,13 +1710,15 @@ void sp_cp437gridcommand_set_origin(struct Cp437GridCommand */*notnull*/ command
size_t origin_y);
/**
* Calls method [`servicepoint::Cp437GridCommand::try_into_packet`].
*
*Tries to turn a [`Cp437GridCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `cp437gridcommand` module.
*/
struct Packet *sp_cp437gridcommand_try_into_packet(struct Cp437GridCommand */*notnull*/ command);
struct Packet *sp_cp437gridcommand_try_into_packet(struct Cp437GridCommand */*notnull*/ instance);
/**
* Calls method [`servicepoint::DisplayBitVec::as_raw_mut_slice`].
@ -1752,14 +1729,14 @@ struct Packet *sp_cp437gridcommand_try_into_packet(struct Cp437GridCommand */*no
*
* This function is part of the `displaybitvec` module.
*/
struct ByteSlice sp_displaybitvec_as_raw_mut_slice(BitVec */*notnull*/ instance);
struct ByteSlice sp_displaybitvec_as_raw_mut_slice(DisplayBitVec */*notnull*/ instance);
/**
*Clones a [`DisplayBitVec`] instance.
*
* This function is part of the `displaybitvec` module.
*/
BitVec */*notnull*/ sp_displaybitvec_clone(BitVec */*notnull*/ instance);
DisplayBitVec */*notnull*/ sp_displaybitvec_clone(DisplayBitVec */*notnull*/ instance);
/**
* Calls method [`servicepoint::DisplayBitVec::fill`].
@ -1772,14 +1749,14 @@ BitVec */*notnull*/ sp_displaybitvec_clone(BitVec */*notnull*/ instance);
*
* This function is part of the `displaybitvec` module.
*/
void sp_displaybitvec_fill(BitVec */*notnull*/ instance, bool value);
void sp_displaybitvec_fill(DisplayBitVec */*notnull*/ instance, bool value);
/**
*Deallocates a [`DisplayBitVec`] instance.
*
* This function is part of the `displaybitvec` module.
*/
void sp_displaybitvec_free(BitVec */*notnull*/ instance);
void sp_displaybitvec_free(DisplayBitVec */*notnull*/ instance);
/**
* Calls method [`servicepoint::DisplayBitVec::get`].
@ -1799,7 +1776,7 @@ void sp_displaybitvec_free(BitVec */*notnull*/ instance);
*
* This function is part of the `displaybitvec` module.
*/
bool sp_displaybitvec_get(BitVec */*notnull*/ instance, size_t index);
bool sp_displaybitvec_get(DisplayBitVec */*notnull*/ instance, size_t index);
/**
* Calls method [`servicepoint::DisplayBitVec::is_empty`].
@ -1808,7 +1785,7 @@ bool sp_displaybitvec_get(BitVec */*notnull*/ instance, size_t index);
*
* This function is part of the `displaybitvec` module.
*/
bool sp_displaybitvec_is_empty(BitVec */*notnull*/ instance);
bool sp_displaybitvec_is_empty(DisplayBitVec */*notnull*/ instance);
/**
* Calls method [`servicepoint::DisplayBitVec::len`].
@ -1817,7 +1794,7 @@ bool sp_displaybitvec_is_empty(BitVec */*notnull*/ instance);
*
* This function is part of the `displaybitvec` module.
*/
size_t sp_displaybitvec_len(BitVec */*notnull*/ instance);
size_t sp_displaybitvec_len(DisplayBitVec */*notnull*/ instance);
/**
* Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
@ -1826,7 +1803,7 @@ size_t sp_displaybitvec_len(BitVec */*notnull*/ instance);
*
* This function is part of the `displaybitvec` module.
*/
BitVec */*notnull*/ sp_displaybitvec_load(struct ByteSlice data);
DisplayBitVec */*notnull*/ sp_displaybitvec_load(struct ByteSlice data);
/**
* Creates a new [DisplayBitVec] instance.
@ -1843,7 +1820,7 @@ BitVec */*notnull*/ sp_displaybitvec_load(struct ByteSlice data);
*
* This function is part of the `displaybitvec` module.
*/
BitVec */*notnull*/ sp_displaybitvec_new(size_t size);
DisplayBitVec */*notnull*/ sp_displaybitvec_new(size_t size);
/**
* Calls method [`servicepoint::DisplayBitVec::set`].
@ -1861,11 +1838,13 @@ BitVec */*notnull*/ sp_displaybitvec_new(size_t size);
*
* This function is part of the `displaybitvec` module.
*/
void sp_displaybitvec_set(BitVec */*notnull*/ instance,
void sp_displaybitvec_set(DisplayBitVec */*notnull*/ instance,
size_t index,
bool value);
/**
* Calls method [`servicepoint::DisplayBitVec::try_into_packet`].
*
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
*
* The provided [DisplayBitVec] gets consumed.
@ -1874,7 +1853,7 @@ void sp_displaybitvec_set(BitVec */*notnull*/ instance,
*
* This function is part of the `displaybitvec` module.
*/
struct Packet *sp_displaybitvec_try_into_packet(BitVec */*notnull*/ bitvec,
struct Packet *sp_displaybitvec_try_into_packet(DisplayBitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
@ -1911,13 +1890,52 @@ void sp_fadeoutcommand_free(struct FadeOutCommand */*notnull*/ instance);
struct FadeOutCommand */*notnull*/ sp_fadeoutcommand_new(void);
/**
* Calls method [`servicepoint::FadeOutCommand::try_into_packet`].
*
*Tries to turn a [`FadeOutCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `fadeoutcommand` module.
*/
struct Packet *sp_fadeoutcommand_try_into_packet(struct FadeOutCommand */*notnull*/ command);
struct Packet *sp_fadeoutcommand_try_into_packet(struct FadeOutCommand */*notnull*/ instance);
/**
*Clones a [`GenericCommand`] instance.
*
* This function is part of the `genericcommand` module.
*/
struct GenericCommand */*notnull*/ sp_genericcommand_clone(struct GenericCommand */*notnull*/ instance);
/**
*Deallocates a [`GenericCommand`] instance.
*
* This function is part of the `genericcommand` module.
*/
void sp_genericcommand_free(struct GenericCommand */*notnull*/ instance);
/**
* Tries to turn a [Packet] into a [GenericCommand].
*
* The packet is dropped in the process.
*
* Returns: pointer to new [GenericCommand] instance or NULL if parsing failed.
*
* This function is part of the `genericcommand` module.
*/
struct GenericCommand */*notnull*/ sp_genericcommand_try_from_packet(struct Packet */*notnull*/ packet);
/**
* Calls method [`servicepoint::GenericCommand::try_into_packet`].
*
* Tries to turn a [GenericCommand] into a [Packet].
* The [GenericCommand] gets consumed.
*
* Returns tag [CommandTag::Invalid] in case of an error.
*
* This function is part of the `genericcommand` module.
*/
struct Packet *sp_genericcommand_try_into_packet(struct GenericCommand */*notnull*/ command);
/**
*Clones a [`GlobalBrightnessCommand`] instance.
@ -1958,13 +1976,15 @@ void sp_globalbrightnesscommand_set_brightness(struct GlobalBrightnessCommand */
Brightness value);
/**
* Calls method [`servicepoint::GlobalBrightnessCommand::try_into_packet`].
*
*Tries to turn a [`GlobalBrightnessCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `globalbrightnesscommand` module.
*/
struct Packet *sp_globalbrightnesscommand_try_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
struct Packet *sp_globalbrightnesscommand_try_into_packet(struct GlobalBrightnessCommand */*notnull*/ instance);
/**
*Clones a [`HardResetCommand`] instance.
@ -1992,13 +2012,15 @@ void sp_hardresetcommand_free(struct HardResetCommand */*notnull*/ instance);
struct HardResetCommand */*notnull*/ sp_hardresetcommand_new(void);
/**
* Calls method [`servicepoint::HardResetCommand::try_into_packet`].
*
*Tries to turn a [`HardResetCommand`] into a [Packet].
*
* Returns: NULL or a [Packet] containing the command.
*
* This function is part of the `hardresetcommand` module.
*/
struct Packet *sp_hardresetcommand_try_into_packet(struct HardResetCommand */*notnull*/ command);
struct Packet *sp_hardresetcommand_try_into_packet(struct HardResetCommand */*notnull*/ instance);
/**
*Clones a [`Packet`] instance.
@ -2147,7 +2169,9 @@ struct UdpSocket *sp_udpsocket_open_ipv4(uint8_t ip1,
uint16_t port);
/**
* Sends a [SPCommand] to the display using the [UdpSocket].
* Calls method [`servicepoint::UdpSocket::send_command`].
*
* Sends a [GenericCommand] to the display using the [UdpSocket].
*
* The passed `command` gets consumed.
*
@ -2162,9 +2186,11 @@ struct UdpSocket *sp_udpsocket_open_ipv4(uint8_t ip1,
* This function is part of the `udpsocket` module.
*/
bool sp_udpsocket_send_command(struct UdpSocket */*notnull*/ connection,
struct Command command);
struct GenericCommand */*notnull*/ command);
/**
* Calls method [`servicepoint::UdpSocket::send_header`].
*
* Sends a [Header] to the display using the [UdpSocket].
*
* returns: true in case of success
@ -2181,6 +2207,8 @@ bool sp_udpsocket_send_header(struct UdpSocket */*notnull*/ udp_connection,
struct Header header);
/**
* Calls method [`servicepoint::UdpSocket::send_packet`].
*
* Sends a [Packet] to the display using the [UdpSocket].
*
* The passed `packet` gets consumed.