public void ScheduleInCFRunLoop (CFRunLoop runloop, NSString mode)
		{
			if (notifying)
				return;
			notifying = true;
			Notify (CFStreamEventType.HasBytesAvailable);
			notifying = false;
		}
Exemplo n.º 2
0
 /// <summary>
 /// Removes a CFRunLoopSource. Necessary because we can't directly construct CFRunLoopSource from native IntPtr values in MonoMac.
 /// </summary>
 /// <param name="loop">The CFRunLoop from which the source is to be removed.</param>
 /// <param name="source">The CFRunLoopSource to remove.</param>
 /// <param name="mode">The mode for the run loop.</param>
 /// <returns><c>true</c> if the CFRunLoopSource was removed.</returns>
 public static bool CFRunLoopRemoveSource(CFRunLoop loop, System.IntPtr source, NSString mode)
 {
     if (mode == null)
     {
         throw new System.ArgumentNullException("mode");
     }
     return(CFRunLoopRemoveSource(loop.Handle, source, mode.Handle));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a CFRunLoopSource. Necessary because we can't directly construct CFRunLoopSource from native IntPtr values in MonoMac.
        /// </summary>
        /// <param name="loop">The CFRunLoop to which the source is to be added.</param>
        /// <param name="source">The CFRunLoopSource to add.</param>
        /// <param name="mode">The mode for the run loop.</param>
        public static void CFRunLoopAddSource(CFRunLoop loop, System.IntPtr source, NSString mode)
        {
            if (mode == null)
            {
                throw new System.ArgumentNullException("mode");
            }

            CFRunLoopAddSource(loop.Handle, source, mode.Handle);
        }
Exemplo n.º 4
0
 public void ScheduleInCFRunLoop(CFRunLoop runloop, NSString mode)
 {
     if (notifying)
     {
         return;
     }
     notifying = true;
     Notify(CFStreamEventType.HasBytesAvailable);
     notifying = false;
 }
        public bool Schedule(CFRunLoop runLoop, string mode)
        {
            if (runLoop == null)
            {
                throw new ArgumentNullException("runLoop");
            }

            // new CFString already does a null check
            using (var cfstring = new CFString(mode)){
                return(SCNetworkReachabilityScheduleWithRunLoop(handle, runLoop.Handle, cfstring.Handle));
            }
        }
Exemplo n.º 6
0
 public void UnscheduleFromRunLoop(CFRunLoop runLoop, NSString mode)
 {
     ThrowIfDisposed();
     if (runLoop == null)
     {
         throw new ArgumentNullException("runLoop");
     }
     if (mode == null)
     {
         throw new ArgumentNullException("mode");
     }
     IOHIDManagerUnscheduleFromRunLoop(Handle, runLoop.Handle, mode.Handle);
 }
Exemplo n.º 7
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop, NSString runLoopMode)
 {
     ThrowIfDisposed();
     if (runLoop == null)
     {
         throw new ArgumentNullException("runLoop");
     }
     if (runLoopMode == null)
     {
         throw new ArgumentNullException("runLoopMode");
     }
     IOHIDDeviceScheduleWithRunLoop(Handle, runLoop.Handle, runLoopMode.Handle);
 }
Exemplo n.º 8
0
        public AudioServicesError AddSystemSoundCompletion(Action routine, CFRunLoop runLoop = null)
        {
            if (gc_handle.IsAllocated)
            {
                throw new ArgumentException("Only single completion routine is supported");
            }

            gc_handle         = GCHandle.Alloc(this);
            completionRoutine = routine;

            return(AudioServicesAddSystemSoundCompletion(soundId,
                                                         runLoop == null ? IntPtr.Zero : runLoop.Handle,
                                                         IntPtr.Zero,              // runLoopMode should be enum runLoopMode == null ? IntPtr.Zero : runLoopMode.Handle,
                                                         SoundCompletionCallback, GCHandle.ToIntPtr(gc_handle)));
        }
        public bool Unschedule(CFRunLoop runLoop, string mode)
        {
            if (runLoop == null)
            {
                throw new ArgumentNullException("runLoop");
            }

            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }

            using (var cfstring = new CFString(mode)){
                return(SCNetworkReachabilityUnscheduleFromRunLoop(handle, runLoop.Handle, cfstring.Handle) != 0);
            }
        }
Exemplo n.º 10
0
        public static void Initialize(CFRunLoop runLoop, string runMode)
        {
            CFString s = runMode == null ? null : new CFString(runMode);
            int      k = AudioSessionInitialize(runLoop == null ? IntPtr.Zero : runLoop.Handle, s == null ? IntPtr.Zero : s.Handle, Interruption, IntPtr.Zero);

            if (k != 0 && k != (int)AudioSessionErrors.AlreadyInitialized)
            {
                throw new AudioSessionException(k);
            }

            if (initialized)
            {
                return;
            }

            IntPtr lib = Dlfcn.dlopen(Constants.AudioToolboxLibrary, 0);

            AudioRouteKey_Inputs  = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_AudioRouteKey_Inputs"));
            AudioRouteKey_Outputs = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_AudioRouteKey_Outputs"));
            AudioRouteKey_Type    = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_AudioRouteKey_Type"));

            InputRoute_LineIn       = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionInputRoute_LineIn"));
            InputRoute_BuiltInMic   = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionInputRoute_BuiltInMic"));
            InputRoute_HeadsetMic   = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionInputRoute_HeadsetMic"));
            InputRoute_BluetoothHFP = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionInputRoute_BluetoothHFP"));
            InputRoute_USBAudio     = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionInputRoute_USBAudio"));

            OutputRoute_LineOut         = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_LineOut"));
            OutputRoute_Headphones      = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_Headphones"));
            OutputRoute_BluetoothHFP    = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_BluetoothHFP"));
            OutputRoute_BluetoothA2DP   = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_BluetoothA2DP"));
            OutputRoute_BuiltInReceiver = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_BuiltInReceiver"));
            OutputRoute_BuiltInSpeaker  = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_BuiltInSpeaker"));
            OutputRoute_USBAudio        = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_USBAudio"));
            OutputRoute_HDMI            = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_HDMI"));
            OutputRoute_AirPlay         = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSessionOutputRoute_AirPlay"));

            InputSourceKey_ID          = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_InputSourceKey_ID"));
            InputSourceKey_Description = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_InputSourceKey_Description"));

            OutputDestinationKey_ID          = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_OutputDestinationKey_ID"));
            OutputDestinationKey_Description = new NSString(Dlfcn.GetIntPtr(lib, "kAudioSession_OutputDestinationKey_Description"));

            Dlfcn.dlclose(lib);

            initialized = true;
        }
Exemplo n.º 11
0
        public static void Initialize(CFRunLoop runLoop, string runMode)
        {
            if (initialized)
            {
                return;
            }

            CFString s = runMode == null ? null : new CFString(runMode);
            int      k = AudioSessionInitialize(runLoop == null ? IntPtr.Zero : runLoop.Handle, s == null ? IntPtr.Zero : s.Handle, Interruption, IntPtr.Zero);

            if (k != 0)
            {
                throw new AudioSessionException(k);
            }

            initialized = true;
        }
Exemplo n.º 12
0
        public void Main()
        {
            source = new Source(this);

            loop = CFRunLoop.Current;
            loop.AddSource(source, CFRunLoop.ModeDefault);

            context = new Context(this);
            SynchronizationContext.SetSynchronizationContext(context);

            readyEvent.Set();

            loop.Run();

            cts.Dispose();
            source.Dispose();
        }
Exemplo n.º 13
0
        public OutputAudioQueue(AudioStreamBasicDescription desc, CFRunLoop runLoop, CFString runMode)
        {
            IntPtr   h;
            GCHandle gch = GCHandle.Alloc(this);

            var code = AudioQueueNewOutput(ref desc, dOutputCallback, GCHandle.ToIntPtr(gch),
                                           runLoop == null ? IntPtr.Zero : runLoop.Handle,
                                           runMode == null ? IntPtr.Zero : runMode.Handle, 0, out h);

            if (code != 0)
            {
                gch.Free();
                throw new AudioQueueException(code);
            }

            this.gch = gch;
            handle   = h;
        }
Exemplo n.º 14
0
        public void StopWatchingMediaKeys()
        {
            if (tapThread != null)
            {
                tapThread.Stop();
                tapThread = null;
            }

            if (eventPort != null)
            {
                eventPort.Invalidate();
                eventPort.Dispose();
                eventPort = null;
            }

            if (eventPortSource != null)
            {
                eventPortSource.Invalidate();
                eventPortSource.Dispose();
                eventPortSource = null;
            }
        }
