<div dir="ltr">Hi Ken, <div><br></div><div>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:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">static CFStringRef copy_device_name(IOHIDDeviceRef device)<br>{<br>    CFTypeRef ref;<br>    CFStringRef name = NULL;<br>    <br>    if(device)<br>    {<br>        assert(IOHIDDeviceGetTypeID() == CFGetTypeID(device));<br>        ref = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));<br>        if (ref && CFStringGetTypeID() == CFGetTypeID(ref))<br>            name = CFStringCreateCopy(kCFAllocatorDefault,ref);<br>        else if (ref)<br>            name = CFCopyDescription(ref);<br>        else<br>            name = CFStringCreateCopy(kCFAllocatorDefault,CFSTR("(null)"));<br>    }<br>    else<br>        ERR("Invalid Device requested %p\n",device);<br>        <br>    return name;<br>}<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">static CFComparisonResult device_name_comparator(IOHIDDeviceRef device1, IOHIDDeviceRef device2)<br>{<br>    CFStringRef name1 = copy_device_name(device1), name2 = copy_device_name(device2);<br>    CFComparisonResult result = CFStringCompare(name1, name2, (kCFCompareForcedOrdering | kCFCompareNumerically));<br>    if(name1)<br>        CFRelease(name1);<br>    if(name2)<br>        CFRelease(name2);<br>    return  result;<br>}</blockquote><div><br></div><div>What do you think?</div><div><br></div><div>Cheers,</div><div>David </div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 17, 2016 at 8:20 PM, DavidL <span dir="ltr"><<a href="mailto:david.dljunk@gmail.com" target="_blank">david.dljunk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Right-o! I was wondering what the CFRelease was doing in the debugstr_cf function. :) <div><br></div><div>Cheers,</div><div>David</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 17, 2016 at 2:11 PM, Ken Thomases <span dir="ltr"><<a href="mailto:ken@codeweavers.com" target="_blank">ken@codeweavers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Jul 17, 2016, at 4:08 PM, Ken Thomases <<a href="mailto:ken@codeweavers.com" target="_blank">ken@codeweavers.com</a>> wrote:<br>
><br>
> On Jul 16, 2016, at 3:15 AM, David Lawrie <<a href="mailto:david.dljunk@gmail.com" target="_blank">david.dljunk@gmail.com</a>> wrote:<br>
>><br>
</span><span>>> +static CFStringRef get_device_name(IOHIDDeviceRef device)<br>
>> +{<br>
>> +    CFTypeRef ref;<br>
>> +    CFStringRef name = CFSTR("Default Name");<br>
><br>
> You can probably do better for a fallback.  For example, you can format the vendor ID and product ID into a string.  For an extreme take on this, see the Copy_DeviceName() function in Apple's HID Calibrator sample code:<br>
> <a href="https://developer.apple.com/library/mac/samplecode/HID_Calibrator/Listings/HID_Calibrator_IOHIDDeviceWindowCtrl_m.html" rel="noreferrer" target="_blank">https://developer.apple.com/library/mac/samplecode/HID_Calibrator/Listings/HID_Calibrator_IOHIDDeviceWindowCtrl_m.html</a><br>
<br>
</span>Oh, and for the case where device is NULL, it's fine to return NULL.  It should never happen and, if it does, we want a crash to figure out why and fix things in a better manner, rather than papering over it with a bogus value.<br>
<span><font color="#888888"><br>
-Ken<br>
<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>