[PD-cvs] externals/io/hidio hidio.c,1.6,1.7

Olaf Matthes olafmatt at users.sourceforge.net
Fri Dec 1 20:40:48 CET 2006


Update of /cvsroot/pure-data/externals/io/hidio
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14076

Modified Files:
	hidio.c 
Log Message:
put reading in child thread


Index: hidio.c
===================================================================
RCS file: /cvsroot/pure-data/externals/io/hidio/hidio.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** hidio.c	1 Dec 2006 16:27:39 -0000	1.6
--- hidio.c	1 Dec 2006 19:40:46 -0000	1.7
***************
*** 73,77 ****
  static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv);
  //static t_int hidio_close(t_hidio *x);
! //static t_int hidio_read(t_hidio *x,int fd);
  //static void hidio_float(t_hidio* x, t_floatarg f);
  
--- 73,77 ----
  static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv);
  //static t_int hidio_close(t_hidio *x);
! //static t_int hidio_read(t_hidio *x);
  //static void hidio_float(t_hidio* x, t_floatarg f);
  
***************
*** 349,362 ****
  	debug_print(LOG_DEBUG,"hidio_close");
  
! /* just to be safe, stop it first */
! 	stop_poll(x);
! 
! 	if(! hidio_close_device(x)) 
! 	{
! 		debug_print(LOG_INFO,"[hidio] closed device %d",x->x_device_number);
! 		x->x_device_open = 0;
! 		return (0);
! 	}
! 
  	return (1);
  }
--- 349,356 ----
  	debug_print(LOG_DEBUG,"hidio_close");
  
! 	pthread_mutex_lock(&x->x_mutex);
! 	x->x_requestcode = REQUEST_CLOSE;
! 	pthread_cond_signal(&x->x_requestcondition);
! 	pthread_mutex_unlock(&x->x_mutex);
  	return (1);
  }
***************
*** 381,385 ****
  	{
  		if( (device_number != x->x_device_number) && (x->x_device_open) ) 
! 			hidio_close(x);
  		if(! x->x_device_open)
  		{
--- 375,379 ----
  	{
  		if( (device_number != x->x_device_number) && (x->x_device_open) ) 
! 			hidio_close(x);	/* LATER move this also to child thread */
  		if(! x->x_device_open)
  		{
***************
*** 394,398 ****
  
  
! t_int hidio_read(t_hidio *x, int fd) 
  {
  //	debug_print(LOG_DEBUG,"hidio_read");
--- 388,392 ----
  
  
! t_int hidio_read(t_hidio *x) 
  {
  //	debug_print(LOG_DEBUG,"hidio_read");
***************
*** 422,432 ****
  		}
  	}
  	if (x->x_started) 
  	{
  		clock_delay(x->x_clock, x->x_delay);
  	}
! 	
! 	// TODO: why is this 1? 
! 	return 1; 
  }
  
--- 416,438 ----
  		}
  	}
+ 	
+ 	// TODO: why is this 1? 
+ 	return 1; 
+ }
+ 
+ static void *hidio_tick(t_hidio *x)
+ {
+ 	pthread_mutex_lock(&x->x_mutex);
+ 	if (x->x_requestcode == REQUEST_NOTHING)
+ 	{
+ 		x->x_requestcode = REQUEST_READ;
+ 		pthread_cond_signal(&x->x_requestcondition);
+ 	}
  	if (x->x_started) 
  	{
  		clock_delay(x->x_clock, x->x_delay);
  	}
! 	pthread_mutex_unlock(&x->x_mutex);
! 	return NULL;
  }
  
***************
*** 510,513 ****
--- 516,522 ----
  		else if (x->x_requestcode == REQUEST_READ)
  		{
+ 			pthread_mutex_unlock(&x->x_mutex);
+ 			hidio_read(x);
+ 			pthread_mutex_lock(&x->x_mutex);
  			if (x->x_requestcode == REQUEST_READ)
  				x->x_requestcode = REQUEST_NOTHING;
***************
*** 536,542 ****
  		else if (x->x_requestcode == REQUEST_CLOSE)
  		{
  			pthread_mutex_unlock(&x->x_mutex);
! 			hidio_close(x);
  			pthread_mutex_lock(&x->x_mutex);
  			if (x->x_requestcode == REQUEST_CLOSE)
  				x->x_requestcode = REQUEST_NOTHING;
--- 545,558 ----
  		else if (x->x_requestcode == REQUEST_CLOSE)
  		{
+ 			t_int ret;
  			pthread_mutex_unlock(&x->x_mutex);
! 			stop_poll(x);
! 			ret = hidio_close_device(x);
  			pthread_mutex_lock(&x->x_mutex);
+ 			if (!ret) 
+ 			{
+ 				debug_print(LOG_INFO,"[hidio] closed device %d",x->x_device_number);
+ 				x->x_device_open = 0;
+ 			}
  			if (x->x_requestcode == REQUEST_CLOSE)
  				x->x_requestcode = REQUEST_NOTHING;
***************
*** 546,550 ****
  		{
  			pthread_mutex_unlock(&x->x_mutex);
! 			hidio_close(x);
  			pthread_mutex_lock(&x->x_mutex);
  			x->x_requestcode = REQUEST_NOTHING;
--- 562,567 ----
  		{
  			pthread_mutex_unlock(&x->x_mutex);
! 			stop_poll(x);
! 			hidio_close_device(x);
  			pthread_mutex_lock(&x->x_mutex);
  			x->x_requestcode = REQUEST_NOTHING;
***************
*** 626,630 ****
    for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
  
!   x->x_clock = clock_new(x, (t_method)hidio_read);
  
    /* create anything outlet used for HID data */ 
--- 643,647 ----
    for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
  
!   x->x_clock = clock_new(x, (t_method)hidio_tick);
  
    /* create anything outlet used for HID data */ 
***************
*** 643,647 ****
    for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
  
!   x->x_clock = clock_new(x, (method)hidio_read);
  
    /* create anything outlet used for HID data */ 
--- 660,664 ----
    for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
  
!   x->x_clock = clock_new(x, (method)hidio_tick);
  
    /* create anything outlet used for HID data */ 
***************
*** 677,681 ****
  	/* add inlet datatype methods */
  	class_addfloat(hidio_class,(t_method) hidio_float);
! 	class_addbang(hidio_class,(t_method) hidio_read);
  /* 	class_addanything(hidio_class,(t_method) hidio_anything); */
  	
--- 694,698 ----
  	/* add inlet datatype methods */
  	class_addfloat(hidio_class,(t_method) hidio_float);
! 	class_addbang(hidio_class,(t_method) hidio_tick);
  /* 	class_addanything(hidio_class,(t_method) hidio_anything); */
  	
***************
*** 760,764 ****
  	class_addmethod(c, (method)hidio_int, 			"int",	 		A_LONG, 0);  
  	class_addmethod(c, (method)hidio_float,			"float", 		A_FLOAT, 0);  
! 	class_addmethod(c, (method)hidio_read, 			"bang",	 		A_GIMME, 0); 
  	
  	/* add inlet message methods */
--- 777,781 ----
  	class_addmethod(c, (method)hidio_int, 			"int",	 		A_LONG, 0);  
  	class_addmethod(c, (method)hidio_float,			"float", 		A_FLOAT, 0);  
! 	class_addmethod(c, (method)hidio_tick, 			"bang",	 		A_GIMME, 0); 
  	
  	/* add inlet message methods */





More information about the Pd-cvs mailing list