-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
New Structs for handling several IO handlers #6
Conversation
New no_std version
…carFdezS/xdevs_no_std.rs into dev-rt_sim_with_input_handler
/// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// A struct representing a multiple output handler for a generic type `T`. |
/// * `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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// * `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. |
/// | ||
/// # 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// | |
/// # 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. |
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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).
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 { |
No description provided.