/*
- * Copyright (c) 2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2009 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* @APPLE_LICENSE_HEADER_END@
*/
/* CFPlugIn_Factory.c
- Copyright (c) 1999-2007 Apple Inc. All rights reserved.
+ Copyright (c) 1999-2009, Apple Inc. All rights reserved.
Responsibility: Doug Davidson
*/
static void _CFPFactoryAddToTable(_CFPFactory *factory) {
__CFSpinLock(&CFPlugInGlobalDataLock);
- if (_factoriesByFactoryID == NULL) {
+ if (!_factoriesByFactoryID) {
CFDictionaryValueCallBacks _factoryDictValueCallbacks = {0, NULL, NULL, NULL, NULL};
- // Use default allocator
_factoriesByFactoryID = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeDictionaryKeyCallBacks, &_factoryDictValueCallbacks);
}
CFDictionarySetValue(_factoriesByFactoryID, factory->_uuid, factory);
static void _CFPFactoryRemoveFromTable(_CFPFactory *factory) {
__CFSpinLock(&CFPlugInGlobalDataLock);
- if (_factoriesByFactoryID != NULL) {
- CFDictionaryRemoveValue(_factoriesByFactoryID, factory->_uuid);
- }
+ if (_factoriesByFactoryID) CFDictionaryRemoveValue(_factoriesByFactoryID, factory->_uuid);
__CFSpinUnlock(&CFPlugInGlobalDataLock);
}
_CFPFactory *result = NULL;
__CFSpinLock(&CFPlugInGlobalDataLock);
- if (_factoriesByFactoryID != NULL) {
+ if (_factoriesByFactoryID) {
result = (_CFPFactory *)CFDictionaryGetValue(_factoriesByFactoryID, factoryID);
- if (result && result->_enabled != enabled) {
- result = NULL;
- }
+ if (result && result->_enabled != enabled) result = NULL;
}
__CFSpinUnlock(&CFPlugInGlobalDataLock);
return result;
_CFPFactoryRemoveFromTable(factory);
- if (factory->_plugIn) {
- _CFPlugInRemoveFactory(factory->_plugIn, factory);
- }
+ if (factory->_plugIn) _CFPlugInRemoveFactory(factory->_plugIn, factory);
/* Remove all types for this factory. */
c = CFArrayGetCount(factory->_types);
- while (c--) {
- _CFPFactoryRemoveType(factory, (CFUUIDRef)CFArrayGetValueAtIndex(factory->_types, c));
- }
+ while (c-- > 0) _CFPFactoryRemoveType(factory, (CFUUIDRef)CFArrayGetValueAtIndex(factory->_types, c));
CFRelease(factory->_types);
- if (factory->_funcName) {
- CFRelease(factory->_funcName);
- }
-
- if (factory->_uuid) {
- CFRelease(factory->_uuid);
- }
+ if (factory->_funcName) CFRelease(factory->_funcName);
+ if (factory->_uuid) CFRelease(factory->_uuid);
CFAllocatorDeallocate(allocator, factory);
CFRelease(allocator);
_CFPFactory *factory;
UInt32 size;
size = sizeof(_CFPFactory);
- allocator = ((NULL == allocator) ? (CFAllocatorRef)CFRetain(__CFGetDefaultAllocator()) : (CFAllocatorRef)CFRetain(allocator));
+ allocator = (allocator ? (CFAllocatorRef)CFRetain(allocator) : (CFAllocatorRef)CFRetain(__CFGetDefaultAllocator()));
factory = (_CFPFactory *)CFAllocatorAllocate(allocator, size, 0);
- if (NULL == factory) {
+ if (!factory) {
CFRelease(allocator);
return NULL;
}
factory->_allocator = allocator;
-
factory->_uuid = (CFUUIDRef)CFRetain(factoryID);
factory->_enabled = true;
factory->_instanceCount = 0;
factory->_func = NULL;
factory->_plugIn = plugIn;
- if (plugIn) {
- _CFPlugInAddFactory(plugIn, factory);
- }
+ if (plugIn) _CFPlugInAddFactory(plugIn, factory);
factory->_funcName = (funcName ? (CFStringRef)CFStringCreateCopy(allocator, funcName) : NULL);
return factory;
__private_extern__ void *_CFPFactoryCreateInstance(CFAllocatorRef allocator, _CFPFactory *factory, CFUUIDRef typeID) {
void *result = NULL;
if (factory->_enabled) {
- if (factory->_func == NULL) {
+ if (!factory->_func) {
factory->_func = (CFPlugInFactoryFunction)CFBundleGetFunctionPointerForName(factory->_plugIn, factory->_funcName);
- if (factory->_func == NULL) {
- CFLog(__kCFLogPlugIn, CFSTR("Cannot find function pointer %@ for factory %@ in %@"), factory->_funcName, factory->_uuid, factory->_plugIn);
- }
+ if (!factory->_func) CFLog(__kCFLogPlugIn, CFSTR("Cannot find function pointer %@ for factory %@ in %@"), factory->_funcName, factory->_uuid, factory->_plugIn);
#if BINARY_SUPPORT_CFM
- else {
- // return values from CFBundleGetFunctionPointerForName will always be dyld, but
- // we must force-fault them because pointers to glue code do not fault correctly
+ if (factory->_func) {
+ // return values from CFBundleGetFunctionPointerForName will always be dyld, but we must force-fault them because pointers to glue code do not fault correctly
factory->_func = (void *)((uint32_t)(factory->_func) | 0x1);
}
#endif /* BINARY_SUPPORT_CFM */
__private_extern__ void _CFPFactoryDisable(_CFPFactory *factory) {
factory->_enabled = false;
- if (factory->_instanceCount == 0) {
- _CFPFactoryDeallocate(factory);
- }
+ if (factory->_instanceCount == 0) _CFPFactoryDeallocate(factory);
}
__private_extern__ Boolean _CFPFactoryIsEnabled(_CFPFactory *factory) {
/* Add the factory to the type's array of factories */
__CFSpinLock(&CFPlugInGlobalDataLock);
- if (_factoriesByTypeID == NULL) {
- // Create this from default allocator
- _factoriesByTypeID = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
- }
+ if (!_factoriesByTypeID) _factoriesByTypeID = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
array = (CFMutableArrayRef)CFDictionaryGetValue(_factoriesByTypeID, typeID);
- if (array == NULL) {
+ if (!array) {
CFArrayCallBacks _factoryArrayCallbacks = {0, NULL, NULL, NULL, NULL};
// Create this from default allocator
array = CFArrayCreateMutable(kCFAllocatorSystemDefault, 0, &_factoryArrayCallbacks);
SInt32 idx;
idx = CFArrayGetFirstIndexOfValue(factory->_types, CFRangeMake(0, CFArrayGetCount(factory->_types)), typeID);
- if (idx >=0) {
- CFArrayRemoveValueAtIndex(factory->_types, idx);
- }
+ if (idx >= 0) CFArrayRemoveValueAtIndex(factory->_types, idx);
/* Remove the factory from the type's list of factories */
__CFSpinLock(&CFPlugInGlobalDataLock);
- if (_factoriesByTypeID != NULL) {
+ if (_factoriesByTypeID) {
CFMutableArrayRef array = (CFMutableArrayRef)CFDictionaryGetValue(_factoriesByTypeID, typeID);
- if (array != NULL) {
+ if (array) {
idx = CFArrayGetFirstIndexOfValue(array, CFRangeMake(0, CFArrayGetCount(array)), factory);
- if (idx >=0) {
+ if (idx >= 0) {
CFArrayRemoveValueAtIndex(array, idx);
- if (CFArrayGetCount(array) == 0) {
- CFDictionaryRemoveValue(_factoriesByTypeID, typeID);
- }
+ if (CFArrayGetCount(array) == 0) CFDictionaryRemoveValue(_factoriesByTypeID, typeID);
}
}
}
SInt32 idx;
idx = CFArrayGetFirstIndexOfValue(factory->_types, CFRangeMake(0, CFArrayGetCount(factory->_types)), typeID);
- return ((idx >= 0) ? true : false);
+ return (idx >= 0 ? true : false);
}
__private_extern__ CFArrayRef _CFPFactoryFindForType(CFUUIDRef typeID) {
CFArrayRef result = NULL;
__CFSpinLock(&CFPlugInGlobalDataLock);
- if (_factoriesByTypeID != NULL) {
- result = (CFArrayRef)CFDictionaryGetValue(_factoriesByTypeID, typeID);
- }
+ if (_factoriesByTypeID) result = (CFArrayRef)CFDictionaryGetValue(_factoriesByTypeID, typeID);
__CFSpinUnlock(&CFPlugInGlobalDataLock);
return result;
__private_extern__ void _CFPFactoryAddInstance(_CFPFactory *factory) {
/* MF:!!! Assert that factory is enabled. */
factory->_instanceCount++;
- if (factory->_plugIn) {
- _CFPlugInAddPlugInInstance(factory->_plugIn);
- }
+ if (factory->_plugIn) _CFPlugInAddPlugInInstance(factory->_plugIn);
}
__private_extern__ void _CFPFactoryRemoveInstance(_CFPFactory *factory) {
/* MF:!!! Assert that _instanceCount > 0. */
factory->_instanceCount--;
- if (factory->_plugIn) {
- _CFPlugInRemovePlugInInstance(factory->_plugIn);
- }
- if ((factory->_instanceCount == 0) && (!factory->_enabled)) {
- _CFPFactoryDeallocate(factory);
- }
+ if (factory->_plugIn) _CFPlugInRemovePlugInInstance(factory->_plugIn);
+ if (factory->_instanceCount == 0 && !factory->_enabled) _CFPFactoryDeallocate(factory);
}