Hardware/Mainboard/Mainboard.cs
author moel.mich
Sat, 25 Jun 2011 14:46:28 +0000
changeset 304 16a86362c2ca
parent 275 35788ddd1825
child 308 d882720734bf
permissions -rw-r--r--
Changed the maximum buffer size for double buffering of controls that isn't disposed after each draw call to the size of the screen. This should reduce the memory allocation and disposing on each sensor update. Also page faults are no longer increasing with this change.
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@165
    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@64
   127
      return r.ToString();
moel@64
   128
    }
moel@64
   129
moel@64
   130
    public void Update() { }
moel@64
   131
moel@135
   132
    public void Close() {
moel@135
   133
      if (lmSensors != null)
moel@135
   134
        lmSensors.Close();
moel@298
   135
      foreach (Hardware hardware in superIOHardware)
moel@298
   136
        hardware.Close();
moel@135
   137
    }
moel@64
   138
moel@64
   139
    public IHardware[] SubHardware {
moel@130
   140
      get { return superIOHardware; }
moel@64
   141
    }
moel@64
   142
moel@64
   143
    public ISensor[] Sensors {
moel@64
   144
      get { return new ISensor[0]; }
moel@64
   145
    }
moel@64
   146
moel@64
   147
    #pragma warning disable 67
moel@64
   148
    public event SensorEventHandler SensorAdded;
moel@64
   149
    public event SensorEventHandler SensorRemoved;
moel@64
   150
    #pragma warning restore 67
moel@110
   151
moel@110
   152
    public void Accept(IVisitor visitor) {
moel@167
   153
      if (visitor == null)
moel@167
   154
        throw new ArgumentNullException("visitor");
moel@167
   155
      visitor.VisitHardware(this);
moel@110
   156
    }
moel@110
   157
moel@110
   158
    public void Traverse(IVisitor visitor) {
moel@130
   159
      foreach (IHardware hardware in superIOHardware)
moel@110
   160
        hardware.Accept(visitor);     
moel@110
   161
    }
moel@64
   162
  }
moel@64
   163
}