Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        internal OsxUsbData(IntPtr registry_entry)
        {
            // 1st approach - get IODeviceTree's parent locationID, then find by location ID

            /*string path = properties.GetStringValue ("DAMediaPath");
             * IntPtr entry = IORegistryEntryFromPath (IntPtr.Zero, path);
             * CFString s = new CFString ("locationID");
             * IntPtr plane = new CFString ("IODeviceTree").Handle;
             * IntPtr parent = IntPtr.Zero;
             * IORegistryEntryGetParentEntry (entry, "IODeviceTree", out parent);
             * if (parent != IntPtr.Zero) {
             *  IntPtr ptr = IORegistryEntryCreateCFProperty (parent, s.Handle, IntPtr.Zero, 0);
             *  CFShow (ptr);
             * }*/
            // TODO recursive find

            // 2nd approach - walk the tree (which one?) up until we find
            // a idVendor - at worst, up to the root
            IntPtr cf_ref;

            // populate properties from the usb device info

            cf_ref = IOKit.GetUsbProperty(registry_entry, "idVendor");
            if (cf_ref != IntPtr.Zero)
            {
                Int32 num;
                CoreFoundation.CFNumberGetValue(cf_ref, 3, out num);
                VendorId = (uint)num;
            }

            cf_ref = IOKit.GetUsbProperty(registry_entry, "idProduct");
            if (cf_ref != IntPtr.Zero)
            {
                Int32 num;
                CoreFoundation.CFNumberGetValue(cf_ref, 3, out num);
                ProductId = (uint)num;
            }

            cf_ref = IOKit.GetUsbProperty(registry_entry, "USB Vendor Name");
            if (cf_ref != IntPtr.Zero)
            {
                VendorName = new CFString(cf_ref).ToString();
            }

            cf_ref = IOKit.GetUsbProperty(registry_entry, "USB Product Name");
            if (cf_ref != IntPtr.Zero)
            {
                ProductName = new CFString(cf_ref).ToString();
            }

            cf_ref = IOKit.GetUsbProperty(registry_entry, "USB Serial Number");
            if (cf_ref != IntPtr.Zero)
            {
                UsbSerial = new CFString(cf_ref).ToString();
            }
        }
        public static IntPtr GetUsbProperty(IntPtr registry_entry, CFString key)
        {
            if (registry_entry == IntPtr.Zero || key.Handle == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            IntPtr parent_entry = IOKit.FindInParent(registry_entry, key);

            if (parent_entry == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            IntPtr ptr = IORegistryEntryCreateCFProperty(parent_entry, key.Handle, IntPtr.Zero, 0);

            //CFShow (ptr);
            return(ptr);
        }