add Send requirement on traits

This commit is contained in:
Robin Müller 2022-12-21 19:50:31 +01:00
parent f109d59d56
commit 78c54cf617
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
5 changed files with 14 additions and 4 deletions

View File

@ -140,6 +140,8 @@ mod tests {
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket}; use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use std::vec::Vec; use std::vec::Vec;
fn is_send<T: Send>(_: &T) {}
#[derive(Default)] #[derive(Default)]
struct PingReceiver { struct PingReceiver {
pub sent_cmds: VecDeque<Vec<u8>>, pub sent_cmds: VecDeque<Vec<u8>>,
@ -161,8 +163,10 @@ mod tests {
let mut buf = [0; 32]; let mut buf = [0; 32];
let dest_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7777); let dest_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7777);
let ping_receiver = PingReceiver::default(); let ping_receiver = PingReceiver::default();
is_send(&ping_receiver);
let mut udp_tc_server = UdpTcServer::new(dest_addr, 2048, Box::new(ping_receiver)) let mut udp_tc_server = UdpTcServer::new(dest_addr, 2048, Box::new(ping_receiver))
.expect("Creating UDP TMTC server failed"); .expect("Creating UDP TMTC server failed");
is_send(&udp_tc_server);
let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true);
let len = pus_tc let len = pus_tc

View File

@ -99,7 +99,7 @@ use spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch, SpHeader};
/// This trait automatically implements the [downcast_rs::Downcast] to allow a more convenient API /// 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 /// to cast trait objects back to their concrete type after the handler was passed to the
/// distributor. /// distributor.
pub trait CcsdsPacketHandler: Downcast { pub trait CcsdsPacketHandler: Downcast + Send {
type Error; type Error;
fn valid_apids(&self) -> &'static [u16]; fn valid_apids(&self) -> &'static [u16];
@ -199,6 +199,8 @@ pub(crate) mod tests {
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::vec::Vec; use std::vec::Vec;
fn is_send<T: Send>(_: &T) {}
pub fn generate_ping_tc(buf: &mut [u8]) -> &[u8] { pub fn generate_ping_tc(buf: &mut [u8]) -> &[u8] {
let mut sph = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); 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(), unknown_packet_queue: unknown_packet_queue.clone(),
}; };
let mut ccsds_distrib = CcsdsDistributor::new(Box::new(apid_handler)); let mut ccsds_distrib = CcsdsDistributor::new(Box::new(apid_handler));
is_send(&ccsds_distrib);
let mut test_buf: [u8; 32] = [0; 32]; let mut test_buf: [u8; 32] = [0; 32];
let tc_slice = generate_ping_tc(test_buf.as_mut_slice()); let tc_slice = generate_ping_tc(test_buf.as_mut_slice());

View File

@ -48,7 +48,7 @@ impl AddressableId {
/// This trait is implemented by both the [crate::tmtc::pus_distrib::PusDistributor] and the /// 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 /// [crate::tmtc::ccsds_distrib::CcsdsDistributor] which allows to pass the respective packets in
/// raw byte format into them. /// raw byte format into them.
pub trait ReceivesTc: Downcast { pub trait ReceivesTc: Downcast + Send {
type Error; type Error;
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>; fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>;
} }

View File

@ -67,7 +67,7 @@ use spacepackets::ecss::{PusError, PusPacket};
use spacepackets::tc::PusTc; use spacepackets::tc::PusTc;
use spacepackets::SpHeader; use spacepackets::SpHeader;
pub trait PusServiceProvider: Downcast { pub trait PusServiceProvider: Downcast + Send {
type Error; type Error;
fn handle_pus_tc_packet( fn handle_pus_tc_packet(
&mut self, &mut self,
@ -147,6 +147,8 @@ mod tests {
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
fn is_send<T: Send>(_: &T) {}
struct PusHandlerSharedQueue { struct PusHandlerSharedQueue {
pub pus_queue: Arc<Mutex<VecDeque<(u8, u16, Vec<u8>)>>>, pub pus_queue: Arc<Mutex<VecDeque<(u8, u16, Vec<u8>)>>>,
} }
@ -263,7 +265,7 @@ mod tests {
let pus_distrib = PusDistributor { let pus_distrib = PusDistributor {
service_provider: Box::new(pus_handler), service_provider: Box::new(pus_handler),
}; };
is_send(&pus_distrib);
let apid_handler = ApidHandlerShared { let apid_handler = ApidHandlerShared {
pus_distrib, pus_distrib,
handler_base, handler_base,

View File

@ -69,6 +69,7 @@ impl EcssTmSender for EventTmSender {
self.sender.send(addr).map_err(EcssTmError::SendError) self.sender.send(addr).map_err(EcssTmError::SendError)
} }
} }
fn main() { fn main() {
println!("Running OBSW example"); println!("Running OBSW example");
let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]); let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]);