Exemplo n.º 1
0
        private void startArbiter()
        {
            diskAppearedCallback    disk_appeared_callback    = new diskAppearedCallback(NativeDiskAppeared);
            diskChangedCallback     disk_changed_callback     = new diskChangedCallback(NativeDiskChanged);
            diskDisappearedCallback disk_disappeared_callback = new diskDisappearedCallback(NativeDiskDisappeared);

            // create a DiskArbitration session
            IntPtr allocator = CoreFoundation.CFAllocatorGetDefault();

            da_session = DiskArbitration.DASessionCreate(allocator);

            this.callback_appeared    = Marshal.GetFunctionPointerForDelegate(disk_appeared_callback);
            this.callback_changed     = Marshal.GetFunctionPointerForDelegate(disk_changed_callback);
            this.callback_disappeared = Marshal.GetFunctionPointerForDelegate(disk_disappeared_callback);

            DiskArbitration.DARegisterDiskAppearedCallback(da_session, IntPtr.Zero, callback_appeared, IntPtr.Zero);
            DiskArbitration.DARegisterDiskDescriptionChangedCallback(da_session, IntPtr.Zero, IntPtr.Zero, callback_changed, IntPtr.Zero);
            DiskArbitration.DARegisterDiskDisappearedCallback(da_session, IntPtr.Zero, callback_disappeared, IntPtr.Zero);

            //IntPtr runloop = CFRunLoopGetCurrent ();
            runloop = MonoMac.CoreFoundation.CFRunLoop.Current.Handle;

            var mode = MonoMac.CoreFoundation.CFRunLoop.CFDefaultRunLoopMode.Handle;

            DiskArbitration.DASessionScheduleWithRunLoop(da_session, runloop, mode);

            // this blocks the thread
            CoreFoundation.CFRunLoopRun();

            // this code is actually never run, but keeps our native references
            // and callbacks alive to prevent the GC from removing it
            GC.KeepAlive(allocator);
            GC.KeepAlive(da_session);
            GC.KeepAlive(callback_changed);
            GC.KeepAlive(callback_appeared);
            GC.KeepAlive(callback_disappeared);
            GC.KeepAlive(disk_appeared_callback);
            GC.KeepAlive(disk_changed_callback);
            GC.KeepAlive(disk_disappeared_callback);
        }
Exemplo n.º 2
0
        private void startArbiter()
        {
            diskAppearedCallback disk_appeared_callback = new diskAppearedCallback (NativeDiskAppeared);
            diskChangedCallback disk_changed_callback = new diskChangedCallback (NativeDiskChanged);
            diskDisappearedCallback disk_disappeared_callback = new diskDisappearedCallback (NativeDiskDisappeared);

            // create a DiskArbitration session
            IntPtr allocator = CoreFoundation.CFAllocatorGetDefault ();
            da_session = DiskArbitration.DASessionCreate (allocator);

            this.callback_appeared = Marshal.GetFunctionPointerForDelegate (disk_appeared_callback);
            this.callback_changed = Marshal.GetFunctionPointerForDelegate (disk_changed_callback);
            this.callback_disappeared = Marshal.GetFunctionPointerForDelegate (disk_disappeared_callback);

            DiskArbitration.DARegisterDiskAppearedCallback (da_session, IntPtr.Zero, callback_appeared, IntPtr.Zero);
            DiskArbitration.DARegisterDiskDescriptionChangedCallback (da_session, IntPtr.Zero, IntPtr.Zero, callback_changed, IntPtr.Zero);
            DiskArbitration.DARegisterDiskDisappearedCallback (da_session, IntPtr.Zero, callback_disappeared, IntPtr.Zero);

            //IntPtr runloop = CFRunLoopGetCurrent ();
            runloop = MonoMac.CoreFoundation.CFRunLoop.Current.Handle;

            var mode = MonoMac.CoreFoundation.CFRunLoop.CFDefaultRunLoopMode.Handle;
            DiskArbitration.DASessionScheduleWithRunLoop (da_session, runloop, mode);

            // this blocks the thread
            CoreFoundation.CFRunLoopRun ();

            // this code is actually never run, but keeps our native references
            // and callbacks alive to prevent the GC from removing it
            GC.KeepAlive (allocator);
            GC.KeepAlive (da_session);
            GC.KeepAlive (callback_changed);
            GC.KeepAlive (callback_appeared);
            GC.KeepAlive (callback_disappeared);
            GC.KeepAlive (disk_appeared_callback);
            GC.KeepAlive (disk_changed_callback);
            GC.KeepAlive (disk_disappeared_callback);
        }