mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 20:09:59 +03:00
59 lines
1.0 KiB
Rust
59 lines
1.0 KiB
Rust
use std::net::SocketAddr;
|
|
|
|
#[derive(Eq, Hash, PartialEq, Clone, Copy)]
|
|
pub enum Position {
|
|
Left,
|
|
Right,
|
|
Top,
|
|
Bottom,
|
|
}
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub struct Client {
|
|
pub addr: SocketAddr,
|
|
pub pos: Position,
|
|
pub handle: ClientHandle,
|
|
}
|
|
|
|
impl Client {
|
|
pub fn handle(&self) -> ClientHandle {
|
|
return self.handle;
|
|
}
|
|
}
|
|
|
|
pub enum ClientEvent {
|
|
Create(Client),
|
|
Destroy(Client),
|
|
}
|
|
|
|
pub struct ClientManager {
|
|
next_id: u32,
|
|
clients: Vec<Client>,
|
|
}
|
|
|
|
pub type ClientHandle = u32;
|
|
|
|
impl ClientManager {
|
|
fn new_id(&mut self) -> ClientHandle {
|
|
self.next_id += 1;
|
|
self.next_id
|
|
}
|
|
|
|
pub fn new() -> Self {
|
|
ClientManager {
|
|
next_id: 0,
|
|
clients: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn add_client(&mut self, addr: SocketAddr, pos: Position) {
|
|
let handle = self.new_id();
|
|
let client = Client { addr, pos, handle };
|
|
self.clients.push(client);
|
|
}
|
|
|
|
pub fn get_clients(&self) -> Vec<Client> {
|
|
self.clients.clone()
|
|
}
|
|
}
|