1use crate::utils::*;
2use crate::DbusObjects;
3
4#[derive(Clone, Debug, Default)]
5pub struct Drive {
6 pub can_power_off: bool,
7 pub connection_bus: String,
8 pub ejectable: bool,
9 pub id: String,
10 pub media_available: bool,
11 pub media_change_detected: bool,
12 pub media_compatibility: Vec<String>,
13 pub media_removable: bool,
14 pub media: Option<String>,
15 pub model: String,
16 pub optical: bool,
17 pub optical_blank: bool,
18 pub optical_num_tracks: u64,
19 pub optical_num_audio_tracks: u64,
20 pub optical_num_data_tracks: u64,
21 pub optical_num_sessions: u64,
22 pub path: String,
23 pub removable: bool,
24 pub revision: String,
25 pub rotation_rate: i64,
26 pub seat: String,
27 pub serial: String,
28 pub sibling_id: String,
29 pub size: u64,
30 pub sort_key: String,
31 pub time_detected: u64,
32 pub time_media_detected: u64,
33 pub vendor: String,
34 pub wwn: String,
35}
36
37impl ParseFrom for Drive {
38 fn parse_from(path: &str, objects: &DbusObjects) -> Option<Drive> {
39 if let Some(object) = objects.get("org.freedesktop.UDisks2.Drive") {
40 let mut drive = Drive::default();
41 drive.path = path.to_owned();
42 drive.parse(object);
43
44 Some(drive)
45 } else {
46 None
47 }
48 }
49}
50
51impl Drive {
52 fn parse(&mut self, objects: &KeyVariant) {
53 for (key, ref value) in objects {
54 match key.as_str() {
55 "CanPowerOff" => self.can_power_off = get_bool(value),
56 "ConnectionBus" => self.connection_bus = get_string(value).unwrap_or_default(),
57 "Ejectable" => self.ejectable = get_bool(value),
58 "Id" => self.id = get_string(value).unwrap_or_default(),
59 "Media" => self.media = get_string(value),
60 "MediaAvailable" => self.media_available = get_bool(value),
61 "MediaChangeDetected" => self.media_change_detected = get_bool(value),
62 "MediaCompatibility" => {
63 self.media_compatibility = get_string_array(value).unwrap_or_default()
64 }
65 "MediaRemovable" => self.media_removable = get_bool(value),
66 "Model" => self.model = get_string(value).unwrap_or_default(),
67 "Optical" => self.optical = get_bool(value),
68 "OpticalBlank" => self.optical_blank = get_bool(value),
69 "OpticalNumTracks" => self.optical_num_tracks = get_u64(value),
70 "OpticalNumAudioTracks" => self.optical_num_audio_tracks = get_u64(value),
71 "OpticalNumDataTracks" => self.optical_num_data_tracks = get_u64(value),
72 "OpticalNumSessions" => self.optical_num_sessions = get_u64(value),
73 "Removable" => self.removable = get_bool(value),
74 "Revision" => self.revision = get_string(value).unwrap_or_default(),
75 "RotationRate" => self.rotation_rate = get_u64(value) as i64,
76 "Seat" => self.seat = get_string(value).unwrap_or_default(),
77 "Serial" => self.serial = get_string(value).unwrap_or_default(),
78 "SiblingId" => self.sibling_id = get_string(value).unwrap_or_default(),
79 "Size" => self.size = get_u64(value),
80 "SortKey" => self.sort_key = get_string(value).unwrap_or_default(),
81 "TimeDetected" => self.time_detected = get_u64(value),
82 "TimeMediaDetected" => self.time_media_detected = get_u64(value),
83 "Vendor" => self.vendor = get_string(value).unwrap_or_default(),
84 "WWN" => self.wwn = get_string(value).unwrap_or_default(),
85 _ => {
86 #[cfg(debug_assertions)]
87 eprintln!("unhandled org.freedesktop.UDisks2.Drive::{}", key);
88 }
89 }
90 }
91 }
92}
93
94impl<'a> From<&'a Drive> for dbus::Path<'a> {
95 fn from(drive: &'a Drive) -> Self {
96 (&drive.path).into()
97 }
98}