feat: complete daemon core milestone
Finish Milestone 3 with persisted config, socket IPC, registry CRUD, periodic discovery, manual add, and app-cache refresh support.
This commit is contained in:
+40
-2
@@ -1,3 +1,41 @@
|
||||
use anyhow::Context;
|
||||
|
||||
use crate::adapters::Device;
|
||||
|
||||
use super::registry::{AdapterRegistry, DeviceRegistry};
|
||||
|
||||
/// Background discovery orchestration for supported TV platforms.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct DiscoveryService;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DiscoveryService {
|
||||
adapters: AdapterRegistry,
|
||||
}
|
||||
|
||||
impl DiscoveryService {
|
||||
/// Create a discovery service over the registered adapters.
|
||||
pub fn new(adapters: AdapterRegistry) -> Self {
|
||||
Self { adapters }
|
||||
}
|
||||
|
||||
/// Discover all supported platforms and merge them into the registry.
|
||||
pub async fn discover_all(&self, registry: &mut DeviceRegistry) -> anyhow::Result<Vec<Device>> {
|
||||
let mut discovered = Vec::new();
|
||||
for platform in self.adapters.supported_platforms() {
|
||||
let mut devices = self
|
||||
.discover_platform(platform, registry)
|
||||
.await
|
||||
.with_context(|| format!("failed discovery for platform '{platform}'"))?;
|
||||
discovered.append(&mut devices);
|
||||
}
|
||||
Ok(discovered)
|
||||
}
|
||||
|
||||
/// Discover one platform and merge the results into the registry.
|
||||
pub async fn discover_platform(
|
||||
&self,
|
||||
platform: &str,
|
||||
registry: &mut DeviceRegistry,
|
||||
) -> anyhow::Result<Vec<Device>> {
|
||||
let discovered = self.adapters.discover(platform).await?;
|
||||
Ok(registry.merge_discovered(discovered))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user