Exemplo n.º 15
0
        public InputAudioQueue(AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode)
        {
            IntPtr   h;
            GCHandle mygch = GCHandle.Alloc(this);
            CFString s     = runMode == null ? null : new CFString(runMode);

            var code = AudioQueueNewInput(ref desc, dInputCallback, GCHandle.ToIntPtr(mygch),
                                          runLoop == null ? IntPtr.Zero : runLoop.Handle,
                                          s == null ? IntPtr.Zero : s.Handle, 0, out h);

            if (s != null)
            {
                s.Dispose();
            }

            if (code == 0)
            {
                handle = h;
                gch    = mygch;
                return;
            }
            gch.Free();
            throw new AudioQueueException(code);
        }
Exemplo n.º 16
0
 protected abstract void ScheduleWithRunLoop(CFRunLoop loop, NSString mode);
Exemplo n.º 17
0
        public void EnableEvents(CFRunLoop runLoop, NSString runLoopMode)
        {
            if (open || closed || (loop != null))
                throw new InvalidOperationException ();
            CheckHandle ();

            loop = runLoop;
            loopMode = runLoopMode;

            var ctx = new CFStreamClientContext ();
            ctx.Info = GCHandle.ToIntPtr (gch);

            var args = CFStreamEventType.OpenCompleted |
                CFStreamEventType.CanAcceptBytes | CFStreamEventType.HasBytesAvailable |
                CFStreamEventType.CanAcceptBytes | CFStreamEventType.ErrorOccurred |
                CFStreamEventType.EndEncountered;

            var ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (CFStreamClientContext)));
            try {
                Marshal.StructureToPtr (ctx, ptr, false);
                if (!DoSetClient (OnCallback, (int)args, ptr))
                    throw new InvalidOperationException ("Stream does not support async events.");
            } finally {
                Marshal.FreeHGlobal (ptr);
            }

            ScheduleWithRunLoop (runLoop, runLoopMode);
        }
Exemplo n.º 18
0
 public void Close()
 {
     if (!open)
         return;
     CheckHandle ();
     if (loop != null) {
         DoSetClient (null, 0, IntPtr.Zero);
         UnscheduleFromRunLoop (loop, loopMode);
         loop = null;
         loopMode = null;
     }
     try {
         DoClose ();
     } finally {
         open = false;
         closed = true;
     }
 }
 public TestInputAudioQueue(AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode) : base(desc, runLoop, runMode)
 {
 }
Exemplo n.º 20
0
 protected override void OnCancel(CFRunLoop loop, CFRunLoopModeString mode)
 {
     ;
 }
Exemplo n.º 21
0
 protected override void OnSchedule(CFRunLoop loop, CFRunLoopModeString mode)
 {
     ;
 }
Exemplo n.º 22
0
 public OutputAudioQueue(AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode)
     : this(desc, runLoop, runMode == null ? null : new CFString(runMode))
 {
 }
Exemplo n.º 23
0
 protected override void OnCancel(CFRunLoop loop, CFRunLoopString mode)
 {
     DebugOutput("IOService.FileSystemNotifcationPort.OnCancel()");
 }
Exemplo n.º 24
0
		public override void ScheduleInCFRunLoop (CFRunLoop runloop, NSString mode)
		{
			Notify (CFStreamEventType.HasBytesAvailable);
		}
Exemplo n.º 25
0
 public void UnscheduleInCFRunLoop(CFRunLoop runloop, NSString mode)
 {
     // Nothing to do here
 }
Exemplo n.º 26
0
 public void ScheduleInCFRunLoop(CFRunLoop runloop, NSString mode)
 {
     Notify(CFStreamEventType.HasBytesAvailable);
 }
Exemplo n.º 27
0
		public override void UnscheduleInCFRunLoop (CFRunLoop runloop, NSString mode)
		{
			// Nothing to do here
		}
Exemplo n.º 28
0
 protected abstract void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode);
Exemplo n.º 29
0
		public bool Schedule (CFRunLoop runLoop, string mode)
		{
			if (runLoop == null)
				throw new ArgumentNullException ("runLoop");

			// new CFString already does a null check			
			using (var cfstring = new CFString (mode)){
				return SCNetworkReachabilityScheduleWithRunLoop (handle, runLoop.Handle, cfstring.Handle);
			}
		}
Exemplo n.º 30
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop)
 {
     ScheduleWithRunLoop(runLoop, CFRunLoop.ModeDefault);
 }
