mtp_rs/transport/virtual_device/config.rs
1//! Configuration types for virtual MTP devices.
2
3use std::path::PathBuf;
4use std::time::Duration;
5
6/// Configuration for a virtual MTP device.
7///
8/// Defines the identity and storages of a virtual device that operates against
9/// a local filesystem directory instead of real USB hardware.
10///
11/// # Example
12///
13/// ```rust
14/// use std::path::PathBuf;
15/// use std::time::Duration;
16/// use mtp_rs::transport::virtual_device::config::{VirtualDeviceConfig, VirtualStorageConfig};
17///
18/// let config = VirtualDeviceConfig {
19/// manufacturer: "Google".into(),
20/// model: "Virtual Pixel 9".into(),
21/// serial: "virtual-001".into(),
22/// storages: vec![VirtualStorageConfig {
23/// description: "Internal Storage".into(),
24/// capacity: 64 * 1024 * 1024 * 1024,
25/// backing_dir: PathBuf::from("/tmp/mtp-test"),
26/// read_only: false,
27/// }],
28/// supports_rename: true,
29/// event_poll_interval: Duration::from_millis(50),
30/// watch_backing_dirs: true,
31/// };
32/// ```
33#[derive(Debug, Clone)]
34pub struct VirtualDeviceConfig {
35 /// Manufacturer name reported by the virtual device.
36 pub manufacturer: String,
37 /// Model name reported by the virtual device.
38 pub model: String,
39 /// Serial number for the virtual device.
40 pub serial: String,
41 /// Storage configurations. At least one storage is required.
42 pub storages: Vec<VirtualStorageConfig>,
43 /// Whether the device advertises SetObjectPropValue support (rename).
44 pub supports_rename: bool,
45 /// How long `receive_interrupt` waits when no events are pending.
46 /// Simulates the USB interrupt endpoint blocking behavior.
47 /// Default: 50ms for production use. Use `Duration::ZERO` in tests
48 /// to avoid slowing down the test suite.
49 pub event_poll_interval: Duration,
50 /// Watch backing directories for out-of-band changes and emit MTP events.
51 /// When `true`, a background filesystem watcher detects files created or
52 /// removed directly in the backing directories (bypassing MTP) and queues
53 /// `ObjectAdded`/`ObjectRemoved` events. Set to `false` for tests that
54 /// don't need this (faster startup, no background threads).
55 pub watch_backing_dirs: bool,
56}
57
58/// Configuration for a single storage within a virtual device.
59#[derive(Debug, Clone)]
60pub struct VirtualStorageConfig {
61 /// Human-readable storage description (for example, "Internal Storage").
62 pub description: String,
63 /// Maximum storage capacity in bytes.
64 pub capacity: u64,
65 /// Local directory backing this storage. Files here become MTP objects.
66 pub backing_dir: PathBuf,
67 /// If true, write operations return `StoreReadOnly`.
68 pub read_only: bool,
69}