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, (nint)(long)args, ptr))
                {
                    throw new InvalidOperationException("Stream does not support async events.");
                }
            } finally {
                Marshal.FreeHGlobal(ptr);
            }

            ScheduleWithRunLoop(runLoop, runLoopMode);
        }
Exemple #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, (nuint)(ulong)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.ModeDefault);
        }
Exemple #3
0
        public override bool Equals(object other)
        {
            CFRunLoop cfother = other as CFRunLoop;

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

            return(cfother.Handle == handle);
        }
Exemple #4
0
 protected override void ScheduleWithRunLoop(CFRunLoop loop, NSString mode)
 {
     if (loop == null)
     {
         throw new ArgumentNullException("loop");
     }
     if (mode == null)
     {
         throw new ArgumentNullException("mode");
     }
     CFReadStreamScheduleWithRunLoop(Handle, loop.Handle, mode.Handle);
 }
Exemple #5
0
 protected override void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode)
 {
     if (loop == null)
     {
         throw new ArgumentNullException("loop");
     }
     if (mode == null)
     {
         throw new ArgumentNullException("mode");
     }
     CFWriteStreamUnscheduleFromRunLoop(Handle, loop.Handle, mode.Handle);
 }
Exemple #6
0
        static void Cancel(IntPtr info, IntPtr runLoop, IntPtr mode)
        {
            var source = GCHandle.FromIntPtr(info).Target as CFRunLoopSourceCustom;

            using (var loop = new CFRunLoop(runLoop))
                using (var mstring = new NSString(mode)) {
#if XAMCORE_2_0
                    source.OnCancel(loop, mstring);
#else
                    source.OnCancel(loop, (string)mstring);
#endif
                }
        }
 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;
     }
 }
Exemple #8
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop, NSString runLoopMode)
 {
     CheckDisposed ();
     FSEventStreamScheduleWithRunLoop (handle, runLoop.Handle, runLoopMode.Handle);
 }
Exemple #9
0
 protected abstract void OnSchedule(CFRunLoop loop, string mode);
Exemple #10
0
		protected abstract void OnCancel (CFRunLoop loop, string mode);
Exemple #11
0
 protected override void ScheduleWithRunLoop(CFRunLoop loop, NSString mode)
 {
     if (loop == null)
         throw new ArgumentNullException ("loop");
     if (mode == null)
         throw new ArgumentNullException ("mode");
     CFWriteStreamScheduleWithRunLoop (Handle, loop.Handle, mode.Handle);
 }
Exemple #12
0
 protected override void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode)
 {
     if (loop == null)
         throw new ArgumentNullException ("loop");
     if (mode == null)
         throw new ArgumentNullException ("mode");
     CFReadStreamUnscheduleFromRunLoop (Handle, loop.Handle, mode.Handle);
 }
Exemple #13
0
 protected abstract void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode);
Exemple #14
0
 protected abstract void ScheduleWithRunLoop(CFRunLoop loop, NSString mode);
Exemple #15
0
		static void Cancel (IntPtr info, IntPtr runLoop, IntPtr mode)
		{
			var source = GCHandle.FromIntPtr (info).Target as CFRunLoopSourceCustom;

			using (var loop = new CFRunLoop (runLoop))
			using (var mstring = new NSString (mode)) {
#if XAMCORE_2_0
				source.OnCancel (loop, mstring);
#else
				source.OnCancel (loop, (string)mstring);
#endif
			}
		}
Exemple #16
0
 protected abstract void OnCancel(CFRunLoop loop, string mode);
Exemple #17
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;
        }
Exemple #18
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));
        }
Exemple #19
0
 public CFSocket(AddressFamily family, SocketType type, ProtocolType proto, CFRunLoop loop)
     : this(CFSocketSignature.AddressFamilyToInt(family),
            CFSocketSignature.SocketTypeToInt(type),
            CFSocketSignature.ProtocolToInt(proto), loop)
 {
 }
Exemple #20
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop)
 {
     ScheduleWithRunLoop (runLoop, CFRunLoop.ModeDefault);
 }
Exemple #21
0
		protected abstract void OnSchedule (CFRunLoop loop, string mode);