Skip to content

New Structs for handling several IO handlers#6

Open
OscarFdezS wants to merge 7 commits into
iscar-ucm:mainfrom
OscarFdezS:dev-rt_sim_with_input_handler
Open

New Structs for handling several IO handlers#6
OscarFdezS wants to merge 7 commits into
iscar-ucm:mainfrom
OscarFdezS:dev-rt_sim_with_input_handler

Conversation

@OscarFdezS
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/simulator/std.rs
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
Copy Markdown
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.

Comment thread src/simulator/std.rs

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

/// A struct that represents a multiple output handler.
Copy link
Copy Markdown
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.

Comment thread src/simulator/std.rs
ohs: Vec<OutputHandler<T>>,
}

/// A struct representing a multiple output handler for a generic type `T`.
Copy link
Copy Markdown
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 thread src/simulator/std.rs
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
Copy Markdown
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 thread src/simulator/std.rs
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
Copy Markdown
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 thread src/simulator/std.rs
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
Copy Markdown
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,

Comment thread src/simulator/std.rs
pub fn new(window_time: Option<Duration>, inject_event: F) -> Self {
let (tx, rx) = mpsc::channel::<U>();
Self {
phantom: std::marker::PhantomData,
Copy link
Copy Markdown
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,

Comment thread src/simulator/std.rs
}

/// 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
Copy Markdown
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