Hardware/Mainboard/Mainboard.cs
author moel.mich
Sun, 27 May 2012 14:23:31 +0000
changeset 344 3145aadca3d2
parent 320 df3493f75225
child 370 8e4dedc41924
permissions -rw-r--r--
Changed the license to the Mozilla Public License 2.0 and update the licensing information.
moel@135
     1
/*
moel@64
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@64
     6
 
moel@344
     7
  Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@64
     9
*/
moel@64
    10
moel@64
    11
using System;
moel@64
    12
using System.Text;
moel@64
    13
using OpenHardwareMonitor.Hardware.LPC;
moel@64
    14
moel@64
    15
namespace OpenHardwareMonitor.Hardware.Mainboard {
moel@165
    16
  internal class Mainboard : IHardware {
moel@195
    17
    private readonly SMBIOS smbios;
moel@195
    18
    private readonly string name;
moel@275
    19
    private string customName;
moel@275
    20
    private readonly ISettings settings;
moel@195
    21
    private readonly LPCIO lpcio;
moel@195
    22
    private readonly LMSensors lmSensors;
moel@298
    23
    private readonly Hardware[] superIOHardware;
moel@64
    24
moel@165
    25
    public Mainboard(ISettings settings) {
moel@275
    26
      this.settings = settings;
moel@64
    27
      this.smbios = new SMBIOS();
moel@76
    28
     
moel@76
    29
      if (smbios.Board != null) {
moel@167
    30
        if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
moel@126
    31
          if (smbios.Board.Manufacturer == Manufacturer.Unknown)
moel@76
    32
            this.name = smbios.Board.ProductName;
moel@76
    33
          else
moel@76
    34
            this.name = smbios.Board.Manufacturer + " " +
moel@76
    35
              smbios.Board.ProductName;
moel@76
    36
        } else {
moel@76
    37
          this.name = smbios.Board.Manufacturer.ToString();
moel@76
    38
        }
moel@64
    39
      } else {
moel@126
    40
        this.name = Manufacturer.Unknown.ToString();
moel@64
    41
      }
moel@76
    42
moel@275
    43
      this.customName = settings.GetValue(
moel@275
    44
        new Identifier(Identifier, "name").ToString(), name);
moel@275
    45
moel@135
    46
      ISuperIO[] superIO;
moel@195
    47
      int p = (int)Environment.OSVersion.Platform;
moel@135
    48
      if ((p == 4) || (p == 128)) {
moel@135
    49
        this.lmSensors = new LMSensors();
moel@135
    50
        superIO = lmSensors.SuperIO;
moel@135
    51
      } else {
moel@135
    52
        this.lpcio = new LPCIO();       
moel@135
    53
        superIO = lpcio.SuperIO;
moel@135
    54
      }
moel@135
    55
      
moel@298
    56
      superIOHardware = new Hardware[superIO.Length];
moel@130
    57
      for (int i = 0; i < superIO.Length; i++)
moel@176
    58
        superIOHardware[i] = new SuperIOHardware(this, superIO[i], 
moel@130
    59
          smbios.Board != null ? smbios.Board.Manufacturer : 
moel@165
    60
          Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model :
moel@320
    61
          Model.Unknown, settings);
moel@64
    62
    }
moel@64
    63
moel@64
    64
    public string Name {
moel@275
    65
      get {
moel@275
    66
        return customName;
moel@275
    67
      }
moel@275
    68
      set {
moel@275
    69
        if (!string.IsNullOrEmpty(value))
moel@275
    70
          customName = value;
moel@275
    71
        else
moel@275
    72
          customName = name;
moel@275
    73
        settings.SetValue(new Identifier(Identifier, "name").ToString(),
moel@275
    74
          customName);
moel@275
    75
      }
moel@64
    76
    }
moel@64
    77
moel@109
    78
    public Identifier Identifier {
moel@109
    79
      get { return new Identifier("mainboard"); }
moel@64
    80
    }
moel@64
    81
moel@165
    82
    public HardwareType HardwareType {
moel@165
    83
      get { return HardwareType.Mainboard; }
moel@64
    84
    }
moel@64
    85
moel@176
    86
    public virtual IHardware Parent {
moel@176
    87
      get { return null; }
moel@176
    88
    }
moel@176
    89
moel@64
    90
    public string GetReport() {
moel@64
    91
      StringBuilder r = new StringBuilder(); 
moel@64
    92
moel@64
    93
      r.AppendLine("Mainboard");
moel@64
    94
      r.AppendLine();           
moel@64
    95
      r.Append(smbios.GetReport());
moel@64
    96
moel@136
    97
      if (lpcio != null)
moel@136
    98
        r.Append(lpcio.GetReport());
moel@67
    99
moel@308
   100
      byte[] table = 
moel@308
   101
        FirmwareTable.GetTable(FirmwareTable.Provider.ACPI, "TAMG");
moel@308
   102
      if (table != null) {
moel@308
   103
        GigabyteTAMG tamg = new GigabyteTAMG(table);
moel@308
   104
        r.Append(tamg.GetReport());
moel@308
   105
      }
moel@308
   106
moel@64
   107
      return r.ToString();
moel@64
   108
    }
moel@64
   109
moel@64
   110
    public void Update() { }
moel@64
   111
moel@135
   112
    public void Close() {
moel@135
   113
      if (lmSensors != null)
moel@135
   114
        lmSensors.Close();
moel@298
   115
      foreach (Hardware hardware in superIOHardware)
moel@298
   116
        hardware.Close();
moel@135
   117
    }
moel@64
   118
moel@64
   119
    public IHardware[] SubHardware {
moel@130
   120
      get { return superIOHardware; }
moel@64
   121
    }
moel@64
   122
moel@64
   123
    public ISensor[] Sensors {
moel@64
   124
      get { return new ISensor[0]; }
moel@64
   125
    }
moel@64
   126
moel@64
   127
    #pragma warning disable 67
moel@64
   128
    public event SensorEventHandler SensorAdded;
moel@64
   129
    public event SensorEventHandler SensorRemoved;
moel@64
   130
    #pragma warning restore 67
moel@110
   131
moel@110
   132
    public void Accept(IVisitor visitor) {
moel@167
   133
      if (visitor == null)
moel@167
   134
        throw new ArgumentNullException("visitor");
moel@167
   135
      visitor.VisitHardware(this);
moel@110
   136
    }
moel@110
   137
moel@110
   138
    public void Traverse(IVisitor visitor) {
moel@130
   139
      foreach (IHardware hardware in superIOHardware)
moel@110
   140
        hardware.Accept(visitor);     
moel@110
   141
    }
moel@64
   142
  }
moel@64
   143
}