src/hidapi/mac/hid.c
/* The Run Loop calls this function for each input report received.
 This function puts the data into a linked list to be picked up by
 hid_read(). */
The Run Loop calls this function for each input report received.
This function puts the data into a linked list to be picked up by
hid_read().
The Run Loop calls this function for each input report received . This function puts the data into a linked list to be picked up by hid_read () .
static void hid_report_callback(void *context, IOReturn result, void *sender,
								IOHIDReportType report_type, uint32_t report_id,
								uint8_t *report, CFIndex report_length)
{
	struct input_report *rpt;
	hid_device *dev = (hid_device *)context;
	rpt = (struct input_report *)calloc(1, sizeof(struct input_report));
	rpt->data = (uint8_t *)calloc(1, report_length);
	memcpy(rpt->data, report, report_length);
	rpt->len = report_length;
	rpt->next = NULL;
	pthread_mutex_lock(&dev->mutex);
	if (dev->input_reports == NULL) {
		dev->input_reports = rpt;
	}
	else {
		struct input_report *cur = dev->input_reports;
		int num_queued = 0;
		while (cur->next != NULL) {
			cur = cur->next;
			num_queued++;
		}
		cur->next = rpt;
		if (num_queued > 30) {
			return_data(dev, NULL, 0);
		}
	}
	pthread_cond_signal(&dev->condition);
	pthread_mutex_unlock(&dev->mutex);
}
static void hid_report_callback ( void * context , IOReturn result , void * sender , IOHIDReportType report_type , uint32_t report_id , uint8_t * report , CFIndex report_length ) { struct input_report * rpt ; hid_device * dev = ( hid_device * ) context ; rpt = ( struct input_report * ) calloc ( 1 , sizeof ( struct input_report ) ) ; rpt -> data = ( uint8_t * ) calloc ( 1 , report_length ) ; memcpy ( rpt -> data , report , report_length ) ; rpt -> len = report_length ; rpt -> next = NULL ; pthread_mutex_lock ( & dev -> mutex ) ; if ( dev -> input_reports == NULL ) { dev -> input_reports = rpt ; } else { struct input_report * cur = dev -> input_reports ; int num_queued = 0 ; while ( cur -> next != NULL ) { cur = cur -> next ; num_queued ++ ; } cur -> next = rpt ; if ( num_queued > 30 ) { return_data ( dev , NULL , 0 ) ; } } pthread_cond_signal ( & dev -> condition ) ; pthread_mutex_unlock ( & dev -> mutex ) ; }
The Run Loop calls this function for each input report received.
The Run Loop calls this function for each input report received .
/* Make a new Input Report object */ /* Lock this section */ /* Attach the new report object to the end of the list. */ /* The list is empty. Put it at the root. */ /* Find the end of the list and attach. */ /* Pop one off if we've reached 30 in the queue. This
		 way we don't grow forever if the user never reads
		 anything from the device. */ /* Signal a waiting thread that there is data. */ /* Unlock */