本文整理匯總了C++中CFNumberGetTypeID函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFNumberGetTypeID函數的具體用法?C++ CFNumberGetTypeID怎麽用?C++ CFNumberGetTypeID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFNumberGetTypeID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: IOHIDDevice_GetUInt32Property
static Boolean IOHIDDevice_GetUInt32Property(IOHIDDeviceRef inIOHIDDeviceRef, CFStringRef inKey, uint32_t *outValue) {
Boolean result = FALSE;
if ( inIOHIDDeviceRef ) {
assert( IOHIDDeviceGetTypeID() == CFGetTypeID(inIOHIDDeviceRef) );
CFTypeRef tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, inKey);
if ( tCFTypeRef ) {
// if this is a number
if ( CFNumberGetTypeID() == CFGetTypeID(tCFTypeRef) ) {
// get it's value
result = CFNumberGetValue( (CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, outValue );
}
}
}
return (result);
} // IOHIDDevice_GetUInt32Property
示例2: print_keys
void print_keys(const void *key, const void *value, void *context)
{
CFStringRef k = (CFStringRef)key;
std::string key_str = CFStringGetCStringPtr(k, kCFStringEncodingMacRoman);
std::string value_str;
CFTypeID id = CFGetTypeID(value);
if(id == CFStringGetTypeID())
{
CFStringRef v = (CFStringRef)value;
if(CFStringGetCStringPtr(v, kCFStringEncodingMacRoman))
{
value_str = CFStringGetCStringPtr(v, kCFStringEncodingMacRoman);
if(key_str == "kCGWindowName")
window_lst[window_lst.size()-1].name = value_str;
else if(key_str == "kCGWindowOwnerName")
window_lst[window_lst.size()-1].owner = value_str;
}
}
else if(id == CFNumberGetTypeID())
{
CFNumberRef v = (CFNumberRef)value;
int myint;
CFNumberGetValue(v, kCFNumberSInt64Type, &myint);
value_str = std::to_string(myint);
if(key_str == "kCGWindowLayer")
window_lst[window_lst.size()-1].layer = myint;
else if(key_str == "kCGWindowOwnerPID")
window_lst[window_lst.size()-1].pid = myint;
else if(key_str == "X")
window_lst[window_lst.size()-1].x = myint;
else if(key_str == "Y")
window_lst[window_lst.size()-1].y = myint;
else if(key_str == "Width")
window_lst[window_lst.size()-1].width = myint;
else if(key_str == "Height")
window_lst[window_lst.size()-1].height = myint;
}
else if(id == CFDictionaryGetTypeID())
{
CFDictionaryRef elem = (CFDictionaryRef)value;
CFDictionaryApplyFunction(elem, print_keys, NULL);
CFRelease(elem);
}
}
示例3: getPrefDouble
static Boolean getPrefDouble(CFStringRef key, CFStringRef app, double *val)
{
CFPropertyListRef prefRef;
Boolean ok;
double ret;
ok = false;
prefRef = CFPreferencesCopyAppValue(key, app);
if ( prefRef ) {
if ( CFGetTypeID(prefRef) == CFNumberGetTypeID() && CFNumberIsFloatType(prefRef) ) {
ok = CFNumberGetValue(prefRef, kCFNumberDoubleType, &ret);
if ( ok && val )
*val = ret;
}
CFRelease(prefRef);
}
return ok;
}
示例4: GetNumericProperty
static bool
GetNumericProperty (io_service_t ioDeviceObj, CFStringRef propName, SInt32& value)
{
// Get the property:
CFTypeRef prop = IORegistryEntryCreateCFProperty (ioDeviceObj,
propName,
kCFAllocatorDefault, 0);
if (prop == NULL)
return false;
// Make sure it's a number, and get the value:
bool success = false;
if (CFGetTypeID (prop) == CFNumberGetTypeID ())
success = CFNumberGetValue ((CFNumberRef) prop, kCFNumberSInt32Type, &value);
CFRelease (prop);
return success;
}
示例5: GetIntProperty
static int GetIntProperty( io_registry_entry_t entry, CFStringRef key )
{
CFTypeRef t = IORegistryEntryCreateCFProperty( entry, key, NULL, 0 );
if( !t )
return -1;
if( CFGetTypeID( t ) != CFNumberGetTypeID() )
{
CFRelease( t );
return -1;
}
int num;
if( !CFNumberGetValue(CFNumberRef(t), kCFNumberIntType, &num) )
num = -1;
CFRelease( t );
return num;
}
示例6: getHIDCookies
static int getHIDCookies(IOHIDDeviceInterface122 **handle,
IOHIDElementCookie **cookies,
int *nr_cookies)
{
CFTypeRef object;
long number;
CFArrayRef elements;
CFDictionaryRef element;
CFIndex i;
*nr_cookies = 0;
if (!handle || !(*handle))
return -1;
// Copy all elements, since we're grabbing most of the elements
// for this device anyway, and thus, it's faster to iterate them
// ourselves. When grabbing only one or two elements, a matching
// dictionary should be passed in here instead of NULL.
if (((*handle)->copyMatchingElements(handle, NULL, &elements)) != kIOReturnSuccess)
return -1;
// No elements, still a valid result.
if (CFArrayGetCount(elements)==0)
return 0;
*cookies = calloc(CFArrayGetCount(elements), sizeof(IOHIDElementCookie));
if (*cookies == NULL)
return -1;
for (i=0; i<CFArrayGetCount(elements); i++) {
element = CFArrayGetValueAtIndex(elements, i);
// Get cookie.
object = CFDictionaryGetValue(element, CFSTR(kIOHIDElementCookieKey));
if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID())
continue;
if (!CFNumberGetValue((CFNumberRef)object, kCFNumberLongType, &number))
continue;
(*cookies)[(*nr_cookies)++] = (IOHIDElementCookie)number;
}
return 0;
}
示例7: genOSXPrefValues
void genOSXPrefValues(const CFTypeRef& value,
const Row& base,
QueryData& results,
size_t depth) {
if (value == nullptr) {
return;
}
// Since we recurse when parsing Arrays/Dicts, monitor stack limits.
if (++depth > kPreferenceDepthLimit) {
TLOG << "The macOS preference: " << base.at("domain")
<< " exceeded subkey depth limit: " << kPreferenceDepthLimit;
return;
}
// Emit a string representation for each preference type.
Row r = base;
if (CFGetTypeID(value) == CFNumberGetTypeID()) {
r["value"] = stringFromCFNumber(static_cast<CFDataRef>(value));
} else if (CFGetTypeID(value) == CFStringGetTypeID()) {
r["value"] = stringFromCFString(static_cast<CFStringRef>(value));
} else if (CFGetTypeID(value) == CFDateGetTypeID()) {
auto unix_time = CFDateGetAbsoluteTime(static_cast<CFDateRef>(value)) +
kCFAbsoluteTimeIntervalSince1970;
r["value"] = boost::lexical_cast<std::string>(std::llround(unix_time));
} else if (CFGetTypeID(value) == CFBooleanGetTypeID()) {
r["value"] = (CFBooleanGetValue(static_cast<CFBooleanRef>(value)) == TRUE)
? "true"
: "false";
} else if (CFGetTypeID(value) == CFDataGetTypeID()) {
// Do not include data preferences.
} else if (CFGetTypeID(value) == CFArrayGetTypeID()) {
genOSXListPref(static_cast<CFArrayRef>(value), base, results, depth);
return;
} else if (CFGetTypeID(value) == CFDictionaryGetTypeID()) {
// Generate a row for each hash key.
TRowResults trow(base, results, depth);
CFDictionaryApplyFunction(
static_cast<CFDictionaryRef>(value), &genOSXHashPref, &trow);
return;
}
results.push_back(std::move(r));
}
示例8: PrintPropertyListCallback
static pascal void PrintPropertyListCallback(CFTypeRef key, CFTypeRef node, void *context)
// A callback routine used by PrintPropertyList to print
// a property list in a nicely formatted way.
{
#pragma unused(key)
int i;
int depth;
depth = (int)context;
for (i = 0; i < depth; i++) {
fprintf(stderr, " ");
}
{
CFStringRef fullDesc;
CFStringRef typeDesc;
CFStringRef valueDesc;
fullDesc = NULL;
typeDesc = CFCopyTypeIDDescription(CFGetTypeID(node));
valueDesc = NULL;
if ( CFQPropertyListIsLeaf(node) ) {
if ( CFGetTypeID(node) == CFStringGetTypeID() ) {
valueDesc = (CFStringRef) CFRetain(node);
} else if ( CFGetTypeID(node) == CFNumberGetTypeID() ) {
valueDesc = (CFStringRef) CFRetain(node);
} else {
valueDesc = CFCopyDescription(node);
}
fullDesc = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ : %@ [%d] = %@"), key, typeDesc, CFGetRetainCount(node), valueDesc);
} else {
fullDesc = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ : %@ [%d]"), key, typeDesc, CFGetRetainCount(node));
}
CFShow(fullDesc);
CFQRelease(fullDesc);
CFQRelease(valueDesc);
CFQRelease(typeDesc);
}
if ( ! CFQPropertyListIsLeaf(node) ) {
CFQPropertyListShallowApplyFunction(node, PrintPropertyListCallback, (void *) (depth + 1) );
}
}
示例9: makeRGBA32FromARGBCFArray
static bool makeRGBA32FromARGBCFArray(CFArrayRef colorArray, RGBA32& color)
{
if (CFArrayGetCount(colorArray) < 4)
return false;
float componentArray[4];
for (int i = 0; i < 4; i++) {
CFNumberRef value = static_cast<CFNumberRef>(CFArrayGetValueAtIndex(colorArray, i));
if (CFGetTypeID(value) != CFNumberGetTypeID())
return false;
float component;
CFNumberGetValue(value, kCFNumberFloatType, &component);
componentArray[i] = component;
}
color = makeRGBA32FromFloats(componentArray[1], componentArray[2], componentArray[3], componentArray[0]);
return true;
}
示例10: cf_hash_to_rb_hash
static void cf_hash_to_rb_hash(const void *raw_key, const void * raw_value, void *ctx){
CFTypeRef value = (CFTypeRef)raw_value;
CFStringRef key = (CFStringRef)raw_key;
VALUE rubyValue = Qnil;
VALUE hash = (VALUE)ctx;
if(CFStringGetTypeID() == CFGetTypeID(value)){
rubyValue = cfstring_to_rb_string((CFStringRef)value);
}
else if(CFDataGetTypeID() == CFGetTypeID(value)){
CFDataRef data = (CFDataRef)value;
rubyValue = rb_enc_str_new((const char*)CFDataGetBytePtr(data),CFDataGetLength(data), rb_ascii8bit_encoding());
}
else if(CFBooleanGetTypeID() == CFGetTypeID(value)){
Boolean booleanValue = CFBooleanGetValue(value);
rubyValue = booleanValue ? Qtrue : Qfalse;
}
else if(CFNumberGetTypeID() == CFGetTypeID(value)){
if(CFNumberIsFloatType(value))
{
double doubleValue;
CFNumberGetValue(value, kCFNumberDoubleType, &doubleValue);
rubyValue = rb_float_new(doubleValue);
}else{
long long longValue;
CFNumberGetValue(value, kCFNumberLongLongType, &longValue);
rubyValue = LL2NUM(longValue);
}
}
else if (CFDateGetTypeID() == CFGetTypeID(value)){
CFDateRef date = (CFDateRef) value;
CFAbsoluteTime abs_time = CFDateGetAbsoluteTime(date);
double secondsSinceUnixEpoch = abs_time + kCFAbsoluteTimeIntervalSince1970;
time_t seconds = (time_t)secondsSinceUnixEpoch;
long usec = (secondsSinceUnixEpoch - seconds) * 1000000;
rubyValue = rb_time_new((time_t)secondsSinceUnixEpoch, usec);
}
if(!NIL_P(rubyValue)){
rb_hash_aset(hash, cfstring_to_rb_string(key), rubyValue);
}
}
示例11: ctx
//
// Construct and prepare an SQL query on the authority table, operating on some set of existing authority records.
// In essence, this appends a suitable WHERE clause to the stanza passed and prepares it on the statement given.
//
void PolicyEngine::selectRules(SQLite::Statement &action, std::string phrase, std::string table,
CFTypeRef inTarget, AuthorityType type, SecAssessmentFlags flags, CFDictionaryRef context, std::string suffix /* = "" */)
{
CFDictionary ctx(context, errSecCSInvalidAttributeValues);
CFCopyRef<CFTypeRef> target = inTarget;
std::string filter_unsigned; // ignored; used just to trigger ad-hoc signing
normalizeTarget(target, ctx, &filter_unsigned);
string label;
if (CFStringRef lab = ctx.get<CFStringRef>(kSecAssessmentUpdateKeyLabel))
label = cfString(CFStringRef(lab));
if (!target) {
if (label.empty()) {
if (type == kAuthorityInvalid) {
action.query(phrase + suffix);
} else {
action.query(phrase + " WHERE " + table + ".type = :type" + suffix);
action.bind(":type").integer(type);
}
} else { // have label
if (type == kAuthorityInvalid) {
action.query(phrase + " WHERE " + table + ".label = :label" + suffix);
} else {
action.query(phrase + " WHERE " + table + ".type = :type AND " + table + ".label = :label" + suffix);
action.bind(":type").integer(type);
}
action.bind(":label") = label;
}
} else if (CFGetTypeID(target) == CFNumberGetTypeID()) {
action.query(phrase + " WHERE " + table + ".id = :id" + suffix);
action.bind(":id").integer(cfNumber<uint64_t>(target.as<CFNumberRef>()));
} else if (CFGetTypeID(target) == SecRequirementGetTypeID()) {
if (type == kAuthorityInvalid)
type = kAuthorityExecute;
CFRef<CFStringRef> requirementText;
MacOSError::check(SecRequirementCopyString(target.as<SecRequirementRef>(), kSecCSDefaultFlags, &requirementText.aref()));
action.query(phrase + " WHERE " + table + ".type = :type AND " + table + ".requirement = :requirement" + suffix);
action.bind(":type").integer(type);
action.bind(":requirement") = requirementText.get();
} else
MacOSError::throwMe(errSecCSInvalidObjectRef);
}
示例12: xpcEngineUpdate
CFDictionaryRef xpcEngineUpdate(CFTypeRef target, uint flags, CFDictionaryRef context)
{
Message msg("update");
// target can be NULL, a CFURLRef, a SecRequirementRef, or a CFNumberRef
if (target) {
if (CFGetTypeID(target) == CFNumberGetTypeID())
xpc_dictionary_set_uint64(msg, "rule", cfNumber<int64_t>(CFNumberRef(target)));
else if (CFGetTypeID(target) == CFURLGetTypeID())
xpc_dictionary_set_string(msg, "url", cfString(CFURLRef(target)).c_str());
else if (CFGetTypeID(target) == SecRequirementGetTypeID()) {
CFRef<CFDataRef> data;
MacOSError::check(SecRequirementCopyData(SecRequirementRef(target), kSecCSDefaultFlags, &data.aref()));
xpc_dictionary_set_data(msg, "requirement", CFDataGetBytePtr(data), CFDataGetLength(data));
} else
MacOSError::throwMe(errSecCSInvalidObjectRef);
}
xpc_dictionary_set_int64(msg, "flags", flags);
CFRef<CFMutableDictionaryRef> ctx = makeCFMutableDictionary();
if (context)
CFDictionaryApplyFunction(context, copyCFDictionary, ctx);
AuthorizationRef localAuthorization = NULL;
if (CFDictionaryGetValue(ctx, kSecAssessmentUpdateKeyAuthorization) == NULL) { // no caller-provided authorization
MacOSError::check(AuthorizationCreate(NULL, NULL, kAuthorizationFlagDefaults, &localAuthorization));
AuthorizationExternalForm extForm;
MacOSError::check(AuthorizationMakeExternalForm(localAuthorization, &extForm));
CFDictionaryAddValue(ctx, kSecAssessmentUpdateKeyAuthorization, CFTempData(&extForm, sizeof(extForm)));
}
CFRef<CFDataRef> contextData = makeCFData(CFDictionaryRef(ctx));
xpc_dictionary_set_data(msg, "context", CFDataGetBytePtr(contextData), CFDataGetLength(contextData));
msg.send();
if (localAuthorization)
AuthorizationFree(localAuthorization, kAuthorizationFlagDefaults);
if (int64_t error = xpc_dictionary_get_int64(msg, "error"))
MacOSError::throwMe(error);
size_t resultLength;
const void *resultData = xpc_dictionary_get_data(msg, "result", &resultLength);
return makeCFDictionaryFrom(resultData, resultLength);
}
示例13: CFPreferencesAppIntegerValue
__private_extern__ CFIndex CFPreferencesAppIntegerValue(CFStringRef key, CFStringRef appName, Boolean *keyExistsAndHasValidFormat) {
CFPropertyListRef value;
CFIndex result;
CFTypeID typeID = 0;
Boolean valid;
CFAssert1(appName != NULL, __kCFLogAssertion, "%s(): Cannot access application preferences with a NULL application name", __PRETTY_FUNCTION__);
CFAssert1(key != NULL, __kCFLogAssertion, "%s(): Cannot access preferences with a NULL key", __PRETTY_FUNCTION__);
value = CFPreferencesCopyAppValue(key, appName);
if (!keyExistsAndHasValidFormat) {
keyExistsAndHasValidFormat = &valid;
}
if (!value) {
*keyExistsAndHasValidFormat = false;
return 0;
}
typeID = CFGetTypeID(value);
if (typeID == CFStringGetTypeID()) {
SInt32 charIndex = 0;
SInt32 intVal;
CFStringInlineBuffer buf;
Boolean success;
CFStringInitInlineBuffer((CFStringRef)value, &buf, CFRangeMake(0, CFStringGetLength((CFStringRef)value)));
success = __CFStringScanInteger(&buf, NULL, &charIndex, false, &intVal);
*keyExistsAndHasValidFormat = (success && charIndex == CFStringGetLength((CFStringRef)value));
result = (*keyExistsAndHasValidFormat) ? intVal : 0;
} else if (typeID == CFNumberGetTypeID()) {
*keyExistsAndHasValidFormat = !CFNumberIsFloatType((CFNumberRef)value);
if (*keyExistsAndHasValidFormat) {
CFNumberGetValue((CFNumberRef)value, kCFNumberCFIndexType, &result);
} else {
result = 0;
}
} else {
// Unknown type
result = 0;
*keyExistsAndHasValidFormat = false;
}
CFRelease(value);
return result;
}
示例14: SQLite3StatementBindCFType
inline SQLite3Status SQLite3StatementBindCFType(SQLite3StatementRef statement, CFIndex index, CFTypeRef value) {
SQLite3Status status = kSQLite3StatusError;
if (value) {
CFTypeID valueTypeID = CFGetTypeID(value);
if (CFStringGetTypeID() == valueTypeID)
status = SQLite3StatementBindString(statement, index, (CFStringRef)value);
else if (CFDataGetTypeID() == valueTypeID)
status = SQLite3StatementBindData(statement, index, (CFDataRef)value);
// else if (CGImageGetTypeID() == valueTypeID)
// status = SQLite3StatementBindImage(statement, index, (CGImageRef)value);
else if (CFDateGetTypeID() == valueTypeID)
status = SQLite3StatementBindDate(statement, index, (CFDateRef)value);
else if (CFNumberGetTypeID() == valueTypeID)
status = SQLite3StatementBindNumber(statement, index, (CFNumberRef)value);
else
status = kSQLite3StatusError;
} else {
status = SQLite3StatementBindNULL(statement, index);
}
return status;
}
示例15: GetPointerAccelerationThreshold
long int GetPointerAccelerationThreshold() {
#if defined COREFOUNDATION
bool successful = false;
SInt32 threshold;
#endif
long int value = -1;
#ifdef COREFOUNDATION
if (!successful) {
CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("mouseDriverMaxSpeed"), CFSTR("com.apple.universalaccess"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &threshold)) {
value = (long) threshold;
}
}
}
#endif
return value;
}