Hardware/Mainboard/Mainboard.cs
author moel.mich
Mon, 07 Jun 2010 20:03:48 +0000
changeset 136 fa2957aa0699
parent 135 51a15cf90d22
child 138 1301992d8ae5
permissions -rw-r--r--
Added (partial) SMBIOS support for Linux by reading from sysfs.
     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.Drawing;
    41 using System.Text;
    42 using OpenHardwareMonitor.Hardware.LPC;
    43 
    44 namespace OpenHardwareMonitor.Hardware.Mainboard {
    45   public class Mainboard : IHardware {
    46     private SMBIOS smbios;
    47     private string name;
    48     private Image icon;
    49 
    50     private LPCIO lpcio;
    51     private LMSensors lmSensors;
    52     private IHardware[] superIOHardware;
    53 
    54     public Mainboard() {
    55       this.smbios = new SMBIOS();
    56      
    57       if (smbios.Board != null) {
    58         if (smbios.Board.ProductName != null
    59           && smbios.Board.ProductName != "") {
    60           if (smbios.Board.Manufacturer == Manufacturer.Unknown)
    61             this.name = smbios.Board.ProductName;
    62           else
    63             this.name = smbios.Board.Manufacturer + " " +
    64               smbios.Board.ProductName;
    65         } else {
    66           this.name = smbios.Board.Manufacturer.ToString();
    67         }
    68       } else {
    69         this.name = Manufacturer.Unknown.ToString();
    70       }
    71 
    72       this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png");
    73       ISuperIO[] superIO;
    74       int p = (int)System.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 IHardware[superIO.Length];
    84       for (int i = 0; i < superIO.Length; i++)
    85         superIOHardware[i] = new SuperIOHardware(superIO[i], 
    86           smbios.Board != null ? smbios.Board.Manufacturer : 
    87           Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model : 
    88           Model.Unknown);      
    89     }
    90 
    91     public string Name {
    92       get { return name; } 
    93     }
    94 
    95     public Identifier Identifier {
    96       get { return new Identifier("mainboard"); }
    97     }
    98 
    99     public Image Icon {
   100       get { return icon; }
   101     }
   102 
   103     public string GetReport() {
   104       StringBuilder r = new StringBuilder(); 
   105 
   106       r.AppendLine("Mainboard");
   107       r.AppendLine();           
   108       r.Append(smbios.GetReport());
   109 
   110       if (lpcio != null)
   111         r.Append(lpcio.GetReport());
   112 
   113       return r.ToString();
   114     }
   115 
   116     public void Update() { }
   117 
   118     public void Close() {
   119       if (lmSensors != null)
   120         lmSensors.Close();
   121     }
   122 
   123     public IHardware[] SubHardware {
   124       get { return superIOHardware; }
   125     }
   126 
   127     public ISensor[] Sensors {
   128       get { return new ISensor[0]; }
   129     }
   130 
   131     #pragma warning disable 67
   132     public event SensorEventHandler SensorAdded;
   133     public event SensorEventHandler SensorRemoved;
   134     #pragma warning restore 67
   135 
   136     public void Accept(IVisitor visitor) {
   137       visitor.VisitHardware(this);
   138     }
   139 
   140     public void Traverse(IVisitor visitor) {
   141       foreach (IHardware hardware in superIOHardware)
   142         hardware.Accept(visitor);     
   143     }
   144   }
   145 }