示例#1
0
        public IDictionary <IOHIDElement, IOHIDValue> GetValues(IOHIDElement[] elements)
        {
            ThrowIfDisposed();
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }
            var elementArray = CFArray.FromNativeObjects(elements);

            IOHIDElement[] keys        = new IOHIDElement[elements.Length];
            IOHIDValue[]   values      = new IOHIDValue[elements.Length];
            CFDictionary   multiple    = CFDictionary.FromObjectsAndKeys(values, keys);
            var            multipleRef = multiple.Handle;
            var            result      = IOHIDDeviceCopyValueMultiple(Handle, elementArray.Handle, ref multipleRef);

            IOObject.ThrowIfError(result);
            var dict = new Dictionary <IOHIDElement, IOHIDValue> (multiple.Count);

            IntPtr[] keyRefs, valueRefs;
            multiple.GetKeysAndValues(out keyRefs, out valueRefs);
            for (int i = 0; i < multiple.Count; i++)
            {
                dict.Add(new IOHIDElement(keyRefs [i], true), new IOHIDValue(valueRefs [i], true));
            }
            CFType.Release(multiple.Handle);
            return(dict);
        }
示例#2
0
        static InitConstants()
        {
            // ensure we can init. This is needed before iOS6 (as per doc).
            IntPtr p = ABAddressBook.ABAddressBookCreate();

            ABGroupProperty.Init();
            ABLabel.Init();
            ABPersonAddressKey.Init();
            ABPersonDateLabel.Init();
            ABPersonInstantMessageKey.Init();
            ABPersonInstantMessageService.Init();
            ABPersonKindId.Init();
            ABPersonPhoneLabel.Init();
            ABPersonPropertyId.Init();
            ABPersonRelatedNamesLabel.Init();
            ABPersonUrlLabel.Init();
            ABSourcePropertyId.Init();

            // From iOS 6.0+ this might return NULL, e.g. if the application is not authorized to access the
            // address book, and we would crash if we tried to release a null pointer
            if (p != IntPtr.Zero)
            {
                CFType.Release(p);
            }
        }
示例#3
0
 public virtual void Dispose(bool disposing)
 {
     if (handle != IntPtr.Zero)
     {
         CFType.Release(handle);
         handle = IntPtr.Zero;
     }
 }
示例#4
0
        static string GetClassName(IntPtr handle)
        {
            var classNameRef = IOObjectCopyClass(handle);
            var className    = new CFString(classNameRef);

            CFType.Release(classNameRef);
            return(className.ToString());
        }
示例#5
0
文件: CMSync.cs 项目: NikoXu/maccore
 protected virtual void Dispose(bool disposing)
 {
     if (Handle != IntPtr.Zero)
     {
         CFType.Release(Handle);
         handle = IntPtr.Zero;
     }
 }
示例#6
0
        public NSMutableDictionary CreateCFProperties()
        {
            ThrowIfDisposed();
            CFMutableDictionaryRef propertiesRef;
            var result = IORegistryEntryCreateCFProperties(Handle, out propertiesRef, IntPtr.Zero, 0);

            ThrowIfError(result);
            var dict = new NSMutableDictionary(propertiesRef);

            CFType.Release(propertiesRef);
            return(dict);
        }
示例#7
0
        public NSObject GetLocalizedAttribute(NSString attribute, out NSString language)
        {
            IntPtr lang;
            var    o = Runtime.GetNSObject(CTFontDescriptorCopyLocalizedAttribute(Handle, attribute.Handle, out lang));

            language = (NSString)Runtime.GetNSObject(lang);
            if (lang != IntPtr.Zero)
            {
                CFType.Release(lang);
            }
            return(o);
        }
示例#8
0
        public static string GetBundleIdentifierForClass(string className)
        {
            var classNameAsCFString = new CFString(className);
            var bundleIdentifierRef = IOObjectCopyBundleIdentifierForClass(classNameAsCFString.Handle);
            var bundleIdentifier    = new CFString(bundleIdentifierRef);

            if (bundleIdentifierRef == IntPtr.Zero)
            {
                return(null);
            }
            CFType.Release(bundleIdentifierRef);
            return(bundleIdentifier.ToString());
        }
示例#9
0
        public void SetValueMultiple(IDictionary <IOHIDElement, IOHIDValue> dictonary)
        {
            ThrowIfDisposed();
            if (dictonary == null)
            {
                throw new ArgumentNullException("multiple");
            }
            var multiple = CFDictionary.FromObjectsAndKeys(dictonary.Values.ToArray(), dictonary.Keys.ToArray());
            var result   = IOHIDDeviceSetValueMultiple(Handle, multiple.Handle);

            CFType.Release(multiple.Handle);
            IOObject.ThrowIfError(result);
        }
