Mercurial > hg > ucis.core
comparison 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 |
comparison
equal
deleted
inserted
replaced
59:4e1a5dec786a | 60:3424fa5a12c9 |
---|---|
1 using System; | 1 using System; |
2 using System.Runtime.InteropServices; | 2 using System.Collections.Generic; |
3 using Microsoft.Win32.SafeHandles; | 3 using Microsoft.Win32.SafeHandles; |
4 using UCIS.HWLib.Windows.Devices; | 4 using UCIS.HWLib.Windows.Devices; |
5 using UCIS.USBLib.Internal.Windows; | 5 using UCIS.USBLib.Internal.Windows; |
6 | 6 |
7 namespace UCIS.HWLib.Windows.USB { | 7 namespace UCIS.HWLib.Windows.USB { |
8 public class UsbController { | 8 public class UsbController { |
9 static readonly Guid IID_DEVINTERFACE_USB_CONTROLLER = new Guid(UsbApi.GUID_DEVINTERFACE_HUBCONTROLLER); | |
9 public String DevicePath { get; private set; } | 10 public String DevicePath { get; private set; } |
10 public DeviceNode DeviceNode { get; private set; } | 11 public DeviceNode DeviceNode { get; private set; } |
11 public String DeviceDescription { | 12 public String DeviceDescription { get { return DeviceNode.DeviceDescription; } } |
12 get { return DeviceNode.GetPropertyString(SPDRP.DeviceDesc); } | 13 public String DriverKey { get { return DeviceNode.DriverKey; } } |
13 } | |
14 public String DriverKey { | |
15 get { return DeviceNode.GetPropertyString(SPDRP.Driver); } | |
16 } | |
17 public UsbHub RootHub { | 14 public UsbHub RootHub { |
18 get { | 15 get { |
19 String rootHubName; | 16 String rootHubName; |
20 using (SafeFileHandle handle = UsbHub.OpenHandle(DevicePath)) rootHubName = UsbHub.GetRootHubName(handle); | 17 using (SafeFileHandle handle = UsbHub.OpenHandle(DevicePath)) rootHubName = UsbHub.GetRootHubName(handle); |
21 return new UsbHub(null, new USB_NODE_CONNECTION_INFORMATION_EX(), @"\\?\" + rootHubName, 0, true); | 18 return new UsbHub(null, new USB_NODE_CONNECTION_INFORMATION_EX(), @"\\?\" + rootHubName, 0, true); |
22 } | 19 } |
23 } | 20 } |
24 internal UsbController(UsbBus parent, DeviceNode di, String devicePath) { | 21 private UsbController(DeviceNode di, String devicePath) { |
25 this.DeviceNode = di; | 22 this.DeviceNode = di; |
26 this.DevicePath = devicePath; | 23 this.DevicePath = devicePath; |
27 } | 24 } |
25 | |
26 public static UsbController GetControllerForDeviceNode(DeviceNode node) { | |
27 String[] interfaces = node.GetInterfaces(IID_DEVINTERFACE_USB_CONTROLLER); | |
28 if (interfaces == null || interfaces.Length == 0) return null; | |
29 return new UsbController(node, interfaces[0]); | |
30 } | |
31 | |
32 public static IList<UsbController> GetControllers() { | |
33 IList<UsbController> devices = new List<UsbController>(); | |
34 foreach (DeviceNode dev in DeviceNode.GetDevices(IID_DEVINTERFACE_USB_CONTROLLER)) { | |
35 UsbController controller = GetControllerForDeviceNode(dev); | |
36 if (controller != null) devices.Add(controller); | |
37 } | |
38 return devices; | |
39 } | |
28 } | 40 } |
29 } | 41 } |