Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ypo committed Mar 14, 2024
1 parent d4b122c commit 9a3f16b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 16 deletions.
26 changes: 19 additions & 7 deletions src/receiver/multireceiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl MultiReceiver {
/// Creates a new `MultiReceiver` instance, which allows receiving multiple interlaced FLUTE sessions.
///
/// # Arguments
/// if `None`, all Transport Session are accepted
///
/// * `writer` - Responsible to write object to its final destination.
///
/// * `config` - Configuration of the FLUTE `Receiver`. if `None`, default `Config` will be used
///
/// * `enable_tsi_filtering` - Enable TSI filter mechanism
/// # Example
/// ```
/// // Receive objects from Transport Session 1
Expand Down Expand Up @@ -99,9 +99,9 @@ impl MultiReceiver {
/// Accept a TSI session for a given endpoint and TSI
///
/// # Arguments
/// * `maddendpointr` - Add the TSI filter for this endpoint.
/// * `endpoint` - Add the TSI filter for this endpoint.
///
/// * `param` - tsi The TSI value to filter.
/// * `tsi` - tsi The TSI value to filter.
///
pub fn add_listen_tsi(&mut self, endpoint: UDPEndpoint, tsi: u64) {
if self.enable_tsi_filtering == false {
Expand All @@ -118,7 +118,7 @@ impl MultiReceiver {
/// # Arguments
/// * `endpoint` - remove the TSI filter for this endpoint.
///
/// * `param` - The TSI value to remove the filter for.
/// * `tsi` - The TSI value to remove the filter for.
///
pub fn remove_listen_tsi(&mut self, endpoint: &UDPEndpoint, tsi: u64) {
self.tsifilter.remove(endpoint, tsi);
Expand All @@ -139,12 +139,24 @@ impl MultiReceiver {
self.tsifilter.remove_endpoint_bypass(endpoint);
}

/// Push an ALC/LCT packet to the `Receiver`.
///
/// Push a ALC/LCT packet to the receiver.
/// Returns as error the the packet is not a valid ALC/LCT format
/// This method is used to push an ALC/LCT packet (the payload of a UDP/IP packet)
/// to the `Receiver`.
///
/// # Arguments
/// * `pkt`- Payload of the UDP/IP packet.
///
/// * `endpoint` - The `UDPEndpoint` from where the packet is received.
/// * `pkt` - The payload of the UDP/IP packet.
/// * `now` - The current `SystemTime` to use for time-related operations.
///
/// # Returns
///
/// A `Result` indicating success (`Ok`) or an error (`Err`).
///
/// # Errors
///
/// Returns an error if the packet is not valid or the receiver is in an error state.
///
pub fn push(
&mut self,
Expand Down
76 changes: 67 additions & 9 deletions src/receiver/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,19 @@ pub struct Receiver {
}

impl Receiver {
/// Return a new `Receiver`
///
/// Create a new FLUTE Receiver
/// # Arguments
///
/// * `endpoint` - The `UDPEndpoint` from where the data are received.
/// * `tsi` - The Transport Session Identifier of this FLUTE Session.
/// * `writer` - An `ObjectWriterBuilder` used for writing received objects.
/// * `config` - Configuration for the `Receiver`.
///
/// # Returns
///
/// A new `Receiver` instance.
///
pub fn new(
endpoint: &UDPEndpoint,
tsi: u64,
Expand All @@ -97,9 +108,14 @@ impl Receiver {
}
}

/// Check if the receiver is expired.
///
/// Check is the receiver is expired
/// true -> the receiver should be destroyed to free the resources
/// This method checks whether the receiver is expired and returns `true` if it is.
/// This indicates that the receiver should be destroyed.
///
/// # Returns
///
/// `true` if the receiver is expired, otherwise `false`.
///
pub fn is_expired(&self) -> bool {
if self.config.session_timeout.is_none() {
Expand All @@ -112,22 +128,39 @@ impl Receiver {
.gt(self.config.session_timeout.as_ref().unwrap())
}

/// Get the number of objects being received.
///
/// This method returns the number of objects that are currently being received by the `Receiver`.
///
/// Number of objects that are we are receiving
/// # Returns
///
/// The number of objects being received.
///
pub fn nb_objects(&self) -> usize {
self.objects.len()
}

/// Get the number of objects in error state.
///
/// This method returns the number of objects that are currently in an error state
/// in the `Receiver`.
///
/// Number objects in error state
/// # Returns
///
/// The number of objects in error state.
///
pub fn nb_objects_error(&self) -> usize {
self.objects_error.len()
}

/// Free objects that timed out.
///
/// Free objects after `object_timeout`
/// This method performs cleanup operations on the `Receiver`, freeing objects that
/// have timed out.
///
/// # Arguments
///
/// * `now` - The current `SystemTime` to use for time-related operations.
///
pub fn cleanup(&mut self, now: std::time::SystemTime) {
self.cleanup_objects();
Expand Down Expand Up @@ -187,10 +220,23 @@ impl Receiver {
}
}

/// Push data to the `Receiver`
/// Push an ALC/LCT packet to the `Receiver`.
///
/// This method is used to push data (the payload of a UDP/IP packet) to the `Receiver`.
///
/// # Arguments
/// * `data`- Payload of the UDP/IP packet.
///
/// * `data` - The payload of the UDP/IP packet.
/// * `now` - The current `SystemTime` to use for time-related operations.
///
/// # Returns
///
/// A `Result` indicating success (`Ok`) or an error (`Err`).
///
/// # Errors
///
/// Returns as error if the packet is not a valid
///
pub fn push_data(&mut self, data: &[u8], now: std::time::SystemTime) -> Result<()> {
let alc = alc::parse_alc_pkt(data)?;
if alc.lct.tsi != self.tsi {
Expand All @@ -200,7 +246,19 @@ impl Receiver {
self.push(&alc, now)
}

/// Push ALC/LCT packets to the `Receiver`
/// Push ALC/LCT packets to the `Receiver`.
///
/// This method is used to push ALC/LCT packets to the `Receiver`.
///
/// # Arguments
///
/// * `alc_pkt` - The ALC/LCT packet to push.
/// * `now` - The current `SystemTime` to use for time-related operations.
///
/// # Returns
///
/// A `Result` indicating success (`Ok`) or an error (`Err`).
///
pub fn push(&mut self, alc_pkt: &alc::AlcPkt, now: std::time::SystemTime) -> Result<()> {
debug_assert!(self.tsi == alc_pkt.lct.tsi);
self.last_activity = Instant::now();
Expand Down

0 comments on commit 9a3f16b

Please sign in to comment.