From c5ed966070c5a871911b942baf2d4df3e80a3d15 Mon Sep 17 00:00:00 2001 From: Baud Date: Sat, 16 Mar 2024 17:59:12 +0000 Subject: [PATCH] fix: Panic more! --- .../src/commands/command_base.rs | 4 +- atem-test/src/main.rs | 44 +++++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/atem-connection-rs/src/commands/command_base.rs b/atem-connection-rs/src/commands/command_base.rs index edcfc38..6296c95 100644 --- a/atem-connection-rs/src/commands/command_base.rs +++ b/atem-connection-rs/src/commands/command_base.rs @@ -11,7 +11,7 @@ pub trait CommandDeserializer: Send + Sync { fn deserialize(&self, buffer: &[u8]) -> Arc; } -pub trait SerializableCommand { +pub trait SerializableCommand: Send + Sync { fn payload(&self, version: &ProtocolVersion) -> Vec; } @@ -27,7 +27,7 @@ impl SerializableCommand for &'_ Box { } } -pub trait BasicWritableCommand: SerializableCommand { +pub trait BasicWritableCommand: SerializableCommand + Send + Sync { fn get_raw_name(&self) -> &'static str; fn get_minimum_version(&self) -> ProtocolVersion; } diff --git a/atem-test/src/main.rs b/atem-test/src/main.rs index 0c1e1d2..6233de9 100644 --- a/atem-test/src/main.rs +++ b/atem-test/src/main.rs @@ -13,7 +13,7 @@ use atem_connection_rs::{ use clap::Parser; use color_eyre::Report; -use tokio::time::sleep; +use tokio::{select, time::sleep}; use tokio_util::sync::CancellationToken; /// ATEM Rust Library Test App @@ -38,29 +38,35 @@ async fn main() { let cancel_task = cancel.clone(); let mut atem_socket = AtemSocket::new(atem_event_tx); - tokio::spawn(async move { - atem_socket.run(socket_message_rx, cancel_task).await; - }); + let atem_socket_run = atem_socket.run(socket_message_rx, cancel_task); let atem = Arc::new(Atem::new(socket_message_tx)); let atem_thread = atem.clone(); - tokio::spawn(async move { - atem_thread.run(atem_event_rx, cancel).await; + let atem_run = atem_thread.run(atem_event_rx, cancel); + + let switch_loop = tokio::spawn(async move { + let address = Ipv4Addr::from_str(&args.ip).unwrap(); + let socket = SocketAddrV4::new(address, 9910); + atem.connect(socket.into()).await; + + loop { + sleep(Duration::from_millis(5000)).await; + log::info!("Switch to source 1"); + atem.send_commands(vec![Box::new(ProgramInput::new(0, 1))]) + .await; + log::info!("Switched to source 1"); + sleep(Duration::from_millis(5000)).await; + log::info!("Switch to source 2"); + atem.send_commands(vec![Box::new(ProgramInput::new(0, 2))]) + .await; + log::info!("Switched to source 2"); + } }); - let address = Ipv4Addr::from_str(&args.ip).unwrap(); - let socket = SocketAddrV4::new(address, 9910); - atem.connect(socket.into()).await; - - loop { - sleep(Duration::from_millis(5000)).await; - log::info!("Switch to source 1"); - atem.send_commands(vec![Box::new(ProgramInput::new(0, 1))]) - .await; - sleep(Duration::from_millis(5000)).await; - log::info!("Switch to source 2"); - atem.send_commands(vec![Box::new(ProgramInput::new(0, 2))]) - .await; + select! { + _ = atem_socket_run => {}, + _ = atem_run => {}, + _ = switch_loop => {} } }