Hardware/Mainboard/Mainboard.cs
author moel.mich
Sun, 17 Oct 2010 16:04:19 +0000
changeset 228 458a6c3de579
parent 182 4801e9eaf979
child 275 35788ddd1825
permissions -rw-r--r--
Added code to read the additional fans on the ASRock P55 Deluxe mainboard via special GPIO switching.
     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-2010
    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 
    47     private readonly LPCIO lpcio;
    48     private readonly LMSensors lmSensors;
    49     private readonly IHardware[] superIOHardware;
    50 
    51     public Mainboard(ISettings settings) {
    52       this.smbios = new SMBIOS();
    53      
    54       if (smbios.Board != null) {
    55         if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
    56           if (smbios.Board.Manufacturer == Manufacturer.Unknown)
    57             this.name = smbios.Board.ProductName;
    58           else
    59             this.name = smbios.Board.Manufacturer + " " +
    60               smbios.Board.ProductName;
    61         } else {
    62           this.name = smbios.Board.Manufacturer.ToString();
    63         }
    64       } else {
    65         this.name = Manufacturer.Unknown.ToString();
    66       }
    67 
    68       ISuperIO[] superIO;
    69       int p = (int)Environment.OSVersion.Platform;
    70       if ((p == 4) || (p == 128)) {
    71         this.lmSensors = new LMSensors();
    72         superIO = lmSensors.SuperIO;
    73       } else {
    74         this.lpcio = new LPCIO();       
    75         superIO = lpcio.SuperIO;
    76       }
    77       
    78       superIOHardware = new IHardware[superIO.Length];
    79       for (int i = 0; i < superIO.Length; i++)
    80         superIOHardware[i] = new SuperIOHardware(this, superIO[i], 
    81           smbios.Board != null ? smbios.Board.Manufacturer : 
    82           Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model :
    83           Model.Unknown, settings);
    84     }
    85 
    86     public string Name {
    87       get { return name; } 
    88     }
    89 
    90     public Identifier Identifier {
    91       get { return new Identifier("mainboard"); }
    92     }
    93 
    94     public HardwareType HardwareType {
    95       get { return HardwareType.Mainboard; }
    96     }
    97 
    98     public virtual IHardware Parent {
    99       get { return null; }
   100     }
   101 
   102     public string GetReport() {
   103       StringBuilder r = new StringBuilder(); 
   104 
   105       r.AppendLine("Mainboard");
   106       r.AppendLine();           
   107       r.Append(smbios.GetReport());
   108 
   109       if (lpcio != null)
   110         r.Append(lpcio.GetReport());
   111 
   112       return r.ToString();
   113     }
   114 
   115     public void Update() { }
   116 
   117     public void Close() {
   118       if (lmSensors != null)
   119         lmSensors.Close();
   120     }
   121 
   122     public IHardware[] SubHardware {
   123       get { return superIOHardware; }
   124     }
   125 
   126     public ISensor[] Sensors {
   127       get { return new ISensor[0]; }
   128     }
   129 
   130     #pragma warning disable 67
   131     public event SensorEventHandler SensorAdded;
   132     public event SensorEventHandler SensorRemoved;
   133     #pragma warning restore 67
   134 
   135     public void Accept(IVisitor visitor) {
   136       if (visitor == null)
   137         throw new ArgumentNullException("visitor");
   138       visitor.VisitHardware(this);
   139     }
   140 
   141     public void Traverse(IVisitor visitor) {
   142       foreach (IHardware hardware in superIOHardware)
   143         hardware.Accept(visitor);     
   144     }
   145   }
   146 }