pub mod orchestrator;
pub mod thread_channel;
pub mod udp;
#[cfg(unix)]
pub mod unix;
pub mod worker;
use std::time::{Duration, Instant};
use crate::controller::context::ControllerCtx;
use deimos_shared::peripherals::PeripheralId;
pub type SocketId = usize;
pub type SocketAddr = (usize, PeripheralId);
pub type SocketAddrToken = u64;
pub use orchestrator::SocketOrchestrator;
pub use worker::{SocketWorker, SocketWorkerCommand, SocketWorkerEvent, SocketWorkerHandle};
pub struct SocketPacketMeta {
pub pid: Option<PeripheralId>,
pub token: SocketAddrToken,
pub time: Instant,
pub size: usize,
}
pub struct SocketRecvMeta {
pub socket_id: SocketId,
pub pid: Option<PeripheralId>,
pub token: SocketAddrToken,
pub time: Instant,
pub size: usize,
}
#[typetag::serde(tag = "type")]
pub trait Socket: Send + Sync {
fn is_open(&self) -> bool;
fn open(&mut self, ctx: &ControllerCtx) -> Result<(), String>;
fn close(&mut self);
fn send(&mut self, id: PeripheralId, msg: &[u8]) -> Result<(), String>;
fn recv(&mut self, buf: &mut [u8], timeout: Duration) -> Option<SocketPacketMeta>;
fn broadcast(&mut self, msg: &[u8]) -> Result<(), String>;
fn update_map(&mut self, id: PeripheralId, token: SocketAddrToken) -> Result<(), String>;
}