Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Structs for handling several IO handlers #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

OscarFdezS
Copy link
Contributor

No description provided.

Comment on lines 8 to +10
/// Closure for RT simulation on targets with `std`.
/// It sleeps until the next state transition.
/// It is an implementation of the `wait_until` closure for the `Simulator::simulate_rt` method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Closure for RT simulation on targets with `std`.
/// It sleeps until the next state transition.
/// It is an implementation of the `wait_until` closure for the `Simulator::simulate_rt` method.
/// Closure for RT simulation on targets with `std`. It sleeps until the next state transition.
/// It is an implementation of the `wait_until` closure for the `Simulator::simulate_rt` method.


type OutputHandler<T> = Box<dyn FnMut(&T)>;

/// A struct that represents a multiple output handler.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A struct that represents a multiple output handler.
/// A struct that aggregates multiple output handlers.

ohs: Vec<OutputHandler<T>>,
}

/// A struct representing a multiple output handler for a generic type `T`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A struct representing a multiple output handler for a generic type `T`.

Comment on lines +144 to +145
/// * `F` - The function type used to inject events into the model. This function is implementaion-specific and it takes a mutable reference to T and event U as input.
/// * `U` - It is the event type handled by the mpsc channel. It must implement the `Default` trait.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// * `F` - The function type used to inject events into the model. This function is implementaion-specific and it takes a mutable reference to T and event U as input.
/// * `U` - It is the event type handled by the mpsc channel. It must implement the `Default` trait.
/// * `U` - It is the event type handled by the mpsc channel. It must implement the `Default` trait.
/// * `F` - The function type used to inject events into the model.
/// This function is implementation-specific and it takes a mutable reference to T and event U as input.

Comment on lines +146 to +153
///
/// # Fields
/// * `phantom` - A phantom data marker to hold the generic type `T`.
/// * `tx` - The sender side of the mpsc channel used to send events.
/// * `rx` - The receiver side of the mpsc channel used to receive events.
/// * `thread_handles` - A vector holding the handles of the spawned threads.
/// * `window_time` - An optional duration representing the window time for collecting extra events.
/// * `inject_event` - A function used to inject events into the model.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///
/// # Fields
/// * `phantom` - A phantom data marker to hold the generic type `T`.
/// * `tx` - The sender side of the mpsc channel used to send events.
/// * `rx` - The receiver side of the mpsc channel used to receive events.
/// * `thread_handles` - A vector holding the handles of the spawned threads.
/// * `window_time` - An optional duration representing the window time for collecting extra events.
/// * `inject_event` - A function used to inject events into the model.

Comment on lines +158 to +163
phantom: std::marker::PhantomData<T>,
tx: std::sync::mpsc::Sender<U>,
rx: std::sync::mpsc::Receiver<U>,
thread_handles: Vec<std::thread::JoinHandle<()>>,
window_time: Option<Duration>,
inject_event: F,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
phantom: std::marker::PhantomData<T>,
tx: std::sync::mpsc::Sender<U>,
rx: std::sync::mpsc::Receiver<U>,
thread_handles: Vec<std::thread::JoinHandle<()>>,
window_time: Option<Duration>,
inject_event: F,
_phantom: std::marker::PhantomData<T>,
/// The sender side of the mpsc channel used to send events.
tx: std::sync::mpsc::Sender<U>,
/// The receiver side of the mpsc channel used to receive events.
rx: std::sync::mpsc::Receiver<U>,
/// A vector holding the handles of the spawned threads.
thread_handles: Vec<std::thread::JoinHandle<()>>,
/// An optional duration representing the window time for collecting extra events.
window_time: Option<Duration>,
/// A function used to inject events into the model.
inject_event: F,

pub fn new(window_time: Option<Duration>, inject_event: F) -> Self {
let (tx, rx) = mpsc::channel::<U>();
Self {
phantom: std::marker::PhantomData,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
phantom: std::marker::PhantomData,
_phantom: std::marker::PhantomData,

}

/// Internal function to get the event from the receiver within the specified duration
fn _get_event<U: core::default::Default>(rx: &mpsc::Receiver<U>, d: Duration) -> U {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underscore thing in Rust is for unused stuff (or weird embedded functions).

Suggested change
fn _get_event<U: core::default::Default>(rx: &mpsc::Receiver<U>, d: Duration) -> U {
fn get_event<U: core::default::Default>(rx: &mpsc::Receiver<U>, d: Duration) -> U {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants