mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	added full async interface to timer API
- added snd_async_add_timer_handler and snd_async_handler_get_timer functions - added async command to test/timer.c
This commit is contained in:
		
							parent
							
								
									a022bc1fbc
								
							
						
					
					
						commit
						8ec3e4ea6c
					
				
					 7 changed files with 99 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -197,6 +197,9 @@ ALSA_1.0.9 {
 | 
			
		|||
 | 
			
		||||
    snd_pcm_parse_control_id;
 | 
			
		||||
 | 
			
		||||
    snd_async_add_timer_handler;
 | 
			
		||||
    snd_async_handler_get_timer;
 | 
			
		||||
 | 
			
		||||
    snd_timer_ginfo_sizeof;
 | 
			
		||||
    snd_timer_ginfo_malloc;
 | 
			
		||||
    snd_timer_ginfo_free;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -238,6 +238,10 @@ int snd_timer_close(snd_timer_t *timer)
 | 
			
		|||
{
 | 
			
		||||
	int err;
 | 
			
		||||
  	assert(timer);
 | 
			
		||||
	while (!list_empty(&timer->async_handlers)) {
 | 
			
		||||
		snd_async_handler_t *h = list_entry(timer->async_handlers.next, snd_async_handler_t, hlist);
 | 
			
		||||
		snd_async_del_handler(h);
 | 
			
		||||
	}
 | 
			
		||||
	if ((err = timer->ops->close(timer)) < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	if (timer->name)
 | 
			
		||||
| 
						 | 
				
			
			@ -273,6 +277,55 @@ snd_timer_type_t snd_timer_type(snd_timer_t *timer)
 | 
			
		|||
	return timer->type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Add an async handler for a timer
 | 
			
		||||
 * \param handler Returned handler handle
 | 
			
		||||
 * \param timer timer handle
 | 
			
		||||
 * \param callback Callback function
 | 
			
		||||
 * \param private_data Callback private data
 | 
			
		||||
 * \return 0 otherwise a negative error code on failure
 | 
			
		||||
 *
 | 
			
		||||
 * The asynchronous callback is called when new timer event occurs.
 | 
			
		||||
 */
 | 
			
		||||
int snd_async_add_timer_handler(snd_async_handler_t **handler, snd_timer_t *timer,
 | 
			
		||||
				snd_async_callback_t callback, void *private_data)
 | 
			
		||||
{
 | 
			
		||||
	int err;
 | 
			
		||||
	int was_empty;
 | 
			
		||||
	snd_async_handler_t *h;
 | 
			
		||||
	err = snd_async_add_handler(&h, timer->poll_fd,
 | 
			
		||||
				    callback, private_data);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	h->type = SND_ASYNC_HANDLER_TIMER;
 | 
			
		||||
	h->u.timer = timer;
 | 
			
		||||
	was_empty = list_empty(&timer->async_handlers);
 | 
			
		||||
	list_add_tail(&h->hlist, &timer->async_handlers);
 | 
			
		||||
	if (was_empty) {
 | 
			
		||||
		err = snd_timer_async(timer, snd_async_handler_get_signo(h), getpid());
 | 
			
		||||
		if (err < 0) {
 | 
			
		||||
			snd_async_del_handler(h);
 | 
			
		||||
			return err;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	*handler = h;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Return timer handle related to an async handler
 | 
			
		||||
 * \param handler Async handler handle
 | 
			
		||||
 * \return timer handle
 | 
			
		||||
 */
 | 
			
		||||
snd_timer_t *snd_async_handler_get_timer(snd_async_handler_t *handler)
 | 
			
		||||
{
 | 
			
		||||
	if (handler->type != SND_ASYNC_HANDLER_TIMER) {
 | 
			
		||||
		SNDMSG("invalid handler type %d", handler->type);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	return handler->u.timer;
 | 
			
		||||
}                                                            
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get count of poll descriptors for timer handle
 | 
			
		||||
 * \param timer timer handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -265,6 +265,7 @@ int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int
 | 
			
		|||
	tmr->name = strdup(name);
 | 
			
		||||
	tmr->poll_fd = fd;
 | 
			
		||||
	tmr->ops = &snd_timer_hw_ops;
 | 
			
		||||
	INIT_LIST_HEAD(&tmr->async_handlers);
 | 
			
		||||
	*handle = tmr;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,6 +45,7 @@ struct _snd_timer {
 | 
			
		|||
	int poll_fd;
 | 
			
		||||
	snd_timer_ops_t *ops;
 | 
			
		||||
	void *private_data;
 | 
			
		||||
	struct list_head async_handlers;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int dev_sclass, int card, int device, int subdevice, int mode);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue