add SequenceCountProvider blanket impl

This commit is contained in:
Robin Müller 2023-01-03 13:09:14 +01:00
parent a952a8405f
commit c606bfae5a
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 21 additions and 23 deletions

View File

@ -94,7 +94,7 @@ pub use alloc_mod::{
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
}; };
use crate::seq_count::SequenceCountProvider; use crate::seq_count::SequenceCountProviderCore;
#[cfg(all(feature = "crossbeam", feature = "std"))] #[cfg(all(feature = "crossbeam", feature = "std"))]
pub use stdmod::CrossbeamVerifSender; pub use stdmod::CrossbeamVerifSender;
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -340,7 +340,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>> ) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
{ {
@ -371,7 +371,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
let tm = self let tm = self
@ -399,7 +399,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>> ) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
{ {
@ -432,7 +432,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
let tm = self let tm = self
@ -460,7 +460,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<(), EcssTmError<E>> { ) -> Result<(), EcssTmError<E>> {
@ -486,7 +486,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
let tm = self let tm = self
@ -515,7 +515,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
let tm = self let tm = self
@ -544,7 +544,7 @@ impl VerificationReporterCore {
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
let tm = self let tm = self
@ -665,7 +665,7 @@ impl VerificationReporterCore {
mod alloc_mod { mod alloc_mod {
use super::*; use super::*;
use crate::pus::alloc_mod::EcssTmSender; use crate::pus::alloc_mod::EcssTmSender;
use crate::seq_count::SequenceCountProviderClonable; use crate::seq_count::SequenceCountProvider;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec; use alloc::vec;
use alloc::vec::Vec; use alloc::vec::Vec;
@ -673,7 +673,7 @@ mod alloc_mod {
#[derive(Clone)] #[derive(Clone)]
pub struct VerificationReporterCfg { pub struct VerificationReporterCfg {
apid: u16, apid: u16,
seq_counter: Box<dyn SequenceCountProviderClonable<u16> + Send>, seq_counter: Box<dyn SequenceCountProvider<u16> + Send>,
pub step_field_width: usize, pub step_field_width: usize,
pub fail_code_field_width: usize, pub fail_code_field_width: usize,
pub max_fail_data_len: usize, pub max_fail_data_len: usize,
@ -682,7 +682,7 @@ mod alloc_mod {
impl VerificationReporterCfg { impl VerificationReporterCfg {
pub fn new( pub fn new(
apid: u16, apid: u16,
seq_counter: Box<dyn SequenceCountProviderClonable<u16> + Send>, seq_counter: Box<dyn SequenceCountProvider<u16> + Send>,
step_field_width: usize, step_field_width: usize,
fail_code_field_width: usize, fail_code_field_width: usize,
max_fail_data_len: usize, max_fail_data_len: usize,
@ -705,7 +705,7 @@ mod alloc_mod {
#[derive(Clone)] #[derive(Clone)]
pub struct VerificationReporter { pub struct VerificationReporter {
source_data_buf: Vec<u8>, source_data_buf: Vec<u8>,
seq_counter: Box<dyn SequenceCountProviderClonable<u16> + Send + 'static>, seq_counter: Box<dyn SequenceCountProvider<u16> + Send + 'static>,
pub reporter: VerificationReporterCore, pub reporter: VerificationReporterCore,
} }

View File

@ -3,7 +3,8 @@ use dyn_clone::DynClone;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use stdmod::*; pub use stdmod::*;
pub trait SequenceCountProvider<Raw> { /// Core trait for objects which can provide a sequence count.
pub trait SequenceCountProviderCore<Raw> {
fn get(&self) -> Raw; fn get(&self) -> Raw;
fn increment(&mut self); fn increment(&mut self);
fn get_and_increment(&mut self) -> Raw { fn get_and_increment(&mut self) -> Raw {
@ -14,16 +15,18 @@ pub trait SequenceCountProvider<Raw> {
} }
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub trait SequenceCountProviderClonable<Raw>: SequenceCountProvider<Raw> + DynClone {} pub trait SequenceCountProvider<Raw>: SequenceCountProviderCore<Raw> + DynClone {}
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
dyn_clone::clone_trait_object!(SequenceCountProviderClonable<u16>); dyn_clone::clone_trait_object!(SequenceCountProvider<u16>);
#[cfg(feature = "alloc")]
impl<T, Raw> SequenceCountProvider<Raw> for T where T: SequenceCountProviderCore<Raw> + Clone {}
#[derive(Default, Clone)] #[derive(Default, Clone)]
pub struct SimpleSeqCountProvider { pub struct SimpleSeqCountProvider {
seq_count: u16, seq_count: u16,
} }
impl SequenceCountProvider<u16> for SimpleSeqCountProvider { impl SequenceCountProviderCore<u16> for SimpleSeqCountProvider {
fn get(&self) -> u16 { fn get(&self) -> u16 {
self.seq_count self.seq_count
} }
@ -37,9 +40,6 @@ impl SequenceCountProvider<u16> for SimpleSeqCountProvider {
} }
} }
#[cfg(feature = "alloc")]
impl SequenceCountProviderClonable<u16> for SimpleSeqCountProvider {}
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod stdmod { pub mod stdmod {
use super::*; use super::*;
@ -51,7 +51,7 @@ pub mod stdmod {
seq_count: Arc<AtomicU16>, seq_count: Arc<AtomicU16>,
} }
impl SequenceCountProvider<u16> for SyncSeqCountProvider { impl SequenceCountProviderCore<u16> for SyncSeqCountProvider {
fn get(&self) -> u16 { fn get(&self) -> u16 {
self.seq_count.load(Ordering::SeqCst) self.seq_count.load(Ordering::SeqCst)
} }
@ -64,6 +64,4 @@ pub mod stdmod {
self.seq_count.fetch_add(1, Ordering::SeqCst) self.seq_count.fetch_add(1, Ordering::SeqCst)
} }
} }
impl SequenceCountProviderClonable<u16> for SyncSeqCountProvider {}
} }