Skip to content

Commit d3af10b

Browse files
committed
More rigorous & even C++ compatible code for macOS
1 parent ac84fb6 commit d3af10b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

mac/hid.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
226226
if (!len)
227227
return 0;
228228

229-
str = IOHIDDeviceGetProperty(device, prop);
229+
str = (CFStringRef)IOHIDDeviceGetProperty(device, prop);
230230

231231
buf[0] = 0;
232232

@@ -296,7 +296,8 @@ static wchar_t *dup_wcs(const wchar_t *s)
296296
static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
297297
{
298298
static void *iokit_framework = NULL;
299-
static io_service_t (*dynamic_IOHIDDeviceGetService)(IOHIDDeviceRef device) = NULL;
299+
typedef io_service_t (*dynamic_IOHIDDeviceGetService_t)(IOHIDDeviceRef device);
300+
static dynamic_IOHIDDeviceGetService_t dynamic_IOHIDDeviceGetService;
300301

301302
/* Use dlopen()/dlsym() to get a pointer to IOHIDDeviceGetService() if it exists.
302303
* If any of these steps fail, dynamic_IOHIDDeviceGetService will be left NULL
@@ -306,7 +307,7 @@ static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
306307
iokit_framework = dlopen("/System/Library/IOKit.framework/IOKit", RTLD_LAZY);
307308

308309
if (iokit_framework != NULL)
309-
dynamic_IOHIDDeviceGetService = dlsym(iokit_framework, "IOHIDDeviceGetService");
310+
dynamic_IOHIDDeviceGetService = (dynamic_IOHIDDeviceGetService_t)dlsym(iokit_framework, "IOHIDDeviceGetService");
310311
}
311312

312313
if (dynamic_IOHIDDeviceGetService != NULL) {
@@ -544,7 +545,7 @@ static void hid_device_removal_callback(void *context, IOReturn result,
544545
void *sender)
545546
{
546547
/* Stop the Run Loop for this device. */
547-
hid_device *d = context;
548+
hid_device *d = (hid_device*)context;
548549

549550
d->disconnected = 1;
550551
CFRunLoopStop(d->run_loop);
@@ -558,7 +559,7 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
558559
uint8_t *report, CFIndex report_length)
559560
{
560561
struct input_report *rpt;
561-
hid_device *dev = context;
562+
hid_device *dev = (hid_device*)context;
562563

563564
/* Make a new Input Report object */
564565
rpt = (input_report*) calloc(1, sizeof(struct input_report));
@@ -605,13 +606,13 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
605606
hid_close(), and serves to stop the read_thread's run loop. */
606607
static void perform_signal_callback(void *context)
607608
{
608-
hid_device *dev = context;
609+
hid_device *dev = (hid_device*)context;
609610
CFRunLoopStop(dev->run_loop); /*TODO: CFRunLoopGetCurrent()*/
610611
}
611612

612613
static void *read_thread(void *param)
613614
{
614-
hid_device *dev = param;
615+
hid_device *dev = (hid_device*)param;
615616
SInt32 code;
616617

617618
/* Move the device's run loop to this thread. */
@@ -682,6 +683,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
682683
{
683684
hid_device *dev = NULL;
684685
io_registry_entry_t entry = MACH_PORT_NULL;
686+
IOReturn ret;
685687

686688
dev = new_hid_device();
687689

@@ -704,7 +706,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
704706
}
705707

706708
/* Open the IOHIDDevice */
707-
IOReturn ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
709+
ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
708710
if (ret == kIOReturnSuccess) {
709711
char str[32];
710712

0 commit comments

Comments
 (0)