//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // SampleEffectUnit::GetParameterValueStrings // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OSStatus SampleEffectUnit::GetParameterValueStrings( AudioUnitScope inScope, AudioUnitParameterID inParameterID, CFArrayRef * outStrings) { if ( (inScope == kAudioUnitScope_Global) && (inParameterID == kParam_Three_Indexed) ) { if (outStrings == NULL) return noErr; //called by GetPropInfo CFStringRef strings[] = { kParameterValueStringsOne, kParameterValueStringsTwo, kParameterValueStringsThree }; *outStrings = CFArrayCreate( NULL, (const void **)strings, 3, NULL); return noErr; } return kAudioUnitErr_InvalidProperty; }
OSStatus SinSynthWithMidi::GetProperty( AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, void * outData) { if (inScope == kAudioUnitScope_Global) { if (inID == kAudioUnitProperty_MIDIOutputCallbackInfo) { CFStringRef strs[1]; strs[0] = CFSTR("MIDI Callback"); CFArrayRef callbackArray = CFArrayCreate(NULL, (const void **)strs, 1, &kCFTypeArrayCallBacks); *(CFArrayRef *)outData = callbackArray; return noErr; } } return SinSynth::GetProperty (inID, inScope, inElement, outData); }
/*! Creates a CFArray object containing CFString objects with names of * all of the targets in the discovery record. * @param discoveryRec the discovery record. * @return an array of strings with names of the targets in the record. */ CFArrayRef iSCSIDiscoveryRecCreateArrayOfTargets(iSCSIDiscoveryRecRef discoveryRec) { // Validate input if(!discoveryRec) return NULL; // Get all keys, which correspond to the targets const CFIndex count = CFDictionaryGetCount(discoveryRec); const void * keys[count]; CFDictionaryGetKeysAndValues(discoveryRec,keys,NULL); CFArrayRef targets = CFArrayCreate(kCFAllocatorDefault, keys, count, &kCFTypeArrayCallBacks); return targets; }
static void tests(void) { SecTrustResultType trustResult = kSecTrustResultProceed; SecPolicyRef policy = NULL; SecTrustRef trust = NULL; CFArrayRef certs = NULL; CFDataRef appleid_record_signing_cert_data = NULL; isnt(appleid_record_signing_cert_data = CFDataCreate(kCFAllocatorDefault, kLeafCert, sizeof(kLeafCert)), NULL, "Get the AppleID Record Signing Leaf Certificate Data"); SecCertificateRef appleid_record_signing_cert = NULL; isnt(appleid_record_signing_cert = SecCertificateCreateWithData(kCFAllocatorDefault, appleid_record_signing_cert_data), NULL, "Get the AppleID Record Signing Leaf Certificate Data"); CFDataRef appleid_intermediate_cert_data = NULL; isnt(appleid_intermediate_cert_data = CFDataCreate(kCFAllocatorDefault, kIntermediateCert, sizeof(kIntermediateCert)), NULL, "Get the AppleID Intermediate Certificate Data"); SecCertificateRef appleid_intermediate_cert = NULL; isnt(appleid_intermediate_cert = SecCertificateCreateWithData(kCFAllocatorDefault, appleid_intermediate_cert_data), NULL, "Get the AppleID Intermediate Certificate"); SecCertificateRef certs_to_use[] = {appleid_record_signing_cert, appleid_intermediate_cert}; certs = CFArrayCreate(NULL, (const void **)certs_to_use, 2, NULL); isnt(policy = SecPolicyCreateAppleIDValidationRecordSigningPolicy(), NULL, "Create AppleID Record signing policy SecPolicyRef"); ok_status(SecTrustCreateWithCertificates(certs, policy, &trust), "Create AppleID record signing leaf"); ok_status(SecTrustEvaluate(trust, &trustResult), "evaluate escrow service trust for club 1"); is_status(trustResult, kSecTrustResultUnspecified, "Trust is kSecTrustResultUnspecified AppleID record signing leaf"); CFReleaseSafe(trust); CFReleaseSafe(policy); CFReleaseSafe(certs); CFReleaseSafe(appleid_record_signing_cert); CFReleaseSafe(appleid_intermediate_cert_data); CFReleaseSafe(appleid_record_signing_cert_data); }
int main(int argc, char *argv[]) { /* Define variables and create a CFArray object containing CFString objects containing paths to watch. */ CFStringRef mypath = CFSTR("/"); CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL); void *callbackInfo = NULL; // could put stream-specific data here. FSEventStreamRef stream; CFAbsoluteTime latency = 3.0; /* Latency in seconds */ struct stat Status; stat("/", &Status); dev_t device = Status.st_dev; CFUUIDRef uuidO; CFStringRef uuid; uuidO = FSEventsCopyUUIDForDevice(device); uuid = CFUUIDCreateString(NULL, uuidO); show(CFSTR("%@:256"), uuid); /* Create the stream, passing in a callback, */ stream = FSEventStreamCreateRelativeToDevice(NULL, &myCallbackFunction, callbackInfo, device, pathsToWatch, atoi(argv[2]), /* Or a previous event ID */ latency, kFSEventStreamCreateFlagNone /* Flags explained in reference */ ); /* Create the stream before calling this. */ FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart(stream); //CFRunLoopRun(); CFRunLoopRunInMode(kCFRunLoopDefaultMode,atoi(argv[1]),false); //sleep(10); }
static void ShowErrorVa(const wchar_t *de, const wchar_t *en, va_list args) { // Get current language const wchar_t *stringToUse = en; #ifdef _WIN32 if ((GetUserDefaultLangID() & 0xFF) == LANG_GERMAN) stringToUse = de; #elif defined(__APPLE_CC__) CFStringRef localisations[2] = { CFSTR("en"), CFSTR("de") }; CFArrayRef allLocalisations = CFArrayCreate(kCFAllocatorDefault, (const void **) localisations, 2, &kCFTypeArrayCallBacks); CFArrayRef preferredLocalisations = CFBundleCopyPreferredLocalizationsFromArray(allLocalisations); CFStringRef oldStyleLang = (CFStringRef) CFArrayGetValueAtIndex(preferredLocalisations, 0); CFStringRef newStyleLang = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, oldStyleLang); if (CFStringHasPrefix(newStyleLang, CFSTR("de"))) stringToUse = de; CFRelease(allLocalisations); CFRelease(preferredLocalisations); CFRelease(newStyleLang); #else // TODO: Implement something here for android. #endif // Create output string wchar_t text[1024]; vswprintf(text, 1024, stringToUse, args); // Show message #ifdef _WIN32 MessageBoxW(NULL, text, L"Mindstorms Simulator", MB_TASKMODAL & MB_ICONWARNING); #elif defined(IPHONE) // Ignore it #elif defined(__APPLE_CC__) CFStringRef messageString = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *) text, sizeof(wchar_t) * wcslen(text), (CFByteOrderGetCurrent() == CFByteOrderBigEndian) ? kCFStringEncodingUTF32BE : kCFStringEncodingUTF32LE, false); CFUserNotificationDisplayAlert(0.0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, messageString, NULL, NULL, NULL, NULL, NULL); CFRelease(messageString); #else // TODO: Implement something here for android. size_t length = wcslen(text)+1; char *englishMangledASCII = new char[length]; for (unsigned i = 0; i < length; i++) englishMangledASCII[i] = (char) en[i]; __android_log_print(ANDROID_LOG_FATAL, "librobosim.so", "Error: %s", englishMangledASCII); delete englishMangledASCII; #endif }
/* * Function: EAPOLClientConfigurationCopyProfiles * * Purpose: * Get the list of defined profiles. If there are no profiles defined, * returns NULL. * * Returns: * NULL if no profiles are defined, non-NULL non-empty array of profiles * otherwise. */ CFArrayRef /* of EAPOLClientProfileRef */ EAPOLClientConfigurationCopyProfiles(EAPOLClientConfigurationRef cfg) { CFAllocatorRef allocator = CFGetAllocator(cfg); int count; CFArrayRef profiles; const void * * values; count = CFDictionaryGetCount(cfg->profiles); if (count == 0) { return (NULL); } values = (const void * *)malloc(sizeof(*values) * count); CFDictionaryGetKeysAndValues(cfg->profiles, NULL, values); profiles = CFArrayCreate(allocator, values, count, &kCFTypeArrayCallBacks); free(values); return (profiles); }
/** * initially this logic was being threaded off using pthreads, but the FSEventStreamCreate call itself has its own threading, and there's no need * for this extra layer of threading, especially as it makes it difficult to consume from Java because of the extra complexity of threading in JNI code */ void *event_processing_thread( char * path ) { char *pathToMonitor = path ; CFStringRef mypath = CFStringCreateWithCString(NULL, pathToMonitor, NULL); CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL); CFAbsoluteTime latency = 0.3; FSEventStreamRef stream = FSEventStreamCreate(NULL, &file_system_changed_callback, NULL , pathsToWatch, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNoDefer); FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart(stream); CFRunLoopRun(); return NULL; }
IOReturn IONetworkSetPacketFiltersMask( io_connect_t connect, const io_name_t filterGroup, UInt32 filtersMask, IOOptionBits options __unused ) { IOReturn kr = kIOReturnNoMemory; CFStringRef keys[3]; CFArrayRef keysArray = 0; CFStringRef group = 0; CFNumberRef num = 0; CFDictionaryRef dict = 0; do { num = CFNumberCreate( kCFAllocatorDefault, kCFNumberSInt32Type, &filtersMask ); if ( num == 0 ) break; group = CFStringCreateWithCString( kCFAllocatorDefault, filterGroup, CFStringGetSystemEncoding() ); if ( group == 0 ) break; keys[0] = CFSTR( kIONetworkInterfaceProperties ); keys[1] = CFSTR( kIORequiredPacketFilters ); keys[2] = group; keysArray = CFArrayCreate( NULL, (void *)keys, 3, &kCFTypeArrayCallBacks ); if ( keysArray == 0 ) break; dict = CreateNestedDictionariesUsingKeys( keysArray, num ); if ( dict == 0 ) break; kr = IOConnectSetCFProperties( connect, dict ); } while ( 0 ); if ( num ) CFRelease( num ); if ( group ) CFRelease( group ); if ( keysArray ) CFRelease( keysArray ); if ( dict ) CFRelease( dict ); return kr; }
static FSEventStreamRef add_watch (SeafWTMonitorPriv *priv, const char* repo_id) { SeafRepo *repo = NULL; const char *path = NULL; repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id); if (!repo) { seaf_warning ("[wt mon] cannot find repo %s.\n", repo_id); return 0; } path = repo->worktree; CFStringRef mypath = CFStringCreateWithCString (kCFAllocatorDefault, path, kCFStringEncodingUTF8); CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL); FSEventStreamRef stream; /* Create the stream, passing in a callback */ struct FSEventStreamContext ctx = {0, priv, NULL, NULL, NULL}; stream = FSEventStreamCreate(kCFAllocatorDefault, stream_callback, &ctx, pathsToWatch, kFSEventStreamEventIdSinceNow, 1.0, kFSEventStreamCreateFlagWatchRoot ); CFRelease (mypath); CFRelease (pathsToWatch); if (!stream) { seaf_warning ("[wt] Failed to create event stream \n"); return stream; } FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart (stream); #ifdef FSEVENT_DEBUG FSEventStreamShow (stream); seaf_debug ("[wt mon] Add repo %s watch success :%s.\n", repo_id, repo->worktree); #endif return stream; }
CFArrayRef SecACLCopyAuthorizations(SecACLRef acl) { CFArrayRef result = NULL; if (NULL == acl) { return result; } AclAuthorizationSet auths = ACL::required(acl)->authorizations(); uint32 numAuths = (uint32)auths.size(); CSSM_ACL_AUTHORIZATION_TAG* tags = new CSSM_ACL_AUTHORIZATION_TAG[numAuths]; int i; for (i = 0; i < numAuths; ++i) { tags[i] = NULL; } OSStatus err = SecACLGetAuthorizations(acl, tags, &numAuths); if (errSecSuccess != err) { return result; } CFTypeRef* strings = new CFTypeRef[numAuths]; for (i = 0; i < numAuths; ++i) { strings[i] = NULL; } for (size_t iCnt = 0; iCnt < numAuths; iCnt++) { strings[iCnt] = (CFTypeRef)GetAuthStringFromACLAuthorizationTag(tags[iCnt]); } result = CFArrayCreate(kCFAllocatorDefault, (const void **)strings, numAuths, &kCFTypeArrayCallBacks); delete[] strings; delete[] tags; return result; }
static Boolean RegisterConsoleUserChangeCallback() { CFStringRef consoleUserNameChangeKey = NULL; CFArrayRef notificationKeys = NULL; Boolean success = TRUE; write_log(LOG_NOTICE, "Creating ConsoleUser key."); consoleUserNameChangeKey = SCDynamicStoreKeyCreateConsoleUser(NULL); if(consoleUserNameChangeKey == NULL) { write_log(LOG_ERR, "Couldn't create ConsoleUser key!"); success = FALSE; goto EXIT; } write_log(LOG_NOTICE, "Creating notification key array."); notificationKeys = CFArrayCreate(NULL, (void*)&consoleUserNameChangeKey, (CFIndex)1, &kCFTypeArrayCallBacks); if(notificationKeys == NULL) { write_log(LOG_ERR, "Couldn't create notification key array!"); success = FALSE; goto EXIT; } write_log(LOG_NOTICE, "Setting up DynamicStore notification."); if(SCDynamicStoreSetNotificationKeys(dsSession, notificationKeys, NULL) == FALSE) { write_log(LOG_ERR, "Couldn't set up DynamicStore notification!"); success = FALSE; goto EXIT; } EXIT: if(notificationKeys != NULL) { CFRelease(notificationKeys); notificationKeys = NULL; } if(consoleUserNameChangeKey != NULL) { CFRelease(consoleUserNameChangeKey); consoleUserNameChangeKey = NULL; } return success; }
HIDGamepadProvider::HIDGamepadProvider() : m_shouldDispatchCallbacks(false) , m_connectionDelayTimer(this, &HIDGamepadProvider::connectionDelayTimerFired) , m_inputNotificationTimer(this, &HIDGamepadProvider::inputNotificationTimerFired) { m_manager = adoptCF(IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone)); RetainPtr<CFDictionaryRef> joystickDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick); RetainPtr<CFDictionaryRef> gamepadDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad); CFDictionaryRef devices[] = { joystickDictionary.get(), gamepadDictionary.get() }; RetainPtr<CFArrayRef> matchingArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, (const void**)devices, 2, &kCFTypeArrayCallBacks)); IOHIDManagerSetDeviceMatchingMultiple(m_manager.get(), matchingArray.get()); IOHIDManagerRegisterDeviceMatchingCallback(m_manager.get(), deviceAddedCallback, this); IOHIDManagerRegisterDeviceRemovalCallback(m_manager.get(), deviceRemovedCallback, this); IOHIDManagerRegisterInputValueCallback(m_manager.get(), deviceValuesChangedCallback, this); }
static void tests(void) { SecTrustRef trust; SecCertificateRef leaf, wwdr_intermediate; SecPolicyRef policy; isnt(wwdr_intermediate = SecCertificateCreateWithBytes(kCFAllocatorDefault, wwdr_intermediate_cert, sizeof(wwdr_intermediate_cert)), NULL, "create WWDR intermediate"); isnt(leaf = SecCertificateCreateWithBytes(kCFAllocatorDefault, codesigning_certificate, sizeof(codesigning_certificate)), NULL, "create leaf"); const void *vcerts[] = { leaf, wwdr_intermediate }; CFArrayRef certs = CFArrayCreate(kCFAllocatorDefault, vcerts, 2, NULL); isnt(policy = SecPolicyCreateiPhoneProfileApplicationSigning(), NULL, "create iPhoneProfileApplicationSigning policy instance"); ok_status(SecTrustCreateWithCertificates(certs, policy, &trust), "create trust for leaf"); CFDateRef verifyDate = CFDateCreate(kCFAllocatorDefault, 228244066); ok_status(SecTrustSetVerifyDate(trust, verifyDate), "set verify date"); CFReleaseNull(verifyDate); SecTrustResultType trustResult; CFArrayRef properties = NULL; properties = SecTrustCopyProperties(trust); is(properties, NULL, "no properties returned before eval"); CFReleaseNull(properties); ok_status(SecTrustEvaluate(trust, &trustResult), "evaluate trust"); is_status(trustResult, kSecTrustResultUnspecified, "trust is kSecTrustResultUnspecified"); properties = SecTrustCopyProperties(trust); if (properties) { print_plist(properties); print_cert(leaf, true); print_cert(wwdr_intermediate, false); } CFReleaseNull(properties); CFReleaseNull(trust); CFReleaseNull(wwdr_intermediate); CFReleaseNull(leaf); CFReleaseNull(certs); CFReleaseNull(policy); CFReleaseNull(trust); }
static CFArrayRef gst_mio_video_src_output_available_formats (gpointer instance, gboolean ensure_only) { GstMIOVideoSrc *self = GST_MIO_VIDEO_SRC (instance); CMFormatDescriptionRef format_desc; GST_DEBUG_OBJECT (self, "%s: ensure_only=%d", G_STRFUNC, ensure_only); if (ensure_only) return NULL; g_assert (self->device != NULL); format_desc = gst_mio_video_device_get_selected_format (self->device); g_assert (format_desc != NULL); return CFArrayCreate (kCFAllocatorDefault, (const void **) &format_desc, 1, &kCFTypeArrayCallBacks); }
static void match_fonts(ASS_Library *lib, ASS_FontProvider *provider, char *name) { const size_t attributes_n = 3; CTFontDescriptorRef ctdescrs[attributes_n]; CFMutableDictionaryRef cfattrs[attributes_n]; CFStringRef attributes[attributes_n] = { kCTFontFamilyNameAttribute, kCTFontDisplayNameAttribute, kCTFontNameAttribute, }; CFStringRef cfname = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8); for (int i = 0; i < attributes_n; i++) { cfattrs[i] = CFDictionaryCreateMutable(NULL, 0, 0, 0); CFDictionaryAddValue(cfattrs[i], attributes[i], cfname); ctdescrs[i] = CTFontDescriptorCreateWithAttributes(cfattrs[i]); } CFArrayRef descriptors = CFArrayCreate(NULL, (const void **)&ctdescrs, attributes_n, NULL); CTFontCollectionRef ctcoll = CTFontCollectionCreateWithFontDescriptors(descriptors, 0); CFArrayRef fontsd = CTFontCollectionCreateMatchingFontDescriptors(ctcoll); process_descriptors(provider, fontsd); SAFE_CFRelease(fontsd); SAFE_CFRelease(ctcoll); for (int i = 0; i < attributes_n; i++) { SAFE_CFRelease(cfattrs[i]); SAFE_CFRelease(ctdescrs[i]); } SAFE_CFRelease(descriptors); SAFE_CFRelease(cfname); }
void start_watches() { CFStringRef watch_paths[100]; int path_count = 0; int i; for (i = 0; i < 100; i += 1) { if (NULL != FSEVENTS_GLOBAL(watches)[i].path) { watch_paths[i] = CFStringCreateWithCString(NULL, FSEVENTS_GLOBAL(watches)[i].path, kCFStringEncodingUTF8); path_count++; } } void *callback_info = NULL; // could put stream-specific data here. CFArrayRef watch_path_array = CFArrayCreate(NULL, (void *) watch_paths, path_count, NULL); CFAbsoluteTime latency = .75; /* Latency in seconds */ CFRunLoopRef run_loop = CFRunLoopGetMain(); FSEventStreamRef stream; /* Create the stream, passing in a callback */ stream = FSEventStreamCreate( NULL, (FSEventStreamCallback)&handle_events, callback_info, watch_path_array, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNone ); FSEventStreamScheduleWithRunLoop( stream, run_loop, kCFRunLoopDefaultMode ); FSEventStreamStart(stream); CFRunLoopRun(); FSEventStreamFlushSync(stream); FSEventStreamStop(stream); }
int main(int argc, const char * argv[]) { CFStringRef mypath = CFSTR("/Volumes/BACKUP/images"); CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL); FSEventStreamRef stream; CFAbsoluteTime latency = 3.0; /* Latency in seconds */ /* Create the stream, passing in a callback */ stream = FSEventStreamCreate(NULL, &fsEventStreamCallback, NULL, pathsToWatch, kFSEventStreamEventIdSinceNow, /* Or a previous event ID */ latency, kFSEventStreamCreateFlagFileEvents /* Flags explained in reference */ ); FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(),kCFRunLoopDefaultMode); FSEventStreamStart(stream); CFRunLoopRun(); return 0; }
static OSStatus _EAPSecIdentityCreateCertificateTrustChain(SecIdentityRef identity, CFArrayRef * ret_chain) { SecCertificateRef cert = NULL; CFArrayRef certs; SecPolicyRef policy = NULL; OSStatus status; SecTrustRef trust = NULL; SecTrustResultType trust_result; *ret_chain = NULL; ok(policy = SecPolicyCreateBasicX509(), "SecPolicyCreateBasicX509"); ok_status(status = SecIdentityCopyCertificate(identity, &cert), "SecIdentityCopyCertificate"); certs = CFArrayCreate(NULL, (const void **)&cert, 1, &kCFTypeArrayCallBacks); CFReleaseNull(cert); ok_status(status = SecTrustCreateWithCertificates(certs, policy, &trust), "SecTrustCreateWithCertificates"); CFReleaseNull(certs); ok_status(status = SecTrustEvaluate(trust, &trust_result), "SecTrustEvaluate"); { CFMutableArrayRef array; CFIndex count = SecTrustGetCertificateCount(trust); CFIndex i; isnt(count, 0, "SecTrustGetCertificateCount is nonzero"); array = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks); for (i = 0; i < count; i++) { SecCertificateRef s; s = SecTrustGetCertificateAtIndex(trust, i); CFArrayAppendValue(array, s); } *ret_chain = array; } CFReleaseNull(trust); CFReleaseNull(policy); return (status); }
Boolean GetMetadataForURL(void* thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFURLRef url) { CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); if (!dataProvider) return FALSE; CFDataRef data = CGDataProviderCopyData(dataProvider); CGDataProviderRelease(dataProvider); if (!data) return FALSE; const UInt8 *buf = CFDataGetBytePtr(data); int *height= ((int*) buf) + 3; int *width = ((int*) buf) + 4; int *pflags= ((int*) buf) + 20; CFStringRef format=NULL; if ((*pflags)&DDPF_FOURCC) format = CFStringCreateWithBytes(kCFAllocatorDefault, buf + 0x54, 4, kCFStringEncodingASCII, false); else if ((*pflags)&DDPF_RGB) format = (*pflags)&DDPF_ALPHAPIXELS ? CFSTR("RGBA") : CFSTR("RGB"); if (format) { CFArrayRef codecs = CFArrayCreate(kCFAllocatorDefault, (const void **) &format, 1, &kCFTypeArrayCallBacks); CFDictionaryAddValue(attributes, kMDItemCodecs, codecs); CFRelease(format); CFRelease(codecs); } CFNumberRef cfheight = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, height); CFDictionaryAddValue(attributes, kMDItemPixelHeight, cfheight); CFRelease(cfheight); CFNumberRef cfwidth = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, width); CFDictionaryAddValue(attributes, kMDItemPixelWidth, cfwidth); CFRelease(cfwidth); CFRelease(data); return TRUE; }
/* * Function: EAPOLClientConfigurationCopyMatchingProfiles * * Purpose: * Find the profile(s) matching the specified profile. * A profile is matched based on the profileID, the WLAN SSID, and * the WLAN domain, all of which must be unique in the configuration. * * Usually invoked after calling * EAPOLClientProfileCreateWithPropertyList() to instantiate a profile * from an external format. * * Returns: * NULL if no matching profile is part of the configuration, * non-NULL CFArrayRef of EAPOLClientProfileRef if found. */ CFArrayRef /* of EAPOLClientProfileRef */ EAPOLClientConfigurationCopyMatchingProfiles(EAPOLClientConfigurationRef cfg, EAPOLClientProfileRef profile) { int count; EAPOLClientProfileRef matching_profile; CFStringRef profileID = EAPOLClientProfileGetID(profile); CFDataRef ssid; const void * values[2] = { NULL, NULL }; count = 0; matching_profile = EAPOLClientConfigurationGetProfileWithID(cfg, profileID); if (matching_profile != NULL) { values[count] = matching_profile; count++; } matching_profile = NULL; ssid = EAPOLClientProfileGetWLANSSIDAndSecurityType(profile, NULL); if (ssid != NULL) { matching_profile = EAPOLClientConfigurationGetProfileWithWLANSSID(cfg, ssid); } else { CFStringRef domain; domain = EAPOLClientProfileGetWLANDomain(profile); if (domain != NULL) { matching_profile = EAPOLClientConfigurationGetProfileWithWLANDomain(cfg, domain); } } if (matching_profile != NULL && values[0] != matching_profile) { values[count] = matching_profile; count++; } if (count == 0) { return (NULL); } return (CFArrayCreate(CFGetAllocator(cfg), values, count, &kCFTypeArrayCallBacks)); }
inline CFArrayRef SQLite3StatementCreateArrayForAllColumns(SQLite3StatementRef statement) { CFArrayRef array = NULL; if (statement) { CFIndex count = SQLite3StatementGetColumnCount(statement); if (count > 0) { const void **values = CFAllocatorAllocate(statement->allocator, sizeof(const void *) * count, 0); if (values) { for (CFIndex i = 0; i < count; i++) { values[i] = SQLite3StatementCreateCFTypeWithColumn(statement, i); } array = CFArrayCreate(statement->allocator, values, count, &kCFTypeArrayCallBacks); for (CFIndex i = 0; i < count; i++) { if (values[i]) CFRelease(values[i]); } CFAllocatorDeallocate(statement->allocator, values); } } } return array; }
static void * EventProcessingThread(void *data) { CFStringRef path = CFSTR("/"); CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&path, 1, NULL); void *callbackInfo = NULL; CFAbsoluteTime latency = 0.3; // Latency in seconds FSEventStreamRef stream = FSEventStreamCreate( NULL, &callback, callbackInfo, pathsToWatch, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNoDefer ); FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart(stream); CFRunLoopRun(); return NULL; }
AppleReloadManager::AppleReloadManager() { //Register with file system CFStringRef mypath = CFSTR("assets"); CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL); FSEventStreamContext *callbackInfo = NULL; // could put stream-specific data here. auto myCallbackFunction = AppleReloadManager::eventCallback; CFAbsoluteTime latency = 3.0; /* Latency in seconds */ /* Create the stream, passing in a callback */ stream = FSEventStreamCreate(NULL, myCallbackFunction, callbackInfo, pathsToWatch, kFSEventStreamEventIdSinceNow, /* Or a previous event ID */ latency, kFSEventStreamCreateFlagFileEvents /* Flags explained in reference */ ); FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart(stream); pthread_mutex_init(&AppleReloadManager::reloadMutex, NULL); }
int main(int argc, const char * argv[]) { size_t width = 2000; size_t height = 2000; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(nullptr, width, height, 8, width * 4, colorSpace, kCGImageAlphaNoneSkipLast); CGColorSpaceRelease(colorSpace); const std::vector<uint8_t> fontVector = generateFont(); std::ofstream outputFile("/Volumes/Data/home/mmaxfield/tmp/output.otf", std::ios::out | std::ios::binary); for (uint8_t b : fontVector) outputFile << b; outputFile.close(); CFDataRef fontData = CFDataCreate(kCFAllocatorDefault, fontVector.data(), fontVector.size()); CTFontDescriptorRef fontDescriptor = CTFontManagerCreateFontDescriptorFromData(fontData); CFRelease(fontData); CFTypeRef featureValues[] = { CFSTR("liga"), CFSTR("clig"), CFSTR("dlig"), CFSTR("hlig"), CFSTR("calt"), CFSTR("subs"), CFSTR("sups"), CFSTR("smcp"), CFSTR("c2sc"), CFSTR("pcap"), CFSTR("c2pc"), CFSTR("unic"), CFSTR("titl"), CFSTR("onum"), CFSTR("pnum"), CFSTR("tnum"), CFSTR("frac"), CFSTR("afrc"), CFSTR("ordn"), CFSTR("zero"), CFSTR("hist"), CFSTR("jp78"), CFSTR("jp83"), CFSTR("jp90"), CFSTR("jp04"), CFSTR("smpl"), CFSTR("trad"), CFSTR("fwid"), CFSTR("pwid"), CFSTR("ruby") }; CFArrayRef features = CFArrayCreate(kCFAllocatorDefault, featureValues, 30, &kCFTypeArrayCallBacks); for (CFIndex i = 0; i < CFArrayGetCount(features); ++i) { drawTextWithFeature(context, fontDescriptor, static_cast<CFStringRef>(CFArrayGetValueAtIndex(features, i)), 1, CGPointMake(25, 1950 - 50 * i)); drawTextWithFeature(context, fontDescriptor, static_cast<CFStringRef>(CFArrayGetValueAtIndex(features, i)), 0, CGPointMake(25, 1925 - 50 * i)); } CFRelease(features); CFRelease(fontDescriptor); CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/Volumes/Data/home/mmaxfield/tmp/output.png"), kCFURLPOSIXPathStyle, FALSE); CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, nullptr); CFRelease(url); CGImageDestinationAddImage(imageDestination, image, nullptr); CGImageRelease(image); CGImageDestinationFinalize(imageDestination); CFRelease(imageDestination); return 0; }
Boolean SCNetworkSetEstablishDefaultInterfaceConfiguration(SCNetworkSetRef set, SCNetworkInterfaceRef interface) { CFArrayRef interfaces; Boolean updated; if (!isA_SCNetworkSet(set)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } if (!isA_SCNetworkInterface(interface)) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } interfaces = CFArrayCreate(NULL, (const void **)&interface, 1, &kCFTypeArrayCallBacks); assert(interfaces != NULL); updated = __SCNetworkSetEstablishDefaultConfigurationForInterfaces(set, interfaces, FALSE); CFRelease(interfaces); return updated; }
CFDataRef createDataFromURL( CFURLRef url ) { SInt32 errorCode = 0; CFDataRef fileContent; CFDictionaryRef dict; CFArrayRef arr = CFArrayCreate(NULL, NULL, 0, NULL); Boolean success = CFURLCreateDataAndPropertiesFromResource (NULL, url, &fileContent, &dict, arr, &errorCode); CFRelease(arr); CFRelease(dict); if (!success) { return NULL; } return fileContent; }
// ---------------------------------------------------------- bool ofxAudioUnitSampler::setSample(const std::string &samplePath) // ---------------------------------------------------------- { CFURLRef sampleURL[1] = {CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)samplePath.c_str(), samplePath.length(), NULL)}; CFArrayRef sample = CFArrayCreate(NULL, (const void **)&sampleURL, 1, &kCFTypeArrayCallBacks); OFXAU_PRINT(AudioUnitSetProperty(*_unit, kAUSamplerProperty_LoadAudioFiles, kAudioUnitScope_Global, 0, &sample, sizeof(sample)), "setting ofxAudioUnitSampler's source sample"); CFRelease(sample); CFRelease(sampleURL[0]); return true; }
CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers(void) { int32_t locale, localeCount = uloc_countAvailable(); CFMutableSetRef working = CFSetCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeSetCallBacks); for (locale = 0; locale < localeCount; ++locale) { const char *localeID = uloc_getAvailable(locale); CFStringRef string1 = CFStringCreateWithCString(kCFAllocatorSystemDefault, localeID, kCFStringEncodingASCII); CFStringRef string2 = CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorSystemDefault, string1); CFSetAddValue(working, string1); // do not include canonicalized version as IntlFormats cannot cope with that in its popup CFRelease(string1); CFRelease(string2); } CFIndex cnt = CFSetGetCount(working); #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_LINUX || (DEPLOYMENT_TARGET_WINDOWS && __GNUC__) STACK_BUFFER_DECL(const void *, buffer, cnt); #else const void* buffer[BUFFER_SIZE]; #endif CFSetGetValues(working, buffer); CFArrayRef result = CFArrayCreate(kCFAllocatorSystemDefault, buffer, cnt, &kCFTypeArrayCallBacks); CFRelease(working); return result; }
void watch_directory(VALUE self) { VALUE rb_registered_directories = rb_iv_get(self, "@registered_directories"); int i, dir_size; dir_size = RARRAY_LEN(rb_registered_directories); VALUE *rb_dir_names = RARRAY_PTR(rb_registered_directories); CFStringRef dir_names[dir_size]; for (i = 0; i < dir_size; i++) { dir_names[i] = CFStringCreateWithCString(NULL, (char *)RSTRING_PTR(rb_dir_names[i]), kCFStringEncodingUTF8); } CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&dir_names, dir_size, NULL); VALUE rb_latency = rb_iv_get(self, "@latency"); CFAbsoluteTime latency = NUM2DBL(rb_latency); FSEventStreamContext context; context.version = 0; context.info = (VALUE *)self; context.retain = NULL; context.release = NULL; context.copyDescription = NULL; stream = FSEventStreamCreate(NULL, &callback, &context, pathsToWatch, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNone ); FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); FSEventStreamStart(stream); CFRunLoopRun(); }