Hardware/Mainboard/Mainboard.cs
author moel.mich
Thu, 12 Aug 2010 20:53:27 +0000
changeset 166 fa9dfbfc4145
parent 165 813d8bc3192f
child 167 b7cc9d09aefe
permissions -rw-r--r--
Changed the project files to Visual Studio 2010. Fixed some Code Analysis warnings.
     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.Collections.Generic;
    40 using System.Text;
    41 using OpenHardwareMonitor.Hardware.LPC;
    42 
    43 namespace OpenHardwareMonitor.Hardware.Mainboard {
    44   internal class Mainboard : IHardware {
    45     private SMBIOS smbios;
    46     private string name;
    47 
    48     private LPCIO lpcio;
    49     private LMSensors lmSensors;
    50     private IHardware[] superIOHardware;
    51 
    52     public Mainboard(ISettings settings) {
    53       this.smbios = new SMBIOS();
    54      
    55       if (smbios.Board != null) {
    56         if (smbios.Board.ProductName != null
    57           && 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       ISuperIO[] superIO;
    71       int p = (int)System.Environment.OSVersion.Platform;
    72       if ((p == 4) || (p == 128)) {
    73         this.lmSensors = new LMSensors();
    74         superIO = lmSensors.SuperIO;
    75       } else {
    76         this.lpcio = new LPCIO();       
    77         superIO = lpcio.SuperIO;
    78       }
    79       
    80       superIOHardware = new IHardware[superIO.Length];
    81       for (int i = 0; i < superIO.Length; i++)
    82         superIOHardware[i] = new SuperIOHardware(superIO[i], 
    83           smbios.Board != null ? smbios.Board.Manufacturer : 
    84           Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model :
    85           Model.Unknown, settings);
    86     }
    87 
    88     public string Name {
    89       get { return name; } 
    90     }
    91 
    92     public Identifier Identifier {
    93       get { return new Identifier("mainboard"); }
    94     }
    95 
    96     public HardwareType HardwareType {
    97       get { return HardwareType.Mainboard; }
    98     }
    99 
   100     public string GetReport() {
   101       StringBuilder r = new StringBuilder(); 
   102 
   103       r.AppendLine("Mainboard");
   104       r.AppendLine();           
   105       r.Append(smbios.GetReport());
   106 
   107       if (lpcio != null)
   108         r.Append(lpcio.GetReport());
   109 
   110       return r.ToString();
   111     }
   112 
   113     public void Update() { }
   114 
   115     public void Close() {
   116       if (lmSensors != null)
   117         lmSensors.Close();
   118     }
   119 
   120     public IHardware[] SubHardware {
   121       get { return superIOHardware; }
   122     }
   123 
   124     public ISensor[] Sensors {
   125       get { return new ISensor[0]; }
   126     }
   127 
   128     #pragma warning disable 67
   129     public event SensorEventHandler SensorAdded;
   130     public event SensorEventHandler SensorRemoved;
   131     #pragma warning restore 67
   132 
   133     public void Accept(IVisitor visitor) {
   134       if (visitor != null)
   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 }