Hi Ken,��
So I wanted to try to hew as close to the behavior of debugstr_cf as possible since that is the output that the user sees already in trace logs. Here's how I decided handle each case:
static CFStringRef copy_device_name(IOHIDDeviceRef device)
{
�� �� CFTypeRef ref;
�� �� CFStringRef name = NULL;
�� ����
�� �� if(device)
�� �� {
�� �� �� �� assert(IOHIDDeviceGetTypeID() == CFGetTypeID(device));
�� �� �� �� ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
�� �� �� �� if (ref && CFStringGetTypeID() == CFGetTypeID(ref))
�� �� �� �� �� �� name = CFStringCreateCopy(kCFAllocatorDefault,ref);
�� �� �� �� else if (ref)
�� �� �� �� �� �� name = CFCopyDescription(ref);
�� �� �� �� else
�� �� �� �� �� �� name = CFStringCreateCopy(kCFAllocatorDefault,CFSTR("(null)"));
�� �� }
�� �� else
�� �� �� �� ERR("Invalid Device requested %p\n",device);
�� �� �� ����
�� �� return name;
}
��
static CFComparisonResult device_name_comparator(IOHIDDeviceRef device1, IOHIDDeviceRef device2)
{
�� �� CFStringRef name1 = copy_device_name(device1), name2 = copy_device_name(device2);
�� �� CFComparisonResult result = CFStringCompare(name1, name2, (kCFCompareForcedOrdering | kCFCompareNumerically));
�� �� if(name1)
�� �� �� �� CFRelease(name1);
�� �� if(name2)
�� �� �� �� CFRelease(name2);
�� �� return ��result;
}
What do you think?
Cheers,
David��