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