Files @ 0781cf1b7abf
Branch filter:

Location: CSY/reowolf/src/runtime2/communication.rs

0781cf1b7abf 2.0 KiB application/rls-services+xml Show Annotation Show as Raw Download as Raw
MH
WIP: Adding debug logs, add sync test
use crate::protocol::eval::*;
use super::runtime::*;
use super::component::*;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct PortId(pub u32);


impl PortId {
    /// This value is not significant, it is chosen to make debugging easier: a
    /// very large port number is more likely to shine a light on bugs.
    pub fn new_invalid() -> Self {
        return Self(u32::MAX);
    }
}

pub struct Peer {
    pub id: CompId,
    pub num_associated_ports: u32,
    pub(crate) handle: CompHandle,
}

#[derive(Debug, PartialEq, Eq)]
pub enum PortKind {
    Putter,
    Getter,
}

#[derive(Debug, PartialEq, Eq)]
pub enum PortState {
    Open,
    Blocked,
    Closed,
}

pub struct Port {
    pub self_id: PortId,
    pub peer_id: PortId,
    pub kind: PortKind,
    pub state: PortState,
    pub peer_comp_id: CompId,
}

pub struct Channel {
    pub putter_id: PortId,
    pub getter_id: PortId,
}

#[derive(Debug)]
pub struct DataMessage {
    pub data_header: MessageDataHeader,
    pub sync_header: MessageSyncHeader,
    pub content: ValueGroup,
}

#[derive(Debug)]
pub struct MessageSyncHeader {
    pub sync_round: u32,
}

#[derive(Debug)]
pub struct MessageDataHeader {
    pub expected_mapping: Vec<(PortId, u32)>,
    pub new_mapping: u32,
    pub source_port: PortId,
    pub target_port: PortId,
}

#[derive(Debug)]
pub struct ControlMessage {
    pub(crate) id: ControlId,
    pub sender_comp_id: CompId,
    pub target_port_id: Option<PortId>,
    pub content: ControlMessageContent,
}

#[derive(Copy, Clone, Debug)]
pub enum ControlMessageContent {
    Ack,
    BlockPort(PortId),
    UnblockPort(PortId),
    ClosePort(PortId),
    PortPeerChangedBlock(PortId),
    PortPeerChangedUnblock(PortId, CompId),
}

#[derive(Debug)]
pub enum Message {
    Data(DataMessage),
    Control(ControlMessage),
}

impl Message {
    pub(crate) fn target_port(&self) -> Option<PortId> {
        match self {
            Message::Data(v) =>
                return Some(v.data_header.target_port),
            Message::Control(v) =>
                return v.target_port_id,
        }
    }
}