refactor adapters into modular file structure

config-sqlite: split into repository/ (per entity) + serialization/ (per type) + error.rs
http-api: split into dto/ (per resource) + routes/ (per resource)
tcp-server: split into broadcaster, event_bus, server, error
rss: split parser from adapter, external tests
media: split error, external tests
This commit is contained in:
2026-06-18 22:57:58 +02:00
parent 366d98a1ae
commit 6e77236936
37 changed files with 1428 additions and 1253 deletions

View File

@@ -0,0 +1,76 @@
use tokio::sync::broadcast;
use domain::{
BroadcastPort, Layout, WidgetId, WidgetState,
};
use protocol::{
ServerMessage, WidgetDescriptor, WireDisplayHint, WireLayoutNode,
encode,
};
use crate::error::TcpServerError;
pub struct TcpBroadcaster {
tx: broadcast::Sender<Vec<u8>>,
}
impl TcpBroadcaster {
pub fn new(capacity: usize) -> Self {
let (tx, _) = broadcast::channel(capacity);
Self { tx }
}
pub fn subscribe(&self) -> broadcast::Receiver<Vec<u8>> {
self.tx.subscribe()
}
fn send_frame(&self, frame: Vec<u8>) -> Result<(), TcpServerError> {
let _ = self.tx.send(frame);
Ok(())
}
}
impl BroadcastPort for TcpBroadcaster {
type Error = TcpServerError;
async fn push_screen_update(
&self,
layout: &Layout,
widgets: &[(WidgetId, WidgetState)],
) -> Result<(), Self::Error> {
let wire_layout: WireLayoutNode = (&layout.root).into();
let wire_widgets: Vec<WidgetDescriptor> = widgets.iter().map(|(id, state)| {
WidgetDescriptor {
id: *id,
display_hint: WireDisplayHint::IconValue,
state: state.into(),
}
}).collect();
let msg = ServerMessage::ScreenUpdate {
layout: wire_layout,
widgets: wire_widgets,
};
let frame = encode(&msg).map_err(TcpServerError::Encode)?;
self.send_frame(frame)
}
async fn push_data_update(
&self,
updates: &[(WidgetId, WidgetState)],
) -> Result<(), Self::Error> {
let wire_widgets: Vec<WidgetDescriptor> = updates.iter().map(|(id, state)| {
WidgetDescriptor {
id: *id,
display_hint: WireDisplayHint::IconValue,
state: state.into(),
}
}).collect();
let msg = ServerMessage::DataUpdate {
widgets: wire_widgets,
};
let frame = encode(&msg).map_err(TcpServerError::Encode)?;
self.send_frame(frame)
}
}