这篇教程C++ CFSetGetValues函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CFSetGetValues函数的典型用法代码示例。如果您正苦于以下问题:C++ CFSetGetValues函数的具体用法?C++ CFSetGetValues怎么用?C++ CFSetGetValues使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CFSetGetValues函数的21个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: CFSetCreateMutableCopyCFMutableSetRefCFSetCreateMutableCopy (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);}
开发者ID:NSKevin,项目名称:gnustep-corebase,代码行数:26,
示例2: CFSetCreateCopyCFSetRef 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;}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:13,
示例3: IOHIDManagerCopyDevicesbool 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;}
开发者ID:ReallyRad,项目名称:ofxOculusRift,代码行数:48,
示例4: FindDeviceIOHIDDeviceRef 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;}
开发者ID:AndresPozo,项目名称:phd2,代码行数:47,
示例5: CFSetCreateMutableCopyCFMutableSetRef 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;}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:18,
示例6: CFSetApplyFunctionvoidCFSetApplyFunction (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);}
开发者ID:NSKevin,项目名称:gnustep-corebase,代码行数:20,
示例7: getDevRefstatic 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;}
开发者ID:LudovicRousseau,项目名称:yoctolib_cpp,代码行数:20,
示例8: setAllKeyboardsvoid 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);}
开发者ID:pawlowskialex,项目名称:CAPS,代码行数:41,
示例9: CFSetCreateCopyCFSetRefCFSetCreateCopy (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);}
开发者ID:NSKevin,项目名称:gnustep-corebase,代码行数:21,
示例10: mainint 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;}
开发者ID:rsravanreddy,项目名称:hidapi,代码行数:39,
示例11: CFLocaleCopyAvailableLocaleIdentifiersCFArrayRef 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;}
开发者ID:AbhinavBansal,项目名称:opencflite,代码行数:23,
示例12: CFSetGetCountbool JoystickImpl::open(unsigned int index){ m_index = index; Location deviceLoc = m_locationIDs[index]; // The device we need to load // Get all devices CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks(); if (devices == NULL) return false; // Get a usable copy of the joysticks devices. CFIndex joysticksCount = CFSetGetCount(devices); CFTypeRef devicesArray[joysticksCount]; CFSetGetValues(devices, devicesArray); // Get the desired joystick. IOHIDDeviceRef self = 0; for (CFIndex i(0); i < joysticksCount; ++i) { IOHIDDeviceRef d = (IOHIDDeviceRef)devicesArray[i]; if (deviceLoc == HIDInputManager::getLocationID(d)) { self = d; break; // We found it so we stop looping. } } if (self == 0) { // This shouldn't happen! CFRelease(devices); return false; } m_identification.name = getDeviceString(self, CFSTR(kIOHIDProductKey), m_index); m_identification.vendorId = getDeviceUint(self, CFSTR(kIOHIDVendorIDKey), m_index); m_identification.productId = getDeviceUint(self, CFSTR(kIOHIDProductIDKey), m_index); // Get a list of all elements attached to the device. CFArrayRef elements = IOHIDDeviceCopyMatchingElements(self, NULL, kIOHIDOptionsTypeNone); if (elements == NULL) { CFRelease(devices); return false; } // How many elements are there? CFIndex elementsCount = CFArrayGetCount(elements); if (elementsCount == 0) { // What is a joystick with no element? CFRelease(elements); CFRelease(devices); return false; } // Go through all connected elements. for (int i = 0; i < elementsCount; ++i) { IOHIDElementRef element = (IOHIDElementRef) CFArrayGetValueAtIndex(elements, i); switch (IOHIDElementGetType(element)) { case kIOHIDElementTypeInput_Misc: switch (IOHIDElementGetUsage(element)) { case kHIDUsage_GD_X: m_axis[Joystick::X] = element; break; case kHIDUsage_GD_Y: m_axis[Joystick::Y] = element; break; case kHIDUsage_GD_Z: m_axis[Joystick::Z] = element; break; case kHIDUsage_GD_Rx: m_axis[Joystick::U] = element; break; case kHIDUsage_GD_Ry: m_axis[Joystick::V] = element; break; case kHIDUsage_GD_Rz: m_axis[Joystick::R] = element; break; // kHIDUsage_GD_Vx, kHIDUsage_GD_Vy, kHIDUsage_GD_Vz are ignored. } break; case kIOHIDElementTypeInput_Button: if (m_buttons.size() < Joystick::ButtonCount) // If we have free slot... m_buttons.push_back(element); // ...we add this element to the list // Else: too many buttons. We ignore this one. break; default: // Make compiler happy break; } } // Ensure that the buttons will be indexed in the same order as their // HID Usage (assigned by manufacturer and/or a driver). std::sort(m_buttons.begin(), m_buttons.end(), JoystickButtonSortPredicate); // Note: Joy::AxisPovX/Y are not supported (yet). // Maybe kIOHIDElementTypeInput_Axis is the corresponding type but I can't test. // Retain all these objects for personal use for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it) CFRetain(*it); for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) CFRetain(it->second);//.........这里部分代码省略.........
开发者ID:AnatoliiPotapov,项目名称:SFML,代码行数:101,
示例13: mainint main( int argc, const char * argv[] ){ Boolean initialized = FALSE; if (( argc != 4 ) && ( argc != 5 )) { printf ( "usage: Dream Cheeky Notifier R G B [A]/n/tRGB values should be 0-31. A is an optional parameter on whether to do the LED activation sequence. Anything larger than 0 is YES, default is 0 (activate)./n/n"); exit ( -1 ); } char r = (int)strtol ( argv[1], NULL, 10 ); char g = (int)strtol ( argv[2], NULL, 10 ); char b = (int)strtol ( argv[3], NULL, 10 ); if ( argc == 5 ) { initialized = TRUE; } if ((r < 0) || (r > 31) || (g < 0) || (g > 31) || (b < 0) || (b > 31)) { printf("RGB values must be within 0-31."); exit -1; } // create a IO HID Manager reference IOHIDManagerRef tIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone ); // Create a device matching dictionary CFDictionaryRef matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( TRUE, kHIDPage_GenericDesktop, 0x10 ); // set the HID device matching dictionary IOHIDManagerSetDeviceMatching( tIOHIDManagerRef, matchingCFDictRef ); if ( matchingCFDictRef ) { CFRelease( matchingCFDictRef ); } // Now open the IO HID Manager reference IOReturn tIOReturn = IOHIDManagerOpen( tIOHIDManagerRef, kIOHIDOptionsTypeNone ); // and copy out its devices CFSetRef deviceCFSetRef = IOHIDManagerCopyDevices( tIOHIDManagerRef ); // how many devices in the set? CFIndex deviceIndex, deviceCount = CFSetGetCount( deviceCFSetRef ); // allocate a block of memory to extact the device ref's from the set into IOHIDDeviceRef * tIOHIDDeviceRefs = malloc( sizeof( IOHIDDeviceRef ) * deviceCount ); // now extract the device ref's from the set CFSetGetValues( deviceCFSetRef, (const void **) tIOHIDDeviceRefs ); // before we get into the device loop we'll setup our element matching dictionary (Note: we don't do element matching anymore) matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( FALSE, 0, 0 ); for ( deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++ ) { // if this isn't the notifier device... TODO: let's detect via vendor/product ids instead long vendor_id = 0; IOHIDDevice_GetLongProperty(tIOHIDDeviceRefs[deviceIndex], CFSTR(kIOHIDVendorIDKey), &vendor_id); long product_id = 0; IOHIDDevice_GetLongProperty(tIOHIDDeviceRefs[deviceIndex], CFSTR(kIOHIDProductIDKey), &product_id); if ((vendor_id != 0x1D34 ) || (product_id != 0x0004 )) { printf(" skipping device %p./n", tIOHIDDeviceRefs[deviceIndex] ); continue; // ...skip it } printf( " device = %p./n", tIOHIDDeviceRefs[deviceIndex] ); unsigned char report[8]; if (initialized == FALSE) { report[0] = 0x1F; // turn on LEDs report[1] = 0x02; report[2] = 0x00; report[3] = 0x5F; report[4] = 0x00; report[5] = 0x00; report[6] = 0x1A; report[7] = 0x03; // Note: We don't use the returned value here, so the compiler might throw a warning. IOReturn tIOReturn = IOHIDDeviceSetReport( tIOHIDDeviceRefs[deviceIndex], // IOHIDDeviceRef for the HID device kIOHIDReportTypeInput, // IOHIDReportType for the report (input, output, feature) 0, // CFIndex for the report ID report, // address of report buffer 8); // length of the report initialized = TRUE; } report[0] = r; // set brightness on LEDs to r, g, & b report[1] = g; report[2] = b; report[3] = 0x00; report[4] = 0x00; report[5] = 0x00; report[6] = 0x1A; report[7] = 0x05; tIOReturn = IOHIDDeviceSetReport( tIOHIDDeviceRefs[deviceIndex], // IOHIDDeviceRef for the HID device kIOHIDReportTypeInput, // IOHIDReportType for the report (input, output, feature) 0, // CFIndex for the report ID report, // address of report buffer//.........这里部分代码省略.........
开发者ID:edelbrp,项目名称:dream-cheeky-notifier-macosx,代码行数:101,
示例14: IOHIDManagerCopyDevicesbool HIDDevice::openDevice(){ // Have to iterate through devices again to generate paths. CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager->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. IOHIDDeviceRef device = NULL; for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { IOHIDDeviceRef tmpDevice = devices[deviceIndex]; if (!tmpDevice) { continue; } String path; if (!HIDManager->getPath(tmpDevice, &path)) { continue; } if (path == DevDesc.Path) { device = tmpDevice; break; } } OVR_FREE(devices); if (!device) { CFRelease(deviceSet); return false; } // Attempt to open device. if (IOHIDDeviceOpen(device, kIOHIDOptionsTypeSeizeDevice) != kIOReturnSuccess) { CFRelease(deviceSet); return false; } // Retain the device before we release the set. CFRetain(device); CFRelease(deviceSet); Device = device; if (!initInfo()) { IOHIDDeviceClose(Device, kIOHIDOptionsTypeSeizeDevice); CFRelease(Device); Device = NULL; return false; } // Setup the Run Loop and callbacks. IOHIDDeviceScheduleWithRunLoop(Device, HIDManager->getRunLoop(), kCFRunLoopDefaultMode); IOHIDDeviceRegisterInputReportCallback(Device, ReadBuffer, ReadBufferSize, staticHIDReportCallback, this); IOHIDDeviceRegisterRemovalCallback(Device, staticDeviceRemovedCallback, this); return true;}
开发者ID:123woodman,项目名称:minko,代码行数:88,
示例15: process_pending_eventsstruct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id){ struct hid_device_info *root = NULL; /* return object */ struct hid_device_info *cur_dev = NULL; CFIndex num_devices; int i; /* Set up the HID Manager if it hasn't been done */ if (hid_init() < 0) return NULL; /* give the IOHIDManager a chance to update itself */ process_pending_events(); /* Get a list of the Devices */ IOHIDManagerSetDeviceMatching(hid_mgr, NULL); CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); /* Convert the list into a C array so we can iterate easily. */ num_devices = CFSetGetCount(device_set); IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef)); CFSetGetValues(device_set, (const void **) device_array); /* Iterate over each device, making an entry for it. */ for (i = 0; i < num_devices; i++) { unsigned short dev_vid; unsigned short dev_pid; #define BUF_LEN 256 wchar_t buf[BUF_LEN]; IOHIDDeviceRef dev = device_array[i]; if (!dev) { continue; } dev_vid = get_vendor_id(dev); dev_pid = get_product_id(dev); /* Check the VID/PID against the arguments */ if ((vendor_id == 0x0 || vendor_id == dev_vid) && (product_id == 0x0 || product_id == dev_pid)) { struct hid_device_info *tmp; io_object_t iokit_dev; kern_return_t res; io_string_t path; /* VID/PID match. Create the record. */ tmp = malloc(sizeof(struct hid_device_info)); if (cur_dev) { cur_dev->next = tmp; } else { root = tmp; } cur_dev = tmp; /* Get the Usage Page and Usage for this device. */ cur_dev->usage_page = get_int_property(dev, CFSTR(kIOHIDPrimaryUsagePageKey)); cur_dev->usage = get_int_property(dev, CFSTR(kIOHIDPrimaryUsageKey)); /* Fill out the record */ cur_dev->next = NULL; /* Fill in the path (IOService plane) */ iokit_dev = hidapi_IOHIDDeviceGetService(dev); res = IORegistryEntryGetPath(iokit_dev, kIOServicePlane, path); if (res == KERN_SUCCESS) cur_dev->path = strdup(path); else cur_dev->path = strdup(""); /* Serial Number */ get_serial_number(dev, buf, BUF_LEN); cur_dev->serial_number = dup_wcs(buf); /* Manufacturer and Product strings */ get_manufacturer_string(dev, buf, BUF_LEN); cur_dev->manufacturer_string = dup_wcs(buf); get_product_string(dev, buf, BUF_LEN); cur_dev->product_string = dup_wcs(buf); /* VID/PID */ cur_dev->vendor_id = dev_vid; cur_dev->product_id = dev_pid; /* Release Number */ cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey)); /* Interface Number (Unsupported on Mac)*/ cur_dev->interface_number = -1; } } free(device_array); CFRelease(device_set); return root;}
开发者ID:billsq,项目名称:hidapi,代码行数:98,
示例16: yUSBGetInterfacesint yUSBGetInterfaces(yInterfaceSt **ifaces,int *nbifaceDetect,char *errmsg){ int nbifaceAlloc; int deviceIndex; CFSetRef deviceCFSetRef; CFIndex deviceCount; IOHIDDeviceRef *dev_refs; // allocate buffer for detected interfaces *nbifaceDetect = 0; nbifaceAlloc = 8; *ifaces =yMalloc(nbifaceAlloc * sizeof(yInterfaceSt)); memset(*ifaces, 0 ,nbifaceAlloc * sizeof(yInterfaceSt)); yEnterCriticalSection(&yContext->hidMCS); deviceCFSetRef = IOHIDManagerCopyDevices( yContext->hidM ); yLeaveCriticalSection(&yContext->hidMCS); if(deviceCFSetRef== NULL){ //no device found return 0; } // how many devices in the set? deviceCount = CFSetGetCount( deviceCFSetRef ); HALLOG("%ld usb interfaces detected/n",deviceCount); dev_refs = yMalloc( sizeof(IOHIDDeviceRef) * (u32)deviceCount ); // now extract the device ref's from the set CFSetGetValues( deviceCFSetRef, (const void **) dev_refs ); for(deviceIndex=0 ; deviceIndex < deviceCount ;deviceIndex++){ u16 vendorid; u16 deviceid; IOHIDDeviceRef dev = dev_refs[deviceIndex]; yInterfaceSt *iface; vendorid = get_int_property(dev,CFSTR(kIOHIDVendorIDKey)); deviceid = get_int_property(dev,CFSTR(kIOHIDProductIDKey)); //ensure the buffer of detected interface is big enought if(*nbifaceDetect == nbifaceAlloc){ yInterfaceSt *tmp; tmp = (yInterfaceSt*) yMalloc(nbifaceAlloc*2 * sizeof(yInterfaceSt)); memset(tmp,0,nbifaceAlloc*2 * sizeof(yInterfaceSt)); yMemcpy(tmp,*ifaces, nbifaceAlloc * sizeof(yInterfaceSt) ); yFree(*ifaces); *ifaces = tmp; nbifaceAlloc *=2; } iface = *ifaces + *nbifaceDetect; iface->devref = dev; iface->vendorid = vendorid; iface->deviceid = deviceid; get_txt_property(dev,iface->serial,YOCTO_SERIAL_LEN*2, CFSTR(kIOHIDSerialNumberKey)); HALLOG("work on interface %d (%x:%x:%s)/n",deviceIndex,vendorid,deviceid,iface->serial); (*nbifaceDetect)++; } CFRelease(deviceCFSetRef); yFree(dev_refs); return YAPI_SUCCESS;}
开发者ID:octet8,项目名称:yoctolib_cpp,代码行数:62,
示例17: find_osx_devices/************************************************************************** * find_osx_devices */static int find_osx_devices(void){ IOHIDManagerRef hid_manager; int usages[] = { kHIDUsage_GD_Joystick, kHIDUsage_GD_GamePad }; int i; CFDictionaryRef matching_dicts[sizeof(usages) / sizeof(usages[0])]; CFArrayRef matching; CFSetRef devset; TRACE("()/n"); hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L); if (IOHIDManagerOpen(hid_manager, 0) != kIOReturnSuccess) { ERR("Couldn't open IOHIDManager./n"); CFRelease(hid_manager); return 0; } for (i = 0; i < sizeof(matching_dicts) / sizeof(matching_dicts[0]); i++) { matching_dicts[i] = create_osx_device_match(usages[i]); if (!matching_dicts[i]) { while (i > 0) CFRelease(matching_dicts[--i]); goto fail; } } matching = CFArrayCreate(NULL, (const void**)matching_dicts, sizeof(matching_dicts) / sizeof(matching_dicts[0]), &kCFTypeArrayCallBacks); for (i = 0; i < sizeof(matching_dicts) / sizeof(matching_dicts[0]); i++) CFRelease(matching_dicts[i]); IOHIDManagerSetDeviceMatchingMultiple(hid_manager, matching); CFRelease(matching); devset = IOHIDManagerCopyDevices(hid_manager); if (devset) { CFIndex num_devices, num_main_elements; const void** refs; CFArrayRef devices; num_devices = CFSetGetCount(devset); refs = HeapAlloc(GetProcessHeap(), 0, num_devices * sizeof(*refs)); if (!refs) { CFRelease(devset); goto fail; } CFSetGetValues(devset, refs); devices = CFArrayCreate(NULL, refs, num_devices, &kCFTypeArrayCallBacks); HeapFree(GetProcessHeap(), 0, refs); CFRelease(devset); if (!devices) goto fail; device_main_elements = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); if (!device_main_elements) { CFRelease(devices); goto fail; } num_main_elements = 0; for (i = 0; i < num_devices; i++) { IOHIDDeviceRef hid_device = (IOHIDDeviceRef)CFArrayGetValueAtIndex(devices, i); TRACE("hid_device %s/n", debugstr_device(hid_device)); num_main_elements += find_top_level(hid_device, device_main_elements); } CFRelease(devices); TRACE("found %i device(s), %i collection(s)/n",(int)num_devices,(int)num_main_elements); return (int)num_main_elements; }fail: IOHIDManagerClose(hid_manager, 0); CFRelease(hid_manager); return 0;}
开发者ID:AmineKhaldi,项目名称:mbedtls-cleanup,代码行数:89,
示例18: main// ----------------------------------------------------int main(int argc, const char * argv[]) {#pragma unused ( argc, argv ) IOHIDManagerRef tIOHIDManagerRef = NULL; CFSetRef deviceCFSetRef = NULL; IOHIDDeviceRef *tIOHIDDeviceRefs = nil; do { tIOHIDManagerRef = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (!tIOHIDManagerRef) { break; } IOHIDManagerSetDeviceMatching(tIOHIDManagerRef, NULL); IOReturn tIOReturn = IOHIDManagerOpen(tIOHIDManagerRef, kIOHIDOptionsTypeNone); if (noErr != tIOReturn) { break; } deviceCFSetRef = IOHIDManagerCopyDevices(tIOHIDManagerRef); if (!deviceCFSetRef) { break; } CFIndex deviceIndex, deviceCount = CFSetGetCount(deviceCFSetRef); tIOHIDDeviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount); if (!tIOHIDDeviceRefs) { break; } CFSetGetValues(deviceCFSetRef, (const void **)tIOHIDDeviceRefs); CFRelease(deviceCFSetRef); deviceCFSetRef = NULL; for (deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { if (!tIOHIDDeviceRefs[deviceIndex]) { continue; } HIDDumpDeviceInfo(tIOHIDDeviceRefs[deviceIndex]);#if true // and copy all the elements CFArrayRef elementCFArrayRef = IOHIDDeviceCopyMatchingElements(tIOHIDDeviceRefs[deviceIndex], NULL /* matchingCFDictRef */, kIOHIDOptionsTypeNone); if (elementCFArrayRef) { // iterate over all the elements CFIndex elementIndex, elementCount = CFArrayGetCount(elementCFArrayRef); for (elementIndex = 0; elementIndex < elementCount; elementIndex++) { IOHIDElementRef tIOHIDElementRef = (IOHIDElementRef)CFArrayGetValueAtIndex(elementCFArrayRef, elementIndex); if (tIOHIDElementRef) { HIDDumpElementInfo(tIOHIDElementRef); } } CFRelease(elementCFArrayRef); }#endif } } while (false); if (tIOHIDDeviceRefs) { free(tIOHIDDeviceRefs); } if (deviceCFSetRef) { CFRelease(deviceCFSetRef); deviceCFSetRef = NULL; } if (tIOHIDManagerRef) { CFRelease(tIOHIDManagerRef); } return (0);} // main
开发者ID:Vincent7,项目名称:CocoaSampleCode,代码行数:85,
示例19: CFSetGetCountbool JoystickImpl::open(unsigned int index){ m_index = index; m_hat = NULL; Location deviceLoc = m_locationIDs[index]; // The device we need to load // Get all devices CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks(); if (devices == NULL) return false; // Get a usable copy of the joysticks devices. CFIndex joysticksCount = CFSetGetCount(devices); CFTypeRef devicesArray[joysticksCount]; CFSetGetValues(devices, devicesArray); // Get the desired joystick. IOHIDDeviceRef self = 0; for (CFIndex i(0); self == 0 && i < joysticksCount; ++i) { IOHIDDeviceRef d = (IOHIDDeviceRef)devicesArray[i]; if (deviceLoc == HIDInputManager::getLocationID(d)) self = d; } if (self == 0) { CFRelease(devices); return false; } m_identification.name = getDeviceString(self, CFSTR(kIOHIDProductKey), m_index); m_identification.vendorId = getDeviceUint(self, CFSTR(kIOHIDVendorIDKey), m_index); m_identification.productId = getDeviceUint(self, CFSTR(kIOHIDProductIDKey), m_index); // Get a list of all elements attached to the device. CFArrayRef elements = IOHIDDeviceCopyMatchingElements(self, NULL, kIOHIDOptionsTypeNone); if (elements == NULL) { CFRelease(devices); return false; } // Go through all connected elements. CFIndex elementsCount = CFArrayGetCount(elements); for (int i = 0; i < elementsCount; ++i) { IOHIDElementRef element = (IOHIDElementRef) CFArrayGetValueAtIndex(elements, i); switch (IOHIDElementGetUsagePage(element)) { case kHIDPage_GenericDesktop: switch (IOHIDElementGetUsage(element)) { case kHIDUsage_GD_X: m_axis[Joystick::X] = element; break; case kHIDUsage_GD_Y: m_axis[Joystick::Y] = element; break; case kHIDUsage_GD_Z: m_axis[Joystick::Z] = element; break; case kHIDUsage_GD_Rx: m_axis[Joystick::U] = element; break; case kHIDUsage_GD_Ry: m_axis[Joystick::V] = element; break; case kHIDUsage_GD_Rz: m_axis[Joystick::R] = element; break; case kHIDUsage_GD_Hatswitch: // From §4.3 MiscellaneousControls of HUT v1.12: // // > Hat Switch: // > A typical example is four switches that are capable of generating // > information about four possible directions in which the knob can be // > tilted. Intermediate positions can also be decoded if the hardware // > allows two switches to be reported simultaneously. // // We assume this model here as well. Hence, with 4 switches and intermediate // positions we have 8 values (0-7) plus the "null" state (8). { CFIndex min = IOHIDElementGetLogicalMin(element); CFIndex max = IOHIDElementGetLogicalMax(element); if (min != 0 || max != 7) { sf::err() << std::hex << "Joystick (vendor/product id: 0x" << m_identification.vendorId << "/0x" << m_identification.productId << std::dec << ") range is an unexpected one: [" << min << ", " << max << "]" << std::endl; } else { m_hat = element; } } break; case kHIDUsage_GD_GamePad: // We assume a game pad is an application collection, meaning it doesn't hold // any values per say. They kind of "emit" the joystick's usages. // See §3.4.3 Usage Types (Collection) of HUT v1.12 if (IOHIDElementGetCollectionType(element) != kIOHIDElementCollectionTypeApplication) { sf::err() << std::hex << "Gamepage (vendor/product id: 0x" << m_identification.vendorId << "/0x" << m_identification.productId << ") is not an CA but a 0x" << IOHIDElementGetCollectionType(element) << std::dec << std::endl;//.........这里部分代码省略.........
开发者ID:anthnich,项目名称:SFML,代码行数:101,
示例20: setlocalestruct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id){ struct hid_device_info *root = NULL; // return object struct hid_device_info *cur_dev = NULL; CFIndex num_devices; int i; setlocale(LC_ALL,""); /* Set up the HID Manager if it hasn't been done */ hid_init(); /* Get a list of the Devices */ CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); /* Convert the list into a C array so we can iterate easily. */ num_devices = CFSetGetCount(device_set); IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef)); CFSetGetValues(device_set, (const void **) device_array); /* Iterate over each device, making an entry for it. */ for (i = 0; i < num_devices; i++) { unsigned short dev_vid; unsigned short dev_pid; #define BUF_LEN 256 wchar_t buf[BUF_LEN]; char cbuf[BUF_LEN]; IOHIDDeviceRef dev = device_array[i]; if (!dev) { continue; } dev_vid = get_vendor_id(dev); dev_pid = get_product_id(dev); /* Check the VID/PID against the arguments */ if ((vendor_id == 0x0 && product_id == 0x0) || (vendor_id == dev_vid && product_id == dev_pid)) { struct hid_device_info *tmp; size_t len; /* VID/PID match. Create the record. */ tmp = malloc(sizeof(struct hid_device_info)); if (cur_dev) { cur_dev->next = tmp; } else { root = tmp; } cur_dev = tmp; // Get the Usage Page and Usage for this device. cur_dev->usage_page = get_int_property(dev, CFSTR(kIOHIDPrimaryUsagePageKey)); cur_dev->usage = get_int_property(dev, CFSTR(kIOHIDPrimaryUsageKey)); /* Fill out the record */ cur_dev->next = NULL; len = make_path(dev, cbuf, sizeof(cbuf)); cur_dev->path = strdup(cbuf); /* Serial Number */ get_serial_number(dev, buf, BUF_LEN); cur_dev->serial_number = dup_wcs(buf); /* Manufacturer and Product strings */ get_manufacturer_string(dev, buf, BUF_LEN); cur_dev->manufacturer_string = dup_wcs(buf); get_product_string(dev, buf, BUF_LEN); cur_dev->product_string = dup_wcs(buf); /* VID/PID */ cur_dev->vendor_id = dev_vid; cur_dev->product_id = dev_pid; /* Release Number */ cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey)); /* Interface Number (Unsupported on Mac)*/ cur_dev->interface_number = -1; } } free(device_array); CFRelease(device_set); return root;}
开发者ID:AaronPerl,项目名称:HackRU-DigitalTheremin,代码行数:88,
示例21: hid_open_pathhid_device * HID_API_EXPORT hid_open_path(const char *path){ int i; hid_device *dev = NULL; CFIndex num_devices; dev = new_hid_device(); /* Set up the HID Manager if it hasn't been done */ hid_init(); CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr); 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++) { char cbuf[BUF_LEN]; size_t len; IOHIDDeviceRef os_dev = device_array[i]; len = make_path(os_dev, cbuf, sizeof(cbuf)); if (!strcmp(cbuf, path)) { // Matched Paths. Open this Device. IOReturn ret = IOHIDDeviceOpen(os_dev, kIOHIDOptionsTypeNone); if (ret == kIOReturnSuccess) { char str[32]; free(device_array); CFRelease(device_set); dev->device_handle = os_dev; /* Create the buffers for receiving data */ dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev); dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t)); /* Create the Run Loop Mode for this device. printing the reference seems to work. */ sprintf(str, "HIDAPI_%p", os_dev); dev->run_loop_mode = CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII); /* Attach the device to a Run Loop */ IOHIDDeviceRegisterInputReportCallback( os_dev, dev->input_report_buf, dev->max_input_report_len, &hid_report_callback, dev); IOHIDManagerRegisterDeviceRemovalCallback(hid_mgr, hid_device_removal_callback, NULL); /* Start the read thread */ pthread_create(&dev->thread, NULL, read_thread, dev); /* Wait here for the read thread to be initialized. */ pthread_barrier_wait(&dev->barrier); return dev; } else { goto return_error; } } }return_error: free(device_array); CFRelease(device_set); free_hid_device(dev); return NULL;}
开发者ID:AaronPerl,项目名称:HackRU-DigitalTheremin,代码行数:68,
注:本文中的CFSetGetValues函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CFShow函数代码示例 C++ CFSetGetCount函数代码示例 |