2  * Copyright (c) 2016 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  26  * SOSPersist.h -- Utility routines for get/set in CFDictionary 
  29 #ifndef _SOSPERSIST_H_ 
  30 #define _SOSPERSIST_H_ 
  34 #include <utilities/SecCFRelease.h> 
  35 #include <utilities/SecCFWrappers.h> 
  36 #include <CoreFoundation/CoreFoundation.h> 
  40 #include <AssertMacros.h> 
  43 static inline bool SOSPeerGetPersistedBoolean(CFDictionaryRef persisted
, CFStringRef key
) { 
  44     CFBooleanRef boolean 
= CFDictionaryGetValue(persisted
, key
); 
  45     return boolean 
&& CFBooleanGetValue(boolean
); 
  48 static inline CFDataRef 
SOSPeerGetPersistedData(CFDictionaryRef persisted
, CFStringRef key
) { 
  49     return asData(CFDictionaryGetValue(persisted
, key
), NULL
); 
  52 static inline int64_t SOSPeerGetPersistedInt64(CFDictionaryRef persisted
, CFStringRef key
) { 
  54     CFNumberRef number 
= CFDictionaryGetValue(persisted
, key
); 
  56         CFNumberGetValue(number
, kCFNumberSInt64Type
, &integer
); 
  61 static inline bool SOSPeerGetOptionalPersistedCFIndex(CFDictionaryRef persisted
, CFStringRef key
, CFIndex 
*value
) { 
  63     CFNumberRef number 
= CFDictionaryGetValue(persisted
, key
); 
  66         CFNumberGetValue(number
, kCFNumberCFIndexType
, value
); 
  71 static inline void SOSPersistBool(CFMutableDictionaryRef persist
, CFStringRef key
, bool value
) { 
  72     CFDictionarySetValue(persist
, key
, value 
? kCFBooleanTrue 
: kCFBooleanFalse
); 
  75 static inline void SOSPersistInt64(CFMutableDictionaryRef persist
, CFStringRef key
, int64_t value
) { 
  76     CFNumberRef number 
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberSInt64Type
, &value
); 
  77     CFDictionarySetValue(persist
, key
, number
); 
  78     CFReleaseSafe(number
); 
  81 static inline void SOSPersistCFIndex(CFMutableDictionaryRef persist
, CFStringRef key
, CFIndex value
) { 
  82     CFNumberRef number 
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberCFIndexType
, &value
); 
  83     CFDictionarySetValue(persist
, key
, number
); 
  84     CFReleaseSafe(number
); 
  87 static inline void SOSPersistOptionalValue(CFMutableDictionaryRef persist
, CFStringRef key
, CFTypeRef value
) { 
  89         CFDictionarySetValue(persist
, key
, value
); 
  94 #endif /* !_SOSPERSIST_H_ */