本文整理匯總了C++中CFDictionaryCreateMutableCopy函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFDictionaryCreateMutableCopy函數的具體用法?C++ CFDictionaryCreateMutableCopy怎麽用?C++ CFDictionaryCreateMutableCopy使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFDictionaryCreateMutableCopy函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: copyIF
static CFMutableDictionaryRef
copyIF(CFStringRef key, CFMutableDictionaryRef oldIFs, CFMutableDictionaryRef newIFs)
{
CFDictionaryRef dict = NULL;
CFMutableDictionaryRef newDict = NULL;
if (CFDictionaryGetValueIfPresent(newIFs, key, (const void **)&dict)) {
newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict);
} else {
dict = cache_SCDynamicStoreCopyValue(store, key);
if (dict) {
CFDictionarySetValue(oldIFs, key, dict);
if (isA_CFDictionary(dict)) {
newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict);
CFDictionaryRemoveValue(newDict, kSCPropNetIPv6Addresses);
CFDictionaryRemoveValue(newDict, kSCPropNetIPv6DestAddresses);
CFDictionaryRemoveValue(newDict, kSCPropNetIPv6Flags);
CFDictionaryRemoveValue(newDict, kSCPropNetIPv6PrefixLength);
#ifdef NOTYET
CFDictionaryRemoveValue(newDict, kSCPropNetIPv6ScopeID);
#endif /* NOTYET */
}
CFRelease(dict);
}
}
if (!newDict) {
newDict = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
return newDict;
}
示例2: CFDictionaryCreateMutableCopy
CFDictionaryRef SFB::Audio::Metadata::CreateDictionaryRepresentation() const
{
CFMutableDictionaryRef dictionaryRepresentation = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, mMetadata);
CFIndex count = CFDictionaryGetCount(mChangedMetadata);
CFTypeRef *keys = (CFTypeRef *)malloc(sizeof(CFTypeRef) * (size_t)count);
CFTypeRef *values = (CFTypeRef *)malloc(sizeof(CFTypeRef) * (size_t)count);
CFDictionaryGetKeysAndValues(mChangedMetadata, keys, values);
for(CFIndex i = 0; i < count; ++i) {
if(kCFNull == values[i])
CFDictionaryRemoveValue(dictionaryRepresentation, keys[i]);
else
CFDictionarySetValue(dictionaryRepresentation, keys[i], values[i]);
}
free(keys), keys = nullptr;
free(values), values = nullptr;
CFMutableArray pictureArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
for(auto picture : GetAttachedPictures()) {
CFDictionary pictureRepresentation = picture->CreateDictionaryRepresentation();
CFArrayAppendValue(pictureArray, pictureRepresentation);
}
if(0 < CFArrayGetCount(pictureArray)) {
CFDictionarySetValue(dictionaryRepresentation, kAttachedPicturesKey, pictureArray);
}
return dictionaryRepresentation;
}
示例3: _loadXMLDomainIfStale
// Assumes the domain has already been locked
static void _loadXMLDomainIfStale(CFURLRef url, _CFXMLPreferencesDomain *domain) {
CFAllocatorRef alloc = __CFPreferencesAllocator();
int idx;
if (domain->_domainDict) {
CFDateRef modDate;
CFAbsoluteTime modTime;
CFURLRef testURL = url;
if (CFDictionaryGetCount(domain->_domainDict) == 0) {
// domain never existed; check the parent directory, not the child
testURL = CFURLCreateWithFileSystemPathRelativeToBase(alloc, CFSTR(".."), kCFURLPOSIXPathStyle, true, url);
}
modDate = (CFDateRef )CFURLCreatePropertyFromResource(alloc, testURL, kCFURLFileLastModificationTime, NULL);
modTime = modDate ? CFDateGetAbsoluteTime(modDate) : 0.0;
// free before possible return. we can test non-NULL of modDate but don't depend on contents after this.
if (testURL != url) CFRelease(testURL);
if (modDate) CFRelease(modDate);
if (modDate != NULL && modTime < domain->_lastReadTime) { // We're up-to-date
return;
}
}
// We're out-of-date; destroy domainDict and reload
if (domain->_domainDict) {
CFRelease(domain->_domainDict);
domain->_domainDict = NULL;
}
// We no longer lock on read; instead, we assume parse failures are because someone else is writing the file, and just try to parse again. If we fail 3 times in a row, we assume the file is corrupted. REW, 7/13/99
for (idx = 0; idx < 3; idx ++) {
CFDataRef data;
if (!CFURLCreateDataAndPropertiesFromResource(alloc, url, &data, NULL, NULL, NULL) || !data) {
// Either a file system error (so we can't read the file), or an empty (or perhaps non-existant) file
domain->_domainDict = CFDictionaryCreateMutable(alloc, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
break;
} else {
CFTypeRef pList = CFPropertyListCreateFromXMLData(alloc, data, kCFPropertyListImmutable, NULL);
CFRelease(data);
if (pList && CFGetTypeID(pList) == CFDictionaryGetTypeID()) {
domain->_domainDict = CFDictionaryCreateMutableCopy(alloc, 0, (CFDictionaryRef)pList);
CFRelease(pList);
break;
} else if (pList) {
CFRelease(pList);
}
// Assume the file is being written; sleep for a short time (to allow the write to complete) then re-read
__CFMilliSleep(150);
}
}
if (!domain->_domainDict) {
// Failed to ever load
domain->_domainDict = CFDictionaryCreateMutable(alloc, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
domain->_lastReadTime = CFAbsoluteTimeGetCurrent();
}
示例4: CFLocaleCreateComponentsFromLocaleIdentifier
CF_PRIVATE UCalendar *__CFCalendarCreateUCalendar(CFStringRef calendarID, CFStringRef localeID, CFTimeZoneRef tz) {
if (calendarID) {
CFDictionaryRef components = CFLocaleCreateComponentsFromLocaleIdentifier(kCFAllocatorSystemDefault, localeID);
CFMutableDictionaryRef mcomponents = CFDictionaryCreateMutableCopy(kCFAllocatorSystemDefault, 0, components);
CFDictionarySetValue(mcomponents, kCFLocaleCalendarIdentifier, calendarID);
localeID = CFLocaleCreateLocaleIdentifierFromComponents(kCFAllocatorSystemDefault, mcomponents);
CFRelease(mcomponents);
CFRelease(components);
}
char buffer[BUFFER_SIZE];
const char *cstr = CFStringGetCStringPtr(localeID, kCFStringEncodingASCII);
if (NULL == cstr) {
if (CFStringGetCString(localeID, buffer, BUFFER_SIZE, kCFStringEncodingASCII)) cstr = buffer;
}
if (NULL == cstr) {
if (calendarID) CFRelease(localeID);
return NULL;
}
UChar ubuffer[BUFFER_SIZE];
CFStringRef tznam = CFTimeZoneGetName(tz);
CFIndex cnt = CFStringGetLength(tznam);
if (BUFFER_SIZE < cnt) cnt = BUFFER_SIZE;
CFStringGetCharacters(tznam, CFRangeMake(0, cnt), (UniChar *)ubuffer);
UErrorCode status = U_ZERO_ERROR;
UCalendar *cal = ucal_open(ubuffer, cnt, cstr, UCAL_DEFAULT, &status);
if (calendarID) CFRelease(localeID);
return cal;
}
示例5: rb_singleton_class_clone
VALUE
rb_singleton_class_clone(VALUE obj)
{
VALUE klass = RBASIC(obj)->klass;
if (!RCLASS_SINGLETON(klass)) {
return klass;
}
// Create new singleton class.
VALUE clone = rb_objc_create_class(NULL, RCLASS_SUPER(klass));
// Copy ivars.
CFMutableDictionaryRef ivar_dict = rb_class_ivar_dict(klass);
if (ivar_dict != NULL) {
CFMutableDictionaryRef cloned_ivar_dict =
CFDictionaryCreateMutableCopy(NULL, 0, (CFDictionaryRef)ivar_dict);
rb_class_ivar_set_dict(clone, cloned_ivar_dict);
CFMakeCollectable(cloned_ivar_dict);
}
// Copy methods.
rb_vm_copy_methods((Class)klass, (Class)clone);
rb_singleton_class_attached(clone, obj);
if (RCLASS_SUPER(clone) == rb_cRubyObject) {
long v = RCLASS_VERSION(clone) ^ RCLASS_IS_OBJECT_SUBCLASS;
RCLASS_SET_VERSION(clone, v);
}
RCLASS_SET_VERSION_FLAG(clone, RCLASS_IS_SINGLETON);
return clone;
}
示例6: SRCopyItems
CFArrayRef SRCopyItems(CFArrayRef keychains, CFArrayRef classes) {
CFMutableArrayRef allItems = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(query, kSecMatchSearchList, keychains);
CFDictionarySetValue(query, kSecReturnRef, kCFBooleanTrue);
CFDictionarySetValue(query, kSecReturnAttributes, kCFBooleanTrue);
CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitAll);
for (int i = 0; i < CFArrayGetCount(classes); i++) {
CFTypeRef class = CFArrayGetValueAtIndex(classes, i);
CFDictionarySetValue(query, kSecClass, class);
CFArrayRef items = NULL;
OSStatus status = SecItemCopyMatching(query, (CFTypeRef *)&items);
// If there are not results, that's fine; this class is just empty
if (errSecItemNotFound != status) {
SRHandleError(status, true);
for (int j = 0; j < CFArrayGetCount(items); j++) {
CFDictionaryRef properties = CFArrayGetValueAtIndex(items, j);
CFMutableDictionaryRef newProperties = CFDictionaryCreateMutableCopy(NULL, 0, properties);
CFDictionarySetValue(newProperties, kSRAttrClass, class);
CFArrayAppendValue(allItems, newProperties);
CFRelease(newProperties);
}
CFRelease(items);
}
}
示例7: SecItemCopyAttributeDictionary
static CFDictionaryRef
SecItemCopyAttributeDictionary(CFTypeRef ref) {
CFDictionaryRef refDictionary = NULL;
CFTypeID typeID = CFGetTypeID(ref);
if (typeID == SecKeyGetTypeID()) {
refDictionary = SecKeyCopyAttributeDictionary((SecKeyRef)ref);
} else if (typeID == SecCertificateGetTypeID()) {
refDictionary =
SecCertificateCopyAttributeDictionary((SecCertificateRef)ref);
} else if (typeID == SecIdentityGetTypeID()) {
assert(false);
SecIdentityRef identity = (SecIdentityRef)ref;
SecCertificateRef cert = NULL;
SecKeyRef key = NULL;
if (!SecIdentityCopyCertificate(identity, &cert) &&
!SecIdentityCopyPrivateKey(identity, &key))
{
CFDataRef data = SecCertificateCopyData(cert);
CFDictionaryRef key_dict = SecKeyCopyAttributeDictionary(key);
if (key_dict && data) {
refDictionary = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, key_dict);
CFDictionarySetValue((CFMutableDictionaryRef)refDictionary,
CFSTR(CERTIFICATE_DATA_COLUMN_LABEL), data);
}
CFReleaseNull(key_dict);
CFReleaseNull(data);
}
CFReleaseNull(cert);
CFReleaseNull(key);
} else {
refDictionary = NULL;
}
return refDictionary;
}
示例8: do_dictRemoveKey
__private_extern__
void
do_dictRemoveKey(int argc, char **argv)
{
CFStringRef key;
CFMutableDictionaryRef val;
if (value == NULL) {
SCPrint(TRUE, stdout, CFSTR("d.remove: dictionary must be initialized.\n"));
return;
}
if (!isA_CFDictionary(value)) {
SCPrint(TRUE, stdout, CFSTR("d.remove: data (fetched from configuration server) is not a dictionary.\n"));
return;
}
val = CFDictionaryCreateMutableCopy(NULL, 0, value);
CFRelease(value);
value = val;
key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
CFDictionaryRemoveValue((CFMutableDictionaryRef)value, key);
CFRelease(key);
return;
}
示例9: WorkaroundNetworkPrefsBug
static OSStatus WorkaroundNetworkPrefsBug(CFDictionaryRef *entitiesDictPtr)
// If this is an Ethernet interface and LCPEchoEnabled is false,
// set it to true. This works around what I think is a bug in
// the Network preferences panel <rdar://problem/3182846> where the
// LCPEchoEnabled flag is mysteriously set to false for PCI Ethernet
// interfaces.
{
OSStatus err;
CFStringRef hardwarePath[2];
CFStringRef lcpPath[2];
CFStringRef hardwareStr;
CFNumberRef lcpValue;
long enabled;
hardwarePath[0] = kSCEntNetInterface;
hardwarePath[1] = kSCPropNetInterfaceHardware;
lcpPath[0] = kSCEntNetPPP;
lcpPath[1] = kSCPropNetPPPLCPEchoEnabled;
hardwareStr = NULL; // just to make debugging easier
lcpValue = NULL;
err = noErr;
if ( CFQDictionaryGetValueAtPath(*entitiesDictPtr, (const void **) hardwarePath, 2, (const void **) &hardwareStr) == noErr
&& CFEqual(hardwareStr, kSCEntNetEthernet)
&& CFQDictionaryGetValueAtPath(*entitiesDictPtr, (const void **) lcpPath, 2, (const void **) &lcpValue) == noErr
&& CFNumberGetValue(lcpValue, kCFNumberLongType, &enabled)
&& (enabled == 0) ) {
CFMutableDictionaryRef newDict;
CFNumberRef numRef;
if ( ! gRunQuiet ) {
fprintf(stderr, "Applied workaround\n");
}
numRef = NULL;
newDict = CFDictionaryCreateMutableCopy(NULL, 0, *entitiesDictPtr);
err = CFQError(newDict);
if (err == noErr) {
enabled = true;
numRef = CFNumberCreate(NULL, kCFNumberLongType, &enabled);
err = CFQError(numRef);
}
if (err == noErr) {
err = CFQDictionarySetValueAtPath(newDict, (const void **) lcpPath, 2, numRef);
}
if (err == noErr) {
CFQRelease(*entitiesDictPtr);
*entitiesDictPtr = newDict;
newDict = NULL;
}
CFQRelease(newDict);
CFQRelease(numRef);
}
return err;
}
示例10: _SCBondInterfaceSetMode
static Boolean
_SCBondInterfaceSetMode(SCBondInterfaceRef bond, CFNumberRef mode)
{
SCNetworkInterfacePrivateRef interfacePrivate = (SCNetworkInterfacePrivateRef)bond;
Boolean needs_release = FALSE;
Boolean ok = TRUE;
assert(bond != NULL);
if (mode == NULL) {
int mode_num = IF_BOND_MODE_LACP;
mode = CFNumberCreate(NULL, kCFNumberIntType, &mode_num);
needs_release = TRUE;
}
// set mode in the stored preferences
if (interfacePrivate->prefs != NULL) {
CFDictionaryRef dict;
CFMutableDictionaryRef newDict;
CFStringRef path;
path = CFStringCreateWithFormat(NULL,
NULL,
CFSTR("/%@/%@/%@"),
kSCPrefVirtualNetworkInterfaces,
kSCNetworkInterfaceTypeBond,
interfacePrivate->entity_device);
dict = SCPreferencesPathGetValue(interfacePrivate->prefs, path);
if (!isA_CFDictionary(dict)) {
// if the prefs are confused
CFRelease(path);
_SCErrorSet(kSCStatusFailed);
ok = FALSE;
goto done;
}
newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict);
CFDictionarySetValue(newDict, kSCPropVirtualNetworkInterfacesBondMode, mode);
if (!CFEqual(dict, newDict)) {
ok = SCPreferencesPathSetValue(interfacePrivate->prefs, path, newDict);
}
CFRelease(newDict);
CFRelease(path);
}
if (ok) {
CFRetain(mode);
if (interfacePrivate->bond.mode != NULL) {
CFRelease(interfacePrivate->bond.mode);
}
interfacePrivate->bond.mode = mode;
}
done :
if (needs_release) CFRelease(mode);
return ok;
}
示例11: link_add
__private_extern__
void
link_add(const char *if_name)
{
CFStringRef interface;
CFStringRef cacheKey;
CFDictionaryRef dict;
CFMutableDictionaryRef newDict = NULL;
CFArrayRef ifList;
CFMutableArrayRef newIFList = NULL;
interface = CFStringCreateWithCString(NULL, if_name, kCFStringEncodingMacRoman);
cacheKey = SCDynamicStoreKeyCreateNetworkInterface(NULL,
kSCDynamicStoreDomainState);
dict = cache_SCDynamicStoreCopyValue(store, cacheKey);
if (dict) {
if (isA_CFDictionary(dict)) {
newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict);
ifList = CFDictionaryGetValue(newDict, kSCPropNetInterfaces);
if (isA_CFArray(ifList)) {
newIFList = CFArrayCreateMutableCopy(NULL, 0, ifList);
}
}
CFRelease(dict);
}
if (!newDict) {
newDict = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
if (!newIFList) {
newIFList = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
}
if (CFArrayContainsValue(newIFList,
CFRangeMake(0, CFArrayGetCount(newIFList)),
interface) == FALSE) {
CFArrayAppendValue(newIFList, interface);
CFDictionarySetValue(newDict, kSCPropNetInterfaces, newIFList);
}
cache_SCDynamicStoreSetValue(store, cacheKey, newDict);
link_update_status(if_name, TRUE);
#ifdef KEV_DL_LINK_QUALITY_METRIC_CHANGED
link_update_quality_metric(if_name);
#endif /* KEV_DL_LINK_QUALITY_METRIC_CHANGED */
CFRelease(cacheKey);
CFRelease(interface);
if (newDict) CFRelease(newDict);
if (newIFList) CFRelease(newIFList);
return;
}
示例12: __setPrefsConfiguration
__private_extern__ Boolean
__setPrefsConfiguration(SCPreferencesRef prefs,
CFStringRef path,
CFDictionaryRef config,
Boolean keepInactive)
{
CFDictionaryRef curConfig;
CFMutableDictionaryRef newConfig = NULL;
Boolean ok;
if ((config != NULL) && !isA_CFDictionary(config)) {
_SCErrorSet(kSCStatusInvalidArgument);
return FALSE;
}
curConfig = SCPreferencesPathGetValue(prefs, path);
if (config != NULL) {
newConfig = CFDictionaryCreateMutableCopy(NULL, 0, config);
}
if (keepInactive) {
if (config == NULL) {
newConfig = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
if (isA_CFDictionary(curConfig) && CFDictionaryContainsKey(curConfig, kSCResvInactive)) {
// if currently disabled
CFDictionarySetValue(newConfig, kSCResvInactive, kCFBooleanTrue);
} else {
// if currently enabled
CFDictionaryRemoveValue(newConfig, kSCResvInactive);
}
}
// set new configuration
if (_SC_CFEqual(curConfig, newConfig)) {
// if no change
if (newConfig != NULL) CFRelease(newConfig);
ok = TRUE;
} else if (newConfig != NULL) {
// if new configuration (or we are preserving a disabled state)
ok = SCPreferencesPathSetValue(prefs, path, newConfig);
CFRelease(newConfig);
} else {
ok = SCPreferencesPathRemoveValue(prefs, path);
if (!ok && (SCError() == kSCStatusNoKey)) {
ok = TRUE;
}
}
return ok;
}
示例13: rb_mod_init_copy
VALUE
rb_mod_init_copy(VALUE clone, SEL sel, VALUE orig)
{
rb_obj_init_copy(clone, 0, orig);
VALUE super;
if (!RCLASS_RUBY(orig)) {
super = orig;
rb_warn("cloning class `%s' is not supported, creating a " \
"subclass instead", rb_class2name(orig));
}
else {
super = RCLASS_SUPER(orig);
}
RCLASS_SET_SUPER(clone, super);
// Copy flags.
unsigned long version_flag = RCLASS_IS_RUBY_CLASS;
if ((RCLASS_VERSION(super) & RCLASS_IS_OBJECT_SUBCLASS)
== RCLASS_IS_OBJECT_SUBCLASS) {
version_flag |= RCLASS_IS_OBJECT_SUBCLASS;
}
if (RCLASS_MODULE(orig)) {
version_flag |= RCLASS_IS_MODULE;
}
RCLASS_SET_VERSION(clone, version_flag);
if (!class_isMetaClass((Class)clone)) {
// Clear type info.
RCLASS_SET_VERSION(*(Class *)clone, RCLASS_VERSION(*(Class *)clone));
}
// Copy methods.
rb_vm_copy_methods((Class)orig, (Class)clone);
if (!class_isMetaClass((Class)orig)) {
rb_vm_copy_methods(*(Class *)orig, *(Class *)clone);
}
// Copy ivars.
CFMutableDictionaryRef orig_dict = rb_class_ivar_dict(orig);
CFMutableDictionaryRef clone_dict;
if (orig_dict != NULL) {
clone_dict = CFDictionaryCreateMutableCopy(NULL, 0, orig_dict);
rb_class_ivar_set_dict(clone, clone_dict);
CFMakeCollectable(clone_dict);
}
else {
clone_dict = rb_class_ivar_dict_or_create(clone);
}
// Remove the classpath & classid (name) so that they are not
// copied over the new module / class.
CFDictionaryRemoveValue(clone_dict, (const void *)id_classpath);
CFDictionaryRemoveValue(clone_dict, (const void *)id_classid);
return clone;
}
示例14: __remove_password
__private_extern__
Boolean
__remove_password(SCPreferencesRef prefs,
CFDictionaryRef config,
CFStringRef passwordKey,
CFStringRef encryptionKey,
CFStringRef encryptionKeyChainValue,
CFStringRef unique_id,
CFDictionaryRef *newConfig)
{
CFStringRef encryption = NULL;
Boolean ok = FALSE;
// check for keychain password
if (config != NULL) {
encryption = CFDictionaryGetValue(config, encryptionKey);
}
if ((encryption == NULL) ||
(isA_CFString(encryption) &&
CFEqual(encryption, encryptionKeyChainValue))) {
// remove keychain password
if (prefs != NULL) {
ok = _SCPreferencesSystemKeychainPasswordItemRemove(prefs, unique_id);
} else {
ok = _SCSecKeychainPasswordItemRemove(NULL, unique_id);
}
}
// as needed, check if we have an in-line password that we can remove
if (!ok && (encryption == NULL) && (config != NULL)) {
CFDataRef inline_password;
inline_password = CFDictionaryGetValue(config, passwordKey);
inline_password = __copy_legacy_password(inline_password);
if (inline_password != NULL) {
CFRelease(inline_password);
ok = TRUE;
}
}
if (newConfig != NULL) {
if (ok && (config != NULL)) {
CFMutableDictionaryRef temp;
temp = CFDictionaryCreateMutableCopy(NULL, 0, config);
CFDictionaryRemoveValue(temp, passwordKey);
CFDictionaryRemoveValue(temp, encryptionKey);
*newConfig = (CFDictionaryRef)temp;
} else {
*newConfig = NULL;
}
}
return ok;
}
示例15: SetHibernateMode
int SetHibernateMode(int mode, CFStringRef ps) {
CFNumberRef target_hm;
CFDictionaryRef tmp_settings = 0;
CFMutableDictionaryRef settings = 0;
CFDictionaryRef tmp_node = 0;
CFMutableDictionaryRef node = 0;
IOReturn ret;
int result = 0;
target_hm = CFNumberCreate(kCFAllocatorDefault, hm_type, &mode); /* Create a CFNumber with the mode value */
tmp_settings = IOPMCopyPMPreferences(); /* Get the power management preferences */
if(!tmp_settings) { /* On failure, quit */
CFRelease(tmp_settings);
CFRelease(target_hm);
return 1;
}
settings = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, tmp_settings); /* Copy the preferences to a mutable dictionary */
CFRelease(tmp_settings);
tmp_node = isA_CFDictionary(CFDictionaryGetValue(settings, ps)); /* Get the power source dictionary */
if(tmp_node) {
node = CFDictionaryCreateMutableCopy(0, 0, tmp_node); /* On success, copy it to a mutable dictionary */
if(node) {
CFDictionarySetValue(node, CFSTR("Hibernate Mode"), target_hm); /* Set the hibernate mode to its new value */
CFDictionarySetValue(settings, ps, node); /* link the new power source dictionary to the pm preferences*/
CFRelease(node);
}
}
if(kIOReturnSuccess != (ret = IOPMSetPMPreferences(settings))) { /* Set the new pm preferences */
if(ret == kIOReturnNotPrivileged) { /* On failure, quit */
printf("deepsleep must be run as root...\n");
} else {
printf("Error 0x%08x writing Energy Saver preferences to disk\n", ret);
}
result = 1;
}
CFRelease(settings); /* Cleanup */
CFRelease(target_hm);
return result;
}