diff --git a/Cargo.lock b/Cargo.lock index 486957e..930a6a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "adler2" @@ -425,9 +425,9 @@ dependencies = [ [[package]] name = "servicepoint" -version = "0.15.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91a33bff7f9db5008748b23ca0c906c276fe00694390b681f004a55968a42cfe" +checksum = "f6bd5cfa49c73aeecb344680ffbf697abf73e0563a441b93b9723ae43867500f" dependencies = [ "bitvec", "bzip2", @@ -441,7 +441,7 @@ dependencies = [ [[package]] name = "servicepoint_binding_uniffi" -version = "0.15.0" +version = "0.13.1" dependencies = [ "servicepoint", "thiserror 2.0.11", diff --git a/Cargo.toml b/Cargo.toml index d6d0c18..c9f07fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "servicepoint_binding_uniffi" -version = "0.15.0" +version = "0.13.1" publish = false edition = "2021" license = "GPL-3.0-or-later" @@ -21,7 +21,7 @@ uniffi = { version = "0.28.3" } thiserror = "2.0" [dependencies.servicepoint] -version = "0.15.0" +version = "0.14.1" features = ["all_compressions"] [package.metadata.docs.rs] diff --git a/flake.lock b/flake.lock index f51971e..9e70e85 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1749494155, - "narHash": "sha256-FG4DEYBpROupu758beabUk9lhrblSf5hnv84v1TLqMc=", + "lastModified": 1739357830, + "narHash": "sha256-9xim3nJJUFbVbJCz48UP4fGRStVW5nv4VdbimbKxJ3I=", "owner": "nixos", "repo": "nixpkgs", - "rev": "88331c17ba434359491e8d5889cce872464052c2", + "rev": "0ff09db9d034a04acd4e8908820ba0b410d7a33a", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-25.05", + "ref": "nixos-24.11", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 60cfbb6..f619fe0 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Flake for the servicepoint library."; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; }; outputs = diff --git a/src/bitmap.rs b/src/bitmap.rs new file mode 100644 index 0000000..f658b85 --- /dev/null +++ b/src/bitmap.rs @@ -0,0 +1,77 @@ +use servicepoint::{DataRef, Grid}; +use std::sync::{Arc, RwLock}; + +#[derive(uniffi::Object)] +pub struct Bitmap { + pub(crate) actual: RwLock, +} + +impl Bitmap { + fn internal_new(actual: servicepoint::Bitmap) -> Arc { + Arc::new(Self { + actual: RwLock::new(actual), + }) + } +} + +#[uniffi::export] +impl Bitmap { + #[uniffi::constructor] + pub fn new(width: u64, height: u64) -> Arc { + Self::internal_new(servicepoint::Bitmap::new( + width as usize, + height as usize, + ).unwrap()) + } + + #[uniffi::constructor] + pub fn new_max_sized() -> Arc { + Self::internal_new(servicepoint::Bitmap::max_sized()) + } + + #[uniffi::constructor] + pub fn load(width: u64, height: u64, data: Vec) -> Arc { + Self::internal_new(servicepoint::Bitmap::load( + width as usize, + height as usize, + &data, + ).unwrap()) + } + + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + + pub fn set(&self, x: u64, y: u64, value: bool) { + self.actual + .write() + .unwrap() + .set(x as usize, y as usize, value) + } + + pub fn get(&self, x: u64, y: u64) -> bool { + self.actual.read().unwrap().get(x as usize, y as usize) + } + + pub fn fill(&self, value: bool) { + self.actual.write().unwrap().fill(value) + } + pub fn width(&self) -> u64 { + self.actual.read().unwrap().width() as u64 + } + + pub fn height(&self) -> u64 { + self.actual.read().unwrap().height() as u64 + } + + pub fn equals(&self, other: &Bitmap) -> bool { + let a = self.actual.read().unwrap(); + let b = other.actual.read().unwrap(); + *a == *b + } + + pub fn copy_raw(&self) -> Vec { + self.actual.read().unwrap().data_ref().to_vec() + } +} diff --git a/src/containers/bitvec.rs b/src/bitvec.rs similarity index 65% rename from src/containers/bitvec.rs rename to src/bitvec.rs index 17df9fd..778b7bc 100644 --- a/src/containers/bitvec.rs +++ b/src/bitvec.rs @@ -1,22 +1,34 @@ -use crate::macros::wrap_uniffi_object; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; -wrap_uniffi_object!(DisplayBitVec, BitVec); +#[derive(uniffi::Object)] +pub struct BitVec { + pub(crate) actual: RwLock, +} + +impl BitVec { + fn internal_new(actual: servicepoint::DisplayBitVec) -> Arc { + Arc::new(Self { + actual: RwLock::new(actual), + }) + } +} #[uniffi::export] impl BitVec { #[uniffi::constructor] pub fn new(size: u64) -> Arc { - Self::internal_new(servicepoint::DisplayBitVec::repeat( - false, - size as usize, - )) + Self::internal_new(servicepoint::DisplayBitVec::repeat(false, size as usize)) } #[uniffi::constructor] pub fn load(data: Vec) -> Arc { Self::internal_new(servicepoint::DisplayBitVec::from_slice(&data)) } + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + pub fn set(&self, index: u64, value: bool) { self.actual.write().unwrap().set(index as usize, value) } diff --git a/src/brightness.rs b/src/brightness.rs deleted file mode 100644 index 0ea4591..0000000 --- a/src/brightness.rs +++ /dev/null @@ -1,19 +0,0 @@ -use crate::UniffiCustomTypeConverter; -use servicepoint::Brightness; - -uniffi::custom_type!(Brightness, u8); - -impl UniffiCustomTypeConverter for Brightness { - type Builtin = u8; - - fn into_custom(val: Self::Builtin) -> uniffi::Result - where - Self: Sized, - { - Ok(Brightness::saturating_from(val)) - } - - fn from_custom(obj: Self) -> Self::Builtin { - obj.into() - } -} diff --git a/src/brightness_grid.rs b/src/brightness_grid.rs new file mode 100644 index 0000000..ba84cb4 --- /dev/null +++ b/src/brightness_grid.rs @@ -0,0 +1,86 @@ +use servicepoint::{Brightness, DataRef, Grid}; +use std::sync::{Arc, RwLock}; + +#[derive(uniffi::Object)] +pub struct BrightnessGrid { + pub(crate) actual: RwLock, +} + +impl BrightnessGrid { + fn internal_new(actual: servicepoint::BrightnessGrid) -> Arc { + Arc::new(Self { + actual: RwLock::new(actual), + }) + } +} + +#[uniffi::export] +impl BrightnessGrid { + #[uniffi::constructor] + pub fn new(width: u64, height: u64) -> Arc { + Self::internal_new(servicepoint::BrightnessGrid::new( + width as usize, + height as usize, + )) + } + + #[uniffi::constructor] + pub fn load(width: u64, height: u64, data: Vec) -> Arc { + Self::internal_new(servicepoint::BrightnessGrid::saturating_load( + width as usize, + height as usize, + &data, + ).unwrap()) + } + + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + + pub fn set(&self, x: u64, y: u64, value: u8) { + self.actual.write().unwrap().set( + x as usize, + y as usize, + Brightness::saturating_from(value), + ) + } + + pub fn get(&self, x: u64, y: u64) -> u8 { + self.actual + .read() + .unwrap() + .get(x as usize, y as usize) + .into() + } + + pub fn fill(&self, value: u8) { + self.actual + .write() + .unwrap() + .fill(Brightness::saturating_from(value)) + } + pub fn width(&self) -> u64 { + self.actual.read().unwrap().width() as u64 + } + + pub fn height(&self) -> u64 { + self.actual.read().unwrap().height() as u64 + } + + pub fn equals(&self, other: &BrightnessGrid) -> bool { + let a = self.actual.read().unwrap(); + let b = other.actual.read().unwrap(); + *a == *b + } + + pub fn copy_raw(&self) -> Vec { + self.actual + .read() + .unwrap() + .data_ref() + .iter() + .map(u8::from) + .collect() + } +} diff --git a/src/containers/char_grid.rs b/src/char_grid.rs similarity index 85% rename from src/containers/char_grid.rs rename to src/char_grid.rs index 4300172..e5d59a8 100644 --- a/src/containers/char_grid.rs +++ b/src/char_grid.rs @@ -1,9 +1,12 @@ -use crate::{containers::cp437_grid::Cp437Grid, macros::*}; +use crate::cp437_grid::Cp437Grid; use servicepoint::{Grid, SetValueSeriesError}; -use std::{convert::Into, sync::Arc}; +use std::convert::Into; +use std::sync::{Arc, RwLock}; -wrap_uniffi_object!(CharGrid); -wrap_width_height!(CharGrid); +#[derive(uniffi::Object)] +pub struct CharGrid { + pub(crate) actual: RwLock, +} #[derive(uniffi::Error, thiserror::Error, Debug)] pub enum CharGridError { @@ -30,6 +33,11 @@ impl CharGrid { Self::internal_new(servicepoint::CharGrid::from(&*data)) } + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + pub fn set( &self, x: u64, @@ -58,6 +66,14 @@ impl CharGrid { Ok(()) } + pub fn width(&self) -> u64 { + self.actual.read().unwrap().width() as u64 + } + + pub fn height(&self) -> u64 { + self.actual.read().unwrap().height() as u64 + } + pub fn equals(&self, other: &CharGrid) -> bool { let a = self.actual.read().unwrap(); let b = other.actual.read().unwrap(); @@ -117,6 +133,12 @@ impl CharGrid { } impl CharGrid { + pub(crate) fn internal_new(actual: servicepoint::CharGrid) -> Arc { + Arc::new(Self { + actual: RwLock::new(actual), + }) + } + fn str_to_char(value: String) -> Result { if value.len() != 1 { return Err(CharGridError::StringNotOneChar { value }); diff --git a/src/commands/command.rs b/src/command.rs similarity index 73% rename from src/commands/command.rs rename to src/command.rs index 9041b33..710aeab 100644 --- a/src/commands/command.rs +++ b/src/command.rs @@ -1,20 +1,23 @@ -use crate::{ - compression_code::CompressionCode, - containers::{ - bitmap::Bitmap, bitvec::BitVec, brightness_grid::BrightnessGrid, - char_grid::CharGrid, cp437_grid::Cp437Grid, - }, - errors::ServicePointError, - macros::wrap_uniffi_object, -}; -use servicepoint::{ - BitVecCommand, BrightnessGridCommand, CharGridCommand, ClearCommand, - Cp437GridCommand, FadeOutCommand, GlobalBrightnessCommand, - HardResetCommand, Origin, -}; +use crate::bitmap::Bitmap; +use crate::bitvec::BitVec; +use crate::brightness_grid::BrightnessGrid; +use crate::char_grid::CharGrid; +use crate::compression_code::CompressionCode; +use crate::cp437_grid::Cp437Grid; +use crate::errors::ServicePointError; +use servicepoint::{BitVecCommand, BrightnessGridCommand, CharGridCommand, ClearCommand, Cp437GridCommand, FadeOutCommand, GlobalBrightnessCommand, HardResetCommand, Origin}; use std::sync::Arc; -wrap_uniffi_object!(TypedCommand, Command); +#[derive(uniffi::Object)] +pub struct Command { + pub(crate) actual: servicepoint::TypedCommand, +} + +impl Command { + fn internal_new(actual: servicepoint::TypedCommand) -> Arc { + Arc::new(Command { actual }) + } +} #[uniffi::export] impl Command { @@ -27,7 +30,7 @@ impl Command { pub fn brightness(brightness: u8) -> Result, ServicePointError> { servicepoint::Brightness::try_from(brightness) .map_err(move |value| ServicePointError::InvalidBrightness { - value, + value }) .map(GlobalBrightnessCommand::from) .map(servicepoint::TypedCommand::Brightness) @@ -56,10 +59,8 @@ 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()) } @@ -72,7 +73,7 @@ impl Command { ) -> Arc { 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()) } @@ -87,18 +88,14 @@ 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()) } @@ -111,7 +108,7 @@ impl Command { ) -> Arc { 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()) } @@ -123,12 +120,17 @@ impl Command { ) -> Arc { 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()) } + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.clone()) + } + pub fn equals(&self, other: &Command) -> bool { - *self.actual.read().unwrap() == *other.actual.read().unwrap() + self.actual == other.actual } } diff --git a/src/commands/cc_only.rs b/src/commands/cc_only.rs deleted file mode 100644 index 634e7d0..0000000 --- a/src/commands/cc_only.rs +++ /dev/null @@ -1,23 +0,0 @@ -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 { - const _: () = - assert!(size_of::() == 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); diff --git a/src/commands/mod.rs b/src/commands/mod.rs deleted file mode 100644 index 4be7e73..0000000 --- a/src/commands/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod command; - -pub mod cc_only; diff --git a/src/connection.rs b/src/connection.rs index 1e6a63b..9b0baea 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -1,6 +1,12 @@ -use crate::{commands::command::Command, errors::ServicePointError}; +use std::{ + net::UdpSocket, + sync::Arc +}; use servicepoint::UdpSocketExt; -use std::{net::UdpSocket, sync::Arc}; +use crate::{ + command::Command, + errors::ServicePointError +}; #[derive(uniffi::Object)] pub struct Connection { @@ -19,10 +25,10 @@ impl Connection { } pub fn send(&self, command: Arc) -> Result<(), ServicePointError> { - self.actual - .send_command(command.actual.read().unwrap().clone()) - .ok_or_else(|| ServicePointError::IoError { + self.actual.send_command(command.actual.clone()).ok_or_else(|| { + ServicePointError::IoError { error: "send failed".to_string(), - }) + } + }) } } diff --git a/src/containers/bitmap.rs b/src/containers/bitmap.rs deleted file mode 100644 index 01b99a4..0000000 --- a/src/containers/bitmap.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::macros::*; -use servicepoint::Grid; -use std::{ops::Deref, sync::Arc}; - -wrap_uniffi_object!(Bitmap); -wrap_width_height!(Bitmap); -wrap_get_set_fill_2d!(Bitmap, bool); - -#[uniffi::export] -impl Bitmap { - #[uniffi::constructor] - pub fn new(width: u64, height: u64) -> Arc { - Self::internal_new( - servicepoint::Bitmap::new(width as usize, height as usize).unwrap(), - ) - } - - #[uniffi::constructor] - pub fn new_max_sized() -> Arc { - Self::internal_new(servicepoint::Bitmap::max_sized()) - } - - #[uniffi::constructor] - pub fn load(width: u64, height: u64, data: Vec) -> Arc { - Self::internal_new( - servicepoint::Bitmap::load(width as usize, height as usize, &data) - .unwrap(), - ) - } - - pub fn equals(&self, other: &Bitmap) -> bool { - let a = self.actual.read().unwrap(); - let b = other.actual.read().unwrap(); - *a == *b - } - - pub fn copy_raw(&self) -> Vec { - self.actual.read().unwrap().deref().into() - } -} diff --git a/src/containers/brightness_grid.rs b/src/containers/brightness_grid.rs deleted file mode 100644 index dcfaa47..0000000 --- a/src/containers/brightness_grid.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::macros::*; -use servicepoint::{Brightness, Grid}; -use std::{ops::Deref, sync::Arc}; - -wrap_uniffi_object!(BrightnessGrid); -wrap_width_height!(BrightnessGrid); -wrap_get_set_fill_2d!(BrightnessGrid, Brightness); - -#[uniffi::export] -impl BrightnessGrid { - #[uniffi::constructor] - pub fn new(width: u64, height: u64) -> Arc { - Self::internal_new(servicepoint::BrightnessGrid::new( - width as usize, - height as usize, - )) - } - - #[uniffi::constructor] - pub fn load(width: u64, height: u64, data: Vec) -> Arc { - Self::internal_new( - servicepoint::BrightnessGrid::saturating_load( - width as usize, - height as usize, - &data, - ) - .unwrap(), - ) - } - - pub fn equals(&self, other: &BrightnessGrid) -> bool { - let a = self.actual.read().unwrap(); - let b = other.actual.read().unwrap(); - *a == *b - } - - pub fn copy_raw(&self) -> Vec { - self.actual.read().unwrap().deref().into() - } -} diff --git a/src/containers/cp437_grid.rs b/src/containers/cp437_grid.rs deleted file mode 100644 index bf42122..0000000 --- a/src/containers/cp437_grid.rs +++ /dev/null @@ -1,46 +0,0 @@ -use crate::{containers::char_grid::CharGrid, macros::*}; -use servicepoint::Grid; -use std::{ops::Deref, sync::Arc}; - -wrap_uniffi_object!(Cp437Grid); -wrap_width_height!(Cp437Grid); -wrap_get_set_fill_2d!(Cp437Grid, u8); - -#[uniffi::export] -impl Cp437Grid { - #[uniffi::constructor] - pub fn new(width: u64, height: u64) -> Arc { - Self::internal_new(servicepoint::Cp437Grid::new( - width as usize, - height as usize, - )) - } - - #[uniffi::constructor] - pub fn load(width: u64, height: u64, data: Vec) -> Arc { - Self::internal_new( - servicepoint::Cp437Grid::load( - width as usize, - height as usize, - &data, - ) - .unwrap(), - ) - } - - pub fn equals(&self, other: &Cp437Grid) -> bool { - let a = self.actual.read().unwrap(); - let b = other.actual.read().unwrap(); - *a == *b - } - - pub fn copy_raw(&self) -> Vec { - self.actual.read().unwrap().deref().into() - } - - pub fn to_utf8(&self) -> Arc { - CharGrid::internal_new(servicepoint::CharGrid::from( - &*self.actual.read().unwrap(), - )) - } -} diff --git a/src/containers/mod.rs b/src/containers/mod.rs deleted file mode 100644 index 7dce8bd..0000000 --- a/src/containers/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod bitmap; -pub mod bitvec; -pub mod brightness_grid; -pub mod char_grid; -pub mod cp437_grid; diff --git a/src/cp437_grid.rs b/src/cp437_grid.rs new file mode 100644 index 0000000..89f9420 --- /dev/null +++ b/src/cp437_grid.rs @@ -0,0 +1,79 @@ +use crate::char_grid::CharGrid; +use servicepoint::{DataRef, Grid}; +use std::sync::{Arc, RwLock}; + +#[derive(uniffi::Object)] +pub struct Cp437Grid { + pub(crate) actual: RwLock, +} + +impl Cp437Grid { + pub(crate) fn internal_new(actual: servicepoint::Cp437Grid) -> Arc { + Arc::new(Self { + actual: RwLock::new(actual), + }) + } +} + +#[uniffi::export] +impl Cp437Grid { + #[uniffi::constructor] + pub fn new(width: u64, height: u64) -> Arc { + Self::internal_new(servicepoint::Cp437Grid::new( + width as usize, + height as usize, + )) + } + + #[uniffi::constructor] + pub fn load(width: u64, height: u64, data: Vec) -> Arc { + Self::internal_new(servicepoint::Cp437Grid::load( + width as usize, + height as usize, + &data, + ).unwrap()) + } + + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + + pub fn set(&self, x: u64, y: u64, value: u8) { + self.actual + .write() + .unwrap() + .set(x as usize, y as usize, value) + } + + pub fn get(&self, x: u64, y: u64) -> u8 { + self.actual.read().unwrap().get(x as usize, y as usize) + } + + pub fn fill(&self, value: u8) { + self.actual.write().unwrap().fill(value) + } + pub fn width(&self) -> u64 { + self.actual.read().unwrap().width() as u64 + } + + pub fn height(&self) -> u64 { + self.actual.read().unwrap().height() as u64 + } + + pub fn equals(&self, other: &Cp437Grid) -> bool { + let a = self.actual.read().unwrap(); + let b = other.actual.read().unwrap(); + *a == *b + } + + pub fn copy_raw(&self) -> Vec { + self.actual.read().unwrap().data_ref().to_vec() + } + + pub fn to_utf8(&self) -> Arc { + CharGrid::internal_new(servicepoint::CharGrid::from( + &*self.actual.read().unwrap(), + )) + } +} diff --git a/src/lib.rs b/src/lib.rs index c7addef..2ecad45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,12 @@ uniffi::setup_scaffolding!(); -mod brightness; -mod commands; +mod bitmap; +mod bitvec; +mod brightness_grid; +mod char_grid; +mod command; mod compression_code; mod connection; mod constants; -mod containers; +mod cp437_grid; mod errors; -mod macros; diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index 799a95f..0000000 --- a/src/macros.rs +++ /dev/null @@ -1,72 +0,0 @@ -macro_rules! wrap_uniffi_object { - ($orig_t:ident, $new_t:ident) => { - #[derive(uniffi::Object)] - pub struct $new_t { - pub(crate) actual: std::sync::RwLock, - } - - impl $new_t { - pub(crate) fn internal_new( - actual: servicepoint::$orig_t, - ) -> Arc { - Arc::new(Self { - actual: std::sync::RwLock::new(actual), - }) - } - } - - #[uniffi::export] - impl $new_t { - #[uniffi::constructor] - pub fn clone(other: &Arc) -> Arc { - Self::internal_new(other.actual.read().unwrap().clone()) - } - } - }; - ($t:ident) => { - wrap_uniffi_object!($t, $t); - }; -} - -pub(crate) use wrap_uniffi_object; - -macro_rules! wrap_width_height { - ($t:ident) => { - #[uniffi::export] - impl $t { - pub fn width(&self) -> u64 { - self.actual.read().unwrap().width() as u64 - } - - pub fn height(&self) -> u64 { - self.actual.read().unwrap().height() as u64 - } - } - }; -} - -pub(crate) use wrap_width_height; - -macro_rules! wrap_get_set_fill_2d { - ($t:ident, $contained:ident) => { - #[uniffi::export] - impl $t { - pub fn set(&self, x: u64, y: u64, value: $contained) { - self.actual - .write() - .unwrap() - .set(x as usize, y as usize, value) - } - - pub fn get(&self, x: u64, y: u64) -> $contained { - self.actual.read().unwrap().get(x as usize, y as usize) - } - - pub fn fill(&self, value: $contained) { - self.actual.write().unwrap().fill(value) - } - } - }; -} - -pub(crate) use wrap_get_set_fill_2d;