예제 #1
0
        public static CFMessagePort CreateRemotePort(CFAllocator allocator, string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            IntPtr a = allocator == null ? IntPtr.Zero : allocator.Handle;
            IntPtr n = NSString.CreateNative(name);

            try {
                var portHandle = CFMessagePortCreateRemote(a, n);
                return(portHandle == IntPtr.Zero ? null : new CFMessagePort(portHandle));
            } finally {
                NSString.ReleaseNative(n);
            }
        }
예제 #2
0
        internal static CFMessagePort CreateLocalPort(CFAllocator allocator, string name, CFMessagePortCallBack callback, CFMessagePortContext context)
        {
            IntPtr a = allocator == null ? IntPtr.Zero : allocator.Handle;
            IntPtr n = NSString.CreateNative (name);
            bool shouldFreeInfo = false;
            var contextProxy = new ContextProxy ();

            // a GCHandle is needed because we do not have an handle before calling CFMessagePortCreateLocal
            // and that will call the RetainProxy. So using this (short-lived) GCHandle allow us to find back the
            // original context defined by developer
            var shortHandle = GCHandle.Alloc (contextProxy);

            if (context != null) {
                if (context.Retain != null)
                    contextProxy.retain = RetainProxy;
                if (context.Release != null)
                    contextProxy.release = ReleaseProxy;
                if (context.CopyDescription != null)
                    contextProxy.copyDescription = CopyDescriptionProxy;
                contextProxy.info = (IntPtr)shortHandle;
                lock (messagePortContexts)
                    messagePortContexts.Add (contextProxy.info, context);
            }

            try {
                var portHandle = CFMessagePortCreateLocal (a, n, messageOutputCallback, ref contextProxy, ref shouldFreeInfo);

                // we won't need short GCHandle after the Create call
                shortHandle.Free ();

                // TODO handle should free info
                if (portHandle == IntPtr.Zero)
                    return null;

                var result = new CFMessagePort (portHandle);

                lock (outputHandles)
                    outputHandles.Add (portHandle, callback);

                if (context != null) {
                    lock (messagePortContexts) {
                        messagePortContexts.Remove (contextProxy.info);
                        CFMessagePortGetContext (portHandle, ref contextProxy);
                        messagePortContexts.Add (contextProxy.info, context);
                    }

                    result.contextHandle = contextProxy.info;
                }

                return result;
            } finally {
                NSString.ReleaseNative (n);
            }
        }
예제 #3
0
        public static CFMessagePort CreateRemotePort(CFAllocator allocator, string name)
        {
            if (name == null)
                throw new ArgumentNullException ("name");

            IntPtr a = allocator == null ? IntPtr.Zero : allocator.Handle;
            IntPtr n = NSString.CreateNative (name);

            try {
                var portHandle = CFMessagePortCreateRemote (a, n);
                return portHandle == IntPtr.Zero ? null : new CFMessagePort (portHandle);
            } finally {
                NSString.ReleaseNative (n);
            }
        }
예제 #4
0
        public static CFMessagePort CreateLocalPort(string name, CFMessagePortCallBack callback, CFAllocator allocator = null)
        {
            if (callback == null)
                throw new ArgumentNullException ("callback");

            return CreateLocalPort (allocator, name, callback, context: null);
        }
예제 #5
0
        public FSEventStream(CFAllocator allocator, NSArray pathsToWatch,
            ulong sinceWhenId, TimeSpan latency, FSEventStreamCreateFlags flags)
        {
            if (pathsToWatch == null) {
                throw new ArgumentNullException ("pathsToWatch");
            }

            eventsCallback = new FSEventStreamCallback (EventsCallback);

            handle = FSEventStreamCreate (
                allocator ==  null ? IntPtr.Zero : allocator.Handle,
                eventsCallback, IntPtr.Zero, pathsToWatch.Handle,
                sinceWhenId, latency.TotalSeconds, flags | (FSEventStreamCreateFlags)0x1 /* UseCFTypes */);

            if (handle == IntPtr.Zero) {
                throw new Exception ("Unable to create FSEventStream");
            }
        }
예제 #6
0
        internal static CFMessagePort CreateLocalPort(CFAllocator allocator, string name, CFMessagePortCallBack callback, CFMessagePortContext context)
        {
            IntPtr a = allocator == null ? IntPtr.Zero : allocator.Handle;
            IntPtr n = NSString.CreateNative(name);
            bool   shouldFreeInfo = false;
            var    contextProxy   = new ContextProxy();

            // a GCHandle is needed because we do not have an handle before calling CFMessagePortCreateLocal
            // and that will call the RetainProxy. So using this (short-lived) GCHandle allow us to find back the
            // original context defined by developer
            var shortHandle = GCHandle.Alloc(contextProxy);

            if (context != null)
            {
                if (context.Retain != null)
                {
                    contextProxy.retain = RetainProxy;
                }
                if (context.Release != null)
                {
                    contextProxy.release = ReleaseProxy;
                }
                if (context.CopyDescription != null)
                {
                    contextProxy.copyDescription = CopyDescriptionProxy;
                }
                contextProxy.info = (IntPtr)shortHandle;
                lock (messagePortContexts)
                    messagePortContexts.Add(contextProxy.info, context);
            }

            try {
                var portHandle = CFMessagePortCreateLocal(a, n, messageOutputCallback, ref contextProxy, ref shouldFreeInfo);

                // we won't need short GCHandle after the Create call
                shortHandle.Free();

                // TODO handle should free info
                if (portHandle == IntPtr.Zero)
                {
                    return(null);
                }

                var result = new CFMessagePort(portHandle);

                lock (outputHandles)
                    outputHandles.Add(portHandle, callback);

                if (context != null)
                {
                    lock (messagePortContexts) {
                        messagePortContexts.Remove(contextProxy.info);
                        CFMessagePortGetContext(portHandle, ref contextProxy);
                        messagePortContexts.Add(contextProxy.info, context);
                    }

                    result.contextHandle = contextProxy.info;
                }

                return(result);
            } finally {
                NSString.ReleaseNative(n);
            }
        }
예제 #7
0
        public static CFMessagePort CreateLocalPort(string name, CFMessagePortCallBack callback, CFAllocator allocator = null)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            return(CreateLocalPort(allocator, name, callback, context: null));
        }