move command to module, first separate types
This commit is contained in:
		
							parent
							
								
									227db03d23
								
							
						
					
					
						commit
						c29482ac56
					
				
					 5 changed files with 47 additions and 22 deletions
				
			
		
							
								
								
									
										23
									
								
								src/commands/cc_only.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/commands/cc_only.rs
									
										
									
									
									
										Normal 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); | ||||
|  | @ -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
									
								
							
							
						
						
									
										3
									
								
								src/commands/mod.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| pub mod command; | ||||
| 
 | ||||
| pub mod cc_only; | ||||
|  | @ -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(), | ||||
|             } | ||||
|         }) | ||||
|             }) | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| uniffi::setup_scaffolding!(); | ||||
| 
 | ||||
| mod brightness; | ||||
| mod command; | ||||
| mod commands; | ||||
| mod compression_code; | ||||
| mod connection; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter