mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-09-02 07:15:31 +00:00
Refactored the hardware code and added the visitor pattern for operations on the computer/hardware/sensor/parameter tree.
This commit is contained in:
@@ -60,6 +60,8 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
private SensorSystemTray sensorSystemTray;
|
private SensorSystemTray sensorSystemTray;
|
||||||
private NotifyIcon notifyIcon;
|
private NotifyIcon notifyIcon;
|
||||||
private StartupManager startupManager = new StartupManager();
|
private StartupManager startupManager = new StartupManager();
|
||||||
|
private SensorProperties sensorProperties = new SensorProperties();
|
||||||
|
private UpdateVisitor updateVisitor = new UpdateVisitor();
|
||||||
|
|
||||||
public MainForm() {
|
public MainForm() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -241,7 +243,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void timer_Tick(object sender, EventArgs e) {
|
private void timer_Tick(object sender, EventArgs e) {
|
||||||
computer.Update();
|
computer.Accept(updateVisitor);
|
||||||
treeView.Invalidate();
|
treeView.Invalidate();
|
||||||
plotPanel.Invalidate();
|
plotPanel.Invalidate();
|
||||||
sensorSystemTray.Redraw();
|
sensorSystemTray.Redraw();
|
||||||
|
76
GUI/SensorProperties.cs
Normal file
76
GUI/SensorProperties.cs
Normal file
@@ -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 <m.moeller@gmx.ch>.
|
||||||
|
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<Identifier, Properties> properties =
|
||||||
|
new Dictionary<Identifier, Properties>();
|
||||||
|
|
||||||
|
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; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
GUI/UpdateVisitor.cs
Normal file
58
GUI/UpdateVisitor.cs
Normal file
@@ -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 <m.moeller@gmx.ch>.
|
||||||
|
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) { }
|
||||||
|
}
|
||||||
|
}
|
@@ -82,23 +82,19 @@ namespace OpenHardwareMonitor.Hardware.ATI {
|
|||||||
|
|
||||||
public int DeviceNumber { get { return deviceNumber; } }
|
public int DeviceNumber { get { return deviceNumber; } }
|
||||||
|
|
||||||
public string Name {
|
public override string Name {
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier Identifier {
|
public override Identifier Identifier {
|
||||||
get { return new Identifier("atigpu", adapterIndex.ToString()); }
|
get { return new Identifier("atigpu", adapterIndex.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Icon {
|
public override Image Icon {
|
||||||
get { return icon; }
|
get { return icon; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override void Update() {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update() {
|
|
||||||
ADLTemperature adlt = new ADLTemperature();
|
ADLTemperature adlt = new ADLTemperature();
|
||||||
if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
|
if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
|
||||||
== ADL.ADL_OK)
|
== ADL.ADL_OK)
|
||||||
|
@@ -117,23 +117,19 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public override string Name {
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier Identifier {
|
public override Identifier Identifier {
|
||||||
get { return new Identifier("amdcpu", processorIndex.ToString()); }
|
get { return new Identifier("amdcpu", processorIndex.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Icon {
|
public override Image Icon {
|
||||||
get { return icon; }
|
get { return icon; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override void Update() {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update() {
|
|
||||||
if (pciAddress != 0xFFFFFFFF) {
|
if (pciAddress != 0xFFFFFFFF) {
|
||||||
for (uint i = 0; i < coreTemperatures.Length; i++) {
|
for (uint i = 0; i < coreTemperatures.Length; i++) {
|
||||||
if (WinRing0.WritePciConfigDwordEx(
|
if (WinRing0.WritePciConfigDwordEx(
|
||||||
|
@@ -99,23 +99,19 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public override string Name {
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier Identifier {
|
public override Identifier Identifier {
|
||||||
get { return new Identifier("amdcpu", processorIndex.ToString()); }
|
get { return new Identifier("amdcpu", processorIndex.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Icon {
|
public override Image Icon {
|
||||||
get { return icon; }
|
get { return icon; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override void Update() {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update() {
|
|
||||||
if (pciAddress != 0xFFFFFFFF) {
|
if (pciAddress != 0xFFFFFFFF) {
|
||||||
uint value;
|
uint value;
|
||||||
if (WinRing0.ReadPciConfigDwordEx(pciAddress,
|
if (WinRing0.ReadPciConfigDwordEx(pciAddress,
|
||||||
|
@@ -233,15 +233,15 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public override string Name {
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier Identifier {
|
public override Identifier Identifier {
|
||||||
get { return new Identifier("intelcpu", processorIndex.ToString()); }
|
get { return new Identifier("intelcpu", processorIndex.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Icon {
|
public override Image Icon {
|
||||||
get { return icon; }
|
get { return icon; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override string GetReport() {
|
||||||
StringBuilder r = new StringBuilder();
|
StringBuilder r = new StringBuilder();
|
||||||
|
|
||||||
r.AppendLine("Intel CPU");
|
r.AppendLine("Intel CPU");
|
||||||
@@ -311,7 +311,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
(timeEnd - timeBegin);
|
(timeEnd - timeBegin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
public override void Update() {
|
||||||
for (int i = 0; i < coreTemperatures.Length; i++) {
|
for (int i = 0; i < coreTemperatures.Length; i++) {
|
||||||
uint eax, edx;
|
uint eax, edx;
|
||||||
if (WinRing0.RdmsrTx(
|
if (WinRing0.RdmsrTx(
|
||||||
|
@@ -91,21 +91,6 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
open = true;
|
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 {
|
public bool HDDEnabled {
|
||||||
get { return hddEnabled; }
|
get { return hddEnabled; }
|
||||||
set {
|
set {
|
||||||
@@ -221,5 +206,15 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
|
|
||||||
public event HardwareEventHandler HardwareAdded;
|
public event HardwareEventHandler HardwareAdded;
|
||||||
public event HardwareEventHandler HardwareRemoved;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -110,6 +110,12 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
#pragma warning disable 67
|
#pragma warning disable 67
|
||||||
public event SensorEventHandler SensorAdded;
|
public event SensorEventHandler SensorAdded;
|
||||||
public event SensorEventHandler SensorRemoved;
|
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) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,11 +37,13 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenHardwareMonitor.Utilities;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware {
|
namespace OpenHardwareMonitor.Hardware {
|
||||||
public abstract class Hardware {
|
public abstract class Hardware : IHardware {
|
||||||
|
|
||||||
private List<ISensor> active = new List<ISensor>();
|
private ListSet<ISensor> active = new ListSet<ISensor>();
|
||||||
|
|
||||||
public IHardware[] SubHardware {
|
public IHardware[] SubHardware {
|
||||||
get { return new IHardware[0]; }
|
get { return new IHardware[0]; }
|
||||||
@@ -52,24 +54,39 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void ActivateSensor(Sensor sensor) {
|
protected void ActivateSensor(Sensor sensor) {
|
||||||
if (!active.Contains(sensor)) {
|
if (active.Add(sensor))
|
||||||
active.Add(sensor);
|
|
||||||
if (SensorAdded != null)
|
if (SensorAdded != null)
|
||||||
SensorAdded(sensor);
|
SensorAdded(sensor);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DeactivateSensor(Sensor sensor) {
|
protected void DeactivateSensor(Sensor sensor) {
|
||||||
if (active.Contains(sensor)) {
|
if (active.Remove(sensor))
|
||||||
active.Remove(sensor);
|
|
||||||
if (SensorRemoved != null)
|
if (SensorRemoved != null)
|
||||||
SensorRemoved(sensor);
|
SensorRemoved(sensor);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable 67
|
#pragma warning disable 67
|
||||||
public event SensorEventHandler SensorAdded;
|
public event SensorEventHandler SensorAdded;
|
||||||
public event SensorEventHandler SensorRemoved;
|
public event SensorEventHandler SensorRemoved;
|
||||||
#pragma warning restore 67
|
#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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
|
|
||||||
public delegate void HardwareEventHandler(IHardware hardware);
|
public delegate void HardwareEventHandler(IHardware hardware);
|
||||||
|
|
||||||
public interface IComputer {
|
public interface IComputer : IElement {
|
||||||
|
|
||||||
IHardware[] Hardware { get; }
|
IHardware[] Hardware { get; }
|
||||||
|
|
||||||
|
52
Hardware/IElement.cs
Normal file
52
Hardware/IElement.cs
Normal file
@@ -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 <m.moeller@gmx.ch>.
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -43,7 +43,7 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
|
|
||||||
public delegate void SensorEventHandler(ISensor sensor);
|
public delegate void SensorEventHandler(ISensor sensor);
|
||||||
|
|
||||||
public interface IHardware {
|
public interface IHardware : IElement {
|
||||||
|
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
Identifier Identifier { get; }
|
Identifier Identifier { get; }
|
||||||
|
@@ -40,7 +40,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware {
|
namespace OpenHardwareMonitor.Hardware {
|
||||||
|
|
||||||
public interface IParameter {
|
public interface IParameter : IElement {
|
||||||
|
|
||||||
ISensor Sensor { get; }
|
ISensor Sensor { get; }
|
||||||
Identifier Identifier { get; }
|
Identifier Identifier { get; }
|
||||||
|
@@ -55,7 +55,7 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
DateTime Time { get; }
|
DateTime Time { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ISensor {
|
public interface ISensor : IElement {
|
||||||
|
|
||||||
IHardware Hardware { get; }
|
IHardware Hardware { get; }
|
||||||
|
|
||||||
|
51
Hardware/IVisitor.cs
Normal file
51
Hardware/IVisitor.cs
Normal file
@@ -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 <m.moeller@gmx.ch>.
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -99,7 +99,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override string GetReport() {
|
||||||
StringBuilder r = new StringBuilder();
|
StringBuilder r = new StringBuilder();
|
||||||
|
|
||||||
r.AppendLine("LPC " + this.GetType().Name);
|
r.AppendLine("LPC " + this.GetType().Name);
|
||||||
@@ -123,7 +123,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
return r.ToString();
|
return r.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
public override void Update() {
|
||||||
|
|
||||||
foreach (Sensor sensor in voltages) {
|
foreach (Sensor sensor in voltages) {
|
||||||
int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
|
int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
|
||||||
|
@@ -122,7 +122,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
get { return available; }
|
get { return available; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override string GetReport() {
|
||||||
StringBuilder r = new StringBuilder();
|
StringBuilder r = new StringBuilder();
|
||||||
|
|
||||||
r.AppendLine("LPC " + this.GetType().Name);
|
r.AppendLine("LPC " + this.GetType().Name);
|
||||||
@@ -154,7 +154,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
return r.ToString();
|
return r.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
public override void Update() {
|
||||||
|
|
||||||
foreach (Sensor sensor in voltages) {
|
foreach (Sensor sensor in voltages) {
|
||||||
bool valid;
|
bool valid;
|
||||||
|
@@ -73,15 +73,15 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier Identifier {
|
public override Identifier Identifier {
|
||||||
get { return new Identifier("lpc", chip.ToString().ToLower()); }
|
get { return new Identifier("lpc", chip.ToString().ToLower()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Icon {
|
public override Image Icon {
|
||||||
get { return icon; }
|
get { return icon; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public override string Name {
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware.LPC {
|
namespace OpenHardwareMonitor.Hardware.LPC {
|
||||||
public class LPCGroup : IGroup {
|
public class LPCIO {
|
||||||
|
|
||||||
private List<IHardware> hardware = new List<IHardware>();
|
private List<IHardware> hardware = new List<IHardware>();
|
||||||
private StringBuilder report = new StringBuilder();
|
private StringBuilder report = new StringBuilder();
|
||||||
@@ -119,7 +119,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
WinRing0.WriteIoPortByte(registerPort, 0xAA);
|
WinRing0.WriteIoPortByte(registerPort, 0xAA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LPCGroup() {
|
public LPCIO() {
|
||||||
if (!WinRing0.IsAvailable)
|
if (!WinRing0.IsAvailable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -394,7 +394,5 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
} else
|
} else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close() { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -206,7 +206,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
return value > 0 ? target | mask : target & ~mask;
|
return value > 0 ? target | mask : target & ~mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
public override void Update() {
|
||||||
|
|
||||||
foreach (Sensor sensor in voltages) {
|
foreach (Sensor sensor in voltages) {
|
||||||
if (sensor.Index < 7) {
|
if (sensor.Index < 7) {
|
||||||
@@ -300,7 +300,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
public override string GetReport() {
|
||||||
StringBuilder r = new StringBuilder();
|
StringBuilder r = new StringBuilder();
|
||||||
|
|
||||||
r.AppendLine("LPC " + this.GetType().Name);
|
r.AppendLine("LPC " + this.GetType().Name);
|
||||||
|
@@ -47,7 +47,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
|
|||||||
private string name;
|
private string name;
|
||||||
private Image icon;
|
private Image icon;
|
||||||
|
|
||||||
private LPCGroup lpcGroup;
|
private LPCIO lpcGroup;
|
||||||
|
|
||||||
public Mainboard() {
|
public Mainboard() {
|
||||||
this.smbios = new SMBIOS();
|
this.smbios = new SMBIOS();
|
||||||
@@ -68,7 +68,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png");
|
this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png");
|
||||||
this.lpcGroup = new LPCGroup();
|
this.lpcGroup = new LPCIO();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public string Name {
|
||||||
@@ -97,9 +97,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
|
|||||||
|
|
||||||
public void Update() { }
|
public void Update() { }
|
||||||
|
|
||||||
public void Close() {
|
public void Close() { }
|
||||||
lpcGroup.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IHardware[] SubHardware {
|
public IHardware[] SubHardware {
|
||||||
get { return lpcGroup.Hardware; }
|
get { return lpcGroup.Hardware; }
|
||||||
@@ -113,5 +111,14 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
|
|||||||
public event SensorEventHandler SensorAdded;
|
public event SensorEventHandler SensorAdded;
|
||||||
public event SensorEventHandler SensorRemoved;
|
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) {
|
||||||
|
foreach (IHardware hardware in lpcGroup.Hardware)
|
||||||
|
hardware.Accept(visitor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -89,22 +89,18 @@ namespace OpenHardwareMonitor.Hardware.Nvidia {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public override string Name {
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Identifier Identifier {
|
public override Identifier Identifier {
|
||||||
get { return new Identifier("nvidiagpu", adapterIndex.ToString()); }
|
get { return new Identifier("nvidiagpu", adapterIndex.ToString()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Icon {
|
public override Image Icon {
|
||||||
get { return icon; }
|
get { return icon; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetReport() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NvGPUThermalSettings GetThermalSettings() {
|
private NvGPUThermalSettings GetThermalSettings() {
|
||||||
NvGPUThermalSettings settings = new NvGPUThermalSettings();
|
NvGPUThermalSettings settings = new NvGPUThermalSettings();
|
||||||
settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
|
settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
|
||||||
@@ -117,7 +113,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
public override void Update() {
|
||||||
NvGPUThermalSettings settings = GetThermalSettings();
|
NvGPUThermalSettings settings = GetThermalSettings();
|
||||||
foreach (Sensor sensor in temperatures)
|
foreach (Sensor sensor in temperatures)
|
||||||
sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
|
sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
|
||||||
|
@@ -114,6 +114,12 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
Utilities.Config.Remove(Identifier.ToString());
|
Utilities.Config.Remove(Identifier.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Accept(IVisitor visitor) {
|
||||||
|
visitor.VisitParameter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Traverse(IVisitor visitor) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -205,5 +205,14 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
public float Value { get { return value; } }
|
public float Value { get { return value; } }
|
||||||
public DateTime Time { get { return time; } }
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -341,5 +341,11 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
|
|||||||
|
|
||||||
public event SensorEventHandler SensorAdded;
|
public event SensorEventHandler SensorAdded;
|
||||||
public event SensorEventHandler SensorRemoved;
|
public event SensorEventHandler SensorRemoved;
|
||||||
|
|
||||||
|
public void Accept(IVisitor visitor) {
|
||||||
|
visitor.VisitHardware(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Traverse(IVisitor visitor) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,10 +72,12 @@
|
|||||||
<DependentUpon>ParameterForm.cs</DependentUpon>
|
<DependentUpon>ParameterForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="GUI\SensorNotifyIcon.cs" />
|
<Compile Include="GUI\SensorNotifyIcon.cs" />
|
||||||
|
<Compile Include="GUI\SensorProperties.cs" />
|
||||||
<Compile Include="GUI\SensorSystemTray.cs" />
|
<Compile Include="GUI\SensorSystemTray.cs" />
|
||||||
<Compile Include="GUI\StartupManager.cs" />
|
<Compile Include="GUI\StartupManager.cs" />
|
||||||
<Compile Include="GUI\TaskScheduler.cs" />
|
<Compile Include="GUI\TaskScheduler.cs" />
|
||||||
<Compile Include="GUI\TypeNode.cs" />
|
<Compile Include="GUI\TypeNode.cs" />
|
||||||
|
<Compile Include="GUI\UpdateVisitor.cs" />
|
||||||
<Compile Include="Hardware\CPU\AMD10CPU.cs" />
|
<Compile Include="Hardware\CPU\AMD10CPU.cs" />
|
||||||
<Compile Include="Hardware\CPU\AMD0FCPU.cs" />
|
<Compile Include="Hardware\CPU\AMD0FCPU.cs" />
|
||||||
<Compile Include="Hardware\CPU\CPUID.cs" />
|
<Compile Include="Hardware\CPU\CPUID.cs" />
|
||||||
@@ -86,6 +88,8 @@
|
|||||||
<Compile Include="Hardware\HDD\SMART.cs" />
|
<Compile Include="Hardware\HDD\SMART.cs" />
|
||||||
<Compile Include="Hardware\IComputer.cs" />
|
<Compile Include="Hardware\IComputer.cs" />
|
||||||
<Compile Include="Hardware\Identifier.cs" />
|
<Compile Include="Hardware\Identifier.cs" />
|
||||||
|
<Compile Include="Hardware\IElement.cs" />
|
||||||
|
<Compile Include="Hardware\IVisitor.cs" />
|
||||||
<Compile Include="Hardware\IParameter.cs" />
|
<Compile Include="Hardware\IParameter.cs" />
|
||||||
<Compile Include="Hardware\LPC\Chip.cs" />
|
<Compile Include="Hardware\LPC\Chip.cs" />
|
||||||
<Compile Include="Hardware\LPC\F718XX.cs" />
|
<Compile Include="Hardware\LPC\F718XX.cs" />
|
||||||
@@ -115,7 +119,7 @@
|
|||||||
<Compile Include="Hardware\IHardware.cs" />
|
<Compile Include="Hardware\IHardware.cs" />
|
||||||
<Compile Include="Hardware\ISensor.cs" />
|
<Compile Include="Hardware\ISensor.cs" />
|
||||||
<Compile Include="Hardware\LPC\IT87XX.cs" />
|
<Compile Include="Hardware\LPC\IT87XX.cs" />
|
||||||
<Compile Include="Hardware\LPC\LPCGroup.cs" />
|
<Compile Include="Hardware\LPC\LPCIO.cs" />
|
||||||
<Compile Include="GUI\MainForm.cs">
|
<Compile Include="GUI\MainForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@@ -36,11 +36,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Utilities {
|
namespace OpenHardwareMonitor.Utilities {
|
||||||
public class ListSet<T> {
|
public class ListSet<T> : IEnumerable<T> {
|
||||||
|
|
||||||
private List<T> list = new List<T>();
|
private List<T> list = new List<T>();
|
||||||
|
|
||||||
@@ -65,6 +66,17 @@ namespace OpenHardwareMonitor.Utilities {
|
|||||||
public bool Contains(T item) {
|
public bool Contains(T item) {
|
||||||
return list.Contains(item);
|
return list.Contains(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T[] ToArray() {
|
||||||
|
return list.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator() {
|
||||||
|
return list.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() {
|
||||||
|
return list.GetEnumerator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user