1.1 --- a/Hardware/Computer.cs Sun Jul 08 19:26:00 2012 +0000
1.2 +++ b/Hardware/Computer.cs Wed Jul 11 17:35:30 2012 +0000
1.3 @@ -4,7 +4,7 @@
1.4 License, v. 2.0. If a copy of the MPL was not distributed with this
1.5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
1.6
1.7 - Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
1.8 + Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
1.9
1.10 */
1.11
1.12 @@ -23,7 +23,12 @@
1.13 private readonly ISettings settings;
1.14
1.15 private bool open;
1.16 - private bool hddEnabled;
1.17 +
1.18 + private bool mainboardEnabled;
1.19 + private bool cpuEnabled;
1.20 + private bool gpuEnabled;
1.21 + private bool fanControllerEnabled;
1.22 + private bool hddEnabled;
1.23
1.24 public Computer() {
1.25 this.settings = new Settings();
1.26 @@ -53,6 +58,17 @@
1.27 if (HardwareRemoved != null)
1.28 foreach (IHardware hardware in group.Hardware)
1.29 HardwareRemoved(hardware);
1.30 +
1.31 + group.Close();
1.32 + }
1.33 +
1.34 + private void RemoveType<T>() where T : IGroup {
1.35 + List<IGroup> list = new List<IGroup>();
1.36 + foreach (IGroup group in groups)
1.37 + if (group is T)
1.38 + list.Add(group);
1.39 + foreach (IGroup group in list)
1.40 + Remove(group);
1.41 }
1.42
1.43 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
1.44 @@ -63,33 +79,104 @@
1.45 Ring0.Open();
1.46 Opcode.Open();
1.47
1.48 - Add(new Mainboard.MainboardGroup(settings));
1.49 - Add(new CPU.CPUGroup(settings));
1.50 - Add(new ATI.ATIGroup(settings));
1.51 - Add(new Nvidia.NvidiaGroup(settings));
1.52 - Add(new TBalancer.TBalancerGroup(settings));
1.53 - Add(new Heatmaster.HeatmasterGroup(settings));
1.54 + if (mainboardEnabled)
1.55 + Add(new Mainboard.MainboardGroup(settings));
1.56 +
1.57 + if (cpuEnabled)
1.58 + Add(new CPU.CPUGroup(settings));
1.59 +
1.60 + if (gpuEnabled) {
1.61 + Add(new ATI.ATIGroup(settings));
1.62 + Add(new Nvidia.NvidiaGroup(settings));
1.63 + }
1.64 +
1.65 + if (fanControllerEnabled) {
1.66 + Add(new TBalancer.TBalancerGroup(settings));
1.67 + Add(new Heatmaster.HeatmasterGroup(settings));
1.68 + }
1.69
1.70 if (hddEnabled)
1.71 Add(new HDD.HarddriveGroup(settings));
1.72
1.73 open = true;
1.74 }
1.75 -
1.76 +
1.77 + public bool MainboardEnabled {
1.78 + get { return mainboardEnabled; }
1.79 +
1.80 + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
1.81 + set {
1.82 + if (open && value != mainboardEnabled) {
1.83 + if (value)
1.84 + Add(new Mainboard.MainboardGroup(settings));
1.85 + else
1.86 + RemoveType<Mainboard.MainboardGroup>();
1.87 + }
1.88 + mainboardEnabled = value;
1.89 + }
1.90 + }
1.91 +
1.92 + public bool CPUEnabled {
1.93 + get { return cpuEnabled; }
1.94 +
1.95 + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
1.96 + set {
1.97 + if (open && value != cpuEnabled) {
1.98 + if (value)
1.99 + Add(new CPU.CPUGroup(settings));
1.100 + else
1.101 + RemoveType<CPU.CPUGroup>();
1.102 + }
1.103 + cpuEnabled = value;
1.104 + }
1.105 + }
1.106 +
1.107 + public bool GPUEnabled {
1.108 + get { return gpuEnabled; }
1.109 +
1.110 + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
1.111 + set {
1.112 + if (open && value != gpuEnabled) {
1.113 + if (value) {
1.114 + Add(new ATI.ATIGroup(settings));
1.115 + Add(new Nvidia.NvidiaGroup(settings));
1.116 + } else {
1.117 + RemoveType<ATI.ATIGroup>();
1.118 + RemoveType<Nvidia.NvidiaGroup>();
1.119 + }
1.120 + }
1.121 + gpuEnabled = value;
1.122 + }
1.123 + }
1.124 +
1.125 + public bool FanControllerEnabled {
1.126 + get { return fanControllerEnabled; }
1.127 +
1.128 + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
1.129 + set {
1.130 + if (open && value != fanControllerEnabled) {
1.131 + if (value) {
1.132 + Add(new TBalancer.TBalancerGroup(settings));
1.133 + Add(new Heatmaster.HeatmasterGroup(settings));
1.134 + } else {
1.135 + RemoveType<TBalancer.TBalancerGroup>();
1.136 + RemoveType<Heatmaster.HeatmasterGroup>();
1.137 + }
1.138 + }
1.139 + fanControllerEnabled = value;
1.140 + }
1.141 + }
1.142 +
1.143 public bool HDDEnabled {
1.144 get { return hddEnabled; }
1.145
1.146 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
1.147 set {
1.148 - if (open && value && !hddEnabled) {
1.149 - Add(new HDD.HarddriveGroup(settings));
1.150 - } else if (open && !value && hddEnabled) {
1.151 - List<IGroup> list = new List<IGroup>();
1.152 - foreach (IGroup group in groups)
1.153 - if (group is HDD.HarddriveGroup)
1.154 - list.Add(group);
1.155 - foreach (IGroup group in list)
1.156 - Remove(group);
1.157 + if (open && value != hddEnabled) {
1.158 + if (value)
1.159 + Add(new HDD.HarddriveGroup(settings));
1.160 + else
1.161 + RemoveType<HDD.HarddriveGroup>();
1.162 }
1.163 hddEnabled = value;
1.164 }
1.165 @@ -243,8 +330,7 @@
1.166
1.167 while (groups.Count > 0) {
1.168 IGroup group = groups[groups.Count - 1];
1.169 - Remove(group);
1.170 - group.Close();
1.171 + Remove(group);
1.172 }
1.173
1.174 Opcode.Close();