Changeset - 778c3919cdac
[Not reviewed]
0 1 0
Christopher Esterhuyse - 5 years ago 2020-02-19 17:05:11
christopheresterhuyse@gmail.com
more
1 file changed with 25 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/runtime/experimental/api.rs
Show inline comments
 
@@ -103,23 +103,30 @@ impl Binds<OutPort> for Connecting {
 
        self.bindings.push((coupling, Polarity::Out, addr).into());
 
        let pid: u32 = (self.bindings.len() - 1).try_into().expect("Port ID overflow!");
 
        OutPort(Port(pid))
 
    }
 
}
 
impl Connecting {
 
    pub fn connect(&mut self, timeout: Option<Duration>) -> Result<Connected, ()> {
 
    pub fn connect(&mut self, _timeout: Option<Duration>) -> Result<Connected, ()> {
 
        let controller_id = 42;
 
        let channel_index_stream = ChannelIndexStream::default();
 
        // drain self if successful
 
        todo!()
 
        let native_ports = (0..self.bindings.len()).map(|x| Port(x as u32)).collect();
 
        self.bindings.clear();
 
        Ok(Connected {
 
            controller_id,
 
            channel_index_stream,
 
            components: vec![],
 
            endpoint_exts: vec![],
 
            native_ports,
 
        })
 
    }
 
}
 
pub struct Protocol;
 
impl Protocol {
 
    pub fn parse(_pdl_text: &[u8]) -> Result<Self, ()> {
 
        todo!()
 
        Ok(Protocol)
 
    }
 
}
 
struct ComponentExt {
 
    protocol: Arc<Protocol>,
 
    ports: HashSet<Port>,
 
    name: Vec<u8>,
 
@@ -131,16 +138,14 @@ pub struct Connected {
 
    endpoint_exts: Vec<EndpointExt>, // invaraint
 
    components: Vec<ComponentExt>,
 
}
 
impl Connected {
 
    pub fn new_channel(&mut self) -> (OutPort, InPort) {
 
        assert!(self.endpoint_exts.len() <= std::u32::MAX as usize - 2);
 
        let ports = (
 
            OutPort(Port(self.endpoint_exts.len() as u32 - 1)),
 
            InPort(Port(self.endpoint_exts.len() as u32)),
 
        );
 
        let ports =
 
            [Port(self.endpoint_exts.len() as u32 - 1), Port(self.endpoint_exts.len() as u32)];
 
        let channel_id = ChannelId {
 
            controller_id: self.controller_id,
 
            channel_index: self.channel_index_stream.next(),
 
        };
 
        let [e0, e1] = Endpoint::new_memory_pair();
 
        self.endpoint_exts.push(EndpointExt {
 
@@ -148,13 +153,16 @@ impl Connected {
 
            endpoint: e0,
 
        });
 
        self.endpoint_exts.push(EndpointExt {
 
            info: EndpointInfo { channel_id, polarity: Getter },
 
            endpoint: e1,
 
        });
 
        ports
 
        for p in ports.iter() {
 
            self.native_ports.insert(Port(p.0));
 
        }
 
        (OutPort(ports[0]), InPort(ports[1]))
 
    }
 
    pub fn new_component(
 
        &mut self,
 
        protocol: &Arc<Protocol>,
 
        name: Vec<u8>,
 
        moved_ports: &[Port],
 
@@ -165,33 +173,34 @@ impl Connected {
 
        }
 
        self.native_ports.retain(|e| !moved_ports.contains(e));
 
        self.components.push(ComponentExt { ports: moved_ports, protocol: protocol.clone(), name });
 
        // TODO add a singleton machine
 
        Ok(())
 
    }
 
    pub fn sync_set(&mut self, ops: &mut [PortOp]) {
 
        todo!()
 
    pub fn sync_set(&mut self, _ops: &mut [PortOp]) -> Result<(), ()> {
 
        Ok(())
 
    }
 
    pub fn sync_subsets(
 
        &mut self,
 
        _ops: &mut [PortOp],
 
        bit_subsets: &[&[usize]],
 
    ) -> Result<usize, ()> {
 
        for &bit_subset in bit_subsets {
 
        for (batch_index, bit_subset) in bit_subsets.iter().enumerate() {
 
            println!("batch_index {:?}", batch_index);
 
            use super::bits::BitChunkIter;
 
            let chunk_iter = bit_subset.iter().copied();
 
            for index in BitChunkIter::new(chunk_iter) {
 
                println!("index {:?}", index);
 
                println!("  index {:?}", index);
 
            }
 
        }
 
        todo!()
 
        Ok(0)
 
    }
 
}
 

	
 
#[test]
 
fn test() {
 
fn api_new_test() {
 
    let mut c = Connecting::default();
 
    let net_out: OutPort = c.bind(Coupling::Active, "127.0.0.1:8001".parse().unwrap());
 
    let net_in: InPort = c.bind(Coupling::Active, "127.0.0.1:8001".parse().unwrap());
 
    let proto_0 = Arc::new(Protocol::parse(b"").unwrap());
 
    let mut c = c.connect(None).unwrap();
 
    let (mem_out, mem_in) = c.new_channel();
 
@@ -202,7 +211,8 @@ fn test() {
 
        PortOp::Out { port: &net_out, offer: false, msg: Some(b"hi!") },
 
        PortOp::Out { port: &net_out, offer: false, msg: Some(b"hey!") },
 
        PortOp::Out { port: &net_out, offer: false, msg: Some(b"hello, there!") },
 
        PortOp::In { port: &mem_in, poll: false, msg: Some(&mut buf) },
 
    ];
 
    c.sync_subsets(&mut ops, &[&[0b001], &[0b010], &[0b100]]).unwrap();
 
    c.sync_set(&mut ops).unwrap();
 
}
0 comments (0 inline, 0 general)