Esempio n. 1
0
        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));
                }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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");
        }
Esempio n. 5
0
 public UsbDevice(DeviceArguments arguments)
     : base(arguments)
 {
 }
Esempio n. 6
0
        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));
                    }
                }
            }
        }
Esempio n. 7
0
        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));
                }
            }
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 public DiscVolume(DeviceArguments arguments, IBlockDevice b)
     : base(arguments, b)
 {
 }
Esempio n. 11
0
 public Volume(DeviceArguments arguments, IBlockDevice blockdevice)
     : base(arguments)
 {
     block_parent = blockdevice;
 }
Esempio n. 12
0
 public Volume(DeviceArguments arguments)
     : base(arguments)
 {
 }