From: Jaroslav Kysela Date: Wed, 14 Feb 2001 12:15:03 +0000 (+0000) Subject: Changed behaviour of poll_descriptors function (returns the filled count of fds). X-Git-Tag: v1.0.3~955 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=cc956312b30767fc628be00a1126a6dd7c2e4c26;p=alsa-lib.git Changed behaviour of poll_descriptors function (returns the filled count of fds). Added poll_descriptors_count functions. Added snd_mixer_elem_count function. --- diff --git a/include/control.h b/include/control.h index 45393f9a..2ec4d07f 100644 --- a/include/control.h +++ b/include/control.h @@ -160,6 +160,7 @@ int snd_ctl_open(snd_ctl_t **ctl, const char *name); int snd_ctl_close(snd_ctl_t *ctl); int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock); int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid); +int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl, unsigned int *count); int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space); int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe); int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info); @@ -226,6 +227,7 @@ int snd_hctl_open(snd_hctl_t **hctl, const char *name); int snd_hctl_close(snd_hctl_t *hctl); int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock); int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid); +int snd_hctl_poll_descriptors_count(snd_hctl_t *hctl, unsigned int *count); int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space); unsigned int snd_hctl_get_count(snd_hctl_t *hctl); int snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort); diff --git a/include/mixer.h b/include/mixer.h index b65ed54a..54190e25 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -41,9 +41,11 @@ int snd_mixer_close(snd_mixer_t *mixer); int snd_mixer_info(snd_mixer_t *mixer, snd_mixer_info_t *info); snd_mixer_elem_t *snd_mixer_first_elem(snd_mixer_t *mixer); snd_mixer_elem_t *snd_mixer_last_elem(snd_mixer_t *mixer); +size_t snd_mixer_elem_count(snd_mixer_t *mixer); int snd_mixer_handle_events(snd_mixer_t *mixer); int snd_mixer_attach(snd_mixer_t *mixer, const char *name); int snd_mixer_detach(snd_mixer_t *mixer, const char *name); +int snd_mixer_poll_descriptors_count(snd_mixer_t *mixer, unsigned int *count); int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space); int snd_mixer_load(snd_mixer_t *mixer); int snd_mixer_wait(snd_mixer_t *mixer, int timeout); diff --git a/include/rawmidi.h b/include/rawmidi.h index a87927eb..b46f7b5b 100644 --- a/include/rawmidi.h +++ b/include/rawmidi.h @@ -47,6 +47,7 @@ extern "C" { int snd_rawmidi_open(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi, const char *name, int mode); int snd_rawmidi_close(snd_rawmidi_t *rmidi); +int snd_rawmidi_poll_descriptors_count(snd_rawmidi_t *rmidi, unsigned int *count); int snd_rawmidi_poll_descriptors(snd_rawmidi_t *rmidi, struct pollfd *pfds, unsigned int space); int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi, int nonblock); int snd_rawmidi_info(snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info); diff --git a/include/seq.h b/include/seq.h index 41c44bcc..16730eb8 100644 --- a/include/seq.h +++ b/include/seq.h @@ -324,6 +324,7 @@ extern "C" { int snd_seq_open(snd_seq_t **handle, const char *name, int streams, int mode); int snd_seq_close(snd_seq_t *handle); +int snd_seq_poll_descriptors_count(snd_seq_t *handle, unsigned int *count); int snd_seq_poll_descriptors(snd_seq_t *handle, struct pollfd *pfds, unsigned int space); int snd_seq_nonblock(snd_seq_t *handle, int nonblock); int snd_seq_client_id(snd_seq_t *handle); diff --git a/include/timer.h b/include/timer.h index a40a2807..e72d19a0 100644 --- a/include/timer.h +++ b/include/timer.h @@ -50,6 +50,7 @@ extern "C" { int snd_timer_open(snd_timer_t **handle); int snd_timer_close(snd_timer_t *handle); +int snd_timer_poll_descriptors_count(snd_timer_t *handle, unsigned int *count); int snd_timer_poll_descriptors(snd_timer_t *handle, struct pollfd *pfds, unsigned int space); int snd_timer_next_device(snd_timer_t *handle, snd_timer_id_t *tid); int snd_timer_select(snd_timer_t *handle, snd_timer_select_t *tselect); diff --git a/src/control/control.c b/src/control/control.c index 05e0fdfc..d9d8d404 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -74,14 +74,23 @@ int _snd_ctl_poll_descriptor(snd_ctl_t *ctl) return ctl->ops->poll_descriptor(ctl); } +int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl, unsigned int *count) +{ + assert(ctl); + assert(count); + *count = 1; + return 0; +} + int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space) { assert(ctl); - if (space >= 1) { + if (space > 0) { pfds->fd = ctl->ops->poll_descriptor(ctl); pfds->events = POLLIN; + return 1; } - return 1; + return 0; } int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe) diff --git a/src/control/hcontrol.c b/src/control/hcontrol.c index 939169e6..1b4612cc 100644 --- a/src/control/hcontrol.c +++ b/src/control/hcontrol.c @@ -83,6 +83,13 @@ int snd_hctl_async(snd_hctl_t *hctl, int sig, pid_t pid) return snd_ctl_async(hctl->ctl, sig, pid); } +int snd_hctl_poll_descriptors_count(snd_hctl_t *hctl, unsigned int *count) +{ + assert(hctl); + assert(count); + return snd_ctl_poll_descriptors_count(hctl->ctl, count); +} + int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space) { assert(hctl); diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index 65e8de0b..5b58a70e 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -434,6 +434,25 @@ int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort) return 0; } +int snd_mixer_poll_descriptors_count(snd_mixer_t *mixer, unsigned int *count) +{ + struct list_head *pos; + unsigned int c = 0, v; + assert(mixer); + assert(count); + list_for_each(pos, &mixer->slaves) { + snd_mixer_slave_t *s; + int n; + s = list_entry(pos, snd_mixer_slave_t, list); + n = snd_hctl_poll_descriptors_count(s->hctl, &v); + if (n < 0) + return n; + c += v; + } + *count = c; + return 0; +} + int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space) { struct list_head *pos; @@ -446,8 +465,8 @@ int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned n = snd_hctl_poll_descriptors(s->hctl, pfds, space); if (n < 0) return n; - count += n; - if (space > (unsigned int) n) { + if (space >= (unsigned int) n) { + count += n; space -= n; pfds += n; } else @@ -510,6 +529,12 @@ snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *elem) return list_entry(elem->list.prev, snd_mixer_elem_t, list); } +size_t snd_mixer_elem_count(snd_mixer_t *mixer) +{ + assert(mixer); + return mixer->count; +} + int snd_mixer_handle_events(snd_mixer_t *mixer) { struct list_head *pos; diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c index e22aa06c..a5be7a7c 100644 --- a/src/rawmidi/rawmidi.c +++ b/src/rawmidi/rawmidi.c @@ -58,14 +58,23 @@ int _snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi) return rmidi->poll_fd; } +int snd_rawmidi_poll_descriptors_count(snd_rawmidi_t *rmidi, unsigned int *count) +{ + assert(rmidi); + assert(count); + *count = 1; + return 0; +} + int snd_rawmidi_poll_descriptors(snd_rawmidi_t *rmidi, struct pollfd *pfds, unsigned int space) { assert(rmidi); if (space >= 1) { pfds->fd = rmidi->poll_fd; pfds->events = rmidi->stream == SND_RAWMIDI_STREAM_OUTPUT ? POLLOUT : POLLIN; + return 1; } - return 1; + return 0; } diff --git a/src/seq/seq.c b/src/seq/seq.c index 830846ae..3d3e5aa1 100644 --- a/src/seq/seq.c +++ b/src/seq/seq.c @@ -152,6 +152,14 @@ int _snd_seq_poll_descriptor(snd_seq_t *seq) return seq->poll_fd; } +int snd_seq_poll_descriptors_count(snd_seq_t *seq, unsigned int *count) +{ + assert(seq); + assert(count); + *count = 1; + return 0; +} + int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int space) { assert(seq); @@ -162,8 +170,9 @@ int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int s pfds->events |= POLLIN; if (seq->streams & SND_SEQ_OPEN_OUTPUT) pfds->events |= POLLOUT; + return 1; } - return 1; + return 0; } /* diff --git a/src/timer/timer.c b/src/timer/timer.c index 9a1fff68..38c1498a 100644 --- a/src/timer/timer.c +++ b/src/timer/timer.c @@ -84,14 +84,23 @@ int _snd_timer_poll_descriptor(snd_timer_t *handle) return tmr->fd; } +int snd_timer_poll_descriptors_count(snd_timer_t *timer, unsigned int *count) +{ + assert(timer); + assert(count); + *count = 1; + return 0; +} + int snd_timer_poll_descriptors(snd_timer_t *timer, struct pollfd *pfds, unsigned int space) { assert(timer); if (space >= 1) { pfds->fd = timer->fd; pfds->events = POLLIN; + return 1; } - return 1; + return 0; } int snd_timer_next_device(snd_timer_t *handle, snd_timer_id_t * tid)