I'm trying to write a User-Space Device driver to pull some data from a custom HID device. I'm do the following to store a reference of the device in the HID manage into a variable.
CFSetRef device = IOHIDManagerCopyDevices(HIDManager);
after this I do the following to register my callback which is setting up the report read from the device (another area I'm struggling with.)
IOHIDDeviceRegisterInputReportCallback(device, report, ReadDailyDataResonposeSize, Handle_IOHIDDeviceIOHIDReportCallback, NULL);
I'm getting an error in the above function on the reference to 'device' saying "Incompatible pointer types passing CFSetRef"
If I try to change the type that device is when creating it though I get another saying that it needs to be a CFSetRef. So I'm a little confused, anyone have any advice. I'm very new to C as well as working on Macs. The documentation has come off pretty terse to me thus far.
EDIT: Here Is a link to the rest of my code for reference. http://pastebin.com/rFsHisdh
This is the signature of the IOHIDDeviceRegisterInputReportCallback
function according to the documentation:
CF_EXPORT void IOHIDDeviceRegisterInputReportCallback(
IOHIDDeviceRef device,
uint8_t *report,
CFIndex reportLength,
IOHIDReportCallback callback,
void *context) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
As you can see the first argument should be a IOHIDDeviceRef
and you are passing in a CFSetRef
which provide[s] support for the mathematical concept of a set
as Martin R answer indicates.
To get the elements of the set and pass the device (if any) you should do the following:
CFSetRef devices = IOHIDManagerCopyDevices(HIDManager);
CFIndex size = CFSetGetCount(devices);
if(size > 0) {
CFTypeRef array[size]; // array of IOHIDDeviceRef
CFSetGetValues(devices, array);
IOHIDDeviceRegisterInputReportCallback((IOHIDDeviceRef)array[0], report, ReadDailyDataResonposeSize, Handle_IOHIDDeviceIOHIDReportCallback, NULL);
}
Hope it helps.