private void DeviceAppeared (object o, DeviceArguments args) { Device device = new Device (args); Hyena.Log.DebugFormat ("device appeared: {0}, path: {1}", device.Uuid, args.DeviceProperties.GetStringValue ("DAVolumePath")); lock (this) { // only handle devices which have a VolumePath (=MountPoint) if (!args.DeviceProperties.HasKey ("DAVolumePath")) { return; } var protocol = args.DeviceProperties.GetStringValue ("DADeviceProtocol"); IDevice new_device = null; if (!string.IsNullOrEmpty (protocol) && protocol == "USB") { new_device = new UsbVolume (args); } else { new_device = new Volume (args, null); } // avoid adding a device twice - might happen since DeviceAppeared and DeviceChanged both fire var old_device = devices.Where (v => { return v.Uuid == new_device.Uuid; }).FirstOrDefault (); if (old_device != null) { return; } if (new_device != null) { devices.Add (new_device); // Notify that a device was added (i.e. to refresh device list) DeviceAdded (this, new DeviceAddedArgs ((IDevice) new_device)); } } }
private void NativeDiskDisappeared(IntPtr disk, IntPtr context) { if (this.DeviceDisappeared == null) { // if no-one subscribed to this event, do nothing return; } IntPtr device = DiskArbitration.DADiskCopyIOMedia(disk); IntPtr propertiesRef = DiskArbitration.DADiskCopyDescription(disk); NSDictionary properties = new NSDictionary(propertiesRef); DeviceArguments deviceArguments = new DeviceArguments(properties, this); if (properties.HasKey("DADeviceProtocol") && properties.GetStringValue("DADeviceProtocol") == "USB") { OsxUsbData usb = new OsxUsbData(device); deviceArguments.UsbInfo = usb; } IOKit.IOObjectRelease(device); this.DeviceDisappeared(this, deviceArguments); GC.KeepAlive(this); }
private void NativeDiskChanged(IntPtr disk, IntPtr keys, IntPtr context) { if (this.DeviceChanged == null) { // if no-one subscribed to this event, do nothing return; } IntPtr device = DiskArbitration.DADiskCopyIOMedia(disk); IntPtr propertiesRef = DiskArbitration.DADiskCopyDescription(disk); // using MonoMac we can get a managed NSDictionary from the pointer NSDictionary properties = new NSDictionary(propertiesRef); DeviceArguments deviceArguments = new DeviceArguments(properties, this); if (properties.HasKey("DADeviceProtocol") && properties.GetStringValue("DADeviceProtocol") == "USB") { OsxUsbData usb = new OsxUsbData(device); deviceArguments.UsbInfo = usb; } IOKit.IOObjectRelease(device); // trigger the public event for any subscribers this.DeviceChanged(this, deviceArguments); GC.KeepAlive(this); }
public Device(DeviceArguments arguments) { this.deviceArguments = arguments; // copy values from the NSDictionary so we don't rely on it later this.vendor = deviceArguments.DeviceProperties.GetStringValue("DADeviceVendor"); this.uuid = GetUUIDFromProperties (deviceArguments.DeviceProperties); this.name = deviceArguments.DeviceProperties.GetStringValue ("DAVolumeName"); if (string.IsNullOrEmpty (this.name)) { this.name = deviceArguments.DeviceProperties.GetStringValue ("DAMediaName"); } this.product = deviceArguments.DeviceProperties.GetStringValue("DADeviceModel"); }
public UsbDevice(DeviceArguments arguments) : base(arguments) { }
private void OnDeviceDisappeared(object o, DeviceArguments args) { Device device = new Device (args); Hyena.Log.InformationFormat ("device disappeared: {0}, path: {1}", device.Uuid, args.DeviceProperties.GetStringValue ("DAVolumePath")); lock (this) { var old_device = devices.Where (d => d.Uuid == device.Uuid).FirstOrDefault (); if (old_device != null) { devices.Remove (old_device); var removed_handler = DeviceRemoved; if (removed_handler != null) { removed_handler (this, new DeviceRemovedArgs (old_device.Uuid)); } } } }
private void OnDeviceChanged(object o, DeviceArguments args) { Device device = new Device (args); Hyena.Log.DebugFormat ("device changed: {0}, path: {1}", device.Uuid, args.DeviceProperties.GetStringValue ("DAVolumePath")); lock (this) { var old_device = devices.Where (d => d.Uuid == device.Uuid).FirstOrDefault (); if (old_device != null) { // a device that was currently attached has changed // remove the device and immediately re-add it devices.Remove (old_device); var remove_handler = DeviceRemoved; if (remove_handler != null) { remove_handler (old_device, new DeviceRemovedArgs (old_device.Uuid)); } } // do not add device without a VolumePath (=MountPoint) if (!args.DeviceProperties.HasKey ("DAVolumePath")) { return; } IDevice new_device = null; var protocol = args.DeviceProperties.GetStringValue ("DADeviceProtocol"); if (!string.IsNullOrEmpty (protocol) && protocol == "USB") { new_device = new UsbVolume (args); } else { new_device = new Volume (args); } devices.Add (new_device); var added_handler = DeviceAdded; if (added_handler != null) { added_handler (this, new DeviceAddedArgs ((IDevice)new_device)); } } }
private void NativeDiskDisappeared(IntPtr disk, IntPtr context) { if (this.DeviceDisappeared == null) { // if no-one subscribed to this event, do nothing return; } IntPtr device = DiskArbitration.DADiskCopyIOMedia (disk); IntPtr propertiesRef = DiskArbitration.DADiskCopyDescription (disk); NSDictionary properties = new NSDictionary (propertiesRef); DeviceArguments deviceArguments = new DeviceArguments (properties, this); if (properties.HasKey ("DADeviceProtocol") && properties.GetStringValue ("DADeviceProtocol") == "USB") { OsxUsbData usb = new OsxUsbData (device); deviceArguments.UsbInfo = usb; } IOKit.IOObjectRelease (device); this.DeviceDisappeared (this, deviceArguments); GC.KeepAlive (this); }
private void NativeDiskChanged(IntPtr disk, IntPtr keys, IntPtr context) { if (this.DeviceChanged == null) { // if no-one subscribed to this event, do nothing return; } IntPtr device = DiskArbitration.DADiskCopyIOMedia (disk); IntPtr propertiesRef = DiskArbitration.DADiskCopyDescription (disk); // using MonoMac we can get a managed NSDictionary from the pointer NSDictionary properties = new NSDictionary (propertiesRef); DeviceArguments deviceArguments = new DeviceArguments (properties, this); if (properties.HasKey ("DADeviceProtocol") && properties.GetStringValue ("DADeviceProtocol") == "USB") { OsxUsbData usb = new OsxUsbData (device); deviceArguments.UsbInfo = usb; } IOKit.IOObjectRelease (device); // trigger the public event for any subscribers this.DeviceChanged (this, deviceArguments); GC.KeepAlive (this); }
public DiscVolume(DeviceArguments arguments, IBlockDevice b) : base(arguments, b) { }
public Volume(DeviceArguments arguments, IBlockDevice blockdevice) : base(arguments) { block_parent = blockdevice; }
public Volume(DeviceArguments arguments) : base(arguments) { }