bool decode(ArgumentDecoder* decoder, RetainPtr<CFNumberRef>& result) { CFNumberType numberType; if (!decoder->decodeEnum(numberType)) return false; CoreIPC::DataReference dataReference; if (!decoder->decode(dataReference)) return false; size_t neededBufferSize = sizeForNumberType(numberType); if (!neededBufferSize || dataReference.size() != neededBufferSize) return false; ASSERT(dataReference.data()); CFNumberRef number = CFNumberCreate(0, numberType, dataReference.data()); result.adoptCF(number); return true; }
static CFDictionaryRef createImageSourceOptions(ImageSource::ShouldSkipMetadata skipMetaData, SubsamplingLevel subsamplingLevel) { const CFBooleanRef imageSourceSkipMetadata = (skipMetaData == ImageSource::SkipMetadata) ? kCFBooleanTrue : kCFBooleanFalse; if (!subsamplingLevel) { const unsigned numOptions = 3; const void* keys[numOptions] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32, kCGImageSourceSkipMetadata }; const void* values[numOptions] = { kCFBooleanTrue, kCFBooleanTrue, imageSourceSkipMetadata }; return CFDictionaryCreate(nullptr, keys, values, numOptions, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } short constrainedSubsamplingLevel = std::min<short>(3, std::max<short>(0, subsamplingLevel)); int subsampleInt = 1 << constrainedSubsamplingLevel; // [0..3] => [1, 2, 4, 8] RetainPtr<CFNumberRef> subsampleNumber = adoptCF(CFNumberCreate(nullptr, kCFNumberIntType, &subsampleInt)); const CFIndex numOptions = 4; const void* keys[numOptions] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32, kCGImageSourceSkipMetadata, kCGImageSourceSubsampleFactor }; const void* values[numOptions] = { kCFBooleanTrue, kCFBooleanTrue, imageSourceSkipMetadata, subsampleNumber.get() }; return CFDictionaryCreate(nullptr, keys, values, numOptions, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); }
kim_error kim_os_preferences_set_lifetime_for_key (kim_preference_key in_key, kim_lifetime in_lifetime) { kim_error err = KIM_NO_ERROR; CFNumberRef value = NULL; SInt32 number = (SInt32) in_lifetime; if (!err) { value = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &number); if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { err = kim_os_preferences_set_value (in_key, value); } if (value) { CFRelease (value); } return check_error (err); }
extern pascal OSStatus CFQDictionarySetNumber(CFMutableDictionaryRef dict, const void *key, long value) // See comment in header. { OSStatus err; CFNumberRef valueNum; // Create a CFNumber and add it to the dictionary. err = noErr; valueNum = CFNumberCreate(NULL, kCFNumberLongType, &value); if (valueNum == NULL) { err = coreFoundationUnknownErr; } if (err == noErr) { CFDictionarySetValue(dict, key, valueNum); } CFQRelease(valueNum); return err; }
void MovieWriter::Obj::addFrame( const ImageSourceRef &imageSource, float duration ) { if( mFinished ) throw MovieWriterExcAlreadyFinished(); if( duration <= 0 ) duration = mFormat.mDefaultTime; ::CVPixelBufferRef pixelBuffer = createCvPixelBuffer( imageSource, false ); ::CFNumberRef gammaLevel = CFNumberCreate( kCFAllocatorDefault, kCFNumberFloatType, &mFormat.mGamma ); ::CVBufferSetAttachment( pixelBuffer, kCVImageBufferGammaLevelKey, gammaLevel, kCVAttachmentMode_ShouldPropagate ); ::CFRelease( gammaLevel ); ::ICMValidTimeFlags validTimeFlags = kICMValidTime_DisplayTimeStampIsValid | kICMValidTime_DisplayDurationIsValid; ::ICMCompressionFrameOptionsRef frameOptions = NULL; int64_t durationVal = static_cast<int64_t>( duration * mFormat.mTimeBase ); OSStatus err = ::ICMCompressionSessionEncodeFrame( mCompressionSession, pixelBuffer, mCurrentTimeValue, durationVal, validTimeFlags, frameOptions, NULL, NULL ); mFrameTimes.push_back( std::pair<int64_t,int64_t>( mCurrentTimeValue, durationVal ) ); if( mDoingMultiPass ) { mMultiPassFrameCache->write( (uint32_t)::CVPixelBufferGetWidth( pixelBuffer ) ); mMultiPassFrameCache->write( (uint32_t)::CVPixelBufferGetHeight( pixelBuffer ) ); mMultiPassFrameCache->write( (uint32_t)::CVPixelBufferGetPixelFormatType( pixelBuffer ) ); mMultiPassFrameCache->write( (uint32_t)::CVPixelBufferGetBytesPerRow( pixelBuffer ) ); ::CVPixelBufferLockBaseAddress( pixelBuffer, 0 ); mMultiPassFrameCache->write( (uint32_t) ::CVPixelBufferGetDataSize( pixelBuffer ) ); mMultiPassFrameCache->writeData( ::CVPixelBufferGetBaseAddress( pixelBuffer ), ::CVPixelBufferGetDataSize( pixelBuffer ) ); ::CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 ); } mCurrentTimeValue += durationVal; ++mNumFrames; ::CVPixelBufferRelease( pixelBuffer ); if( err ) throw MovieWriterExcFrameEncode(); }
static OSStatus DoGetVersion( AuthorizationRef auth, const void * userData, CFDictionaryRef request, CFMutableDictionaryRef response, aslclient asl, aslmsg aslMsg ) // Implements the kGetVersionCommand. Returns the version number of // the helper tool. { OSStatus retval = noErr; CFNumberRef value; static const int kCurrentVersion = kToolCurrentVersion; // something very easy to spot asl_log(asl, aslMsg, ASL_LEVEL_DEBUG, "DoGetVersion()"); // Pre-conditions assert(auth != NULL); // userData may be NULL assert(request != NULL); assert(response != NULL); // asl may be NULL // aslMsg may be NULL // Add them to the response. value = CFNumberCreate(NULL, kCFNumberIntType, &kCurrentVersion); if (value == NULL) { retval = coreFoundationUnknownErr; } else { CFDictionaryAddValue(response, CFSTR(kGetVersionResponse), value); } if (value != NULL) { CFRelease(value); } return retval; }
// FIXME: Make these thread-safe / re-entrant. extern void GPDuplexClient_AddObserver(GPDuplexClientRef client, void* observer, GPDuplexClientCallback callback, SInt32 type) { if (client != NULL) { CFNumberRef typeNumber = CFNumberCreate(NULL, kCFNumberSInt32Type, &type); CFMutableSetRef observerSet = (CFMutableSetRef)CFDictionaryGetValue(client->observers, typeNumber); Boolean needRelease = false; if (observerSet == NULL) { needRelease = true; observerSet = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); } CFDataRef observerData = GPDuplexClientCreateObserver(observer, callback); CFSetAddValue(observerSet, observerData); CFRelease(observerData); CFDictionarySetValue(client->observers, typeNumber, observerSet); if (needRelease) CFRelease(observerSet); CFRelease(typeNumber); } }
static CFDictionaryRef CreateStringToNumDictionary() { int numItems = (sizeof(gValues) / sizeof(sint32)); CFMutableDictionaryRef tempDict = CFDictionaryCreateMutable(kCFAllocatorDefault, numItems, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); for (int iCnt = 0; iCnt < numItems; iCnt++) { sint32 aNumber = gValues[iCnt]; CFNumberRef aNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &aNumber); CFStringRef aString = gKeys[iCnt]; CFDictionaryAddValue(tempDict, aString, aNum); CFRelease(aNum); } CFDictionaryRef result = CFDictionaryCreateCopy(kCFAllocatorDefault, tempDict); CFRelease(tempDict); return result; }
bool outOfSpace(CFStringRef pathName) { Boolean validKey; unsigned int minMeg; struct statfs fileSys; minMeg = CFPreferencesGetAppIntegerValue(MINMEG_PREF_KEY,PREF_DOMAIN,&validKey); if (!validKey) { minMeg = DEFAULT_MEG; CFPreferencesSetAppValue(MINMEG_PREF_KEY,CFNumberCreate(kCFAllocatorDefault,kCFNumberIntType,&minMeg),PREF_DOMAIN); } if (statfs(CFStringGetCStringPtr(pathName,CFStringGetFastestEncoding(pathName)),&fileSys)) return false; if ((fileSys.f_bsize/1024)*(fileSys.f_bavail/1024) < minMeg) return true; return false; }
CFDictionaryRef AppleVDADecoder::CreateOutputConfiguration() { // Construct IOSurface Properties const void* IOSurfaceKeys[] = { MacIOSurfaceLib::kPropIsGlobal }; const void* IOSurfaceValues[] = { kCFBooleanTrue }; static_assert(ArrayLength(IOSurfaceKeys) == ArrayLength(IOSurfaceValues), "Non matching keys/values array size"); // Contruct output configuration. AutoCFRelease<CFDictionaryRef> IOSurfaceProperties = CFDictionaryCreate(kCFAllocatorDefault, IOSurfaceKeys, IOSurfaceValues, ArrayLength(IOSurfaceKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); SInt32 PixelFormatTypeValue = kCVPixelFormatType_32BGRA; AutoCFRelease<CFNumberRef> PixelFormatTypeNumber = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &PixelFormatTypeValue); const void* outputKeys[] = { kCVPixelBufferIOSurfacePropertiesKey, kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferOpenGLCompatibilityKey }; const void* outputValues[] = { IOSurfaceProperties, PixelFormatTypeNumber, kCFBooleanTrue }; static_assert(ArrayLength(outputKeys) == ArrayLength(outputValues), "Non matching keys/values array size"); return CFDictionaryCreate(kCFAllocatorDefault, outputKeys, outputValues, ArrayLength(outputKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); }
static void rb_add_value_to_cf_dictionary(CFMutableDictionaryRef dict, CFStringRef key, VALUE value){ switch(TYPE(value)){ case T_STRING: { if(!CFStringCompare(key, kSecValueData,0) || !CFStringCompare(key, kSecAttrGeneric,0)){ CFDataRef dataValue = rb_create_cf_data(value); CFDictionarySetValue(dict,key,dataValue); CFRelease(dataValue); } else{ CFStringRef stringValue = rb_create_cf_string(value); CFDictionarySetValue(dict,key,stringValue); CFRelease(stringValue); } } break; case T_BIGNUM: case T_FIXNUM: { long long longLongValue = NUM2LL(value); CFNumberRef numberValue = CFNumberCreate(NULL,kCFNumberLongLongType,&longLongValue); CFDictionarySetValue(dict,key,numberValue); CFRelease(numberValue); break; } case T_DATA: { if(rb_obj_is_kind_of(value, rb_cTime)){ VALUE floatTime = rb_funcall(value, rb_intern("to_f"),0); CFAbsoluteTime abstime = RFLOAT_VALUE(floatTime) - kCFAbsoluteTimeIntervalSince1970; CFDateRef cfdate = CFDateCreate(NULL, abstime); CFDictionarySetValue(dict, key, cfdate); CFRelease(cfdate); break; } } default: rb_raise(rb_eTypeError, "Can't convert value to cftype: %s", rb_obj_classname(value)); } }
static void appendScopeID(CFMutableDictionaryRef dict, struct sockaddr_in6 *sin6) { CFNumberRef scope; CFArrayRef scopes; CFMutableArrayRef newScopes; scopes = CFDictionaryGetValue(dict, kSCPropNetIPv6ScopeID); if (scopes) { newScopes = CFArrayCreateMutableCopy(NULL, 0, scopes); } else { newScopes = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } scope = CFNumberCreate(NULL, kCFNumberSInt32Type, &sin6->sin6_scope_id); CFArrayAppendValue(newScopes, scope); CFRelease(scope); CFDictionarySetValue(dict, kSCPropNetIPv6ScopeID, newScopes); CFRelease(newScopes); return; }
static void appendFlags(CFMutableDictionaryRef dict, int flags6) { CFArrayRef flags; CFMutableArrayRef newFlags; CFNumberRef v6Flags; flags = CFDictionaryGetValue(dict, kSCPropNetIPv6Flags); if (flags) { newFlags = CFArrayCreateMutableCopy(NULL, 0, flags); } else { newFlags = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); } v6Flags = CFNumberCreate(NULL, kCFNumberIntType, &flags6); CFArrayAppendValue(newFlags, v6Flags); CFRelease(v6Flags); CFDictionarySetValue(dict, kSCPropNetIPv6Flags, newFlags); CFRelease(newFlags); return; }
CFDictionaryRef Font::getCFStringAttributes(bool enableKerning, FontOrientation orientation) const { auto& attributesDictionary = enableKerning ? m_kernedCFStringAttributes : m_nonKernedCFStringAttributes; if (attributesDictionary) return attributesDictionary.get(); attributesDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); CFMutableDictionaryRef mutableAttributes = (CFMutableDictionaryRef)attributesDictionary.get(); CFDictionarySetValue(mutableAttributes, kCTFontAttributeName, platformData().ctFont()); if (!enableKerning) { const float zero = 0; static CFNumberRef zeroKerningValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero); CFDictionarySetValue(mutableAttributes, kCTKernAttributeName, zeroKerningValue); } if (orientation == Vertical) CFDictionarySetValue(mutableAttributes, kCTVerticalFormsAttributeName, kCFBooleanTrue); return attributesDictionary.get(); }
void DisconnectFromSkype(void) { CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter(); if (client_id) { CFNumberRef id_number = CFNumberCreate(NULL, kCFNumberIntType, &client_id); const void *keys[] = {(void *)CFSTR("SKYPE_API_CLIENT_ID")}; const void *values[] = {id_number}; CFDictionaryRef userInfo = CFDictionaryCreate(NULL, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); //disconnect CFNotificationCenterPostNotification( center, CFSTR("SKSkypeAPIDetachRequest"), NULL, userInfo, FALSE); client_id = 0; } }
void os_updateindicators(usbdevice* kb, int force){ // Set NumLock on permanently char ileds = 1; // Set Caps Lock if enabled. Unlike Linux, OSX keyboards have independent caps lock states, so // we use the last-assigned value rather than fetching it from the system if(kb->modifiers & kCGEventFlagMaskAlphaShift) ileds |= 2; kb->hw_ileds = ileds; if(kb->active){ usbmode* mode = kb->profile->currentmode; ileds = (ileds & ~mode->ioff) | mode->ion; } if(force || ileds != kb->ileds){ kb->ileds = ileds; // Get a list of LED elements from handle 0 long ledpage = kHIDPage_LEDs; const void* keys[] = { CFSTR(kIOHIDElementUsagePageKey) }; const void* values[] = { CFNumberCreate(kCFAllocatorDefault, kCFNumberLongType, &ledpage) }; CFDictionaryRef matching = CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFRelease(values[0]); CFArrayRef leds; kern_return_t res = (*kb->handles[0])->copyMatchingElements(kb->handles[0], matching, &leds, 0); CFRelease(matching); if(res != kIOReturnSuccess) return; // Iterate through them and update the LEDs which have changed DELAY_SHORT(kb); CFIndex count = CFArrayGetCount(leds); for(CFIndex i = 0; i < count; i++){ IOHIDElementRef led = (void*)CFArrayGetValueAtIndex(leds, i); uint32_t usage = IOHIDElementGetUsage(led); IOHIDValueRef value = IOHIDValueCreateWithIntegerValue(kCFAllocatorDefault, led, 0, !!(ileds & (1 << (usage - 1)))); (*kb->handles[0])->setValue(kb->handles[0], led, value, 5000, 0, 0, 0); CFRelease(value); } CFRelease(leds); } }
int main() { io_service_t service = IOServiceGetMatchingService( kIOMasterPortDefault, IOServiceMatching("IOWatchDogTimer")); assert(service); //assert(!IORegistryEntrySetCFProperty(service, CFSTR("IOWatchDogEnabled"), kCFBooleanFalse)); long zero = 0; CFNumberRef number = CFNumberCreate(NULL, kCFNumberLongType, &zero); assert(!IORegistryEntrySetCFProperties(service, number)); void *kern_hdr; size_t kern_size; void *devicetree; size_t devicetree_size; load("kern", &kern_hdr, &kern_size); load("devicetree", &devicetree, &devicetree_size); // todo use reboot2 system("launchctl unload /System/Library/LaunchDaemons/com.apple.SpringBoard.plist"); syscall(8, kern_hdr, kern_size, devicetree, devicetree_size); return 0; }
static RetainPtr<CFDictionaryRef> createImageSourceOptions(SubsamplingLevel subsamplingLevel, DecodingMode decodingMode) { RetainPtr<CFMutableDictionaryRef> options = adoptCF(CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); CFDictionarySetValue(options.get(), kCGImageSourceShouldCache, kCFBooleanTrue); CFDictionarySetValue(options.get(), kCGImageSourceShouldPreferRGB32, kCFBooleanTrue); CFDictionarySetValue(options.get(), kCGImageSourceSkipMetadata, kCFBooleanTrue); if (subsamplingLevel > SubsamplingLevel::First) { RetainPtr<CFNumberRef> subsampleNumber; subsamplingLevel = std::min(SubsamplingLevel::Last, std::max(SubsamplingLevel::First, subsamplingLevel)); int subsampleInt = 1 << static_cast<int>(subsamplingLevel); // [0..3] => [1, 2, 4, 8] subsampleNumber = adoptCF(CFNumberCreate(nullptr, kCFNumberIntType, &subsampleInt)); CFDictionarySetValue(options.get(), kCGImageSourceSubsampleFactor, subsampleNumber.get()); } if (decodingMode == DecodingMode::Immediate) { CFDictionarySetValue(options.get(), kCGImageSourceShouldCacheImmediately, kCFBooleanTrue); CFDictionarySetValue(options.get(), kCGImageSourceCreateThumbnailFromImageAlways, kCFBooleanTrue); } return options; }
static void *do_add(void *arg) { int tid=(int)(arg); for(int i=0;i<20;i++) { /* Creating a password */ SInt32 v_eighty = (tid+1)*1000+i; CFNumberRef eighty = CFNumberCreate(NULL, kCFNumberSInt32Type, &v_eighty); const char *v_data = "test"; CFDataRef pwdata = CFDataCreate(NULL, (UInt8 *)v_data, strlen(v_data)); const void *keys[] = { kSecClass, kSecAttrServer, kSecAttrAccount, kSecAttrPort, kSecAttrProtocol, kSecAttrAuthenticationType, kSecValueData }; const void *values[] = { kSecClassInternetPassword, CFSTR("members.spamcop.net"), CFSTR("smith"), eighty, CFSTR("http"), CFSTR("dflt"), pwdata }; CFDictionaryRef item = CFDictionaryCreate(NULL, keys, values, array_size(keys), NULL, NULL); ok_status(SecItemAdd(item, NULL), "add internet password"); } return NULL; }
// output a packet and return its sequence number void ARec::OutPacket(PhraseType k, string wrd, string tag, int pred, int alt, float ac, float lm, float score, float confidence, float nact, HTime start, HTime end) { OutMarkers(start); ++outseqnum; APhraseData *pd = (APhraseData *)new APhraseData(k,outseqnum,pred); pd->alt = alt; pd->ac = ac; pd->lm = lm; pd->score = score; pd->confidence = confidence; pd->word = wrd; pd->tag = tag; pd->nact = nact; APacket p(pd); p.SetStartTime(start); p.SetEndTime(end); out->PutPacket(p); if (showRD) DrawOutLine(k,start,wrd,tag); if (trace&T_OUT) p.Show(); #ifdef __APPLE__ CFMutableDictionaryRef userInfo = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFNumberRef cfPhraseType = CFNumberCreate(NULL, kCFNumberIntType, &k); CFDictionaryAddValue(userInfo, CFSTR("PhraseType"), cfPhraseType); CFRelease(cfPhraseType); CFStringRef cfWord = CFStringCreateWithCString(NULL, wrd.c_str(), kCFStringEncodingUTF8); CFDictionaryAddValue(userInfo, CFSTR("Word"), cfWord); CFRelease(cfWord); CFStringRef cfTag = CFStringCreateWithCString(NULL, tag.c_str(), kCFStringEncodingUTF8); CFDictionaryAddValue(userInfo, CFSTR("Tag"), cfTag); CFRelease(cfTag); CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), CFSTR("ARec::OutPacket"), NULL, userInfo, false); CFRelease(userInfo); #endif }
CFDictionaryRef WebBackForwardList::createCFDictionaryRepresentation(WebPageProxy::WebPageProxySessionStateFilterCallback filter, void* context) const { ASSERT(m_current == NoCurrentItemIndex || m_current < m_entries.size()); RetainPtr<CFMutableArrayRef> entries(AdoptCF, CFArrayCreateMutable(0, m_entries.size(), &kCFTypeArrayCallBacks)); // We may need to update the current index to account for entries that are filtered by the callback. int currentIndex = m_current; for (size_t i = 0; i < m_entries.size(); ++i) { RefPtr<WebURL> webURL = WebURL::create(m_entries[i]->url()); if (filter && !filter(toAPI(m_page), WKPageGetSessionHistoryURLValueType(), toURLRef(m_entries[i]->originalURL().impl()), context)) { if (i <= static_cast<size_t>(m_current)) currentIndex--; continue; } RetainPtr<CFStringRef> url(AdoptCF, m_entries[i]->url().createCFString()); RetainPtr<CFStringRef> title(AdoptCF, m_entries[i]->title().createCFString()); RetainPtr<CFStringRef> originalURL(AdoptCF, m_entries[i]->originalURL().createCFString()); RetainPtr<CFDataRef> entryData(AdoptCF, CFDataCreate(kCFAllocatorDefault, m_entries[i]->backForwardData().data(), m_entries[i]->backForwardData().size())); const void* keys[4] = { SessionHistoryEntryURLKey(), SessionHistoryEntryTitleKey(), SessionHistoryEntryOriginalURLKey(), SessionHistoryEntryDataKey() }; const void* values[4] = { url.get(), title.get(), originalURL.get(), entryData.get() }; RetainPtr<CFDictionaryRef> entryDictionary(AdoptCF, CFDictionaryCreate(0, keys, values, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); CFArrayAppendValue(entries.get(), entryDictionary.get()); } ASSERT(currentIndex < CFArrayGetCount(entries.get())); RetainPtr<CFNumberRef> currentIndexNumber(AdoptCF, CFNumberCreate(0, kCFNumberIntType, ¤tIndex)); const void* keys[2] = { SessionHistoryCurrentIndexKey(), SessionHistoryEntriesKey() }; const void* values[2] = { currentIndexNumber.get(), entries.get() }; return CFDictionaryCreate(0, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); }
CFMutableDictionaryRef keychain_get_item_ios5(sqlite3_stmt* stmt) { const char* name; uint32_t pclass, i, rowid; for(i=0; i < sqlite3_column_count(stmt) ; i++) { name = sqlite3_column_name(stmt,i); if(!strcmp(name, "rowid")) { rowid = sqlite3_column_int(stmt, i); } if(!strcmp(name, "data")) { const void* blob = sqlite3_column_blob(stmt, i); int len = sqlite3_column_bytes(stmt, i); CFMutableDictionaryRef item = decrypt_data_ios5(blob,len,&pclass); if (item != NULL) { CFNumberRef cf_rowid = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &rowid); CFDictionarySetValue(item, CFSTR("rowid"), cf_rowid); CFRelease(cf_rowid); CFDictionarySetValue(item, CFSTR("protection_class"), keychain_protectionClassIdToString(pclass)); CFDataRef vdata = CFDictionaryGetValue(item, CFSTR("v_Data")); CFTypeRef data = keychain_convert_data_to_string_or_plist(vdata); if(data != NULL) { CFDictionaryAddValue(item, CFSTR("data"), data); if (data != vdata) CFRelease(data); } return item; } } } return NULL; }
static void add_default_proxy(CFMutableArrayRef proxies, CFDictionaryRef defaultProxy, Boolean *orderAdded) { CFMutableDictionaryRef myDefault; uint32_t myOrder = DEFAULT_MATCH_ORDER; CFNumberRef order = NULL; if (defaultProxy == NULL) { myDefault = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } else { myDefault = CFDictionaryCreateMutableCopy(NULL, 0, defaultProxy); CFDictionaryRemoveValue(myDefault, kSCPropInterfaceName); order = CFDictionaryGetValue(myDefault, PROXY_MATCH_ORDER_KEY); } // ensure that the default proxy has a search order if (!isA_CFNumber(order) || !CFNumberGetValue(order, kCFNumberIntType, &myOrder)) { myOrder = DEFAULT_MATCH_ORDER; order = CFNumberCreate(NULL, kCFNumberIntType, &myOrder); CFDictionarySetValue(myDefault, PROXY_MATCH_ORDER_KEY, order); CFRelease(order); *orderAdded = TRUE; } // add the default proxy add_proxy(proxies, myDefault); CFRelease(myDefault); return; }
JNIEXPORT void JNICALL Java_bits_hidpunk_osx_OsxHidMatcher_setLongValue (JNIEnv* env, jclass clazz, jlong ptr, jint key, jlong val) { CFMutableDictionaryRef dict; CFNumberRef num; CFStringRef dictKey; long cval = (long)val; if(!ptr) { hidpunk_throwNullPointerException(env, ""); return; } dict = *(CFMutableDictionaryRef*)&ptr; dictKey = hidpunk_findKey((int)key); if(dictKey == NULL) return; num = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongType, &cval); CFDictionarySetValue(dict, dictKey, num); CFRelease(num); }
static String CGImageToDataURL(CGImageRef image, const String& mimeType, const double* quality) { if (!image) return "data:,"; RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0)); if (!data) return "data:,"; RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); ASSERT(uti); RetainPtr<CGImageDestinationRef> destination(AdoptCF, CGImageDestinationCreateWithData(data.get(), uti.get(), 1, 0)); if (!destination) return "data:,"; RetainPtr<CFDictionaryRef> imageProperties = 0; if (CFEqual(uti.get(), jpegUTI()) && quality && *quality >= 0.0 && *quality <= 1.0) { // Apply the compression quality to the JPEG image destination. RetainPtr<CFNumberRef> compressionQuality(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, quality)); const void* key = kCGImageDestinationLossyCompressionQuality; const void* value = compressionQuality.get(); imageProperties.adoptCF(CFDictionaryCreate(0, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); } // Setting kCGImageDestinationBackgroundColor to black for JPEG images in imageProperties would save some math // in the calling functions, but it doesn't seem to work. CGImageDestinationAddImage(destination.get(), image, imageProperties.get()); CGImageDestinationFinalize(destination.get()); Vector<char> base64Data; base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), base64Data); return "data:" + mimeType + ";base64," + base64Data; }
static bool CGImageEncodeToData(CGImageRef image, CFStringRef uti, const double* quality, CFMutableDataRef data) { if (!image || !uti || !data) return false; RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData(data, uti, 1, 0)); if (!destination) return false; RetainPtr<CFDictionaryRef> imageProperties = 0; if (CFEqual(uti, jpegUTI()) && quality && *quality >= 0.0 && *quality <= 1.0) { // Apply the compression quality to the JPEG image destination. RetainPtr<CFNumberRef> compressionQuality = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, quality)); const void* key = kCGImageDestinationLossyCompressionQuality; const void* value = compressionQuality.get(); imageProperties = adoptCF(CFDictionaryCreate(0, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); } // Setting kCGImageDestinationBackgroundColor to black for JPEG images in imageProperties would save some math // in the calling functions, but it doesn't seem to work. CGImageDestinationAddImage(destination.get(), image, imageProperties.get()); return CGImageDestinationFinalize(destination.get()); }
CFMutableDictionaryRef createAudioTrackProperties(uint32_t trackLength) { CFMutableDictionaryRef properties = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFNumberRef value; uint32_t temp; /* Create a properties dictionary for all of the tracks. This dictionary is common to each since each will be an audio track and other than the size will be identical. */ temp = kDRBlockSizeAudio; value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &temp); CFDictionaryAddValue(properties, kDRBlockSizeKey, value); CFRelease(value); temp = kDRBlockTypeAudio; value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &temp); CFDictionaryAddValue(properties, kDRBlockTypeKey, value); CFRelease(value); temp = kDRDataFormAudio; value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &temp); CFDictionaryAddValue(properties, kDRDataFormKey, value); CFRelease(value); temp = kDRSessionFormatAudio; value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &temp); CFDictionaryAddValue(properties, kDRSessionFormatKey, value); CFRelease(value); temp = kDRTrackModeAudio; value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &temp); CFDictionaryAddValue(properties, kDRTrackModeKey, value); CFRelease(value); value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &trackLength); CFDictionarySetValue(properties, kDRTrackLengthKey, value); CFRelease(value); return properties; }
bool GraphicsSurface::platformCreate(const IntSize& size, Flags flags) { unsigned pixelFormat = 'BGRA'; unsigned bytesPerElement = 4; int width = size.width(); int height = size.height(); unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement); if (!bytesPerRow) return false; unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow); if (!allocSize) return false; const void *keys[7]; const void *values[7]; keys[0] = kIOSurfaceWidth; values[0] = CFNumberCreate(0, kCFNumberIntType, &width); keys[1] = kIOSurfaceHeight; values[1] = CFNumberCreate(0, kCFNumberIntType, &height); keys[2] = kIOSurfacePixelFormat; values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat); keys[3] = kIOSurfaceBytesPerElement; values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement); keys[4] = kIOSurfaceBytesPerRow; values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow); keys[5] = kIOSurfaceAllocSize; values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize); keys[6] = kIOSurfaceIsGlobal; values[6] = (flags & GraphicsSurface::SupportsSharing) ? kCFBooleanTrue : kCFBooleanFalse; CFDictionaryRef dict = CFDictionaryCreate(0, keys, values, 7, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); for (unsigned i = 0; i < 7; i++) CFRelease(values[i]); m_platformSurface = IOSurfaceCreate(dict); return !!m_platformSurface; }
static RetainPtr<IOSurfaceRef> createIOSurface(const IntSize& size) { unsigned pixelFormat = 'BGRA'; unsigned bytesPerElement = 4; int width = size.width(); int height = size.height(); unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width() * bytesPerElement); if (!bytesPerRow) return 0; unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, size.height() * bytesPerRow); if (!allocSize) return 0; const void *keys[7]; const void *values[7]; keys[0] = kIOSurfaceWidth; values[0] = CFNumberCreate(0, kCFNumberIntType, &width); keys[1] = kIOSurfaceHeight; values[1] = CFNumberCreate(0, kCFNumberIntType, &height); keys[2] = kIOSurfacePixelFormat; values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat); keys[3] = kIOSurfaceBytesPerElement; values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement); keys[4] = kIOSurfaceBytesPerRow; values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow); keys[5] = kIOSurfaceAllocSize; values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize); keys[6] = kIOSurfaceMemoryRegion; values[6] = CFSTR("PurpleGfxMem"); RetainPtr<CFDictionaryRef> dict(AdoptCF, CFDictionaryCreate(0, keys, values, 7, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); for (unsigned i = 0; i < 7; i++) CFRelease(values[i]); return RetainPtr<IOSurfaceRef>(AdoptCF, IOSurfaceCreate(dict.get())); }
void stringHandling(void) { CFStringRef number; int theValue = 80; double theOtherValue = 123.26; CFNumberRef expected = CFNumberCreate(0, kCFNumberIntType, &theValue); show(CFSTR("------------------Number Magic---------------")); show(CFSTR("1. Integer Parsing")); show(CFSTR(" (a) Decimal Style")); number = CFStringCreateWithCString(NULL, "80.0", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterDecimalStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (b) Currency Style")); CFRelease(number); number = CFStringCreateWithCString(NULL, "$80.00", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterCurrencyStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (c) Percent Style (does not work for integers)")); CFRelease(number); number = CFStringCreateWithCString(NULL, "80%", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterPercentStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (d) Scientific Notation Style (does not work for integers)")); CFRelease(number); number = CFStringCreateWithCString(NULL, "8.0E1", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterScientificStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (e) Spell-Out Style")); CFRelease(number); number = CFStringCreateWithCString(NULL, "eighty", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterSpellOutStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (f) No Style (decimal)")); CFRelease(number); number = CFStringCreateWithCString(NULL, "80.0", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterNoStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (g) No Style (spell out) (is not expected to work)")); CFRelease(number); number = CFStringCreateWithCString(NULL, "eighty", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterNoStyle, kCFNumberFormatterParseIntegersOnly)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR("2. Decimal Parsing")); show(CFSTR(" (a) Decimal Style")); CFRelease(expected); expected = CFNumberCreate(0, kCFNumberDoubleType, &theOtherValue); CFRelease(number); number = CFStringCreateWithCString(NULL, "123.26", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterDecimalStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (b) Currency Style")); CFRelease(number); number = CFStringCreateWithCString(NULL, "$123.26", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterCurrencyStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (c) Percent Style")); CFRelease(number); number = CFStringCreateWithCString(NULL, "123.26%", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterPercentStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (d) Scientific Notation Style")); CFRelease(number); number = CFStringCreateWithCString(NULL, "1.2326e2", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterScientificStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (e) Spell-Out Style")); CFRelease(number); number = CFStringCreateWithCString(NULL, "one hundred twenty-three point two six", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterSpellOutStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (f) No Style (decimal)")); CFRelease(number); number = CFStringCreateWithCString(NULL, "123.26", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterNoStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); show(CFSTR(" (g) No Style (spell-out) (not expected to work)")); CFRelease(number); number = CFStringCreateWithCString(NULL, "one hundred twenty three point two six", kCFStringEncodingASCII); if (equalValues(number, expected, kCFNumberFormatterNoStyle, 0)) show(CFSTR("correct.")); else show(CFSTR("WRONG!!!")); CFRelease(number); }