From 4cd9cd91251b8422c937ed137f897504d62f15d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sun, 9 May 2010 16:22:13 +0000 Subject: [PATCH] Refactored the hardware code and added the visitor pattern for operations on the computer/hardware/sensor/parameter tree. --- GUI/MainForm.cs | 4 +- GUI/SensorProperties.cs | 76 ++++++++++++++++++++++++++ GUI/UpdateVisitor.cs | 58 ++++++++++++++++++++ Hardware/ATI/ATIGPU.cs | 12 ++-- Hardware/CPU/AMD0FCPU.cs | 12 ++-- Hardware/CPU/AMD10CPU.cs | 12 ++-- Hardware/CPU/IntelCPU.cs | 10 ++-- Hardware/Computer.cs | 25 ++++----- Hardware/HDD/HDD.cs | 8 ++- Hardware/Hardware.cs | 35 +++++++++--- Hardware/IComputer.cs | 2 +- Hardware/IElement.cs | 52 ++++++++++++++++++ Hardware/IHardware.cs | 2 +- Hardware/IParameter.cs | 2 +- Hardware/ISensor.cs | 2 +- Hardware/IVisitor.cs | 51 +++++++++++++++++ Hardware/LPC/F718XX.cs | 4 +- Hardware/LPC/IT87XX.cs | 4 +- Hardware/LPC/LPCHardware.cs | 6 +- Hardware/LPC/{LPCGroup.cs => LPCIO.cs} | 6 +- Hardware/LPC/W836XX.cs | 4 +- Hardware/Mainboard/Mainboard.cs | 17 ++++-- Hardware/Nvidia/NvidiaGPU.cs | 12 ++-- Hardware/Parameter.cs | 8 ++- Hardware/Sensor.cs | 9 +++ Hardware/TBalancer/TBalancer.cs | 6 ++ OpenHardwareMonitor.csproj | 6 +- Utilities/ListSet.cs | 16 +++++- 28 files changed, 372 insertions(+), 89 deletions(-) create mode 100644 GUI/SensorProperties.cs create mode 100644 GUI/UpdateVisitor.cs create mode 100644 Hardware/IElement.cs create mode 100644 Hardware/IVisitor.cs rename Hardware/LPC/{LPCGroup.cs => LPCIO.cs} (96%) diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 271d631..349ab31 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -60,6 +60,8 @@ namespace OpenHardwareMonitor.GUI { private SensorSystemTray sensorSystemTray; private NotifyIcon notifyIcon; private StartupManager startupManager = new StartupManager(); + private SensorProperties sensorProperties = new SensorProperties(); + private UpdateVisitor updateVisitor = new UpdateVisitor(); public MainForm() { InitializeComponent(); @@ -241,7 +243,7 @@ namespace OpenHardwareMonitor.GUI { } private void timer_Tick(object sender, EventArgs e) { - computer.Update(); + computer.Accept(updateVisitor); treeView.Invalidate(); plotPanel.Invalidate(); sensorSystemTray.Redraw(); diff --git a/GUI/SensorProperties.cs b/GUI/SensorProperties.cs new file mode 100644 index 0000000..0c94795 --- /dev/null +++ b/GUI/SensorProperties.cs @@ -0,0 +1,76 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using OpenHardwareMonitor.Hardware; +using OpenHardwareMonitor.Utilities; + +namespace OpenHardwareMonitor.GUI { + public class SensorProperties { + + private IDictionary properties = + new Dictionary(); + + private Properties GetProperties(ISensor sensor) { + Properties value; + if (!properties.TryGetValue(sensor.Identifier, out value)) { + value = new Properties(sensor.Identifier, sensor.IsDefaultHidden); + properties.Add(sensor.Identifier, value); + } + return value; + } + + public bool IsHidden(ISensor sensor) { + return GetProperties(sensor).IsHidden; + } + + private class Properties { + private Identifier identifier; + private bool hidden; + + public Properties(Identifier identifier, bool defaultHidden) { + this.identifier = identifier; + + hidden = Config.Get(new Identifier(identifier, "hidden").ToString(), + defaultHidden); + } + + public bool IsHidden { get { return hidden; } } + } + } +} diff --git a/GUI/UpdateVisitor.cs b/GUI/UpdateVisitor.cs new file mode 100644 index 0000000..1d4b192 --- /dev/null +++ b/GUI/UpdateVisitor.cs @@ -0,0 +1,58 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using OpenHardwareMonitor.Hardware; + +namespace OpenHardwareMonitor.GUI { + public class UpdateVisitor : IVisitor { + public void VisitComputer(IComputer computer) { + computer.Traverse(this); + } + + public void VisitHardware(IHardware hardware) { + hardware.Update(); + foreach (IHardware subHardware in hardware.SubHardware) + subHardware.Accept(this); + } + + public void VisitSensor(ISensor sensor) { } + + public void VisitParameter(IParameter parameter) { } + } +} diff --git a/Hardware/ATI/ATIGPU.cs b/Hardware/ATI/ATIGPU.cs index ed59a77..994428f 100644 --- a/Hardware/ATI/ATIGPU.cs +++ b/Hardware/ATI/ATIGPU.cs @@ -82,23 +82,19 @@ namespace OpenHardwareMonitor.Hardware.ATI { public int DeviceNumber { get { return deviceNumber; } } - public string Name { + public override string Name { get { return name; } } - public Identifier Identifier { + public override Identifier Identifier { get { return new Identifier("atigpu", adapterIndex.ToString()); } } - public Image Icon { + public override Image Icon { get { return icon; } } - public string GetReport() { - return null; - } - - public void Update() { + public override void Update() { ADLTemperature adlt = new ADLTemperature(); if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt) == ADL.ADL_OK) diff --git a/Hardware/CPU/AMD0FCPU.cs b/Hardware/CPU/AMD0FCPU.cs index 0f66d8e..4300c16 100644 --- a/Hardware/CPU/AMD0FCPU.cs +++ b/Hardware/CPU/AMD0FCPU.cs @@ -117,23 +117,19 @@ namespace OpenHardwareMonitor.Hardware.CPU { Update(); } - public string Name { + public override string Name { get { return name; } } - public Identifier Identifier { + public override Identifier Identifier { get { return new Identifier("amdcpu", processorIndex.ToString()); } } - public Image Icon { + public override Image Icon { get { return icon; } } - public string GetReport() { - return null; - } - - public void Update() { + public override void Update() { if (pciAddress != 0xFFFFFFFF) { for (uint i = 0; i < coreTemperatures.Length; i++) { if (WinRing0.WritePciConfigDwordEx( diff --git a/Hardware/CPU/AMD10CPU.cs b/Hardware/CPU/AMD10CPU.cs index 6d34119..6fc54bc 100644 --- a/Hardware/CPU/AMD10CPU.cs +++ b/Hardware/CPU/AMD10CPU.cs @@ -99,23 +99,19 @@ namespace OpenHardwareMonitor.Hardware.CPU { Update(); } - public string Name { + public override string Name { get { return name; } } - public Identifier Identifier { + public override Identifier Identifier { get { return new Identifier("amdcpu", processorIndex.ToString()); } } - public Image Icon { + public override Image Icon { get { return icon; } } - public string GetReport() { - return null; - } - - public void Update() { + public override void Update() { if (pciAddress != 0xFFFFFFFF) { uint value; if (WinRing0.ReadPciConfigDwordEx(pciAddress, diff --git a/Hardware/CPU/IntelCPU.cs b/Hardware/CPU/IntelCPU.cs index 36362a7..19f990b 100644 --- a/Hardware/CPU/IntelCPU.cs +++ b/Hardware/CPU/IntelCPU.cs @@ -233,15 +233,15 @@ namespace OpenHardwareMonitor.Hardware.CPU { Update(); } - public string Name { + public override string Name { get { return name; } } - public Identifier Identifier { + public override Identifier Identifier { get { return new Identifier("intelcpu", processorIndex.ToString()); } } - public Image Icon { + public override Image Icon { get { return icon; } } @@ -258,7 +258,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { } } - public string GetReport() { + public override string GetReport() { StringBuilder r = new StringBuilder(); r.AppendLine("Intel CPU"); @@ -311,7 +311,7 @@ namespace OpenHardwareMonitor.Hardware.CPU { (timeEnd - timeBegin); } - public void Update() { + public override void Update() { for (int i = 0; i < coreTemperatures.Length; i++) { uint eax, edx; if (WinRing0.RdmsrTx( diff --git a/Hardware/Computer.cs b/Hardware/Computer.cs index 8c9da33..143ffd7 100644 --- a/Hardware/Computer.cs +++ b/Hardware/Computer.cs @@ -91,21 +91,6 @@ namespace OpenHardwareMonitor.Hardware { open = true; } - private void SubHardwareUpdate(IHardware hardware) { - foreach (IHardware subHardware in hardware.SubHardware) { - subHardware.Update(); - SubHardwareUpdate(subHardware); - } - } - - public void Update() { - foreach (IGroup group in groups) - foreach (IHardware hardware in group.Hardware) { - hardware.Update(); - SubHardwareUpdate(hardware); - } - } - public bool HDDEnabled { get { return hddEnabled; } set { @@ -221,5 +206,15 @@ namespace OpenHardwareMonitor.Hardware { public event HardwareEventHandler HardwareAdded; public event HardwareEventHandler HardwareRemoved; + + public void Accept(IVisitor visitor) { + visitor.VisitComputer(this); + } + + public void Traverse(IVisitor visitor) { + foreach (IGroup group in groups) + foreach (IHardware hardware in group.Hardware) + hardware.Accept(visitor); + } } } diff --git a/Hardware/HDD/HDD.cs b/Hardware/HDD/HDD.cs index 7cc51f2..171ddac 100644 --- a/Hardware/HDD/HDD.cs +++ b/Hardware/HDD/HDD.cs @@ -110,6 +110,12 @@ namespace OpenHardwareMonitor.Hardware.HDD { #pragma warning disable 67 public event SensorEventHandler SensorAdded; public event SensorEventHandler SensorRemoved; - #pragma warning restore 67 + #pragma warning restore 67 + + public void Accept(IVisitor visitor) { + visitor.VisitHardware(this); + } + + public void Traverse(IVisitor visitor) { } } } diff --git a/Hardware/Hardware.cs b/Hardware/Hardware.cs index dfbb82f..8d8b956 100644 --- a/Hardware/Hardware.cs +++ b/Hardware/Hardware.cs @@ -37,11 +37,13 @@ using System; using System.Collections.Generic; +using System.Drawing; +using OpenHardwareMonitor.Utilities; namespace OpenHardwareMonitor.Hardware { - public abstract class Hardware { + public abstract class Hardware : IHardware { - private List active = new List(); + private ListSet active = new ListSet(); public IHardware[] SubHardware { get { return new IHardware[0]; } @@ -52,24 +54,39 @@ namespace OpenHardwareMonitor.Hardware { } protected void ActivateSensor(Sensor sensor) { - if (!active.Contains(sensor)) { - active.Add(sensor); + if (active.Add(sensor)) if (SensorAdded != null) SensorAdded(sensor); - } } protected void DeactivateSensor(Sensor sensor) { - if (active.Contains(sensor)) { - active.Remove(sensor); + if (active.Remove(sensor)) if (SensorRemoved != null) - SensorRemoved(sensor); - } + SensorRemoved(sensor); } #pragma warning disable 67 public event SensorEventHandler SensorAdded; public event SensorEventHandler SensorRemoved; #pragma warning restore 67 + + public abstract string Name { get; } + public abstract Identifier Identifier { get; } + public abstract Image Icon { get; } + + public virtual string GetReport() { + return null; + } + + public abstract void Update(); + + public void Accept(IVisitor visitor) { + visitor.VisitHardware(this); + } + + public void Traverse(IVisitor visitor) { + foreach (ISensor sensor in active) + sensor.Accept(visitor); + } } } diff --git a/Hardware/IComputer.cs b/Hardware/IComputer.cs index 24f13e2..39ce0d1 100644 --- a/Hardware/IComputer.cs +++ b/Hardware/IComputer.cs @@ -42,7 +42,7 @@ namespace OpenHardwareMonitor.Hardware { public delegate void HardwareEventHandler(IHardware hardware); - public interface IComputer { + public interface IComputer : IElement { IHardware[] Hardware { get; } diff --git a/Hardware/IElement.cs b/Hardware/IElement.cs new file mode 100644 index 0000000..a7cc849 --- /dev/null +++ b/Hardware/IElement.cs @@ -0,0 +1,52 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenHardwareMonitor.Hardware { + + public interface IElement { + // accept visitor on this element + void Accept(IVisitor visitor); + + // call accept(visitor) on all child elements (called only from visitors) + void Traverse(IVisitor visitor); + } + +} diff --git a/Hardware/IHardware.cs b/Hardware/IHardware.cs index 009c72f..5a46e81 100644 --- a/Hardware/IHardware.cs +++ b/Hardware/IHardware.cs @@ -43,7 +43,7 @@ namespace OpenHardwareMonitor.Hardware { public delegate void SensorEventHandler(ISensor sensor); - public interface IHardware { + public interface IHardware : IElement { string Name { get; } Identifier Identifier { get; } diff --git a/Hardware/IParameter.cs b/Hardware/IParameter.cs index 6710e22..7f78390 100644 --- a/Hardware/IParameter.cs +++ b/Hardware/IParameter.cs @@ -40,7 +40,7 @@ using System.Collections.Generic; namespace OpenHardwareMonitor.Hardware { - public interface IParameter { + public interface IParameter : IElement { ISensor Sensor { get; } Identifier Identifier { get; } diff --git a/Hardware/ISensor.cs b/Hardware/ISensor.cs index d665285..672a121 100644 --- a/Hardware/ISensor.cs +++ b/Hardware/ISensor.cs @@ -55,7 +55,7 @@ namespace OpenHardwareMonitor.Hardware { DateTime Time { get; } } - public interface ISensor { + public interface ISensor : IElement { IHardware Hardware { get; } diff --git a/Hardware/IVisitor.cs b/Hardware/IVisitor.cs new file mode 100644 index 0000000..be7a468 --- /dev/null +++ b/Hardware/IVisitor.cs @@ -0,0 +1,51 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenHardwareMonitor.Hardware { + + public interface IVisitor { + void VisitComputer(IComputer computer); + void VisitHardware(IHardware hardware); + void VisitSensor(ISensor sensor); + void VisitParameter(IParameter parameter); + } + +} diff --git a/Hardware/LPC/F718XX.cs b/Hardware/LPC/F718XX.cs index 4d24206..d05c1b1 100644 --- a/Hardware/LPC/F718XX.cs +++ b/Hardware/LPC/F718XX.cs @@ -99,7 +99,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { } } - public string GetReport() { + public override string GetReport() { StringBuilder r = new StringBuilder(); r.AppendLine("LPC " + this.GetType().Name); @@ -123,7 +123,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { return r.ToString(); } - public void Update() { + public override void Update() { foreach (Sensor sensor in voltages) { int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index)); diff --git a/Hardware/LPC/IT87XX.cs b/Hardware/LPC/IT87XX.cs index a914d3b..674358c 100644 --- a/Hardware/LPC/IT87XX.cs +++ b/Hardware/LPC/IT87XX.cs @@ -122,7 +122,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { get { return available; } } - public string GetReport() { + public override string GetReport() { StringBuilder r = new StringBuilder(); r.AppendLine("LPC " + this.GetType().Name); @@ -154,7 +154,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { return r.ToString(); } - public void Update() { + public override void Update() { foreach (Sensor sensor in voltages) { bool valid; diff --git a/Hardware/LPC/LPCHardware.cs b/Hardware/LPC/LPCHardware.cs index a057196..4295135 100644 --- a/Hardware/LPC/LPCHardware.cs +++ b/Hardware/LPC/LPCHardware.cs @@ -73,15 +73,15 @@ namespace OpenHardwareMonitor.Hardware.LPC { } } - public Identifier Identifier { + public override Identifier Identifier { get { return new Identifier("lpc", chip.ToString().ToLower()); } } - public Image Icon { + public override Image Icon { get { return icon; } } - public string Name { + public override string Name { get { return name; } } } diff --git a/Hardware/LPC/LPCGroup.cs b/Hardware/LPC/LPCIO.cs similarity index 96% rename from Hardware/LPC/LPCGroup.cs rename to Hardware/LPC/LPCIO.cs index f2da50a..edfb5e8 100644 --- a/Hardware/LPC/LPCGroup.cs +++ b/Hardware/LPC/LPCIO.cs @@ -41,7 +41,7 @@ using System.Text; using System.Threading; namespace OpenHardwareMonitor.Hardware.LPC { - public class LPCGroup : IGroup { + public class LPCIO { private List hardware = new List(); private StringBuilder report = new StringBuilder(); @@ -119,7 +119,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { WinRing0.WriteIoPortByte(registerPort, 0xAA); } - public LPCGroup() { + public LPCIO() { if (!WinRing0.IsAvailable) return; @@ -394,7 +394,5 @@ namespace OpenHardwareMonitor.Hardware.LPC { } else return null; } - - public void Close() { } } } diff --git a/Hardware/LPC/W836XX.cs b/Hardware/LPC/W836XX.cs index da04f2f..c4ac804 100644 --- a/Hardware/LPC/W836XX.cs +++ b/Hardware/LPC/W836XX.cs @@ -206,7 +206,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { return value > 0 ? target | mask : target & ~mask; } - public void Update() { + public override void Update() { foreach (Sensor sensor in voltages) { if (sensor.Index < 7) { @@ -300,7 +300,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { } } - public string GetReport() { + public override string GetReport() { StringBuilder r = new StringBuilder(); r.AppendLine("LPC " + this.GetType().Name); diff --git a/Hardware/Mainboard/Mainboard.cs b/Hardware/Mainboard/Mainboard.cs index c8ad650..6c17723 100644 --- a/Hardware/Mainboard/Mainboard.cs +++ b/Hardware/Mainboard/Mainboard.cs @@ -47,7 +47,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { private string name; private Image icon; - private LPCGroup lpcGroup; + private LPCIO lpcGroup; public Mainboard() { this.smbios = new SMBIOS(); @@ -68,7 +68,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { } this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png"); - this.lpcGroup = new LPCGroup(); + this.lpcGroup = new LPCIO(); } public string Name { @@ -97,9 +97,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { public void Update() { } - public void Close() { - lpcGroup.Close(); - } + public void Close() { } public IHardware[] SubHardware { get { return lpcGroup.Hardware; } @@ -113,5 +111,14 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { public event SensorEventHandler SensorAdded; public event SensorEventHandler SensorRemoved; #pragma warning restore 67 + + public void Accept(IVisitor visitor) { + visitor.VisitHardware(this); + } + + public void Traverse(IVisitor visitor) { + foreach (IHardware hardware in lpcGroup.Hardware) + hardware.Accept(visitor); + } } } diff --git a/Hardware/Nvidia/NvidiaGPU.cs b/Hardware/Nvidia/NvidiaGPU.cs index 6334c70..1c4450f 100644 --- a/Hardware/Nvidia/NvidiaGPU.cs +++ b/Hardware/Nvidia/NvidiaGPU.cs @@ -89,22 +89,18 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { } } - public string Name { + public override string Name { get { return name; } } - public Identifier Identifier { + public override Identifier Identifier { get { return new Identifier("nvidiagpu", adapterIndex.ToString()); } } - public Image Icon { + public override Image Icon { get { return icon; } } - public string GetReport() { - return null; - } - private NvGPUThermalSettings GetThermalSettings() { NvGPUThermalSettings settings = new NvGPUThermalSettings(); settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER; @@ -117,7 +113,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { return settings; } - public void Update() { + public override void Update() { NvGPUThermalSettings settings = GetThermalSettings(); foreach (Sensor sensor in temperatures) sensor.Value = settings.Sensor[sensor.Index].CurrentTemp; diff --git a/Hardware/Parameter.cs b/Hardware/Parameter.cs index 784f56c..114a388 100644 --- a/Hardware/Parameter.cs +++ b/Hardware/Parameter.cs @@ -114,6 +114,12 @@ namespace OpenHardwareMonitor.Hardware { Utilities.Config.Remove(Identifier.ToString()); } } - } + } + + public void Accept(IVisitor visitor) { + visitor.VisitParameter(this); + } + + public void Traverse(IVisitor visitor) { } } } diff --git a/Hardware/Sensor.cs b/Hardware/Sensor.cs index f2d8fb0..2c3c492 100644 --- a/Hardware/Sensor.cs +++ b/Hardware/Sensor.cs @@ -205,5 +205,14 @@ namespace OpenHardwareMonitor.Hardware { public float Value { get { return value; } } public DateTime Time { get { return time; } } } + + public void Accept(IVisitor visitor) { + visitor.VisitSensor(this); + } + + public void Traverse(IVisitor visitor) { + foreach (IParameter parameter in parameters) + parameter.Accept(visitor); + } } } diff --git a/Hardware/TBalancer/TBalancer.cs b/Hardware/TBalancer/TBalancer.cs index c0d2665..283c987 100644 --- a/Hardware/TBalancer/TBalancer.cs +++ b/Hardware/TBalancer/TBalancer.cs @@ -341,5 +341,11 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { public event SensorEventHandler SensorAdded; public event SensorEventHandler SensorRemoved; + + public void Accept(IVisitor visitor) { + visitor.VisitHardware(this); + } + + public void Traverse(IVisitor visitor) { } } } diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 5c7bba0..38388aa 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -72,10 +72,12 @@ ParameterForm.cs + + @@ -86,6 +88,8 @@ + + @@ -115,7 +119,7 @@ - + Form diff --git a/Utilities/ListSet.cs b/Utilities/ListSet.cs index 484ea97..8548fc7 100644 --- a/Utilities/ListSet.cs +++ b/Utilities/ListSet.cs @@ -36,11 +36,12 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.Text; namespace OpenHardwareMonitor.Utilities { - public class ListSet { + public class ListSet : IEnumerable { private List list = new List(); @@ -65,6 +66,17 @@ namespace OpenHardwareMonitor.Utilities { public bool Contains(T item) { return list.Contains(item); } - + + public T[] ToArray() { + return list.ToArray(); + } + + public IEnumerator GetEnumerator() { + return list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() { + return list.GetEnumerator(); + } } }