export value fields via macro
Some checks failed
Rust / build-gnu-apt (pull_request) Failing after 1m31s
Rust / build-size-gnu-unstable (pull_request) Failing after 42s

This commit is contained in:
Vinzenz Schroeter 2025-06-17 23:56:11 +02:00
parent 8296773779
commit 75e2df41fe
6 changed files with 165 additions and 128 deletions

View file

@ -1,5 +1,5 @@
use crate::{
macros::{wrap_clone, wrap_free},
macros::{wrap_clone, wrap_fields, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin, Packet};
@ -48,6 +48,22 @@ pub unsafe extern "C" fn sp_cmd_bitmap_try_into_packet(
wrap_clone!(sp_cmd_bitmap::BitmapCommand);
wrap_free!(sp_cmd_bitmap::BitmapCommand);
wrap_fields!(
sp_cmd_bitmap::BitmapCommand;
//prop bitmap: NonNull<Bitmap> {
// get() {
// return NonNull::from(bitmap);
// };
// set(value) {
// return unsafe { heap_remove(value) };
// };
//};
prop compression: CompressionCode {
get();
set(value);
};
);
/// Returns a pointer to the provided `BitmapCommand`.
///
/// # Safety
@ -97,22 +113,3 @@ pub unsafe extern "C" fn sp_cmd_bitmap_set_origin(
command.as_mut().origin = Origin::new(origin_x, origin_y);
}
}
/// Overwrites the compression kind of the [BitmapCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitmap_set_compression(
mut command: NonNull<BitmapCommand>,
compression: CompressionCode,
) {
unsafe {
command.as_mut().compression = compression;
}
}
/// Reads the compression kind of the [BitmapCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitmap_get_compression(
command: NonNull<BitmapCommand>,
) -> CompressionCode {
unsafe { command.as_ref().compression }
}

View file

@ -1,5 +1,5 @@
use crate::{
macros::{wrap_clone, wrap_free},
macros::{wrap_clone, wrap_fields, wrap_free},
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
};
use servicepoint::{
@ -48,6 +48,22 @@ pub unsafe extern "C" fn sp_cmd_bitvec_try_into_packet(
wrap_clone!(sp_cmd_bitvec::BitVecCommand);
wrap_free!(sp_cmd_bitvec::BitVecCommand);
wrap_fields!(
sp_cmd_bitvec::BitVecCommand;
prop offset: Offset {
get();
set(value);
};
prop operation: BinaryOperation {
get();
set(value);
};
prop compression: CompressionCode {
get();
set(value);
};
);
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_get(
@ -66,60 +82,3 @@ pub unsafe extern "C" fn sp_cmd_bitvec_set(
command.as_mut().bitvec = heap_remove(bitvec);
}
}
/// Reads the offset field of the [BitVecCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_get_offset(
command: NonNull<BitVecCommand>,
) -> Offset {
unsafe { command.as_ref().offset }
}
/// Overwrites the offset field of the [BitVecCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_set_offset(
mut command: NonNull<BitVecCommand>,
offset: Offset,
) {
unsafe {
command.as_mut().offset = offset;
}
}
/// Returns the [BinaryOperation] of the command.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_get_operation(
command: NonNull<BitVecCommand>,
) -> BinaryOperation {
unsafe { command.as_ref().operation }
}
/// Overwrites the [BinaryOperation] of the command.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_set_operation(
mut command: NonNull<BitVecCommand>,
operation: BinaryOperation,
) {
unsafe {
command.as_mut().operation = operation;
}
}
/// Overwrites the compression kind of the [BitVecCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_set_compression(
mut command: NonNull<BitVecCommand>,
compression: CompressionCode,
) {
unsafe {
command.as_mut().compression = compression;
}
}
/// Reads the compression kind of the [BitVecCommand].
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_bitvec_get_compression(
command: NonNull<BitVecCommand>,
) -> CompressionCode {
unsafe { command.as_ref().compression }
}

View file

@ -1,5 +1,5 @@
use crate::{
macros::{wrap_clone, wrap_free},
macros::{wrap_clone, wrap_fields, wrap_free},
mem::{heap_move_nonnull, heap_remove},
};
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
@ -25,20 +25,10 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_into_packet(
wrap_clone!(sp_cmd_brightness_global::GlobalBrightnessCommand);
wrap_free!(sp_cmd_brightness_global::GlobalBrightnessCommand);
/// Moves the provided bitmap to be contained in the command.
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_brightness_global_set(
mut command: NonNull<GlobalBrightnessCommand>,
brightness: Brightness,
) {
unsafe {
command.as_mut().brightness = brightness;
}
}
#[no_mangle]
pub unsafe extern "C" fn sp_cmd_brightness_global_get(
mut command: NonNull<GlobalBrightnessCommand>,
) -> Brightness {
unsafe { command.as_mut().brightness }
}
wrap_fields!(
sp_cmd_brightness_global::GlobalBrightnessCommand;
prop brightness: Brightness {
get();
set(value);
};
);