Hardware/ATI/ATIGroup.cs
author sl
Sun, 03 Feb 2013 18:01:50 +0100
changeset 391 ca4c0e7ae75d
parent 333 c34cbcc7df66
permissions -rw-r--r--
Converted project to VisualStudio 2012.
Adding SoundGraphDisplay and SensorFrontView classes.
They were respectively based on SystemTray and SensorNotifyIcon.
SoundGraphDisplay is now able to load iMONDisplay.dll providing it lives on your PATH.
Adding option to sensor context menu for adding it into FrontView.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Collections.Generic;
    13 using System.Globalization;
    14 using System.Text;
    15 
    16 namespace OpenHardwareMonitor.Hardware.ATI {
    17   internal class ATIGroup : IGroup {
    18 
    19     private readonly List<ATIGPU> hardware = new List<ATIGPU>();
    20     private readonly StringBuilder report = new StringBuilder();
    21 
    22     public ATIGroup(ISettings settings) {
    23       try {
    24         int status = ADL.ADL_Main_Control_Create(1);
    25 
    26         report.AppendLine("AMD Display Library");
    27         report.AppendLine();
    28         report.Append("Status: ");
    29         report.AppendLine(status == ADL.ADL_OK ? "OK" : 
    30           status.ToString(CultureInfo.InvariantCulture));
    31         report.AppendLine();
    32 
    33         if (status == ADL.ADL_OK) {
    34           int numberOfAdapters = 0;
    35           ADL.ADL_Adapter_NumberOfAdapters_Get(ref numberOfAdapters);
    36           
    37           report.Append("Number of adapters: "); 
    38           report.AppendLine(numberOfAdapters.ToString(CultureInfo.InvariantCulture));
    39           report.AppendLine();
    40 
    41           if (numberOfAdapters > 0) {
    42             ADLAdapterInfo[] adapterInfo = new ADLAdapterInfo[numberOfAdapters];
    43             if (ADL.ADL_Adapter_AdapterInfo_Get(adapterInfo) == ADL.ADL_OK)
    44               for (int i = 0; i < numberOfAdapters; i++) {
    45                 int isActive;
    46                 ADL.ADL_Adapter_Active_Get(adapterInfo[i].AdapterIndex,
    47                   out isActive);
    48                 int adapterID;
    49                 ADL.ADL_Adapter_ID_Get(adapterInfo[i].AdapterIndex,
    50                   out adapterID);
    51 
    52                 report.Append("AdapterIndex: "); 
    53                 report.AppendLine(i.ToString(CultureInfo.InvariantCulture));
    54                 report.Append("isActive: "); 
    55                 report.AppendLine(isActive.ToString(CultureInfo.InvariantCulture));
    56                 report.Append("AdapterName: "); 
    57                 report.AppendLine(adapterInfo[i].AdapterName);     
    58                 report.Append("UDID: ");
    59                 report.AppendLine(adapterInfo[i].UDID);
    60                 report.Append("Present: ");
    61                 report.AppendLine(adapterInfo[i].Present.ToString(
    62                   CultureInfo.InvariantCulture));
    63                 report.Append("VendorID: 0x");
    64                 report.AppendLine(adapterInfo[i].VendorID.ToString("X",
    65                   CultureInfo.InvariantCulture));
    66                 report.Append("BusNumber: ");
    67                 report.AppendLine(adapterInfo[i].BusNumber.ToString(
    68                   CultureInfo.InvariantCulture));
    69                 report.Append("DeviceNumber: ");
    70                 report.AppendLine(adapterInfo[i].DeviceNumber.ToString(
    71                  CultureInfo.InvariantCulture));
    72                 report.Append("FunctionNumber: ");
    73                 report.AppendLine(adapterInfo[i].FunctionNumber.ToString(
    74                   CultureInfo.InvariantCulture));
    75                 report.Append("AdapterID: 0x");
    76                 report.AppendLine(adapterID.ToString("X", 
    77                   CultureInfo.InvariantCulture));
    78 
    79                 if (!string.IsNullOrEmpty(adapterInfo[i].UDID) &&
    80                   adapterInfo[i].VendorID == ADL.ATI_VENDOR_ID) 
    81                 {
    82                   bool found = false;
    83                   foreach (ATIGPU gpu in hardware)
    84                     if (gpu.BusNumber == adapterInfo[i].BusNumber &&
    85                       gpu.DeviceNumber == adapterInfo[i].DeviceNumber) {
    86                       found = true;
    87                       break;
    88                     }
    89                   if (!found)
    90                     hardware.Add(new ATIGPU(
    91                       adapterInfo[i].AdapterName.Trim(),
    92                       adapterInfo[i].AdapterIndex,
    93                       adapterInfo[i].BusNumber,
    94                       adapterInfo[i].DeviceNumber, settings));
    95                 }
    96 
    97                 report.AppendLine();
    98               }
    99           }
   100         }
   101       } catch (DllNotFoundException) { } 
   102         catch (EntryPointNotFoundException e) {
   103           report.AppendLine();
   104           report.AppendLine(e.ToString());
   105           report.AppendLine();        
   106         }
   107     }
   108 
   109     public IHardware[] Hardware {
   110       get {
   111         return hardware.ToArray();
   112       }
   113     }
   114 
   115     public string GetReport() {
   116       return report.ToString();
   117     }
   118 
   119     public void Close() {
   120       try {
   121         foreach (ATIGPU gpu in hardware)
   122           gpu.Close();
   123         ADL.ADL_Main_Control_Destroy();
   124       } catch (Exception) { }
   125     }
   126   }
   127 }