use std::collections::VecDeque;
use osiris_data::data::composite::{Array, ProduceConsume};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct CpuId(u16);
impl CpuId {
pub const fn new(raw: u16) -> Self { Self(raw) }
pub const fn to_u16(&self) -> u16 { self.0 }
}
#[derive(Clone, Debug)]
pub struct Message {
recipient: CpuId,
data: Array,
}
impl Message {
pub fn new(recipient: CpuId, data: Array) -> Self {
Message { recipient, data }
}
pub fn is_recipient(&self, cpu_id: CpuId) -> bool { self.recipient == cpu_id }
pub fn recipient(&self) -> CpuId { self.recipient }
pub fn get_data(&self) -> Array { self.data.clone() }
}
#[derive(Clone, Debug, Default)]
pub struct MessageQueue {
queue: VecDeque<Message>
}
impl ProduceConsume<Message> for MessageQueue {
fn produce(&mut self, data: Message) {
self.queue.push_back(data);
}
fn consume(&mut self) -> Option<Message> { self.queue.pop_front() }
fn len(&self) -> usize { self.queue.len() }
fn is_empty(&self) -> bool { self.queue.is_empty() }
}