private string SafelyGetString(string name) { try { if (device.PropertyExists(name)) { return(device[name]); } } catch {} return(null); }
public static UsbDevice Resolve(Hal.Manager manager, Hal.Device device) { if (device["info.subsystem"] == "usb_device" && device.PropertyExists("usb_device.product_id") && device.PropertyExists("usb_device.vendor_id")) { return(new UsbDevice(manager, device)); } return(null); }
public static BlockDevice Resolve <T> (Hal.Manager manager, Hal.Device device) where T : IBlockDevice { if (device.QueryCapability("block") && device.PropertyExists("block.device")) { if (typeof(T) == typeof(ICdromDevice)) { return(CdromDevice.Resolve(manager, device)); } else if (typeof(T) == typeof(IDiskDevice)) { return(DiskDevice.Resolve(manager, device)); } return((BlockDevice)CdromDevice.Resolve(manager, device) ?? (BlockDevice)DiskDevice.Resolve(manager, device)); } return(null); }
public bool PropertyExists(string key) { return(device.PropertyExists(key)); }
private static Stack <Hal.Device> CollectUsbDeviceStack(Hal.Device device) { Stack <Hal.Device> device_stack = new Stack <Hal.Device> (); int usb_vendor_id = -1; int usb_product_id = -1; Hal.Device tmp_device = device; while (tmp_device != null) { // Skip the SCSI parents of the volume if they are in the tree if ((tmp_device.PropertyExists("info.bus") && tmp_device["info.bus"] == "scsi") || (tmp_device.PropertyExists("info.category") && tmp_device["info.category"] == "scsi_host")) { device_stack.Push(tmp_device); tmp_device = tmp_device.Parent; continue; } bool have_usb_ids = false; int _usb_vendor_id = -1; int _usb_product_id = -1; // Figure out the IDs if they exist if (tmp_device.PropertyExists("usb.vendor_id") && tmp_device.PropertyExists("usb.product_id")) { _usb_vendor_id = tmp_device.GetPropertyInteger("usb.vendor_id"); _usb_product_id = tmp_device.GetPropertyInteger("usb.product_id"); have_usb_ids = true; } else if (tmp_device.PropertyExists("usb_device.vendor_id") && tmp_device.PropertyExists("usb_device.product_id")) { _usb_vendor_id = tmp_device.GetPropertyInteger("usb_device.vendor_id"); _usb_product_id = tmp_device.GetPropertyInteger("usb_device.product_id"); have_usb_ids = true; } if (have_usb_ids) { if (usb_vendor_id == -1 && usb_product_id == -1) { // We found the first raw USB device, remember it usb_vendor_id = _usb_vendor_id; usb_product_id = _usb_product_id; } else if (usb_vendor_id != _usb_vendor_id || usb_product_id != _usb_product_id) { // We are no longer looking at the device we care about (could now be at a hub or something) break; } } else if (usb_vendor_id != -1 || usb_product_id != -1) { // We are no longer even looking at USB devices break; } device_stack.Push(tmp_device); tmp_device = tmp_device.Parent; } return(device_stack); }