implémentation concrète de DeviceDescriptionProvider
This commit is contained in:
52
pmocontrol/examples/discover.rs
Normal file
52
pmocontrol/examples/discover.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use pmocontrol::{ControlPoint, DeviceRegistryRead, MediaServerInfo, RendererInfo};
|
||||
use pmocontrol::RendererProtocol;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
// Un tout petit logging optionnel
|
||||
tracing_subscriber::fmt::init();
|
||||
tracing::info!("Starting PMOMusic control point SSDP discovery example...");
|
||||
|
||||
// Lance le control point (timeout HTTP pour les descriptions UPnP)
|
||||
let cp = ControlPoint::spawn(5)?;
|
||||
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(5));
|
||||
|
||||
// Accès thread-safe au DeviceRegistry
|
||||
let reg = cp.registry();
|
||||
let reg = reg.read().expect("registry poisoned");
|
||||
|
||||
let renderers: Vec<RendererInfo> = reg.list_renderers();
|
||||
let servers: Vec<MediaServerInfo> = reg.list_servers();
|
||||
|
||||
println!("=====================");
|
||||
println!("Renderers detected : {}", renderers.len());
|
||||
for r in &renderers {
|
||||
let proto = match r.protocol {
|
||||
RendererProtocol::UpnpAvOnly => "UPnP AV",
|
||||
RendererProtocol::OpenHomeOnly => "OpenHome",
|
||||
RendererProtocol::Hybrid => "Hybrid",
|
||||
};
|
||||
|
||||
println!(
|
||||
"- [{}] {} ({}) [{}] online={}",
|
||||
r.id.0, r.friendly_name, r.model_name, proto, r.online
|
||||
);
|
||||
}
|
||||
|
||||
println!();
|
||||
println!("Media servers detected : {}", servers.len());
|
||||
for s in &servers {
|
||||
println!(
|
||||
"- [{}] {} ({}) online={}",
|
||||
s.id.0, s.friendly_name, s.model_name, s.online
|
||||
);
|
||||
}
|
||||
|
||||
println!("=====================");
|
||||
}
|
||||
}
|
||||
59
pmocontrol/examples/dump_ssdp.rs
Normal file
59
pmocontrol/examples/dump_ssdp.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use pmoupnp::ssdp::{SsdpClient, SsdpEvent};
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
tracing::info!("Starting raw SSDP dump helper...");
|
||||
|
||||
let client = SsdpClient::new()?;
|
||||
|
||||
// Envoie quelques requêtes M-SEARCH ciblées pour accélérer les réponses.
|
||||
let search_targets = [
|
||||
"ssdp:all",
|
||||
"urn:schemas-upnp-org:device:MediaRenderer:1",
|
||||
"urn:av-openhome-org:device:MediaRenderer:1",
|
||||
"urn:schemas-upnp-org:device:MediaServer:1",
|
||||
];
|
||||
for st in &search_targets {
|
||||
if let Err(err) = client.send_msearch(st, 3) {
|
||||
eprintln!("Failed to send M-SEARCH for {}: {}", st, err);
|
||||
}
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
}
|
||||
|
||||
println!("Listening for SSDP events. Press Ctrl+C to stop.");
|
||||
|
||||
client.run_event_loop(|event| match event {
|
||||
SsdpEvent::Alive {
|
||||
usn,
|
||||
nt,
|
||||
location,
|
||||
server,
|
||||
max_age,
|
||||
from,
|
||||
} => {
|
||||
println!(
|
||||
"[ALIVE] from={} usn={} nt={} location={} server={} max_age={}",
|
||||
from, usn, nt, location, server, max_age
|
||||
);
|
||||
}
|
||||
SsdpEvent::SearchResponse {
|
||||
usn,
|
||||
st,
|
||||
location,
|
||||
server,
|
||||
max_age,
|
||||
from,
|
||||
} => {
|
||||
println!(
|
||||
"[SEARCH RESPONSE] from={} usn={} st={} location={} server={} max_age={}",
|
||||
from, usn, st, location, server, max_age
|
||||
);
|
||||
}
|
||||
SsdpEvent::ByeBye { usn, nt, from } => {
|
||||
println!("[BYEBYE] from={} usn={} nt={}", from, usn, nt);
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user