diff --git a/src/runtime/communication.rs b/src/runtime/communication.rs index 0b3d617a931edbbd4ee660bfcace2562c46801bc..839cc539d37d3e5071e143f6af6f952206b034a6 100644 --- a/src/runtime/communication.rs +++ b/src/runtime/communication.rs @@ -85,6 +85,26 @@ impl SyncProtoContext<'_> { } impl Connector { + pub fn put(&mut self, port: PortId, payload: Payload) -> Result<(), PortOpError> { + use PortOpError::*; + if !self.native_ports.contains(&port) { + return Err(PortUnavailable); + } + if Putter != *self.port_info.polarities.get(&port).unwrap() { + return Err(WrongPolarity); + } + match &mut self.phased { + ConnectorPhased::Setup { .. } => Err(NotConnected), + ConnectorPhased::Communication { native_batches, .. } => { + let batch = native_batches.last_mut().unwrap(); + if batch.to_put.contains_key(&port) { + return Err(MultipleOpsOnPort); + } + batch.to_put.insert(port, payload); + Ok(()) + } + } + } pub fn sync(&mut self) -> Result { use SyncError::*; match &mut self.phased {