diff USBLib/Windows/USB/UsbController.cs @ 60:3424fa5a12c9

Updated Windows USB enumeration classes and VBoxUSB backend
author Ivo Smits <Ivo@UCIS.nl>
date Sat, 12 Oct 2013 16:35:24 +0200
parents fd63c453ff65
children edc41c861d96
line wrap: on
line diff
--- a/USBLib/Windows/USB/UsbController.cs	Wed Oct 09 20:56:28 2013 +0200
+++ b/USBLib/Windows/USB/UsbController.cs	Sat Oct 12 16:35:24 2013 +0200
@@ -1,19 +1,16 @@
 using System;
-using System.Runtime.InteropServices;
+using System.Collections.Generic;
 using Microsoft.Win32.SafeHandles;
 using UCIS.HWLib.Windows.Devices;
 using UCIS.USBLib.Internal.Windows;
 
 namespace UCIS.HWLib.Windows.USB {
 	public class UsbController {
+		static readonly Guid IID_DEVINTERFACE_USB_CONTROLLER = new Guid(UsbApi.GUID_DEVINTERFACE_HUBCONTROLLER);
 		public String DevicePath { get; private set; }
 		public DeviceNode DeviceNode { get; private set; }
-		public String DeviceDescription {
-			get { return DeviceNode.GetPropertyString(SPDRP.DeviceDesc); }
-		}
-		public String DriverKey {
-			get { return DeviceNode.GetPropertyString(SPDRP.Driver); }
-		}
+		public String DeviceDescription { get { return DeviceNode.DeviceDescription; } }
+		public String DriverKey { get { return DeviceNode.DriverKey; } }
 		public UsbHub RootHub {
 			get {
 				String rootHubName;
@@ -21,9 +18,24 @@
 				return new UsbHub(null, new USB_NODE_CONNECTION_INFORMATION_EX(), @"\\?\" + rootHubName, 0, true);
 			}
 		}
-		internal UsbController(UsbBus parent, DeviceNode di, String devicePath) {
+		private UsbController(DeviceNode di, String devicePath) {
 			this.DeviceNode = di;
 			this.DevicePath = devicePath;
 		}
+
+		public static UsbController GetControllerForDeviceNode(DeviceNode node) {
+			String[] interfaces = node.GetInterfaces(IID_DEVINTERFACE_USB_CONTROLLER);
+			if (interfaces == null || interfaces.Length == 0) return null;
+			return new UsbController(node, interfaces[0]);
+		}
+
+		public static IList<UsbController> GetControllers() {
+			IList<UsbController>  devices = new List<UsbController>();
+			foreach (DeviceNode dev in DeviceNode.GetDevices(IID_DEVINTERFACE_USB_CONTROLLER)) {
+				UsbController controller = GetControllerForDeviceNode(dev);
+				if (controller != null) devices.Add(controller);
+			}
+			return devices;
+		}
 	}
 }