static void advanceCurrentStream(FormStreamFields *form)
{
    closeCurrentStream(form);

    if (form->remainingElements.isEmpty())
        return;

    // Create the new stream.
    FormDataElement& nextInput = form->remainingElements.last();
    if (nextInput.m_type == FormDataElement::data) {
        size_t size = nextInput.m_data.size();
        char* data = nextInput.m_data.releaseBuffer();
        form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data), size, kCFAllocatorNull);
        form->currentData = data;
    } else {
        CFStringRef filename = nextInput.m_filename.createCFString();
#if PLATFORM(WIN)
        CFURLRef fileURL = CFURLCreateWithFileSystemPath(0, filename, kCFURLWindowsPathStyle, FALSE);
#else
        CFURLRef fileURL = CFURLCreateWithFileSystemPath(0, filename, kCFURLPOSIXPathStyle, FALSE);
#endif
        CFRelease(filename);
        form->currentStream = CFReadStreamCreateWithFile(0, fileURL);
        CFRelease(fileURL);
    }
    form->remainingElements.removeLast();

    // Set up the callback.
    CFStreamClientContext context = { 0, form, NULL, NULL, NULL };
    CFReadStreamSetClient(form->currentStream, kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
        formEventCallback, &context);

    // Schedule with the current set of run loops.
    CFSetApplyFunction(form->scheduledRunLoopPairs, scheduleWithPair, form->currentStream);
}
Exemple #2
0
static VALUE
rb_set_each(VALUE set, SEL sel)
{
    RETURN_ENUMERATOR(set, 0, 0);
    CFSetApplyFunction((CFMutableSetRef)set, rb_set_each_callback, NULL);
    return Qnil;
}
Exemple #3
0
static VALUE
rb_set_union(VALUE set, VALUE other)
{
    VALUE new_set = rb_set_dup(set);
    CFSetApplyFunction((CFMutableSetRef)other, rb_set_union_callback, (void *)new_set);

    return new_set;
}
Exemple #4
0
static VALUE
rb_set_to_a(VALUE set, SEL sel)
{
    VALUE ary = rb_ary_new();
    CFSetApplyFunction((CFMutableSetRef)set, rb_set_to_a_callback, (void *)ary);

    return ary;
}
Exemple #5
0
joy_hid_device_array_t *joy_hidlib_enumerate_devices(void)
{
    if( !mgr ) {
        return NULL;
    }

    /* create set of devices */
    CFSetRef device_set = IOHIDManagerCopyDevices( mgr );
    if ( !device_set ) {
        return NULL;
    }

    /* create array of devices */
    CFMutableArrayRef device_array = CFArrayCreateMutable( kCFAllocatorDefault, 0, 
                                                    & kCFTypeArrayCallBacks );
    if( ! device_array ) {
        CFRelease( device_set );
        return NULL;
    }                                
    CFSetApplyFunction( device_set, CFSetApplierFunctionCopyToCFArray, device_array );
    CFRelease( device_set );

    /* allocate result */
    joy_hid_device_array_t *result = 
        (joy_hid_device_array_t *)lib_malloc(sizeof(joy_hid_device_array_t));
    if(result == NULL) {
        CFRelease( device_array );
        return NULL;
    }

    /* get size */
    CFIndex cnt = CFArrayGetCount( device_array );

    /* fill internal struct */
    result->num_internal_devices = (int)cnt;
    result->internal_devices = device_array;
    result->num_devices = 0;
    result->devices = NULL;
    result->driver_name = "IOHIDManager";

    /* count joysticks -> num devices */
    count_joysticks(result);
    if(result->num_devices == 0)
        return result;
    
    /* allocate our device structs */
    joy_hid_device_t *devices =
        (joy_hid_device_t *)lib_malloc(sizeof(joy_hid_device_t) * result->num_devices);
    if(devices == NULL) {
        lib_free(result);
        CFRelease( device_array );
        return NULL;
    }
    result->devices = devices;
    
    build_joystick_list(result);
    return result;
}
Exemple #6
0
static VALUE
rb_set_subtract(VALUE set, SEL sel, VALUE other)
{
    VALUE new_set = rb_set_dup(set, 0);
    CFMutableSetRef sets[2] = { (CFMutableSetRef)other, (CFMutableSetRef)new_set };
    CFSetApplyFunction((CFMutableSetRef)set, rb_set_subtract_callback, sets);

    return new_set;
}
Exemple #7
0
static VALUE
rb_set_merge(VALUE set, VALUE other)
{
    rb_set_modify_check(set);

    CFSetApplyFunction((CFMutableSetRef)other, rb_set_union_callback, (void *)set);

    return set;
}
Exemple #8
0
static VALUE
rb_set_intersect(VALUE set, SEL sel, VALUE other)
{
    rb_set_modify_check(set);

    VALUE new_set = rb_set_new();
    CFMutableSetRef sets[2] = { (CFMutableSetRef)other, (CFMutableSetRef)new_set };
    CFSetApplyFunction((CFMutableSetRef)set, rb_set_intersect_callback, sets);

    return new_set;
}
Exemple #9
0
static VALUE
rb_set_reject_bang(VALUE set, SEL sel)
{
    rb_set_modify_check(set);

    VALUE new_set = rb_set_dup(set, 0);
    VALUE acted = Qfalse;
    VALUE context[2] = { set, (VALUE)&acted };
    CFSetApplyFunction((CFMutableSetRef)new_set, rb_set_delete_if_callback, (void *)context);

    return acted == Qtrue ? set : Qnil ;
}
Exemple #10
0
static VALUE
rb_set_delete_if(VALUE set)
{
    rb_set_modify_check(set);

    VALUE new_set = rb_set_dup(set);
    VALUE acted = Qfalse;
    VALUE context[2] = { set, (VALUE)&acted };
    CFSetApplyFunction((CFMutableSetRef)new_set, rb_set_delete_if_callback, (void *)context);

    return set;
}
Exemple #11
0
static VALUE
rb_set_merge(VALUE set, SEL sel, VALUE other)
{
    rb_set_modify_check(set);

    VALUE klass = *(VALUE *)other;
    if (klass == rb_cCFSet || klass == rb_cNSSet || klass == rb_cNSMutableSet)
	CFSetApplyFunction((CFMutableSetRef)other, rb_set_union_callback, (void *)set);	
    else
	rb_block_call(other, rb_intern("each"), 0, 0, merge_i, (VALUE)set);

    return set;
}
Exemple #12
0
static CFDataRef GPClientCallback (CFMessagePortRef serverPort_, SInt32 type, CFDataRef data, void* info) {
	switch (type) {
		default: {
			CFNumberRef typeNumber = CFNumberCreate(NULL, kCFNumberSInt32Type, &type);
			CFSetRef observerSet = CFDictionaryGetValue(((GPDuplexClientRef)info)->observers, typeNumber);
			CFRelease(typeNumber);
			
			struct GPDataAndType dataAndType = {data, type};
			CFSetApplyFunction(observerSet, (CFSetApplierFunction)&GPDuplexClientInformObserver, &dataAndType);
			
			break;
		}
	}
	return NULL;
}
Exemple #13
0
void HIDRebuildDevices( void ) {
	// get the set of devices from the IOHID manager
	CFSetRef devCFSetRef = IOHIDManagerCopyDevices( gIOHIDManagerRef );

	if ( devCFSetRef ) {
		// if the existing array isn't empty...
		if ( gDeviceCFArrayRef ) {
			// release it
			CFRelease( gDeviceCFArrayRef );
		}
		// create an empty array
		gDeviceCFArrayRef = CFArrayCreateMutable( kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks );
		// now copy the set to the array
		CFSetApplyFunction( devCFSetRef, CFSetApplierFunctionCopyToCFArray, ( void * ) gDeviceCFArrayRef );
		// now sort the array by location ID's
		CFIndex cnt = CFArrayGetCount( gDeviceCFArrayRef );
		CFArraySortValues( gDeviceCFArrayRef, CFRangeMake( 0, cnt ), CFDeviceArrayComparatorFunction, NULL );

		// and release the set we copied from the IOHID manager
		CFRelease( devCFSetRef );
	}
}   // HIDRebuildDevices
int main (int argc, const char* argv[]) {
	if (argc == 1) {
		printf("Usage: LocalizationStatusHelper <bundle-path>\n");
	} else {
		if (chdir(argv[1]) == -1) {
			printf("Cannot change directory to %s", argv[1]);
			perror("");
			return 0;
		}
		
		DIR* dir = opendir(".");
		if (dir == NULL) {
			printf("Cannot open %s for reading", argv[1]);
			perror("");
			return 0;
		}
		
		struct languagesAndKeys sk;
		
		sk.languages = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
		sk.keys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
		
		CFMutableSetRef unionKeys = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
		
		struct dirent* dp;
		// Scan for the directory.
		while ((dp = readdir(dir)) != NULL) {
			if (dp->d_type == DT_DIR) {
				CFStringRef dirName = CFStringCreateWithCString(NULL, dp->d_name, kCFStringEncodingUTF8);
				
				// Check if it's an lproj.
				if (CFStringHasSuffix(dirName, CFSTR(".lproj"))) {
					CFMutableSetRef langKeys = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
					
					// Scan for strings files.
					chdir(dp->d_name);
					DIR* subdir = opendir(".");
					if (subdir != NULL) {
						struct dirent* dp2;
						while ((dp2 = readdir(subdir)) != NULL) {
							// Ignore linked strings files.
							if (dp2->d_type == DT_REG) {
								CFStringRef stringsName = CFStringCreateWithCString(NULL, dp2->d_name, kCFStringEncodingUTF8);
								// Ignore non-strings files.
								if (CFStringHasSuffix(stringsName, CFSTR(".strings"))) {
									// Convert to 
									CFURLRef stringsURL = CFURLCreateWithFileSystemPath(NULL, stringsName, kCFURLPOSIXPathStyle, false);
									CFReadStreamRef stringsStream = CFReadStreamCreateWithFile(NULL, stringsURL);
									CFRelease(stringsURL);
									CFReadStreamOpen(stringsStream);
									CFPropertyListRef strings = CFPropertyListCreateFromStream(NULL, stringsStream, 0, kCFPropertyListImmutable, NULL, NULL);
									CFReadStreamClose(stringsStream);
									CFRelease(stringsStream);
									CFDictionaryApplyFunction(strings, (CFDictionaryApplierFunction)&addKeysToSet, langKeys);
									CFDictionaryApplyFunction(strings, (CFDictionaryApplierFunction)&addKeysToSet, unionKeys);
									CFRelease(strings);
								}
								CFRelease(stringsName);
							}
						}
						closedir(subdir);
					}
					chdir("..");
					
					CFStringRef langCode = CFStringCreateWithSubstring(NULL, dirName, CFRangeMake(0, CFStringGetLength(dirName)-6));
					CFArrayAppendValue(sk.languages, langCode);
					CFArrayAppendValue(sk.keys, langKeys);
					CFRelease(langKeys);
					CFRelease(langCode);
				}
				CFRelease(dirName);
			}
		}
		closedir(dir);
		
		sk.count = CFArrayGetCount(sk.languages);
		
		printf("|| *Key* ||");
		CFArrayApplyFunction(sk.languages, CFRangeMake(0, sk.count), (CFArrayApplierFunction)&printHeader, NULL);
		printf("\n");
		
		CFSetApplyFunction(unionKeys, (CFSetApplierFunction)&printSupportedLanguages, &sk);
		
		CFRelease(sk.keys);
		CFRelease(sk.languages);
		CFRelease(unionKeys);
	}
	
	return 0;
}
Exemple #15
0
bool Joystick::init()
{
  SYNC;
  if(!p->hidManager)
  {
    VERIFY(p->hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone));
    IOHIDManagerSetDeviceMatching((IOHIDManagerRef) p->hidManager, 0);
    IOHIDManagerOpen((IOHIDManagerRef) p->hidManager, kIOHIDOptionsTypeNone);
    p->nextDevice = 0;
  }

  CFSetRef copyOfDevices = IOHIDManagerCopyDevices((IOHIDManagerRef) p->hidManager);
  CFMutableArrayRef devArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
  CFSetApplyFunction(copyOfDevices, Joystick::Private::copyCallBack, (void*) devArray);
  CFRelease(copyOfDevices);

  while(!p->deviceId && p->nextDevice < (unsigned) CFArrayGetCount(devArray))
  {
    p->deviceId = CFArrayGetValueAtIndex(devArray, p->nextDevice++);
    if(p->deviceId)
    {
      CFArrayRef elemAry = IOHIDDeviceCopyMatchingElements((IOHIDDeviceRef) p->deviceId, 0, 0);
      bool isJoystick = false;
      for(int i = 0; !isJoystick && i < (int) CFArrayGetCount(elemAry); ++i)
      {
        IOHIDElementRef elem = (IOHIDElementRef) CFArrayGetValueAtIndex(elemAry, i);
        isJoystick = IOHIDElementGetUsagePage(elem) == kHIDPage_GenericDesktop &&
                     (IOHIDElementGetUsage(elem) == kHIDUsage_GD_Joystick ||
                      IOHIDElementGetUsage(elem) == kHIDUsage_GD_GamePad);
      }
      if(isJoystick)
      {
        CFRetain((IOHIDDeviceRef) p->deviceId);
        ++(p->usedJoysticks);
        for(int i = 0; i < (int) CFArrayGetCount(elemAry); ++i)
        {
          IOHIDElementRef elem = (IOHIDElementRef) CFArrayGetValueAtIndex(elemAry, i);
          IOHIDElementType elemType = IOHIDElementGetType(elem);

          if(elemType == kIOHIDElementTypeInput_Misc ||
             elemType == kIOHIDElementTypeInput_Button ||
             elemType == kIOHIDElementTypeInput_Axis ||
             elemType == kIOHIDElementTypeInput_ScanCodes)
          {
            if(IOHIDElementGetUsagePage(elem) == kHIDPage_GenericDesktop)
              switch(IOHIDElementGetUsage(elem))
              {
                case kHIDUsage_GD_X:
                case kHIDUsage_GD_Y:
                case kHIDUsage_GD_Z:
                case kHIDUsage_GD_Rx:
                case kHIDUsage_GD_Ry:
                case kHIDUsage_GD_Rz:
                {
                  CFRetain(elem);
                  int axis = IOHIDElementGetUsage(elem) - kHIDUsage_GD_X;
                  p->axisIds[axis] = elem;
                  p->axisMin[axis] = (int) IOHIDElementGetLogicalMin(elem);
                  p->axisMax[axis] = (int) IOHIDElementGetLogicalMax(elem);
                  break;
                }
                case kHIDUsage_GD_Hatswitch:
                  CFRetain(elem);
                  p->hatId = elem;
                  p->axisMin[6] = p->axisMin[7] = -1;
                  p->axisMax[6] = p->axisMax[7] = 1;
                  break;
              }
            else if(IOHIDElementGetUsagePage(elem) == kHIDPage_Button)
            {
              int button = IOHIDElementGetUsage(elem) - 1;
              if(button >= 0 && button < numOfButtons)
              {
                CFRetain(elem);
                p->buttonIds[button] = elem;
              }
            }
          }
        }
      }
      else
        p->deviceId = 0;
      CFRelease(elemAry);
    }
  }

  CFRelease(devArray);

  return p->deviceId != 0;
}
Exemple #16
0
static int find_osx_devices(void)
{
    IOReturn tIOReturn;
    CFMutableDictionaryRef result;
    CFSetRef devset;
    CFArrayRef matching;

    gIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, 0L );
    tIOReturn = IOHIDManagerOpen( gIOHIDManagerRef, 0L);
    if ( kIOReturnSuccess != tIOReturn )
    {
        ERR("Couldn't open IOHIDManager.\n");
        return 0;
    }

    matching = CFArrayCreateMutable( kCFAllocatorDefault, 0,
                                     &kCFTypeArrayCallBacks );

    /* build matching dictionary */
    result = creates_osx_device_match(kHIDUsage_GD_Joystick);
    if (!result)
    {
        CFRelease(matching);
        return 0;
    }
    CFArrayAppendValue( ( CFMutableArrayRef )matching, result );
    result = creates_osx_device_match(kHIDUsage_GD_GamePad);
    if (!result)
    {
        CFRelease(matching);
        return 0;
    }
    CFArrayAppendValue( ( CFMutableArrayRef )matching, result );

    IOHIDManagerSetDeviceMatchingMultiple( gIOHIDManagerRef, matching);
    devset = IOHIDManagerCopyDevices( gIOHIDManagerRef );
    if (devset)
    {
        CFIndex countDevices, countCollections, idx;
        CFArrayRef gDevices = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
        CFSetApplyFunction(devset, CFSetApplierFunctionCopyToCFArray, (void*)gDevices);
        CFRelease( devset);
        countDevices = CFArrayGetCount(gDevices);

        gCollections = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
        if (!gCollections)
            return 0;

        countCollections = 0;
        for (idx = 0; idx < countDevices; idx++)
        {
            CFIndex tTop;
            IOHIDDeviceRef tDevice;

            tDevice = (IOHIDDeviceRef) CFArrayGetValueAtIndex(gDevices, idx);
            tTop = find_top_level(tDevice, gCollections);
            countCollections += tTop;
        }

        CFRelease(gDevices);

        TRACE("found %i device(s), %i collection(s)\n",(int)countDevices,(int)countCollections);
        return (int)countCollections;
    }
    return 0;
}
void *_ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
{
	void *yk = NULL;

	int rc = YK_ENOKEY;

	size_t i;

	IOHIDManagerSetDeviceMatchingMultiple( ykosxManager, NULL );

	CFSetRef devSet = IOHIDManagerCopyDevices( ykosxManager );

	if ( devSet ) {
		CFMutableArrayRef array = CFArrayCreateMutable( kCFAllocatorDefault, 0, NULL );

		CFSetApplyFunction( devSet, _ykosx_CopyToCFArray, array );

		CFIndex cnt = CFArrayGetCount( array );

		CFIndex i;

		for(i = 0; i < cnt; i++) {
			IOHIDDeviceRef dev = (IOHIDDeviceRef)CFArrayGetValueAtIndex( array, i );
			long devVendorId = _ykosx_getIntProperty( dev, CFSTR( kIOHIDVendorIDKey ));
			if(devVendorId == vendor_id) {
				long devProductId = _ykosx_getIntProperty( dev, CFSTR( kIOHIDProductIDKey ));
				size_t j;
				for(j = 0; j < pids_len; j++) {
					if(product_ids[j] == devProductId) {
						if(yk == NULL) {
							yk = dev;
							break;
						} else {
							rc = YK_EMORETHANONE;
							break;
						}
					}
				}
			}
			if(rc == YK_EMORETHANONE) {
				yk = NULL;
				break;
			}
		}

		if(rc != YK_EMORETHANONE) {
			rc = YK_ENOKEY;
		}

		/* this is a workaround for a memory leak in IOHIDManagerCopyDevices() in 10.8 */
		IOHIDManagerScheduleWithRunLoop( ykosxManager, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode );
		IOHIDManagerUnscheduleFromRunLoop( ykosxManager, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode );

		CFRelease( array );
		CFRelease( devSet );
	}

	if (yk) {
		CFRetain(yk);
		_ykusb_IOReturn = IOHIDDeviceOpen( yk, 0L );

		if ( _ykusb_IOReturn != kIOReturnSuccess ) {
			CFRelease(yk);
			rc = YK_EUSBERR;
			goto error;
		}

		return yk;
	}

error:
	yk_errno = rc;
	return 0;
}