Struct rustfbp::ports::Ports
[−]
[src]
pub struct Ports { /* fields omitted */ }
Represents all the ports of a component
It provides help to send and receive IP, and to create ports.
Methods
impl Ports
[src]
fn new(name: String, sched: Sender<CompMsg>, n_input: Vec<String>, n_input_array: Vec<String>, n_output: Vec<String>, n_output_array: Vec<String>) -> Result<(Self, HashMap<String, IPSender>)>
Create a new Ports
Example
let ports = try!(Ports::new("component".to_string(), sched_sender, vec!["input".to_string()], vec![], vec!["output".to_string()], vec![])); let sender = try!(ports.get_sender("input"));Run
fn get_sender(&self, port_in: &str) -> Result<IPSender>
Get the sender of a input ports
Example
let sender = try!(ports.get_sender("input")); let ip = IP::new(); try!(sender.send(ip));Run
fn get_array_sender(&self, port_name: &str, selection: &str) -> Result<IPSender>
Get the sender of a input array ports
Example
let sender = try!(ports.get_sender("inputs", "1")); let ip = IP::new(); try!(sender.send(ip));Run
fn get_input_selections(&self, port_in: &'static str) -> Result<Vec<String>>
Get the list of the current selections in a array input port
Example
let vec = try!(ports.get_input_selections("inputs")); assert_eq!(vec.length(), 0); try!(ports.add_input_selection("inputs", "1")); try!(ports.add_input_selection("inputs", "2")); let vec = try!(ports.get_input_selections("inputs")); for i in vec { print!("{} ", i); } // Produce `1 2`Run
fn get_output_selections(&self, port_out: &'static str) -> Result<Vec<String>>
Get the list of the current selections in a array output port
Example
let vec = try!(ports.get_output_selections("outputs")); assert_eq!(vec.length(), 0); try!(ports.add_output_selection("outputs", "1")); try!(ports.add_output_selection("outputs", "2")); let vec = try!(ports.get_output_selections("outputs")); for i in vec { print!("{} ", i); } // Produce `1 2`Run
fn recv(&self, port_in: &str) -> Result<IP>
Receive an IP from an input ports
Example
let ip = try!(ports.recv("input")); println!("{}", ip.action);Run
fn try_recv(&self, port_in: &str) -> Result<IP>
Try to receive an IP from an input ports
Example
while let Ok(ip) = ports.try_recv("input") { println!("{}", ip.action); }Run
fn recv_array(&self, port_in: &str, selection_in: &str) -> Result<IP>
Receive an IP from an array input ports
Example
let ip = try!(ports.recv_array("inputs", "1")); println!("{}", ip.action);Run
fn try_recv_array(&self, port_in: &str, selection_in: &str) -> Result<IP>
Try to receive an IP from an array input ports
Example
while let Ok(ip) = ports.try_recv_array("input", "1") { println!("{}", ip.action); }Run
fn send(&self, port_out: &str, ip: IP) -> Result<()>
Send an IP outside, through the output port port_out
Example
let ip = IP::new(); try!(ports.send("output", ip));Run
fn send_array(&self, port_out: &str, selection_out: &str, ip: IP) -> Result<()>
Send an IP outside, through the array output port port_out
with the selection selection_out
Example
let ip = IP::new(); try!(ports.send_array("output", "1", ip));Run
fn send_action(&self, port_out: &'static str, ip: IP) -> Result<()>
Send an IP outside, depending of the action
The component must have a simple output port and an array output port with the same name (IE: output). If the array output port had a selection corresponding to the IP action, the IP will be send on it. Otherwise, the IP is send on the simple output port.
Example
try!(ports.add_output_selection("output", "1")); let mut ip = IP::new(); ip.action = "2".to_string(); try!(send_action("output", ip)); // Send on the simple output port "output" let mut ip = IP::new(); ip.action = "1".to_string(); try!(send_action("output", ip)); // Send on the array output port "output", selection "1"Run
fn connect(&mut self, port_out: String, sender: IPSender) -> Result<()>
Connect an simple output port with the IPSender
try!(ports.connect("output", sender));Run
fn connect_array(&mut self, port_out: String, selection_out: String, sender: IPSender) -> Result<()>
Connect an array output port with the IPSender
try!(ports.connect_array("output", "1", sender));Run
fn disconnect(&mut self, port_out: String) -> Result<Option<IPSender>>
Disconnect and retrieve the IPSender of an simple output port
let sender = try!(ports.disconnect("output"));Run
fn disconnect_array(&mut self, port_out: String, selection_out: String) -> Result<Option<IPSender>>
Disconnect and retrieve the IPSender of an array output port
let sender = try!(ports.disconnect_array("outputs", "1"));Run
fn set_receiver(&mut self, port: String, recv: Receiver<IP>)
Change the receiver of a simple output ports
usefull if you want to swap a component, but keep the existing connection
ports.set_receiver("input", receiver);Run
fn remove_receiver(&mut self, port: &str) -> Result<Receiver<IP>>
Get the receiver of a simple output ports
usefull if you want to swap a component, but keep the existing connection
let receiver = try!(ports.remove_receiver("input"));Run
fn remove_array_receiver(&mut self, port_name: &str, selection: &str) -> Result<Receiver<IP>>
Get the receiver of a array output ports
usefull if you want to swap a component, but keep the existing connection
let receiver = try!(ports.remove_array_receiver("inputs", "1"));Run
fn add_input_selection(&mut self, port_in: &str, selection_in: String) -> Result<IPSender>
Add a selection in an input array port, and retrieve the corresponding IPSender
let sender = try!(ports.add_input_selection("inputs", "1"));Run
fn add_input_receiver(&mut self, port_in: &str, selection_in: String, r: Receiver<IP>) -> Result<()>
Change the receiver of an array output ports
usefull if you want to swap a component, but keep the existing connection
ports.add_input_receiver("input", receiver);Run
fn add_output_selection(&mut self, port_out: &str, selection_out: String) -> Result<()>
Add a selection in an input array port
This selection will be able to be connected to another component
try!(ports.add_output_selection("inputs", "1"));Run