Example #1
0
        public void EnableEvents(CFRunLoop runLoop, NSString runLoopMode)
        {
            if (open || closed || (loop != null))
            {
                throw new InvalidOperationException();
            }
            ThrowIfDisposed();

            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);
        }
Example #2
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);
        }
Example #3
0
        public override bool Equals(object other)
        {
            CFRunLoop cfother = other as CFRunLoop;

            if (cfother == null)
            {
                return(false);
            }

            return(cfother.Handle == Handle);
        }
Example #4
0
        static void Cancel(IntPtr info, IntPtr runLoop, IntPtr mode)
        {
            var source = GCHandle.FromIntPtr(info).Target as CFRunLoopSourceCustom;

            var loop    = new CFRunLoop(runLoop);
            var mstring = new CFString(mode);

            try {
                source.OnCancel(loop, (string)mstring);
            } finally {
                loop.Dispose();
                mstring.Dispose();
            }
        }
Example #5
0
 public void Close()
 {
     if (!open)
     {
         return;
     }
     ThrowIfDisposed();
     if (loop != null)
     {
         DoSetClient(null, 0, IntPtr.Zero);
         UnscheduleFromRunLoop(loop, loopMode);
         loop     = null;
         loopMode = null;
     }
     try {
         DoClose();
     } finally {
         open   = false;
         closed = true;
     }
 }
Example #6
0
		static void Cancel (IntPtr info, IntPtr runLoop, IntPtr mode)
		{
			var source = GCHandle.FromIntPtr (info).Target as CFRunLoopSourceCustom;

			var loop = new CFRunLoop (runLoop);
			var mstring = new CFString (mode);

			try {
				source.OnCancel (loop, (string)mstring);
			} finally {
				loop.Dispose ();
				mstring.Dispose ();
			}
		}
Example #7
0
		protected abstract void OnSchedule (CFRunLoop loop, string mode);
Example #8
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;
        }
Example #9
0
 protected override void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode)
 {
     CFWriteStreamUnscheduleFromRunLoop(Handle, loop.Handle, mode.Handle);
 }
Example #10
0
 protected override void ScheduleWithRunLoop(CFRunLoop loop, NSString mode)
 {
     CFWriteStreamScheduleWithRunLoop(Handle, loop.Handle, mode.Handle);
 }
		protected override void ScheduleWithRunLoop (CFRunLoop loop, NSString mode)
		{
			CFReadStreamScheduleWithRunLoop (Handle, loop.Handle, mode.Handle);
		}
Example #12
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);
		}
Example #13
0
 protected abstract void OnCancel(CFRunLoop loop, string mode);
Example #14
0
		protected abstract void OnCancel (CFRunLoop loop, string mode);
Example #15
0
 public CFSocket(AddressFamily family, SocketType type, ProtocolType proto, CFRunLoop loop)
     : this(CFSocketSignature.AddressFamilyToInt(family),
            CFSocketSignature.SocketTypeToInt(type),
            CFSocketSignature.ProtocolToInt(proto), loop)
 {
 }
Example #16
0
 protected abstract void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode);
Example #17
0
 protected abstract void ScheduleWithRunLoop(CFRunLoop loop, NSString mode);
Example #18
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);
		}
Example #19
0
 protected abstract void OnSchedule(CFRunLoop loop, string mode);
Example #20
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));
		}
		protected override void UnscheduleFromRunLoop (CFRunLoop loop, NSString mode)
		{
			CFReadStreamUnscheduleFromRunLoop (Handle, loop.Handle, mode.Handle);
		}
Example #22
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;
        }