29e53d16b0
Finish Milestone 3 with persisted config, socket IPC, registry CRUD, periodic discovery, manual add, and app-cache refresh support.
42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use anyhow::Context;
|
|
|
|
use crate::adapters::Device;
|
|
|
|
use super::registry::{AdapterRegistry, DeviceRegistry};
|
|
|
|
/// Background discovery orchestration for supported TV platforms.
|
|
#[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))
|
|
}
|
|
}
|