示例#10
0
        public static NSMutableDictionary CreateMatchingDictionaryForName(ulong entryId)
        {
            var dictRef = IORegistryEntryIDMatching(entryId);

            if (dictRef == IntPtr.Zero)
            {
                return(null);
            }
            var dict = new NSMutableDictionary(dictRef);

            CFType.Release(dictRef);
            return(dict);
        }
示例#11
0
        internal static NSMutableDictionary CreateMatchingDictionaryForBSDNameWithPort(IntPtr masterPortRef, string bsdName)
        {
            var dictRef = IOBSDNameMatching(masterPortRef, 0, bsdName);

            if (dictRef == IntPtr.Zero)
            {
                return(null);
            }
            var dict = new NSMutableDictionary(dictRef);

            CFType.Release(dictRef);
            return(dict);
        }
示例#12
0
        public CTFontDescriptor[] GetMatchingFontDescriptors()
        {
            var cfArrayRef = CTFontCollectionCreateMatchingFontDescriptors(Handle);

            if (cfArrayRef == IntPtr.Zero)
            {
                return(new CTFontDescriptor [0]);
            }
            var matches = NSArray.ArrayFromHandle(cfArrayRef,
                                                  fd => new CTFontDescriptor(fd, false));

            CFType.Release(cfArrayRef);
            return(matches);
        }
示例#13
0
        public static NSMutableDictionary CreateMatchingDictionaryForClass <T> () where T : IOService
        {
            var className = typeof(T).Name;
            var dictRef   = IOServiceMatching(className);

            if (dictRef == IntPtr.Zero)
            {
                return(null);
            }
            var dict = new NSMutableDictionary(dictRef);

            CFType.Release(dictRef);
            return(dict);
        }
示例#14
0
        public CTFontDescriptor[] GetMatchingFontDescriptors(NSSet mandatoryAttributes)
        {
            var cfArrayRef = CTFontDescriptorCreateMatchingFontDescriptors(Handle,
                                                                           mandatoryAttributes == null ? IntPtr.Zero : mandatoryAttributes.Handle);

            if (cfArrayRef == IntPtr.Zero)
            {
                return(new CTFontDescriptor [0]);
            }
            var matches = NSArray.ArrayFromHandle(cfArrayRef,
                                                  fd => new CTFontDescriptor(cfArrayRef, false));

            CFType.Release(cfArrayRef);
            return(matches);
        }
示例#15
0
        public CFHTTPMessage GetResponseHeader()
        {
            var handle = GetProperty(_ResponseHeader);

            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            if (CFType.GetTypeID(handle) != CFHTTPMessage.TypeID)
            {
                CFType.Release(handle);
                throw new InvalidCastException();
            }
            return(new CFHTTPMessage(handle));
        }
示例#16
0
        public static NSMutableDictionary CreateMatchingDictionaryForName(string name)
        {
            var dictRef = IOServiceNameMatching(name);

            if (dictRef == IntPtr.Zero)
            {
                return(null);
            }
            if (dictRef == IntPtr.Zero)
            {
                return(null);
            }
            var dict = new NSMutableDictionary(dictRef);

            CFType.Release(dictRef);
            return(dict);
        }
示例#17
0
        public CTFontDescriptor[] GetMatchingFontDescriptors(Comparison <CTFontDescriptor> comparer)
        {
            GCHandle comparison = GCHandle.Alloc(comparer);

            try {
                var cfArrayRef = CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
                    Handle,
                    new CTFontCollectionSortDescriptorsCallback(CompareDescriptors),
                    GCHandle.ToIntPtr(comparison));
                if (cfArrayRef == IntPtr.Zero)
                {
                    return(new CTFontDescriptor [0]);
                }
                var matches = NSArray.ArrayFromHandle(cfArrayRef,
                                                      fd => new CTFontDescriptor(cfArrayRef, false));
                CFType.Release(cfArrayRef);
                return(matches);
            }
            finally {
                comparison.Free();
            }
        }
示例#18
0
        public INativeObject Dequeue()
        {
            //
            // Our managed objects already take a reference on the object,
            // and by keeping the objects alive in the `queueObjects'
            // dictionary, we kept the reference alive.   So we need to
            // release the newly acquired reference
            //
            var oHandle = CMBufferQueueDequeueAndRetain(Handle);

            if (oHandle == IntPtr.Zero)
            {
                return(null);
            }

            CFType.Release(oHandle);
            lock (queueObjects){
                var managed = queueObjects [oHandle];
                queueObjects.Remove(oHandle);
                return(managed);
            }
        }