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