Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 3
0
 public virtual void Dispose(bool disposing)
 {
     if (handle != IntPtr.Zero)
     {
         CFType.Release(handle);
         handle = IntPtr.Zero;
     }
 }
Esempio n. 4
0
        static string GetClassName(IntPtr handle)
        {
            var classNameRef = IOObjectCopyClass(handle);
            var className    = new CFString(classNameRef);

            CFType.Release(classNameRef);
            return(className.ToString());
        }
Esempio n. 5
0
 protected virtual void Dispose(bool disposing)
 {
     if (Handle != IntPtr.Zero)
     {
         CFType.Release(Handle);
         handle = IntPtr.Zero;
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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());
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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();
            }
        }
Esempio n. 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);
            }
        }