fix: Panic more!

This commit is contained in:
Baud 2024-03-16 17:59:12 +00:00
parent 7e973af192
commit c5ed966070
2 changed files with 27 additions and 21 deletions

View File

@ -11,7 +11,7 @@ pub trait CommandDeserializer: Send + Sync {
fn deserialize(&self, buffer: &[u8]) -> Arc<dyn DeserializedCommand>;
}
pub trait SerializableCommand {
pub trait SerializableCommand: Send + Sync {
fn payload(&self, version: &ProtocolVersion) -> Vec<u8>;
}
@ -27,7 +27,7 @@ impl<C: SerializableCommand + ?Sized> SerializableCommand for &'_ Box<C> {
}
}
pub trait BasicWritableCommand: SerializableCommand {
pub trait BasicWritableCommand: SerializableCommand + Send + Sync {
fn get_raw_name(&self) -> &'static str;
fn get_minimum_version(&self) -> ProtocolVersion;
}

View File

@ -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 => {}
}
}