From 78c54cf617443d828f7d5126a1f2f064b0769137 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 21 Dec 2022 19:50:31 +0100 Subject: [PATCH] add Send requirement on traits --- satrs-core/src/hal/host/udp_server.rs | 4 ++++ satrs-core/src/tmtc/ccsds_distrib.rs | 5 ++++- satrs-core/src/tmtc/mod.rs | 2 +- satrs-core/src/tmtc/pus_distrib.rs | 6 ++++-- satrs-example/src/main.rs | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/satrs-core/src/hal/host/udp_server.rs b/satrs-core/src/hal/host/udp_server.rs index 97acb64..84a40b7 100644 --- a/satrs-core/src/hal/host/udp_server.rs +++ b/satrs-core/src/hal/host/udp_server.rs @@ -140,6 +140,8 @@ mod tests { use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket}; use std::vec::Vec; + fn is_send(_: &T) {} + #[derive(Default)] struct PingReceiver { pub sent_cmds: VecDeque>, @@ -161,8 +163,10 @@ mod tests { let mut buf = [0; 32]; let dest_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7777); let ping_receiver = PingReceiver::default(); + is_send(&ping_receiver); let mut udp_tc_server = UdpTcServer::new(dest_addr, 2048, Box::new(ping_receiver)) .expect("Creating UDP TMTC server failed"); + is_send(&udp_tc_server); let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap(); let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); let len = pus_tc diff --git a/satrs-core/src/tmtc/ccsds_distrib.rs b/satrs-core/src/tmtc/ccsds_distrib.rs index 8934a90..6ff51a5 100644 --- a/satrs-core/src/tmtc/ccsds_distrib.rs +++ b/satrs-core/src/tmtc/ccsds_distrib.rs @@ -99,7 +99,7 @@ use spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch, SpHeader}; /// This trait automatically implements the [downcast_rs::Downcast] to allow a more convenient API /// to cast trait objects back to their concrete type after the handler was passed to the /// distributor. -pub trait CcsdsPacketHandler: Downcast { +pub trait CcsdsPacketHandler: Downcast + Send { type Error; fn valid_apids(&self) -> &'static [u16]; @@ -199,6 +199,8 @@ pub(crate) mod tests { use std::sync::{Arc, Mutex}; use std::vec::Vec; + fn is_send(_: &T) {} + pub fn generate_ping_tc(buf: &mut [u8]) -> &[u8] { let mut sph = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap(); let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); @@ -292,6 +294,7 @@ pub(crate) mod tests { unknown_packet_queue: unknown_packet_queue.clone(), }; let mut ccsds_distrib = CcsdsDistributor::new(Box::new(apid_handler)); + is_send(&ccsds_distrib); let mut test_buf: [u8; 32] = [0; 32]; let tc_slice = generate_ping_tc(test_buf.as_mut_slice()); diff --git a/satrs-core/src/tmtc/mod.rs b/satrs-core/src/tmtc/mod.rs index 0a31362..6d67887 100644 --- a/satrs-core/src/tmtc/mod.rs +++ b/satrs-core/src/tmtc/mod.rs @@ -48,7 +48,7 @@ impl AddressableId { /// This trait is implemented by both the [crate::tmtc::pus_distrib::PusDistributor] and the /// [crate::tmtc::ccsds_distrib::CcsdsDistributor] which allows to pass the respective packets in /// raw byte format into them. -pub trait ReceivesTc: Downcast { +pub trait ReceivesTc: Downcast + Send { type Error; fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>; } diff --git a/satrs-core/src/tmtc/pus_distrib.rs b/satrs-core/src/tmtc/pus_distrib.rs index 206be08..ee13bb4 100644 --- a/satrs-core/src/tmtc/pus_distrib.rs +++ b/satrs-core/src/tmtc/pus_distrib.rs @@ -67,7 +67,7 @@ use spacepackets::ecss::{PusError, PusPacket}; use spacepackets::tc::PusTc; use spacepackets::SpHeader; -pub trait PusServiceProvider: Downcast { +pub trait PusServiceProvider: Downcast + Send { type Error; fn handle_pus_tc_packet( &mut self, @@ -147,6 +147,8 @@ mod tests { #[cfg(feature = "std")] use std::sync::{Arc, Mutex}; + fn is_send(_: &T) {} + struct PusHandlerSharedQueue { pub pus_queue: Arc)>>>, } @@ -263,7 +265,7 @@ mod tests { let pus_distrib = PusDistributor { service_provider: Box::new(pus_handler), }; - + is_send(&pus_distrib); let apid_handler = ApidHandlerShared { pus_distrib, handler_base, diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index f929798..fe7e88e 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -69,6 +69,7 @@ impl EcssTmSender for EventTmSender { self.sender.send(addr).map_err(EcssTmError::SendError) } } + fn main() { println!("Running OBSW example"); let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]);