various fixes and updates for satrs-core
1. Fix pools integration test to avoid occasional deadlocks 2. tmtc module: The `CcsdsPacketHandler` and `PusServiceProvider` do not require a send bound anymore. However, these traits now have an extension trait called `Sendable<DefaultName>` which requires the trait + Send. A blanket implementation is provided. The helper structs like `PusDistributor` and `CcsdsDistributor` require the new Sendable trait version to allow more ergnomic usage with threads.
This commit is contained in:
@ -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 + Send {
|
||||
pub trait CcsdsPacketHandler: Downcast {
|
||||
type Error;
|
||||
|
||||
fn valid_apids(&self) -> &'static [u16];
|
||||
@ -114,12 +114,21 @@ pub trait CcsdsPacketHandler: Downcast + Send {
|
||||
|
||||
downcast_rs::impl_downcast!(CcsdsPacketHandler assoc Error);
|
||||
|
||||
pub trait SendableCcsdsPacketHandler: CcsdsPacketHandler + Send {}
|
||||
|
||||
impl<T: CcsdsPacketHandler + Send> SendableCcsdsPacketHandler for T {}
|
||||
|
||||
downcast_rs::impl_downcast!(SendableCcsdsPacketHandler assoc Error);
|
||||
|
||||
/// The CCSDS distributor dispatches received CCSDS packets to a user provided packet handler.
|
||||
///
|
||||
/// The passed APID handler is required to be [Send]able to allow more ergonomic usage with
|
||||
/// threads.
|
||||
pub struct CcsdsDistributor<E> {
|
||||
/// User provided APID handler stored as a generic trait object.
|
||||
/// It can be cast back to the original concrete type using the [Self::apid_handler_ref] or
|
||||
/// the [Self::apid_handler_mut] method.
|
||||
pub apid_handler: Box<dyn CcsdsPacketHandler<Error = E>>,
|
||||
pub apid_handler: Box<dyn SendableCcsdsPacketHandler<Error = E>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
@ -155,20 +164,20 @@ impl<E: 'static> ReceivesTcCore for CcsdsDistributor<E> {
|
||||
}
|
||||
|
||||
impl<E: 'static> CcsdsDistributor<E> {
|
||||
pub fn new(apid_handler: Box<dyn CcsdsPacketHandler<Error = E>>) -> Self {
|
||||
pub fn new(apid_handler: Box<dyn SendableCcsdsPacketHandler<Error = E>>) -> Self {
|
||||
CcsdsDistributor { apid_handler }
|
||||
}
|
||||
|
||||
/// This function can be used to retrieve a reference to the concrete instance of the APID
|
||||
/// handler after it was passed to the distributor. See the
|
||||
/// [module documentation][crate::tmtc::ccsds_distrib] for an fsrc-example.
|
||||
pub fn apid_handler_ref<T: CcsdsPacketHandler<Error = E>>(&self) -> Option<&T> {
|
||||
pub fn apid_handler_ref<T: SendableCcsdsPacketHandler<Error = E>>(&self) -> Option<&T> {
|
||||
self.apid_handler.downcast_ref::<T>()
|
||||
}
|
||||
|
||||
/// This function can be used to retrieve a mutable reference to the concrete instance of the
|
||||
/// APID handler after it was passed to the distributor.
|
||||
pub fn apid_handler_mut<T: CcsdsPacketHandler<Error = E>>(&mut self) -> Option<&mut T> {
|
||||
pub fn apid_handler_mut<T: SendableCcsdsPacketHandler<Error = E>>(&mut self) -> Option<&mut T> {
|
||||
self.apid_handler.downcast_mut::<T>()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user