1 // 2 // Sysinfo 3 // 4 // Copyright (c) 2015 Guillaume Gomez 5 // 6 7 use crate::{ 8 sys::{component::Component, Disk, Networks, Process, Processor}, 9 LoadAvg, Pid, RefreshKind, SystemExt, User, 10 }; 11 12 use std::collections::HashMap; 13 14 /// Structs containing system's information. 15 pub struct System { 16 processes_list: HashMap<Pid, Process>, 17 networks: Networks, 18 global_processor: Processor, 19 } 20 21 impl SystemExt for System { 22 const IS_SUPPORTED: bool = false; new(pid: Pid, parent: Option<Pid>, _start_time: u64) -> Process23 24 fn new_with_specifics(_: RefreshKind) -> System { 25 System { 26 processes_list: Default::default(), 27 networks: Networks::new(), 28 global_processor: Processor::new(), 29 } 30 } name(&self) -> &str31 32 fn refresh_memory(&mut self) {} 33 34 fn refresh_cpu(&mut self) {} cmd(&self) -> &[String]35 36 fn refresh_components_list(&mut self) {} 37 38 fn refresh_processes(&mut self) {} exe(&self) -> &Path39 40 fn refresh_process(&mut self, _pid: Pid) -> bool { 41 false 42 } pid(&self) -> Pid43 44 fn refresh_disks_list(&mut self) {} 45 46 fn refresh_users_list(&mut self) {} environ(&self) -> &[String]47 48 // COMMON PART 49 // 50 // Need to be moved into a "common" file to avoid duplication. 51 52 fn processes(&self) -> &HashMap<Pid, Process> { 53 &self.processes_list 54 } root(&self) -> &Path55 56 fn process(&self, _pid: Pid) -> Option<&Process> { 57 None 58 } memory(&self) -> u6459 60 fn networks(&self) -> &Networks { 61 &self.networks 62 } virtual_memory(&self) -> u6463 64 fn networks_mut(&mut self) -> &mut Networks { 65 &mut self.networks 66 } parent(&self) -> Option<Pid>67 68 fn global_processor_info(&self) -> &Processor { 69 &self.global_processor 70 } status(&self) -> ProcessStatus71 72 fn processors(&self) -> &[Processor] { 73 &[] 74 } start_time(&self) -> u6475 76 fn physical_core_count(&self) -> Option<usize> { 77 None 78 } cpu_usage(&self) -> f3279 80 fn total_memory(&self) -> u64 { 81 0 82 } disk_usage(&self) -> DiskUsage83 84 fn free_memory(&self) -> u64 { 85 0 86 } 87 88 fn available_memory(&self) -> u64 { 89 0 90 } 91 92 fn used_memory(&self) -> u64 { 93 0 94 } 95 96 fn total_swap(&self) -> u64 { 97 0 98 } 99 100 fn free_swap(&self) -> u64 { 101 0 102 } 103 104 fn used_swap(&self) -> u64 { 105 0 106 } 107 108 fn components(&self) -> &[Component] { 109 &[] 110 } 111 112 fn components_mut(&mut self) -> &mut [Component] { 113 &mut [] 114 } 115 116 fn disks(&self) -> &[Disk] { 117 &[] 118 } 119 120 fn disks_mut(&mut self) -> &mut [Disk] { 121 &mut [] 122 } 123 124 fn uptime(&self) -> u64 { 125 0 126 } 127 128 fn boot_time(&self) -> u64 { 129 0 130 } 131 132 fn load_average(&self) -> LoadAvg { 133 LoadAvg { 134 one: 0., 135 five: 0., 136 fifteen: 0., 137 } 138 } 139 140 fn users(&self) -> &[User] { 141 &[] 142 } 143 144 fn name(&self) -> Option<String> { 145 None 146 } 147 148 fn long_os_version(&self) -> Option<String> { 149 None 150 } 151 152 fn kernel_version(&self) -> Option<String> { 153 None 154 } 155 156 fn os_version(&self) -> Option<String> { 157 None 158 } 159 160 fn host_name(&self) -> Option<String> { 161 None 162 } 163 } 164 165 impl Default for System { 166 fn default() -> System { 167 System::new() 168 } 169 } 170