update servicepoint library
All checks were successful
Rust / build (pull_request) Successful in 1m59s
All checks were successful
Rust / build (pull_request) Successful in 1m59s
This commit is contained in:
parent
1169d9f1d2
commit
022106e2db
8 changed files with 116 additions and 141 deletions
|
@ -21,7 +21,7 @@ impl Bitmap {
|
|||
Self::internal_new(servicepoint::Bitmap::new(
|
||||
width as usize,
|
||||
height as usize,
|
||||
))
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
@ -35,7 +35,7 @@ impl Bitmap {
|
|||
width as usize,
|
||||
height as usize,
|
||||
&data,
|
||||
))
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
|
|
@ -2,11 +2,11 @@ use std::sync::{Arc, RwLock};
|
|||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct BitVec {
|
||||
pub(crate) actual: RwLock<servicepoint::BitVec>,
|
||||
pub(crate) actual: RwLock<servicepoint::DisplayBitVec>,
|
||||
}
|
||||
|
||||
impl BitVec {
|
||||
fn internal_new(actual: servicepoint::BitVec) -> Arc<Self> {
|
||||
fn internal_new(actual: servicepoint::DisplayBitVec) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
actual: RwLock::new(actual),
|
||||
})
|
||||
|
@ -17,11 +17,11 @@ impl BitVec {
|
|||
impl BitVec {
|
||||
#[uniffi::constructor]
|
||||
pub fn new(size: u64) -> Arc<Self> {
|
||||
Self::internal_new(servicepoint::BitVec::repeat(false, size as usize))
|
||||
Self::internal_new(servicepoint::DisplayBitVec::repeat(false, size as usize))
|
||||
}
|
||||
#[uniffi::constructor]
|
||||
pub fn load(data: Vec<u8>) -> Arc<Self> {
|
||||
Self::internal_new(servicepoint::BitVec::from_slice(&data))
|
||||
Self::internal_new(servicepoint::DisplayBitVec::from_slice(&data))
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
|
|
@ -30,7 +30,7 @@ impl BrightnessGrid {
|
|||
width as usize,
|
||||
height as usize,
|
||||
&data,
|
||||
))
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
|
118
src/command.rs
118
src/command.rs
|
@ -5,16 +5,16 @@ use crate::char_grid::CharGrid;
|
|||
use crate::compression_code::CompressionCode;
|
||||
use crate::cp437_grid::Cp437Grid;
|
||||
use crate::errors::ServicePointError;
|
||||
use servicepoint::Origin;
|
||||
use servicepoint::{BitVecCommand, BrightnessGridCommand, CharGridCommand, ClearCommand, Cp437GridCommand, FadeOutCommand, GlobalBrightnessCommand, HardResetCommand, Origin};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct Command {
|
||||
pub(crate) actual: servicepoint::Command,
|
||||
pub(crate) actual: servicepoint::TypedCommand,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
fn internal_new(actual: servicepoint::Command) -> Arc<Command> {
|
||||
fn internal_new(actual: servicepoint::TypedCommand) -> Arc<Command> {
|
||||
Arc::new(Command { actual })
|
||||
}
|
||||
}
|
||||
|
@ -23,27 +23,28 @@ impl Command {
|
|||
impl Command {
|
||||
#[uniffi::constructor]
|
||||
pub fn clear() -> Arc<Self> {
|
||||
Self::internal_new(servicepoint::Command::Clear)
|
||||
Self::internal_new(ClearCommand.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn brightness(brightness: u8) -> Result<Arc<Self>, ServicePointError> {
|
||||
servicepoint::Brightness::try_from(brightness)
|
||||
.map_err(move |value| ServicePointError::InvalidBrightness {
|
||||
value,
|
||||
value
|
||||
})
|
||||
.map(servicepoint::Command::Brightness)
|
||||
.map(GlobalBrightnessCommand::from)
|
||||
.map(servicepoint::TypedCommand::Brightness)
|
||||
.map(Self::internal_new)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn fade_out() -> Arc<Self> {
|
||||
Self::internal_new(servicepoint::Command::FadeOut)
|
||||
Self::internal_new(FadeOutCommand.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn hard_reset() -> Arc<Self> {
|
||||
Self::internal_new(servicepoint::Command::HardReset)
|
||||
Self::internal_new(HardResetCommand.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
@ -55,13 +56,13 @@ impl Command {
|
|||
) -> Arc<Self> {
|
||||
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
let actual = servicepoint::Command::BitmapLinearWin(
|
||||
let actual = servicepoint::BitmapCommand {
|
||||
origin,
|
||||
bitmap,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
compression: servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
};
|
||||
Self::internal_new(actual.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
@ -72,72 +73,31 @@ 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 = servicepoint::Command::CharBrightness(origin, grid);
|
||||
Self::internal_new(actual)
|
||||
let actual = BrightnessGridCommand {origin, grid};
|
||||
Self::internal_new(actual.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
bitvec: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
operation: BinaryOperation,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
let actual = servicepoint::Command::BitmapLinear(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear_and(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
let actual = servicepoint::Command::BitmapLinearAnd(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear_or(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
let actual = servicepoint::Command::BitmapLinearOr(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn bitmap_linear_xor(
|
||||
offset: u64,
|
||||
bitmap: &Arc<BitVec>,
|
||||
compression: CompressionCode,
|
||||
) -> Arc<Self> {
|
||||
let bitmap = bitmap.actual.read().unwrap().clone();
|
||||
let actual = servicepoint::Command::BitmapLinearXor(
|
||||
offset as usize,
|
||||
bitmap,
|
||||
servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
);
|
||||
Self::internal_new(actual)
|
||||
let bitvec = bitvec.actual.read().unwrap().clone();
|
||||
let actual = BitVecCommand {
|
||||
offset: offset as usize,
|
||||
bitvec,
|
||||
compression: servicepoint::CompressionCode::try_from(compression as u16)
|
||||
.unwrap(),
|
||||
operation: match operation {
|
||||
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())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
@ -148,8 +108,8 @@ 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 = servicepoint::Command::Cp437Data(origin, grid);
|
||||
Self::internal_new(actual)
|
||||
let actual = Cp437GridCommand {origin, grid};
|
||||
Self::internal_new(actual.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
@ -160,8 +120,8 @@ 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 = servicepoint::Command::Utf8Data(origin, grid);
|
||||
Self::internal_new(actual)
|
||||
let actual = CharGridCommand {origin, grid};
|
||||
Self::internal_new(actual.into())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
@ -173,3 +133,11 @@ impl Command {
|
|||
self.actual == other.actual
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(uniffi::Enum)]
|
||||
pub enum BinaryOperation {
|
||||
Overwrite,
|
||||
And,
|
||||
Or,
|
||||
Xor,
|
||||
}
|
||||
|
|
|
@ -1,35 +1,33 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::errors::ServicePointError;
|
||||
use std::{
|
||||
net::UdpSocket,
|
||||
sync::Arc
|
||||
};
|
||||
use servicepoint::UdpSocketExt;
|
||||
use crate::{
|
||||
command::Command,
|
||||
errors::ServicePointError
|
||||
};
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct Connection {
|
||||
actual: servicepoint::Connection,
|
||||
actual: UdpSocket,
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
impl Connection {
|
||||
#[uniffi::constructor]
|
||||
pub fn new(host: String) -> Result<Arc<Self>, ServicePointError> {
|
||||
servicepoint::Connection::open(host)
|
||||
UdpSocket::bind_connect(host)
|
||||
.map(|actual| Arc::new(Connection { actual }))
|
||||
.map_err(|err| ServicePointError::IoError {
|
||||
error: err.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
pub fn new_fake() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
actual: servicepoint::Connection::Fake,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn send(&self, command: Arc<Command>) -> Result<(), ServicePointError> {
|
||||
self.actual.send(command.actual.clone()).map_err(|err| {
|
||||
self.actual.send_command(command.actual.clone()).ok_or_else(|| {
|
||||
ServicePointError::IoError {
|
||||
error: format!("{err:?}"),
|
||||
error: "send failed".to_string(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ impl Cp437Grid {
|
|||
width as usize,
|
||||
height as usize,
|
||||
&data,
|
||||
))
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
#[uniffi::constructor]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue