Skip to main content

hot_plug/
hot_plug.rs

1//! React to CAM insertion and removal edges with `Driver::pump_hotplug`.
2//!
3//! The mock's slot status is flipped by hand; a real `linux` device reports it
4//! from the kernel.
5//!
6//! Run: `cargo run -p dvb-ci-runtime --example hot_plug`
7
8use std::time::Duration;
9
10use dvb_ci_runtime::{Driver, DriverBounds, HotPlug, MockCaDevice, StackBounds, TransportBounds};
11
12fn driver_bounds() -> DriverBounds {
13    DriverBounds {
14        stack: StackBounds {
15            transport: TransportBounds {
16                poll_interval: Duration::from_millis(100),
17                reply_timeout: Duration::from_secs(1),
18                max_setup_attempts: 5,
19                max_reassembly_len: 2 * 1024 * 1024,
20                max_outbound_queue: 64,
21            },
22            max_sessions: 32,
23        },
24        max_pending_notifications: 1024,
25        slot_ready_grace: Duration::from_secs(12),
26        slot_retry: Duration::from_millis(250),
27    }
28}
29
30fn main() -> std::io::Result<()> {
31    let mut driver = Driver::new(MockCaDevice::new([]), driver_bounds());
32    driver.init()?;
33
34    let mut seen = Vec::new();
35    for present in [true, false, true] {
36        driver.device_mut().slot.module_present = present;
37        driver.pump_hotplug(Duration::from_millis(10), |event| match event {
38            HotPlug::CamPresent => seen.push("CAM inserted: re-send pending ca_pmt"),
39            HotPlug::CamRemoved => seen.push("CAM removed: stop descrambling"),
40            _ => seen.push("card event"),
41        })?;
42    }
43    for line in &seen {
44        println!("{line}");
45    }
46    println!("{} hot-plug event(s)", seen.len());
47    Ok(())
48}