本文整理匯總了C++中CFSetGetCount函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFSetGetCount函數的具體用法?C++ CFSetGetCount怎麽用?C++ CFSetGetCount使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFSetGetCount函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CFSetCreateMutableCopy
CFMutableSetRef
CFSetCreateMutableCopy (CFAllocatorRef allocator, CFIndex capacity,
CFSetRef set)
{
if (CF_IS_OBJC (_kCFSetTypeID, set))
{
CFMutableSetRef result;
const CFIndex count = CFSetGetCount (set);
void **values =
(void **) CFAllocatorAllocate (allocator, sizeof (void *) * count, 0);
CFIndex i;
CFSetGetValues (set, (const void **) values);
result = CFSetCreateMutable (allocator, count, &kCFTypeSetCallBacks);
for (i = 0; i < count; i++)
GSHashTableAddValue ((GSHashTableRef) result, values[i], values[i]);
CFAllocatorDeallocate (allocator, (void *) values);
return result;
}
return (CFMutableSetRef) GSHashTableCreateMutableCopy (allocator,
(GSHashTableRef) set,
capacity);
}
示例2: imp_rb_set_count
static CFIndex
imp_rb_set_count(void *rcv, SEL sel)
{
CFIndex count;
PREPARE_RCV(rcv);
count = CFSetGetCount((CFSetRef)rcv);
RESTORE_RCV(rcv);
return count;
}
示例3: CFSetCreateCopy
CFSetRef CFSetCreateCopy(CFAllocatorRef allocator, CFSetRef set) {
CFSetRef result;
const CFSetCallBacks *cb;
CFIndex numValues = CFSetGetCount(set);
const void **list, *buffer[256];
list = (numValues <= 256) ? buffer : CFAllocatorAllocate(allocator, numValues * sizeof(void *), 0);
if (list != buffer && __CFOASafe) __CFSetLastAllocationEventName(list, "CFSet (temp)");
CFSetGetValues(set, list);
cb = CF_IS_OBJC(__kCFSetTypeID, set) ? &kCFTypeSetCallBacks : __CFSetGetCallBacks(set);
result = CFSetCreate(allocator, list, numValues, cb);
if (list != buffer) CFAllocatorDeallocate(allocator, list);
return result;
}
示例4: SOSAccountVerifyAndAcceptHSAApplicants
bool SOSAccountVerifyAndAcceptHSAApplicants(SOSAccountRef account, SOSCircleRef newCircle, CFErrorRef *error) {
SOSFullPeerInfoRef fpi = account->my_identity;
__block bool circleChanged = false;
CFMutableSetRef approvals = SOSAccountCopyPreApprovedHSA2Info(account);
if(approvals && CFSetGetCount(approvals) > 0) {
SOSCircleForEachApplicant(newCircle, ^(SOSPeerInfoRef peer) {
CFStringRef peerID = SOSPeerInfoGetPeerID(peer);
if(CFSetContainsValue(approvals, peerID)) {
SOSPeerInfoRef copypi = SOSPeerInfoCreateCopy(NULL, peer, NULL);
circleChanged = SOSCircleAcceptRequest(newCircle, SOSAccountGetPrivateCredential(account, NULL), fpi, copypi, error);
CFSetRemoveValue(approvals, peerID);
}
});
示例5: IOHIDManagerCopyDevices
bool HIDDeviceManager::Enumerate(HIDEnumerateVisitor* enumVisitor)
{
if (!initializeManager())
{
return false;
}
CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager);
CFIndex deviceCount = CFSetGetCount(deviceSet);
// Allocate a block of memory and read the set into it.
IOHIDDeviceRef* devices = (IOHIDDeviceRef*) OVR_ALLOC(sizeof(IOHIDDeviceRef) * deviceCount);
CFSetGetValues(deviceSet, (const void **) devices);
// Iterate over devices.
for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
{
IOHIDDeviceRef hidDev = devices[deviceIndex];
if (!hidDev)
{
continue;
}
HIDDeviceDesc devDesc;
if (getPath(hidDev, &(devDesc.Path)) &&
initVendorProductVersion(hidDev, &devDesc) &&
enumVisitor->MatchVendorProduct(devDesc.VendorId, devDesc.ProductId) &&
initUsage(hidDev, &devDesc))
{
initStrings(hidDev, &devDesc);
initSerialNumber(hidDev, &devDesc);
// Construct minimal device that the visitor callback can get feature reports from.
OSX::HIDDevice device(this, hidDev);
enumVisitor->Visit(device, devDesc);
}
}
OVR_FREE(devices);
CFRelease(deviceSet);
return true;
}
示例6: FindDevice
IOHIDDeviceRef FindDevice(IOHIDManagerRef manager, long vendorId, long productId)
{
IOHIDDeviceRef theDevice = NULL;
// setup dictionary
CFMutableDictionaryRef dictionary = CFDictionaryCreateMutable(
kCFAllocatorDefault,
2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFNumberRef cfVendorId = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongType, &vendorId);
CFStringRef cfVendorSt = CFStringCreateWithCString(kCFAllocatorDefault, kIOHIDVendorIDKey, kCFStringEncodingUTF8);
CFDictionaryAddValue(dictionary, cfVendorSt, cfVendorId);
CFRelease(cfVendorId);
CFRelease(cfVendorSt);
CFNumberRef cfProductId = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongType, &productId);
CFStringRef cfProductSt = CFStringCreateWithCString(kCFAllocatorDefault, kIOHIDProductIDKey, kCFStringEncodingUTF8);
CFDictionaryAddValue(dictionary, cfProductSt, cfProductId);
CFRelease(cfProductId);
CFRelease(cfProductSt);
// look for devices matching criteria
IOHIDManagerSetDeviceMatching(manager, dictionary);
CFSetRef foundDevices = IOHIDManagerCopyDevices(manager);
CFIndex foundCount = foundDevices ? CFSetGetCount(foundDevices) : 0; // what the API does not say is that it could be null
if(foundCount > 0)
{
CFTypeRef* array = new CFTypeRef[foundCount]; // array of IOHIDDeviceRef
CFSetGetValues(foundDevices, array);
// get first matching device
theDevice = (IOHIDDeviceRef)array[0];
CFRetain(theDevice);
delete [] array;
}
if(foundDevices)
{
CFRelease(foundDevices);
}
CFRelease(dictionary);
return theDevice;
}
示例7: CFSetCreateMutableCopy
CFMutableSetRef CFSetCreateMutableCopy(CFAllocatorRef allocator, CFIndex capacity, CFSetRef set) {
CFMutableSetRef result;
const CFSetCallBacks *cb;
CFIndex idx, numValues = CFSetGetCount(set);
const void **list, *buffer[256];
CFAssert3(0 == capacity || numValues <= capacity, __kCFLogAssertion, "%s(): for fixed-mutable sets, capacity (%d) must be greater than or equal to initial number of values (%d)", __PRETTY_FUNCTION__, capacity, numValues);
list = (numValues <= 256) ? buffer : CFAllocatorAllocate(allocator, numValues * sizeof(void *), 0);
if (list != buffer && __CFOASafe) __CFSetLastAllocationEventName(list, "CFSet (temp)");
CFSetGetValues(set, list);
cb = CF_IS_OBJC(__kCFSetTypeID, set) ? &kCFTypeSetCallBacks : __CFSetGetCallBacks(set);
result = CFSetCreateMutable(allocator, capacity, cb);
if (0 == capacity) _CFSetSetCapacity(result, numValues);
for (idx = 0; idx < numValues; idx++) {
CFSetAddValue(result, list[idx]);
}
if (list != buffer) CFAllocatorDeallocate(allocator, list);
return result;
}
示例8: CFSetApplyFunction
void
CFSetApplyFunction (CFSetRef set, CFSetApplierFunction applier, void *context)
{
// TODO: could be made more efficient by providing a specialized
// implementation for the CF_IS_OBJC case
const CFIndex count = CFSetGetCount (set);
void **values =
(void **) CFAllocatorAllocate (NULL, sizeof (void *) * count, 0);
CFIndex i;
CFSetGetValues (set, (const void **) values);
for (i = 0; i < count; i++)
{
applier (values[i], context);
}
CFAllocatorDeallocate (NULL, (void *) values);
}
示例9: getDevRef
static IOHIDDeviceRef* getDevRef(OSX_HID_REF *hid, CFIndex *deviceCount)
{
CFSetRef deviceCFSetRef;
IOHIDDeviceRef *dev_refs=NULL;
*deviceCount = 0;
yEnterCriticalSection(&hid->hidMCS);
deviceCFSetRef = IOHIDManagerCopyDevices(hid->manager);
yLeaveCriticalSection(&hid->hidMCS);
if (deviceCFSetRef!= NULL) {
// how many devices in the set?
*deviceCount = CFSetGetCount( deviceCFSetRef );
dev_refs = yMalloc( sizeof(IOHIDDeviceRef) * (u32)*deviceCount );
// now extract the device ref's from the set
CFSetGetValues( deviceCFSetRef, (const void **) dev_refs );
}
return dev_refs;
}
示例10: setAllKeyboards
void setAllKeyboards(LedState changes[])
{
IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!manager) {
fprintf(stderr, "Failed to create IOHID manager.\n");
return;
}
CFDictionaryRef keyboard = getKeyboardDictionary();
if (!keyboard) {
fprintf(stderr, "Failed to get dictionary usage page for kHIDUsage_GD_Keyboard.\n");
return;
}
IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(manager, keyboard);
CFSetRef devices = IOHIDManagerCopyDevices(manager);
if (devices) {
CFIndex deviceCount = CFSetGetCount(devices);
if (deviceCount == 0) {
fprintf(stderr, "Could not find any keyboard devices.\n");
}
else {
// Loop through all keyboards attempting to get or display led state
IOHIDDeviceRef *deviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount);
if (deviceRefs) {
CFSetGetValues(devices, (const void **) deviceRefs);
for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
if (isKeyboardDevice(deviceRefs[deviceIndex]))
setKeyboard(deviceRefs[deviceIndex], keyboard, changes);
free(deviceRefs);
}
}
CFRelease(devices);
}
CFRelease(keyboard);
}
示例11: CFSetCreateCopy
CFSetRef
CFSetCreateCopy (CFAllocatorRef allocator, CFSetRef set)
{
if (CF_IS_OBJC (_kCFSetTypeID, set))
{
CFSetRef result;
const CFIndex count = CFSetGetCount (set);
void **values =
(void **) CFAllocatorAllocate (allocator, sizeof (void *) * count, 0);
CFSetGetValues (set, (const void **) values);
result =
CFSetCreate (allocator, (const void **) values, count,
&kCFTypeSetCallBacks);
CFAllocatorDeallocate (allocator, (void *) values);
return result;
}
return (CFSetRef) GSHashTableCreateCopy (allocator, (GSHashTableRef) set);
}
示例12: adjustExternalDiskAssertion
static void adjustExternalDiskAssertion()
{
CFIndex deviceCount = CFSetGetCount(gExternalMediaSet);
if (0 == deviceCount)
{
/*
* Release assertion
*/
InternalReleaseAssertion(&gDiskAssertionID);
return;
}
if (0 < deviceCount)
{
/*
* Create new assertion
*/
CFMutableDictionaryRef assertionDescription = NULL;
assertionDescription = _IOPMAssertionDescriptionCreate(
_kIOPMAssertionTypeExternalMedia,
CFSTR(_kExternalMediaAssertionName),
NULL, CFSTR("An external media device is attached."), NULL, 0, NULL);
InternalCreateAssertion(assertionDescription,
&gDiskAssertionID);
CFRelease(assertionDescription);
return;
}
return;
}
示例13: stop
void IOKitHIDEventPublisher::restart() {
if (run_loop_ == nullptr) {
// There is no run loop to restart.
return;
}
// Remove any existing stream.
stop();
if (manager_ == nullptr) {
manager_ = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
}
// Match anything.
IOHIDManagerSetDeviceMatching(manager_, nullptr);
auto status = IOHIDManagerOpen(manager_, kIOHIDOptionsTypeNone);
if (status != kIOReturnSuccess) {
LOG(WARNING) << RLOG(617) << "Cannot open IOKit HID Manager";
return;
}
// Enumerate initial set of devices matched before time=0.
CFSetRef devices = IOHIDManagerCopyDevices(manager_);
if (devices == nullptr) {
return;
}
initial_device_count_ = CFSetGetCount(devices);
CFRelease(devices);
// Register callbacks.
IOHIDManagerRegisterDeviceMatchingCallback(
manager_, IOKitHIDEventPublisher::MatchingCallback, nullptr);
IOHIDManagerRegisterDeviceRemovalCallback(
manager_, IOKitHIDEventPublisher::RemovalCallback, nullptr);
IOHIDManagerScheduleWithRunLoop(manager_, run_loop_, kCFRunLoopDefaultMode);
manager_started_ = true;
}
示例14: main
int main(void)
{
IOHIDManagerRef mgr;
int i;
mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
IOHIDManagerSetDeviceMatching(mgr, NULL);
IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone);
CFSetRef device_set = IOHIDManagerCopyDevices(mgr);
if (device_set==NULL) {
return 0;
}
CFIndex num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
for (i = 0; i < num_devices; i++) {
IOHIDDeviceRef dev = device_array[i];
printf("Device: %p\n", dev);
printf(" %04hx %04hx\n", get_vendor_id(dev), get_product_id(dev));
wchar_t serial[256], buf[256];
char cbuf[256];
get_serial_number(dev, serial, 256);
printf(" Serial: %ls\n", serial);
printf(" Loc: %ld\n", get_location_id(dev));
get_transport(dev, buf, 256);
printf(" Trans: %ls\n", buf);
make_path(dev, cbuf, 256);
printf(" Path: %s\n", cbuf);
}
return 0;
}
示例15: CFLocaleCopyAvailableLocaleIdentifiers
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;
}