Hardware/Mainboard/Mainboard.cs
author moel.mich
Sun, 01 Jul 2012 21:44:07 +0000
changeset 355 17dbf781401e
parent 320 df3493f75225
child 370 8e4dedc41924
permissions -rw-r--r--
Added experimental support for Nuvoton NCT6779D super I/O chips.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Text;
    13 using OpenHardwareMonitor.Hardware.LPC;
    14 
    15 namespace OpenHardwareMonitor.Hardware.Mainboard {
    16   internal class Mainboard : IHardware {
    17     private readonly SMBIOS smbios;
    18     private readonly string name;
    19     private string customName;
    20     private readonly ISettings settings;
    21     private readonly LPCIO lpcio;
    22     private readonly LMSensors lmSensors;
    23     private readonly Hardware[] superIOHardware;
    24 
    25     public Mainboard(ISettings settings) {
    26       this.settings = settings;
    27       this.smbios = new SMBIOS();
    28      
    29       if (smbios.Board != null) {
    30         if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
    31           if (smbios.Board.Manufacturer == Manufacturer.Unknown)
    32             this.name = smbios.Board.ProductName;
    33           else
    34             this.name = smbios.Board.Manufacturer + " " +
    35               smbios.Board.ProductName;
    36         } else {
    37           this.name = smbios.Board.Manufacturer.ToString();
    38         }
    39       } else {
    40         this.name = Manufacturer.Unknown.ToString();
    41       }
    42 
    43       this.customName = settings.GetValue(
    44         new Identifier(Identifier, "name").ToString(), name);
    45 
    46       ISuperIO[] superIO;
    47       int p = (int)Environment.OSVersion.Platform;
    48       if ((p == 4) || (p == 128)) {
    49         this.lmSensors = new LMSensors();
    50         superIO = lmSensors.SuperIO;
    51       } else {
    52         this.lpcio = new LPCIO();       
    53         superIO = lpcio.SuperIO;
    54       }
    55       
    56       superIOHardware = new Hardware[superIO.Length];
    57       for (int i = 0; i < superIO.Length; i++)
    58         superIOHardware[i] = new SuperIOHardware(this, superIO[i], 
    59           smbios.Board != null ? smbios.Board.Manufacturer : 
    60           Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model :
    61           Model.Unknown, settings);
    62     }
    63 
    64     public string Name {
    65       get {
    66         return customName;
    67       }
    68       set {
    69         if (!string.IsNullOrEmpty(value))
    70           customName = value;
    71         else
    72           customName = name;
    73         settings.SetValue(new Identifier(Identifier, "name").ToString(),
    74           customName);
    75       }
    76     }
    77 
    78     public Identifier Identifier {
    79       get { return new Identifier("mainboard"); }
    80     }
    81 
    82     public HardwareType HardwareType {
    83       get { return HardwareType.Mainboard; }
    84     }
    85 
    86     public virtual IHardware Parent {
    87       get { return null; }
    88     }
    89 
    90     public string GetReport() {
    91       StringBuilder r = new StringBuilder(); 
    92 
    93       r.AppendLine("Mainboard");
    94       r.AppendLine();           
    95       r.Append(smbios.GetReport());
    96 
    97       if (lpcio != null)
    98         r.Append(lpcio.GetReport());
    99 
   100       byte[] table = 
   101         FirmwareTable.GetTable(FirmwareTable.Provider.ACPI, "TAMG");
   102       if (table != null) {
   103         GigabyteTAMG tamg = new GigabyteTAMG(table);
   104         r.Append(tamg.GetReport());
   105       }
   106 
   107       return r.ToString();
   108     }
   109 
   110     public void Update() { }
   111 
   112     public void Close() {
   113       if (lmSensors != null)
   114         lmSensors.Close();
   115       foreach (Hardware hardware in superIOHardware)
   116         hardware.Close();
   117     }
   118 
   119     public IHardware[] SubHardware {
   120       get { return superIOHardware; }
   121     }
   122 
   123     public ISensor[] Sensors {
   124       get { return new ISensor[0]; }
   125     }
   126 
   127     #pragma warning disable 67
   128     public event SensorEventHandler SensorAdded;
   129     public event SensorEventHandler SensorRemoved;
   130     #pragma warning restore 67
   131 
   132     public void Accept(IVisitor visitor) {
   133       if (visitor == null)
   134         throw new ArgumentNullException("visitor");
   135       visitor.VisitHardware(this);
   136     }
   137 
   138     public void Traverse(IVisitor visitor) {
   139       foreach (IHardware hardware in superIOHardware)
   140         hardware.Accept(visitor);     
   141     }
   142   }
   143 }