move command to module, first separate types
Some checks failed
Rust / build (pull_request) Failing after 1m20s

This commit is contained in:
Vinzenz Schroeter 2025-06-13 11:47:23 +02:00
parent cee4937270
commit 635fef0244
5 changed files with 47 additions and 22 deletions

23
src/commands/cc_only.rs Normal file
View file

@ -0,0 +1,23 @@
use std::sync::Arc;
macro_rules! command_code_only_command {
($command_struct:ident) => {
#[derive(uniffi::Object)]
pub struct $command_struct;
#[uniffi::export]
impl $command_struct {
#[uniffi::constructor]
pub fn new() -> Arc<Self> {
const _: () =
assert!(size_of::<servicepoint::$command_struct>() == 0);
Arc::new($command_struct)
}
}
};
}
command_code_only_command!(ClearCommand);
command_code_only_command!(HardResetCommand);
command_code_only_command!(BitmapLegacyCommand);
command_code_only_command!(FadeOutCommand);

View file

@ -27,7 +27,7 @@ impl Command {
pub fn brightness(brightness: u8) -> Result<Arc<Self>, ServicePointError> {
servicepoint::Brightness::try_from(brightness)
.map_err(move |value| ServicePointError::InvalidBrightness {
value
value,
})
.map(GlobalBrightnessCommand::from)
.map(servicepoint::TypedCommand::Brightness)
@ -56,8 +56,10 @@ impl Command {
let actual = servicepoint::BitmapCommand {
origin,
bitmap,
compression: servicepoint::CompressionCode::try_from(compression as u16)
.unwrap(),
compression: servicepoint::CompressionCode::try_from(
compression as u16,
)
.unwrap(),
};
Self::internal_new(actual.into())
}
@ -70,7 +72,7 @@ impl Command {
) -> Arc<Self> {
let origin = Origin::new(offset_x as usize, offset_y as usize);
let grid = grid.actual.read().unwrap().clone();
let actual = BrightnessGridCommand {origin, grid};
let actual = BrightnessGridCommand { origin, grid };
Self::internal_new(actual.into())
}
@ -85,14 +87,18 @@ impl Command {
let actual = BitVecCommand {
offset: offset as usize,
bitvec,
compression: servicepoint::CompressionCode::try_from(compression as u16)
compression: servicepoint::CompressionCode::try_from(
compression as u16,
)
.unwrap(),
operation: match operation {
BinaryOperation::Overwrite => servicepoint::BinaryOperation::Overwrite,
BinaryOperation::Overwrite => {
servicepoint::BinaryOperation::Overwrite
}
BinaryOperation::And => servicepoint::BinaryOperation::And,
BinaryOperation::Or => servicepoint::BinaryOperation::Or,
BinaryOperation::Xor => servicepoint::BinaryOperation::Xor,
}
},
};
Self::internal_new(actual.into())
}
@ -105,7 +111,7 @@ impl Command {
) -> Arc<Self> {
let origin = Origin::new(offset_x as usize, offset_y as usize);
let grid = grid.actual.read().unwrap().clone();
let actual = Cp437GridCommand {origin, grid};
let actual = Cp437GridCommand { origin, grid };
Self::internal_new(actual.into())
}
@ -117,7 +123,7 @@ impl Command {
) -> Arc<Self> {
let origin = Origin::new(offset_x as usize, offset_y as usize);
let grid = grid.actual.read().unwrap().clone();
let actual = CharGridCommand {origin, grid};
let actual = CharGridCommand { origin, grid };
Self::internal_new(actual.into())
}

3
src/commands/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod command;
pub mod cc_only;

View file

@ -1,12 +1,6 @@
use std::{
net::UdpSocket,
sync::Arc
};
use crate::{commands::command::Command, errors::ServicePointError};
use servicepoint::UdpSocketExt;
use crate::{
command::Command,
errors::ServicePointError
};
use std::{net::UdpSocket, sync::Arc};
#[derive(uniffi::Object)]
pub struct Connection {
@ -25,10 +19,10 @@ impl Connection {
}
pub fn send(&self, command: Arc<Command>) -> Result<(), ServicePointError> {
self.actual.send_command(command.actual.read().unwrap().clone()).ok_or_else(|| {
ServicePointError::IoError {
self.actual
.send_command(command.actual.read().unwrap().clone())
.ok_or_else(|| ServicePointError::IoError {
error: "send failed".to_string(),
}
})
})
}
}

View file

@ -1,7 +1,6 @@
uniffi::setup_scaffolding!();
mod brightness;
mod command;
mod commands;
mod compression_code;
mod connection;