mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	Added snd_*_poll_descriptors_revents functions.
This commit is contained in:
		
							parent
							
								
									23ab0b3509
								
							
						
					
					
						commit
						ddb7209e9a
					
				
					 15 changed files with 195 additions and 36 deletions
				
			
		| 
						 | 
				
			
			@ -160,15 +160,33 @@ int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl)
 | 
			
		|||
 */
 | 
			
		||||
int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space)
 | 
			
		||||
{
 | 
			
		||||
	assert(ctl);
 | 
			
		||||
	assert(ctl && pfds);
 | 
			
		||||
	if (space > 0) {
 | 
			
		||||
		pfds->fd = ctl->poll_fd;
 | 
			
		||||
		pfds->events = POLLIN;
 | 
			
		||||
		pfds->events = POLLIN|POLLERR;
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param ctl CTL handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_ctl_poll_descriptors_revents(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
	assert(ctl && pfds && revents);
 | 
			
		||||
	if (nfds == 1) {
 | 
			
		||||
		*revents = pfds->revents;
 | 
			
		||||
                return 0;
 | 
			
		||||
	}
 | 
			
		||||
	return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Ask to be informed about events (poll, #snd_ctl_async, #snd_ctl_read)
 | 
			
		||||
 * \param ctl CTL handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -260,13 +260,13 @@ int snd_hwdep_poll_descriptors(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned
 | 
			
		|||
		pfds->fd = hwdep->poll_fd;
 | 
			
		||||
		switch (hwdep->mode & O_ACCMODE) {
 | 
			
		||||
		case O_WRONLY:
 | 
			
		||||
			pfds->events = POLLOUT;
 | 
			
		||||
			pfds->events = POLLOUT|POLLERR;
 | 
			
		||||
			break;
 | 
			
		||||
		case O_RDONLY:
 | 
			
		||||
			pfds->events = POLLIN;
 | 
			
		||||
			pfds->events = POLLIN|POLLERR;
 | 
			
		||||
			break;
 | 
			
		||||
		case O_RDWR:
 | 
			
		||||
			pfds->events = POLLOUT|POLLIN;
 | 
			
		||||
			pfds->events = POLLOUT|POLLIN|POLLERR;
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			return -EIO;
 | 
			
		||||
| 
						 | 
				
			
			@ -276,6 +276,24 @@ int snd_hwdep_poll_descriptors(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param hwdep HwDep  handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_hwdep_poll_descriptors_revents(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
        assert(hwdep && pfds && revents);
 | 
			
		||||
        if (nfds == 1) {
 | 
			
		||||
                *revents = pfds->revents;
 | 
			
		||||
                return 0;
 | 
			
		||||
        }
 | 
			
		||||
        return -EINVAL;
 | 
			
		||||
}                                                                       
 | 
			
		||||
                                                                       
 | 
			
		||||
/**
 | 
			
		||||
 * \brief set nonblock mode
 | 
			
		||||
 * \param hwdep HwDep handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -599,6 +599,28 @@ int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned
 | 
			
		|||
	return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param mixer Mixer handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_mixer_poll_descriptors_revents(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
	unsigned int idx;
 | 
			
		||||
	unsigned short res;
 | 
			
		||||
        assert(mixer && pfds && revents);
 | 
			
		||||
	if (nfds == 0)
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	res = 0;
 | 
			
		||||
	for (idx = 0; idx < nfds; idx++)
 | 
			
		||||
		res |= pfds->revents & (POLLIN|POLLERR);
 | 
			
		||||
	*revents = res;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Wait for a mixer to become ready (i.e. at least one event pending)
 | 
			
		||||
 * \param mixer Mixer handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1003,14 +1003,33 @@ int snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
 | 
			
		|||
 */
 | 
			
		||||
int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
 | 
			
		||||
{
 | 
			
		||||
	assert(pcm);
 | 
			
		||||
	if (space >= 1) {
 | 
			
		||||
	assert(pcm && pfds);
 | 
			
		||||
	if (space >= 1 && pfds) {
 | 
			
		||||
		pfds->fd = pcm->poll_fd;
 | 
			
		||||
		pfds->events = pcm->stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
 | 
			
		||||
	}
 | 
			
		||||
		pfds->events = pcm->stream == SND_PCM_STREAM_PLAYBACK ? (POLLOUT|POLLERR) : (POLLIN|POLLERR);
 | 
			
		||||
	} else
 | 
			
		||||
		return 0;
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param pcm PCM handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
	assert(pcm && pfds && revents);
 | 
			
		||||
	if (nfds == 1) {
 | 
			
		||||
		*revents = pfds->revents;
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifndef DOC_HIDDEN
 | 
			
		||||
#define STATE(v) [SND_PCM_STATE_##v] = #v
 | 
			
		||||
#define STREAM(v) [SND_PCM_STREAM_##v] = #v
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -313,12 +313,30 @@ int snd_rawmidi_poll_descriptors(snd_rawmidi_t *rawmidi, struct pollfd *pfds, un
 | 
			
		|||
	assert(rawmidi);
 | 
			
		||||
	if (space >= 1) {
 | 
			
		||||
		pfds->fd = rawmidi->poll_fd;
 | 
			
		||||
		pfds->events = rawmidi->stream == SND_RAWMIDI_STREAM_OUTPUT ? POLLOUT : POLLIN;
 | 
			
		||||
		pfds->events = rawmidi->stream == SND_RAWMIDI_STREAM_OUTPUT ? (POLLOUT|POLLERR) : (POLLIN|POLLERR);
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param pcm rawmidi RawMidi handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_rawmidi_poll_descriptors_revents(snd_rawmidi_t *rawmidi, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
        assert(rawmidi && pfds && revents);
 | 
			
		||||
        if (nfds == 1) {
 | 
			
		||||
                *revents = pfds->revents;
 | 
			
		||||
                return 0;
 | 
			
		||||
        }
 | 
			
		||||
        return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief set nonblock mode
 | 
			
		||||
 * \param rawmidi RawMidi handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -305,11 +305,11 @@ int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int s
 | 
			
		|||
	assert(seq);
 | 
			
		||||
	if ((events & POLLIN) && space >= 1) {
 | 
			
		||||
		assert(seq->streams & SND_SEQ_OPEN_INPUT);
 | 
			
		||||
		revents |= POLLIN;
 | 
			
		||||
		revents |= POLLIN|POLLERR;
 | 
			
		||||
	}
 | 
			
		||||
	if ((events & POLLOUT) && space >= 1) {
 | 
			
		||||
		assert(seq->streams & SND_SEQ_OPEN_INPUT);
 | 
			
		||||
		revents |= POLLOUT;
 | 
			
		||||
		revents |= POLLOUT|POLLERR;
 | 
			
		||||
	}
 | 
			
		||||
	if (!revents)
 | 
			
		||||
		return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -318,6 +318,24 @@ int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int s
 | 
			
		|||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param seq sequencer handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_seq_poll_descriptors_revents(snd_seq_t *seq, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
        assert(seq && pfds && revents);
 | 
			
		||||
        if (nfds == 1) {
 | 
			
		||||
                *revents = pfds->revents;
 | 
			
		||||
                return 0;
 | 
			
		||||
        }
 | 
			
		||||
        return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Set nonblock mode
 | 
			
		||||
 * \param seq sequencer handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -261,13 +261,13 @@ int snd_timer_poll_descriptors(snd_timer_t *timer, struct pollfd *pfds, unsigned
 | 
			
		|||
		pfds->fd = timer->poll_fd;
 | 
			
		||||
		switch (timer->mode & O_ACCMODE) {
 | 
			
		||||
		case O_WRONLY:
 | 
			
		||||
			pfds->events = POLLOUT;
 | 
			
		||||
			pfds->events = POLLOUT|POLLERR;
 | 
			
		||||
			break;
 | 
			
		||||
		case O_RDONLY:
 | 
			
		||||
			pfds->events = POLLIN;
 | 
			
		||||
			pfds->events = POLLIN|POLLERR;
 | 
			
		||||
			break;
 | 
			
		||||
		case O_RDWR:
 | 
			
		||||
			pfds->events = POLLOUT|POLLIN;
 | 
			
		||||
			pfds->events = POLLOUT|POLLIN|POLLERR;
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			return -EIO;
 | 
			
		||||
| 
						 | 
				
			
			@ -277,6 +277,24 @@ int snd_timer_poll_descriptors(snd_timer_t *timer, struct pollfd *pfds, unsigned
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief get returned events from poll descriptors
 | 
			
		||||
 * \param timer timer handle
 | 
			
		||||
 * \param pfds array of poll descriptors
 | 
			
		||||
 * \param nfds count of poll descriptors
 | 
			
		||||
 * \param revents returned events
 | 
			
		||||
 * \return zero if success, otherwise a negative error code
 | 
			
		||||
 */
 | 
			
		||||
int snd_timer_poll_descriptors_revents(snd_timer_t *timer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
 | 
			
		||||
{
 | 
			
		||||
        assert(timer && pfds && revents);
 | 
			
		||||
        if (nfds == 1) {
 | 
			
		||||
                *revents = pfds->revents;
 | 
			
		||||
                return 0;
 | 
			
		||||
        }
 | 
			
		||||
        return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief set nonblock mode
 | 
			
		||||
 * \param timer timer handle
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue