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