Exemplo n.º 31
0
 public static extern void IOHIDManagerScheduleWithRunLoop(
     IOHIDManagerRef inIOHIDManagerRef,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Exemplo n.º 32
0
		public bool Unschedule (CFRunLoop runLoop, string mode)
		{
			if (runLoop == null)
				throw new ArgumentNullException ("runLoop");

			if (mode == null)
				throw new ArgumentNullException ("mode");
			
			using (var cfstring = new CFString (mode)){
				return SCNetworkReachabilityUnscheduleFromRunLoop (handle, runLoop.Handle, cfstring.Handle) != 0;
			}
		}
Exemplo n.º 33
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop, NSString runLoopMode)
 {
     CheckDisposed();
     FSEventStreamScheduleWithRunLoop(handle, runLoop.Handle, runLoopMode.Handle);
 }
Exemplo n.º 34
0
 public static extern void IOHIDDeviceScheduleWithRunLoop(
     IOHIDDeviceRef device,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Exemplo n.º 35
0
 public void Stop()
 {
     CFRunLoop.Stop();
 }
Exemplo n.º 36
0
		public CFSocket (AddressFamily family, SocketType type, ProtocolType proto, CFRunLoop loop)
			: this (CFSocketSignature.AddressFamilyToInt (family),
			        CFSocketSignature.SocketTypeToInt (type),
			        CFSocketSignature.ProtocolToInt (proto), loop)
		{
		}
Exemplo n.º 37
0
 void eventTapThread()
 {
     tapThread = CFRunLoop.Current;
     tapThread.AddSource(eventPortSource, CFRunLoop.ModeCommon);
     tapThread.Run();
 }
Exemplo n.º 38
0
 public void WakeUp()
 {
     CFRunLoop.WakeUp();
 }
Exemplo n.º 39
0
 public static extern void IOHIDManagerUnscheduleFromRunLoop(
     IOHIDManagerRef inIOHIDManagerRef,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Exemplo n.º 40
0
 public static extern void IOHIDDeviceUnscheduleWithRunLoop(
     IOHIDDeviceRef device,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Exemplo n.º 41
0
 public static extern void IOHIDDeviceUnscheduleFromRunLoop(
     IOHIDDeviceRef device,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Exemplo n.º 42
0
        public HIDInput()
        {
            Debug.Print("Using HIDInput.");

            RunLoop = CF.CFRunLoopGetMain();
            if (RunLoop == IntPtr.Zero)
                RunLoop = CF.CFRunLoopGetCurrent();
            if (RunLoop == IntPtr.Zero)
            {
                Debug.Print("[Error] No CFRunLoop found for {0}", GetType().FullName);
                throw new InvalidOperationException();
            }
            CF.CFRetain(RunLoop);

            HandleDeviceAdded = DeviceAdded;
            HandleDeviceRemoved = DeviceRemoved;
            HandleDeviceValueReceived = DeviceValueReceived;

            // For retrieving input directly from the hardware
            hidmanager = CreateHIDManager();
            if (hidmanager == IntPtr.Zero)
            {
                Debug.Print("[Mac] Failed to create IO HID manager, HIDInput driver not supported.");
                throw new NotSupportedException();
            }

            RegisterHIDCallbacks(hidmanager);

            // For retrieving the global cursor position
            RegisterMouseMonitor();
        }
Exemplo n.º 43
0
 public static extern void IOHIDManagerScheduleWithRunLoop(
     IOHIDManagerRef inIOHIDManagerRef,
     CFRunLoop inCFRunLoop,
     CFString inCFRunLoopMode);
Exemplo n.º 44
0
		CFSocket (int family, int type, int proto, CFRunLoop loop)
		{
			var cbTypes = CFSocketCallBackType.DataCallBack | CFSocketCallBackType.ConnectCallBack;

			gch = GCHandle.Alloc (this);
			var ctx = new CFStreamClientContext ();
			ctx.Info = GCHandle.ToIntPtr (gch);

			var ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof(CFStreamClientContext)));
			try {
				Marshal.StructureToPtr (ctx, ptr, false);
				handle = CFSocketCreate (
					IntPtr.Zero, family, type, proto, cbTypes, OnCallback, ptr);
			} finally {
				Marshal.FreeHGlobal (ptr);
			}

			if (handle == IntPtr.Zero)
				throw new CFSocketException (CFSocketError.Error);
			gch = GCHandle.Alloc (this);

			var source = new CFRunLoopSource (CFSocketCreateRunLoopSource (IntPtr.Zero, handle, 0));
			loop.AddSource (source, CFRunLoop.CFDefaultRunLoopMode);
		}