PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/Hardware/Mainboard/Mainboard.cs

http://open-hardware-monitor.googlecode.com/
C# | 147 lines | 113 code | 25 blank | 9 comment | 24 complexity | 11b6c2f6fef0fe5f26c312e2684271a3 MD5 | raw file
Possible License(s): BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. This Source Code Form is subject to the terms of the Mozilla Public
  3. License, v. 2.0. If a copy of the MPL was not distributed with this
  4. file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. Copyright (C) 2009-2012 Michael M??ller <mmoeller@openhardwaremonitor.org>
  6. */
  7. using System;
  8. using System.Text;
  9. using OpenHardwareMonitor.Hardware.LPC;
  10. namespace OpenHardwareMonitor.Hardware.Mainboard {
  11. internal class Mainboard : IHardware {
  12. private readonly SMBIOS smbios;
  13. private readonly string name;
  14. private string customName;
  15. private readonly ISettings settings;
  16. private readonly LPCIO lpcio;
  17. private readonly LMSensors lmSensors;
  18. private readonly Hardware[] superIOHardware;
  19. public Mainboard(SMBIOS smbios, ISettings settings) {
  20. this.settings = settings;
  21. this.smbios = smbios;
  22. Manufacturer manufacturer = smbios.Board == null ? Manufacturer.Unknown :
  23. Identification.GetManufacturer(smbios.Board.ManufacturerName);
  24. Model model = smbios.Board == null ? Model.Unknown :
  25. Identification.GetModel(smbios.Board.ProductName);
  26. if (smbios.Board != null) {
  27. if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
  28. if (manufacturer == Manufacturer.Unknown)
  29. this.name = smbios.Board.ProductName;
  30. else
  31. this.name = manufacturer + " " +
  32. smbios.Board.ProductName;
  33. } else {
  34. this.name = manufacturer.ToString();
  35. }
  36. } else {
  37. this.name = Manufacturer.Unknown.ToString();
  38. }
  39. this.customName = settings.GetValue(
  40. new Identifier(Identifier, "name").ToString(), name);
  41. ISuperIO[] superIO;
  42. int p = (int)Environment.OSVersion.Platform;
  43. if ((p == 4) || (p == 128)) {
  44. this.lmSensors = new LMSensors();
  45. superIO = lmSensors.SuperIO;
  46. } else {
  47. this.lpcio = new LPCIO();
  48. superIO = lpcio.SuperIO;
  49. }
  50. superIOHardware = new Hardware[superIO.Length];
  51. for (int i = 0; i < superIO.Length; i++)
  52. superIOHardware[i] = new SuperIOHardware(this, superIO[i],
  53. manufacturer, model, settings);
  54. }
  55. public string Name {
  56. get {
  57. return customName;
  58. }
  59. set {
  60. if (!string.IsNullOrEmpty(value))
  61. customName = value;
  62. else
  63. customName = name;
  64. settings.SetValue(new Identifier(Identifier, "name").ToString(),
  65. customName);
  66. }
  67. }
  68. public Identifier Identifier {
  69. get { return new Identifier("mainboard"); }
  70. }
  71. public HardwareType HardwareType {
  72. get { return HardwareType.Mainboard; }
  73. }
  74. public virtual IHardware Parent {
  75. get { return null; }
  76. }
  77. public string GetReport() {
  78. StringBuilder r = new StringBuilder();
  79. r.AppendLine("Mainboard");
  80. r.AppendLine();
  81. r.Append(smbios.GetReport());
  82. if (lpcio != null)
  83. r.Append(lpcio.GetReport());
  84. byte[] table =
  85. FirmwareTable.GetTable(FirmwareTable.Provider.ACPI, "TAMG");
  86. if (table != null) {
  87. GigabyteTAMG tamg = new GigabyteTAMG(table);
  88. r.Append(tamg.GetReport());
  89. }
  90. return r.ToString();
  91. }
  92. public void Update() { }
  93. public void Close() {
  94. if (lmSensors != null)
  95. lmSensors.Close();
  96. foreach (Hardware hardware in superIOHardware)
  97. hardware.Close();
  98. }
  99. public IHardware[] SubHardware {
  100. get { return superIOHardware; }
  101. }
  102. public ISensor[] Sensors {
  103. get { return new ISensor[0]; }
  104. }
  105. #pragma warning disable 67
  106. public event SensorEventHandler SensorAdded;
  107. public event SensorEventHandler SensorRemoved;
  108. #pragma warning restore 67
  109. public void Accept(IVisitor visitor) {
  110. if (visitor == null)
  111. throw new ArgumentNullException("visitor");
  112. visitor.VisitHardware(this);
  113. }
  114. public void Traverse(IVisitor visitor) {
  115. foreach (IHardware hardware in superIOHardware)
  116. hardware.Accept(visitor);
  117. }
  118. }
  119. }