moel@135: /* moel@64: moel@344: This Source Code Form is subject to the terms of the Mozilla Public moel@344: License, v. 2.0. If a copy of the MPL was not distributed with this moel@344: file, You can obtain one at http://mozilla.org/MPL/2.0/. moel@64: moel@370: Copyright (C) 2009-2012 Michael Möller moel@344: moel@64: */ moel@64: moel@64: using System; moel@64: using System.Text; moel@64: using OpenHardwareMonitor.Hardware.LPC; moel@64: moel@64: namespace OpenHardwareMonitor.Hardware.Mainboard { moel@165: internal class Mainboard : IHardware { moel@195: private readonly SMBIOS smbios; moel@195: private readonly string name; moel@275: private string customName; moel@275: private readonly ISettings settings; moel@195: private readonly LPCIO lpcio; moel@195: private readonly LMSensors lmSensors; moel@298: private readonly Hardware[] superIOHardware; moel@64: moel@370: public Mainboard(SMBIOS smbios, ISettings settings) { moel@275: this.settings = settings; moel@370: this.smbios = smbios; moel@370: moel@370: Manufacturer manufacturer = smbios.Board == null ? Manufacturer.Unknown : moel@370: Identification.GetManufacturer(smbios.Board.ManufacturerName); moel@370: moel@370: Model model = smbios.Board == null ? Model.Unknown : moel@370: Identification.GetModel(smbios.Board.ProductName); moel@370: moel@76: if (smbios.Board != null) { moel@167: if (!string.IsNullOrEmpty(smbios.Board.ProductName)) { moel@370: if (manufacturer == Manufacturer.Unknown) moel@76: this.name = smbios.Board.ProductName; moel@76: else moel@370: this.name = manufacturer + " " + moel@76: smbios.Board.ProductName; moel@76: } else { moel@370: this.name = manufacturer.ToString(); moel@76: } moel@64: } else { moel@126: this.name = Manufacturer.Unknown.ToString(); moel@64: } moel@76: moel@275: this.customName = settings.GetValue( moel@275: new Identifier(Identifier, "name").ToString(), name); moel@275: moel@135: ISuperIO[] superIO; moel@195: int p = (int)Environment.OSVersion.Platform; moel@135: if ((p == 4) || (p == 128)) { moel@135: this.lmSensors = new LMSensors(); moel@135: superIO = lmSensors.SuperIO; moel@135: } else { moel@135: this.lpcio = new LPCIO(); moel@135: superIO = lpcio.SuperIO; moel@135: } moel@135: moel@298: superIOHardware = new Hardware[superIO.Length]; moel@130: for (int i = 0; i < superIO.Length; i++) moel@370: superIOHardware[i] = new SuperIOHardware(this, superIO[i], moel@370: manufacturer, model, settings); moel@64: } moel@64: moel@64: public string Name { moel@275: get { moel@275: return customName; moel@275: } moel@275: set { moel@275: if (!string.IsNullOrEmpty(value)) moel@275: customName = value; moel@275: else moel@275: customName = name; moel@275: settings.SetValue(new Identifier(Identifier, "name").ToString(), moel@275: customName); moel@275: } moel@64: } moel@64: moel@109: public Identifier Identifier { moel@109: get { return new Identifier("mainboard"); } moel@64: } moel@64: moel@165: public HardwareType HardwareType { moel@165: get { return HardwareType.Mainboard; } moel@64: } moel@64: moel@176: public virtual IHardware Parent { moel@176: get { return null; } moel@176: } moel@176: moel@64: public string GetReport() { moel@64: StringBuilder r = new StringBuilder(); moel@64: moel@64: r.AppendLine("Mainboard"); moel@64: r.AppendLine(); moel@64: r.Append(smbios.GetReport()); moel@64: moel@136: if (lpcio != null) moel@136: r.Append(lpcio.GetReport()); moel@67: moel@308: byte[] table = moel@308: FirmwareTable.GetTable(FirmwareTable.Provider.ACPI, "TAMG"); moel@308: if (table != null) { moel@308: GigabyteTAMG tamg = new GigabyteTAMG(table); moel@308: r.Append(tamg.GetReport()); moel@308: } moel@308: moel@64: return r.ToString(); moel@64: } moel@64: moel@64: public void Update() { } moel@64: moel@135: public void Close() { moel@135: if (lmSensors != null) moel@135: lmSensors.Close(); moel@298: foreach (Hardware hardware in superIOHardware) moel@298: hardware.Close(); moel@135: } moel@64: moel@64: public IHardware[] SubHardware { moel@130: get { return superIOHardware; } moel@64: } moel@64: moel@64: public ISensor[] Sensors { moel@64: get { return new ISensor[0]; } moel@64: } moel@64: moel@64: #pragma warning disable 67 moel@64: public event SensorEventHandler SensorAdded; moel@64: public event SensorEventHandler SensorRemoved; moel@64: #pragma warning restore 67 moel@110: moel@110: public void Accept(IVisitor visitor) { moel@167: if (visitor == null) moel@167: throw new ArgumentNullException("visitor"); moel@167: visitor.VisitHardware(this); moel@110: } moel@110: moel@110: public void Traverse(IVisitor visitor) { moel@130: foreach (IHardware hardware in superIOHardware) moel@110: hardware.Accept(visitor); moel@110: } moel@64: } moel@64: }