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

            ScheduleWithRunLoop(runLoop, runLoopMode);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public override bool Equals(object other)
        {
            CFRunLoop cfother = other as CFRunLoop;

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

            return(cfother.Handle == handle);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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
                }
        }
Ejemplo n.º 7
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;
     }
 }
Ejemplo n.º 8
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop, NSString runLoopMode)
 {
     CheckDisposed ();
     FSEventStreamScheduleWithRunLoop (handle, runLoop.Handle, runLoopMode.Handle);
 }
Ejemplo n.º 9
0
 protected abstract void OnSchedule(CFRunLoop loop, string mode);
Ejemplo n.º 10
0
		protected abstract void OnCancel (CFRunLoop loop, string mode);
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 13
0
 protected abstract void UnscheduleFromRunLoop(CFRunLoop loop, NSString mode);
Ejemplo n.º 14
0
 protected abstract void ScheduleWithRunLoop(CFRunLoop loop, NSString mode);
Ejemplo n.º 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
			}
		}
Ejemplo n.º 16
0
 protected abstract void OnCancel(CFRunLoop loop, string mode);
Ejemplo n.º 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;
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 19
0
 public CFSocket(AddressFamily family, SocketType type, ProtocolType proto, CFRunLoop loop)
     : this(CFSocketSignature.AddressFamilyToInt(family),
            CFSocketSignature.SocketTypeToInt(type),
            CFSocketSignature.ProtocolToInt(proto), loop)
 {
 }
Ejemplo n.º 20
0
 public void ScheduleWithRunLoop(CFRunLoop runLoop)
 {
     ScheduleWithRunLoop (runLoop, CFRunLoop.ModeDefault);
 }
Ejemplo n.º 21
0
		protected abstract void OnSchedule (CFRunLoop loop, string mode);