servicepoint-binding-c/src/commands/mod.rs
2025-06-26 18:59:46 +02:00

91 lines
2.9 KiB
Rust

mod bitmap_command;
mod bitvec_command;
mod brightness_grid_command;
mod cc_only_commands;
mod char_grid_command;
mod cp437_grid_command;
mod generic_command;
mod global_brightness_command;
pub use bitmap_command::*;
pub use bitvec_command::*;
pub use brightness_grid_command::*;
pub use char_grid_command::*;
pub use cp437_grid_command::*;
pub use generic_command::*;
macro_rules! wrap_origin_accessors {
( $object_type:ident ) => {
::paste::paste! {
$crate::macros::wrap_methods!($object_type;
#[doc = " Reads the origin field of the [`" $object_type "`]."]
fn get_origin(
ref command,
origin_x: mut ::core::ptr::NonNull<usize>,
origin_y: mut ::core::ptr::NonNull<usize>
) {
let origin = command.origin;
*origin_x = origin.x;
*origin_y = origin.y;
};
#[doc = " Overwrites the origin field of the [`" $object_type "`]."]
fn set_origin(mut command, origin_x: val usize, origin_y: val usize) {
command.origin = ::servicepoint::Origin::new(origin_x, origin_y);
};
);
}
};
}
macro_rules! derive_command_from {
($command:ident) => {
::paste::paste! {
impl From<::servicepoint::[< $command Command >]> for $crate::commands::GenericCommand {
fn from(command: ::servicepoint::[< $command Command >]) -> Self {
Self {
tag: $crate::commands::CommandTag::$command,
data: $crate::commands::CommandUnion {
[< $command:snake >]: $crate::mem::heap_move_nonnull(command)
},
}
}
}
}
};
}
macro_rules! derive_command_into_packet {
($command_type:ident) => {
::paste::paste! {
$crate::macros::wrap_method!($command_type;
#[doc = "Tries to turn a [`" $command_type "`] into a [Packet]."]
///
/// Returns: NULL or a [Packet] containing the command.
fn try_into_packet(move instance) -> move_ok *mut ::servicepoint::Packet {
instance.try_into()
};
);
}
}
}
macro_rules! wrap_command {
($command:ident, $object_type:ident) => {
$crate::macros::derive_clone!($object_type);
$crate::macros::derive_free!($object_type);
$crate::commands::derive_command_from!($command);
$crate::commands::derive_command_into_packet!($object_type);
};
($command:ident) => {
::paste::paste! {
$crate::commands::wrap_command!($command, [< $command Command >]);
}
};
}
pub(crate) use {
derive_command_from, derive_command_into_packet, wrap_command,
wrap_origin_accessors,
};