Skip to content

Commit 7d08fd9

Browse files
iakovQbicz
authored andcommitted
More rigorous & even C++ compatible code for macOS
1 parent 73b9ccb commit 7d08fd9

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
@@ -227,7 +227,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
227227
if (!len)
228228
return 0;
229229

230-
str = IOHIDDeviceGetProperty(device, prop);
230+
str = (CFStringRef)IOHIDDeviceGetProperty(device, prop);
231231

232232
buf[0] = 0;
233233

@@ -297,7 +297,8 @@ static wchar_t *dup_wcs(const wchar_t *s)
297297
static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
298298
{
299299
static void *iokit_framework = NULL;
300-
static io_service_t (*dynamic_IOHIDDeviceGetService)(IOHIDDeviceRef device) = NULL;
300+
typedef io_service_t (*dynamic_IOHIDDeviceGetService_t)(IOHIDDeviceRef device);
301+
static dynamic_IOHIDDeviceGetService_t dynamic_IOHIDDeviceGetService;
301302

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

309310
if (iokit_framework != NULL)
310-
dynamic_IOHIDDeviceGetService = dlsym(iokit_framework, "IOHIDDeviceGetService");
311+
dynamic_IOHIDDeviceGetService = (dynamic_IOHIDDeviceGetService_t)dlsym(iokit_framework, "IOHIDDeviceGetService");
311312
}
312313

313314
if (dynamic_IOHIDDeviceGetService != NULL) {
@@ -555,7 +556,7 @@ static void hid_device_removal_callback(void *context, IOReturn result,
555556
void *sender)
556557
{
557558
/* Stop the Run Loop for this device. */
558-
hid_device *d = context;
559+
hid_device *d = (hid_device*)context;
559560

560561
d->disconnected = 1;
561562
CFRunLoopStop(d->run_loop);
@@ -569,7 +570,7 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
569570
uint8_t *report, CFIndex report_length)
570571
{
571572
struct input_report *rpt;
572-
hid_device *dev = context;
573+
hid_device *dev = (hid_device*)context;
573574

574575
/* Make a new Input Report object */
575576
rpt = (input_report*) calloc(1, sizeof(struct input_report));
@@ -616,13 +617,13 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
616617
hid_close(), and serves to stop the read_thread's run loop. */
617618
static void perform_signal_callback(void *context)
618619
{
619-
hid_device *dev = context;
620+
hid_device *dev = (hid_device*)context;
620621
CFRunLoopStop(dev->run_loop); /*TODO: CFRunLoopGetCurrent()*/
621622
}
622623

623624
static void *read_thread(void *param)
624625
{
625-
hid_device *dev = param;
626+
hid_device *dev = (hid_device*)param;
626627
SInt32 code;
627628

628629
/* Move the device's run loop to this thread. */
@@ -693,6 +694,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
693694
{
694695
hid_device *dev = NULL;
695696
io_registry_entry_t entry = MACH_PORT_NULL;
697+
IOReturn ret;
696698

697699
dev = new_hid_device();
698700

@@ -715,7 +717,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
715717
}
716718

717719
/* Open the IOHIDDevice */
718-
IOReturn ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
720+
ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
719721
if (ret == kIOReturnSuccess) {
720722
char str[32];
721723

0 commit comments

Comments
 (0)