Пример #1
0
 public void Close()
 {
     // Windows that do not have a WindowController use released_when_closed
     // if set to true, the call to Close will release the object, and we will
     // end up with a double free.
     //
     // If that is the case, we take a reference first, and to keep the behavior
     // we call Dispose after that.
     if (WindowController == null)
     {
         bool released_when_closed = ReleasedWhenClosed;
         if (released_when_closed)
         {
             CFType.Retain(Handle);
         }
         _Close();
         if (released_when_closed)
         {
             Dispose();
         }
     }
     else
     {
         _Close();
     }
 }
Пример #2
0
 internal CMClockOrTimebase(IntPtr handle, bool owns)
 {
     if (!owns)
     {
         CFType.Retain(Handle);
     }
     this.handle = handle;
 }
Пример #3
0
        internal static IOService GetMatchingService(IntPtr masterPortRef, IntPtr matchingDictionary)
        {
            CFType.Retain(matchingDictionary);
            var serviceRef = IOServiceGetMatchingService(masterPortRef, matchingDictionary);

            if (serviceRef == IntPtr.Zero)
            {
                return(null);
            }
            return(IOObject.MarshalNativeObject <IOService> (serviceRef, true));
        }
Пример #4
0
        internal SecCertificate(IntPtr handle, bool owns)
        {
            if (handle == IntPtr.Zero)
            {
                throw new Exception("Invalid handle");
            }

            this.handle = handle;
            if (!owns)
            {
                CFType.Retain(handle);
            }
        }
Пример #5
0
        public static void SetArray(IntPtr handle, string symbol, NSArray array)
        {
            var indirect = dlsym(handle, symbol);

            if (indirect == IntPtr.Zero)
            {
                return;
            }
            var arrayHandle = array == null ? IntPtr.Zero : array.Handle;

            if (arrayHandle != IntPtr.Zero)
            {
                CFType.Retain(arrayHandle);
            }
            Marshal.WriteIntPtr(indirect, arrayHandle);
        }
Пример #6
0
        public static void SetString(IntPtr handle, string symbol, NSString value)
        {
            var indirect = dlsym(handle, symbol);

            if (indirect == IntPtr.Zero)
            {
                return;
            }
            var strHandle = value == null ? IntPtr.Zero : value.Handle;

            if (strHandle != IntPtr.Zero)
            {
                CFType.Retain(strHandle);
            }
            Marshal.WriteIntPtr(indirect, strHandle);
        }
Пример #7
0
        public CMTimebase(CMTimebase masterTimebase)
        {
            if (masterTimebase == null)
            {
                throw new ArgumentNullException("masterTimebase");
            }

            var error = CMTimebaseCreateWithMasterTimebase(IntPtr.Zero, masterTimebase.Handle, out handle);

            if (error != CMTimebaseError.None)
            {
                throw new ArgumentException(error.ToString());
            }

            CFType.Retain(Handle);
        }
Пример #8
0
        public static IOIterator <T> AddMatchingNotification <T> (IONotificationPort notifyPort, NotificationType notificationType,
                                                                  NSDictionary matchingDictionary, MatchingCallback <T> callback) where T : IOService
        {
            var notificationTypeString = notificationType.GetKey();
            IOServiceMatchingCallback nativeCallback = (refCon, iteratorRef) =>
            {
                var iterator = MarshalNativeObject <IOIterator <T> > (iteratorRef, false);
                callback.Invoke(iterator);
            };

            callbackStore.Add(nativeCallback);
            IntPtr iteratorRef2;

            CFType.Retain(matchingDictionary.Handle);
            var result = IOServiceAddMatchingNotification(notifyPort.Handle, notificationTypeString, matchingDictionary.Handle,
                                                          nativeCallback, IntPtr.Zero, out iteratorRef2);

            ThrowIfError(result);
            var iterator2 = new IOIterator <T> (iteratorRef2, true);

            iterator2.Disposed += (sender, e) => callbackStore.Remove(nativeCallback);
            return(iterator2);
        }