Hardware/Mainboard/Mainboard.cs
author moel.mich
Mon, 01 Oct 2012 17:10:09 +0000
changeset 381 ed5d5fc482ed
parent 344 3145aadca3d2
permissions -rw-r--r--
Changed a few types to internal (instead of public) in the Open Hardware Monitor library.
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@370
     7
  Copyright (C) 2009-2012 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@370
    25
    public Mainboard(SMBIOS smbios, ISettings settings) {
moel@275
    26
      this.settings = settings;
moel@370
    27
      this.smbios = smbios;
moel@370
    28
moel@370
    29
      Manufacturer manufacturer = smbios.Board == null ? Manufacturer.Unknown :
moel@370
    30
        Identification.GetManufacturer(smbios.Board.ManufacturerName);
moel@370
    31
moel@370
    32
      Model model = smbios.Board == null ? Model.Unknown : 
moel@370
    33
        Identification.GetModel(smbios.Board.ProductName);
moel@370
    34
moel@76
    35
      if (smbios.Board != null) {
moel@167
    36
        if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
moel@370
    37
          if (manufacturer == Manufacturer.Unknown)
moel@76
    38
            this.name = smbios.Board.ProductName;
moel@76
    39
          else
moel@370
    40
            this.name = manufacturer + " " +
moel@76
    41
              smbios.Board.ProductName;
moel@76
    42
        } else {
moel@370
    43
          this.name = manufacturer.ToString();
moel@76
    44
        }
moel@64
    45
      } else {
moel@126
    46
        this.name = Manufacturer.Unknown.ToString();
moel@64
    47
      }
moel@76
    48
moel@275
    49
      this.customName = settings.GetValue(
moel@275
    50
        new Identifier(Identifier, "name").ToString(), name);
moel@275
    51
moel@135
    52
      ISuperIO[] superIO;
moel@195
    53
      int p = (int)Environment.OSVersion.Platform;
moel@135
    54
      if ((p == 4) || (p == 128)) {
moel@135
    55
        this.lmSensors = new LMSensors();
moel@135
    56
        superIO = lmSensors.SuperIO;
moel@135
    57
      } else {
moel@135
    58
        this.lpcio = new LPCIO();       
moel@135
    59
        superIO = lpcio.SuperIO;
moel@135
    60
      }
moel@135
    61
      
moel@298
    62
      superIOHardware = new Hardware[superIO.Length];
moel@130
    63
      for (int i = 0; i < superIO.Length; i++)
moel@370
    64
        superIOHardware[i] = new SuperIOHardware(this, superIO[i],
moel@370
    65
          manufacturer, model, settings);
moel@64
    66
    }
moel@64
    67
moel@64
    68
    public string Name {
moel@275
    69
      get {
moel@275
    70
        return customName;
moel@275
    71
      }
moel@275
    72
      set {
moel@275
    73
        if (!string.IsNullOrEmpty(value))
moel@275
    74
          customName = value;
moel@275
    75
        else
moel@275
    76
          customName = name;
moel@275
    77
        settings.SetValue(new Identifier(Identifier, "name").ToString(),
moel@275
    78
          customName);
moel@275
    79
      }
moel@64
    80
    }
moel@64
    81
moel@109
    82
    public Identifier Identifier {
moel@109
    83
      get { return new Identifier("mainboard"); }
moel@64
    84
    }
moel@64
    85
moel@165
    86
    public HardwareType HardwareType {
moel@165
    87
      get { return HardwareType.Mainboard; }
moel@64
    88
    }
moel@64
    89
moel@176
    90
    public virtual IHardware Parent {
moel@176
    91
      get { return null; }
moel@176
    92
    }
moel@176
    93
moel@64
    94
    public string GetReport() {
moel@64
    95
      StringBuilder r = new StringBuilder(); 
moel@64
    96
moel@64
    97
      r.AppendLine("Mainboard");
moel@64
    98
      r.AppendLine();           
moel@64
    99
      r.Append(smbios.GetReport());
moel@64
   100
moel@136
   101
      if (lpcio != null)
moel@136
   102
        r.Append(lpcio.GetReport());
moel@67
   103
moel@308
   104
      byte[] table = 
moel@308
   105
        FirmwareTable.GetTable(FirmwareTable.Provider.ACPI, "TAMG");
moel@308
   106
      if (table != null) {
moel@308
   107
        GigabyteTAMG tamg = new GigabyteTAMG(table);
moel@308
   108
        r.Append(tamg.GetReport());
moel@308
   109
      }
moel@308
   110
moel@64
   111
      return r.ToString();
moel@64
   112
    }
moel@64
   113
moel@64
   114
    public void Update() { }
moel@64
   115
moel@135
   116
    public void Close() {
moel@135
   117
      if (lmSensors != null)
moel@135
   118
        lmSensors.Close();
moel@298
   119
      foreach (Hardware hardware in superIOHardware)
moel@298
   120
        hardware.Close();
moel@135
   121
    }
moel@64
   122
moel@64
   123
    public IHardware[] SubHardware {
moel@130
   124
      get { return superIOHardware; }
moel@64
   125
    }
moel@64
   126
moel@64
   127
    public ISensor[] Sensors {
moel@64
   128
      get { return new ISensor[0]; }
moel@64
   129
    }
moel@64
   130
moel@64
   131
    #pragma warning disable 67
moel@64
   132
    public event SensorEventHandler SensorAdded;
moel@64
   133
    public event SensorEventHandler SensorRemoved;
moel@64
   134
    #pragma warning restore 67
moel@110
   135
moel@110
   136
    public void Accept(IVisitor visitor) {
moel@167
   137
      if (visitor == null)
moel@167
   138
        throw new ArgumentNullException("visitor");
moel@167
   139
      visitor.VisitHardware(this);
moel@110
   140
    }
moel@110
   141
moel@110
   142
    public void Traverse(IVisitor visitor) {
moel@130
   143
      foreach (IHardware hardware in superIOHardware)
moel@110
   144
        hardware.Accept(visitor);     
moel@110
   145
    }
moel@64
   146
  }
moel@64
   147
}