moel@135
|
1 |
/*
|
moel@64
|
2 |
|
moel@64
|
3 |
Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
moel@64
|
4 |
|
moel@64
|
5 |
The contents of this file are subject to the Mozilla Public License Version
|
moel@64
|
6 |
1.1 (the "License"); you may not use this file except in compliance with
|
moel@64
|
7 |
the License. You may obtain a copy of the License at
|
moel@64
|
8 |
|
moel@64
|
9 |
http://www.mozilla.org/MPL/
|
moel@64
|
10 |
|
moel@64
|
11 |
Software distributed under the License is distributed on an "AS IS" basis,
|
moel@64
|
12 |
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
moel@64
|
13 |
for the specific language governing rights and limitations under the License.
|
moel@64
|
14 |
|
moel@64
|
15 |
The Original Code is the Open Hardware Monitor code.
|
moel@64
|
16 |
|
moel@64
|
17 |
The Initial Developer of the Original Code is
|
moel@64
|
18 |
Michael Möller <m.moeller@gmx.ch>.
|
moel@64
|
19 |
Portions created by the Initial Developer are Copyright (C) 2009-2010
|
moel@64
|
20 |
the Initial Developer. All Rights Reserved.
|
moel@64
|
21 |
|
moel@64
|
22 |
Contributor(s):
|
moel@64
|
23 |
|
moel@64
|
24 |
Alternatively, the contents of this file may be used under the terms of
|
moel@64
|
25 |
either the GNU General Public License Version 2 or later (the "GPL"), or
|
moel@64
|
26 |
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
moel@64
|
27 |
in which case the provisions of the GPL or the LGPL are applicable instead
|
moel@64
|
28 |
of those above. If you wish to allow use of your version of this file only
|
moel@64
|
29 |
under the terms of either the GPL or the LGPL, and not to allow others to
|
moel@64
|
30 |
use your version of this file under the terms of the MPL, indicate your
|
moel@64
|
31 |
decision by deleting the provisions above and replace them with the notice
|
moel@64
|
32 |
and other provisions required by the GPL or the LGPL. If you do not delete
|
moel@64
|
33 |
the provisions above, a recipient may use your version of this file under
|
moel@64
|
34 |
the terms of any one of the MPL, the GPL or the LGPL.
|
moel@64
|
35 |
|
moel@64
|
36 |
*/
|
moel@64
|
37 |
|
moel@64
|
38 |
using System;
|
moel@64
|
39 |
using System.Collections.Generic;
|
moel@64
|
40 |
using System.Text;
|
moel@64
|
41 |
using OpenHardwareMonitor.Hardware.LPC;
|
moel@64
|
42 |
|
moel@64
|
43 |
namespace OpenHardwareMonitor.Hardware.Mainboard {
|
moel@165
|
44 |
internal class Mainboard : IHardware {
|
moel@64
|
45 |
private SMBIOS smbios;
|
moel@64
|
46 |
private string name;
|
moel@64
|
47 |
|
moel@130
|
48 |
private LPCIO lpcio;
|
moel@135
|
49 |
private LMSensors lmSensors;
|
moel@130
|
50 |
private IHardware[] superIOHardware;
|
moel@64
|
51 |
|
moel@165
|
52 |
public Mainboard(ISettings settings) {
|
moel@64
|
53 |
this.smbios = new SMBIOS();
|
moel@76
|
54 |
|
moel@76
|
55 |
if (smbios.Board != null) {
|
moel@167
|
56 |
if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
|
moel@126
|
57 |
if (smbios.Board.Manufacturer == Manufacturer.Unknown)
|
moel@76
|
58 |
this.name = smbios.Board.ProductName;
|
moel@76
|
59 |
else
|
moel@76
|
60 |
this.name = smbios.Board.Manufacturer + " " +
|
moel@76
|
61 |
smbios.Board.ProductName;
|
moel@76
|
62 |
} else {
|
moel@76
|
63 |
this.name = smbios.Board.Manufacturer.ToString();
|
moel@76
|
64 |
}
|
moel@64
|
65 |
} else {
|
moel@126
|
66 |
this.name = Manufacturer.Unknown.ToString();
|
moel@64
|
67 |
}
|
moel@76
|
68 |
|
moel@135
|
69 |
ISuperIO[] superIO;
|
moel@135
|
70 |
int p = (int)System.Environment.OSVersion.Platform;
|
moel@135
|
71 |
if ((p == 4) || (p == 128)) {
|
moel@135
|
72 |
this.lmSensors = new LMSensors();
|
moel@135
|
73 |
superIO = lmSensors.SuperIO;
|
moel@135
|
74 |
} else {
|
moel@135
|
75 |
this.lpcio = new LPCIO();
|
moel@135
|
76 |
superIO = lpcio.SuperIO;
|
moel@135
|
77 |
}
|
moel@135
|
78 |
|
moel@130
|
79 |
superIOHardware = new IHardware[superIO.Length];
|
moel@130
|
80 |
for (int i = 0; i < superIO.Length; i++)
|
moel@130
|
81 |
superIOHardware[i] = new SuperIOHardware(superIO[i],
|
moel@130
|
82 |
smbios.Board != null ? smbios.Board.Manufacturer :
|
moel@165
|
83 |
Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model :
|
moel@165
|
84 |
Model.Unknown, settings);
|
moel@64
|
85 |
}
|
moel@64
|
86 |
|
moel@64
|
87 |
public string Name {
|
moel@64
|
88 |
get { return name; }
|
moel@64
|
89 |
}
|
moel@64
|
90 |
|
moel@109
|
91 |
public Identifier Identifier {
|
moel@109
|
92 |
get { return new Identifier("mainboard"); }
|
moel@64
|
93 |
}
|
moel@64
|
94 |
|
moel@165
|
95 |
public HardwareType HardwareType {
|
moel@165
|
96 |
get { return HardwareType.Mainboard; }
|
moel@64
|
97 |
}
|
moel@64
|
98 |
|
moel@64
|
99 |
public string GetReport() {
|
moel@64
|
100 |
StringBuilder r = new StringBuilder();
|
moel@64
|
101 |
|
moel@64
|
102 |
r.AppendLine("Mainboard");
|
moel@64
|
103 |
r.AppendLine();
|
moel@64
|
104 |
r.Append(smbios.GetReport());
|
moel@64
|
105 |
|
moel@136
|
106 |
if (lpcio != null)
|
moel@136
|
107 |
r.Append(lpcio.GetReport());
|
moel@67
|
108 |
|
moel@64
|
109 |
return r.ToString();
|
moel@64
|
110 |
}
|
moel@64
|
111 |
|
moel@64
|
112 |
public void Update() { }
|
moel@64
|
113 |
|
moel@135
|
114 |
public void Close() {
|
moel@135
|
115 |
if (lmSensors != null)
|
moel@135
|
116 |
lmSensors.Close();
|
moel@135
|
117 |
}
|
moel@64
|
118 |
|
moel@64
|
119 |
public IHardware[] SubHardware {
|
moel@130
|
120 |
get { return superIOHardware; }
|
moel@64
|
121 |
}
|
moel@64
|
122 |
|
moel@64
|
123 |
public ISensor[] Sensors {
|
moel@64
|
124 |
get { return new ISensor[0]; }
|
moel@64
|
125 |
}
|
moel@64
|
126 |
|
moel@64
|
127 |
#pragma warning disable 67
|
moel@64
|
128 |
public event SensorEventHandler SensorAdded;
|
moel@64
|
129 |
public event SensorEventHandler SensorRemoved;
|
moel@64
|
130 |
#pragma warning restore 67
|
moel@110
|
131 |
|
moel@110
|
132 |
public void Accept(IVisitor visitor) {
|
moel@167
|
133 |
if (visitor == null)
|
moel@167
|
134 |
throw new ArgumentNullException("visitor");
|
moel@167
|
135 |
visitor.VisitHardware(this);
|
moel@110
|
136 |
}
|
moel@110
|
137 |
|
moel@110
|
138 |
public void Traverse(IVisitor visitor) {
|
moel@130
|
139 |
foreach (IHardware hardware in superIOHardware)
|
moel@110
|
140 |
hardware.Accept(visitor);
|
moel@110
|
141 |
}
|
moel@64
|
142 |
}
|
moel@64
|
143 |
}
|