feat(input-server): add InputServer<D: InputDevice> with protocol, mock + UART adapters, and tests

This commit is contained in:
2026-10-18 03:08:36 +02:00
parent 5600ce0260
commit c9bd1d2c35
11 changed files with 346 additions and 12 deletions

View File

@@ -0,0 +1,36 @@
use server_framework::Server;
use crate::input_device::InputDevice;
use crate::protocol::{InputRequest, InputResponse};
pub struct InputServer<D: InputDevice> {
device: D,
}
impl<D: InputDevice> InputServer<D> {
pub fn new(device: D) -> Self {
Self { device }
}
pub fn device(&self) -> &D {
&self.device
}
}
impl<D: InputDevice> Server for InputServer<D> {
type Request = InputRequest;
type Response = InputResponse;
fn handle(&mut self, request: InputRequest) -> InputResponse {
match request {
InputRequest::PollEvent => match self.device.poll() {
Some(event) => InputResponse::Event(event),
None => InputResponse::NoEvent,
},
InputRequest::WaitEvent => match self.device.poll() {
Some(event) => InputResponse::Event(event),
None => InputResponse::NoEvent,
},
}
}
}