Hardware/Mainboard/Mainboard.cs
author moel.mich
Sun, 26 Jun 2011 16:00:20 +0000
changeset 305 9652074e6ee5
parent 275 35788ddd1825
child 308 d882720734bf
permissions -rw-r--r--
Added a mainboard specific configuration for the Gigabyte Z68X-UD7-B3 mainboard.
     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       return r.ToString();
   128     }
   129 
   130     public void Update() { }
   131 
   132     public void Close() {
   133       if (lmSensors != null)
   134         lmSensors.Close();
   135       foreach (Hardware hardware in superIOHardware)
   136         hardware.Close();
   137     }
   138 
   139     public IHardware[] SubHardware {
   140       get { return superIOHardware; }
   141     }
   142 
   143     public ISensor[] Sensors {
   144       get { return new ISensor[0]; }
   145     }
   146 
   147     #pragma warning disable 67
   148     public event SensorEventHandler SensorAdded;
   149     public event SensorEventHandler SensorRemoved;
   150     #pragma warning restore 67
   151 
   152     public void Accept(IVisitor visitor) {
   153       if (visitor == null)
   154         throw new ArgumentNullException("visitor");
   155       visitor.VisitHardware(this);
   156     }
   157 
   158     public void Traverse(IVisitor visitor) {
   159       foreach (IHardware hardware in superIOHardware)
   160         hardware.Accept(visitor);     
   161     }
   162   }
   163 }