mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-09 17:25:42 +01:00
alsactl: split event loop code to a function
In a mode of 'monitor', an event loop runs. This commit applies a small refactoring to splits the loop into a function for readability. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
71558a41b0
commit
0ef92b4ee7
1 changed files with 30 additions and 21 deletions
|
@ -84,6 +84,35 @@ static int print_event(int card, snd_ctl_t *ctl)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int run_dispatcher(snd_ctl_t **ctls, int ncards, int show_cards)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
for (;ncards > 0;) {
|
||||
struct pollfd fds[ncards];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ncards; i++)
|
||||
snd_ctl_poll_descriptors(ctls[i], &fds[i], 1);
|
||||
|
||||
err = poll(fds, ncards, -1);
|
||||
if (err <= 0) {
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < ncards; i++) {
|
||||
unsigned short revents;
|
||||
snd_ctl_poll_descriptors_revents(ctls[i], &fds[i], 1,
|
||||
&revents);
|
||||
if (revents & POLLIN)
|
||||
print_event(show_cards ? i : -1, ctls[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#define MAX_CARDS 256
|
||||
|
||||
int monitor(const char *name)
|
||||
|
@ -117,27 +146,7 @@ int monitor(const char *name)
|
|||
show_cards = 0;
|
||||
}
|
||||
|
||||
for (;ncards > 0;) {
|
||||
struct pollfd fds[ncards];
|
||||
|
||||
for (i = 0; i < ncards; i++)
|
||||
snd_ctl_poll_descriptors(ctls[i], &fds[i], 1);
|
||||
|
||||
err = poll(fds, ncards, -1);
|
||||
if (err <= 0) {
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < ncards; i++) {
|
||||
unsigned short revents;
|
||||
snd_ctl_poll_descriptors_revents(ctls[i], &fds[i], 1,
|
||||
&revents);
|
||||
if (revents & POLLIN)
|
||||
print_event(show_cards ? i : -1, ctls[i]);
|
||||
}
|
||||
}
|
||||
|
||||
err = run_dispatcher(ctls, ncards, show_cards);
|
||||
error:
|
||||
for (i = 0; i < ncards; i++)
|
||||
snd_ctl_close(ctls[i]);
|
||||
|
|
Loading…
Reference in a new issue