From e509df69a5100df28921980362488f6947df0aae Mon Sep 17 00:00:00 2001 From: Clemens Ladisch Date: Wed, 26 May 2010 10:07:47 +0200 Subject: [PATCH] alsactl: use snd_config_imake* functions To save a call to snd_config_set_xxx, replace the calls to snd_config_make_xxx with snd_config_imake_xxx. Signed-off-by: Clemens Ladisch --- alsactl/alsactl.h | 10 ++++---- alsactl/state.c | 43 +++++++++++----------------------- alsactl/utils.c | 6 +---- configure.in | 2 +- seq/aconnect/aconnect.c | 51 ++++++++++++++++++++++++++++------------- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index be90efb..89ad295 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -34,16 +34,16 @@ extern char *statefile; #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) #define cerror(cond, ...) do {\ - if (cond || debugflag) { \ - fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \ + if (cond) { \ + fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ fprintf(stderr, __VA_ARGS__); \ putc('\n', stderr); \ } \ } while (0) #else #define cerror(cond, args...) do {\ - if (cond || debugflag) { \ - fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \ + if (cond) { \ + fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ fprintf(stderr, ##args); \ putc('\n', stderr); \ } \ @@ -78,7 +78,7 @@ int generate_names(const char *cfgfile); int file_map(const char *filename, char **buf, size_t *bufsize); void file_unmap(void *buf, size_t bufsize); size_t line_width(const char *buf, size_t bufsize, size_t pos); -void initfailed(int cardnumber, const char *reason, int exitcode); +void initfailed(int cardnumber, const char *reason); static inline int hextodigit(int c) { diff --git a/alsactl/state.c b/alsactl/state.c index e70c6f9..a9ffeea 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -58,7 +58,7 @@ static int snd_config_integer_add(snd_config_t *father, char *id, long integer) { int err; snd_config_t *leaf; - err = snd_config_make_integer(&leaf, id); + err = snd_config_imake_integer(&leaf, id, integer); if (err < 0) return err; err = snd_config_add(father, leaf); @@ -66,11 +66,6 @@ static int snd_config_integer_add(snd_config_t *father, char *id, long integer) snd_config_delete(leaf); return err; } - err = snd_config_set_integer(leaf, integer); - if (err < 0) { - snd_config_delete(leaf); - return err; - } return 0; } @@ -78,7 +73,7 @@ static int snd_config_integer64_add(snd_config_t *father, char *id, long long in { int err; snd_config_t *leaf; - err = snd_config_make_integer64(&leaf, id); + err = snd_config_imake_integer64(&leaf, id, integer); if (err < 0) return err; err = snd_config_add(father, leaf); @@ -86,11 +81,6 @@ static int snd_config_integer64_add(snd_config_t *father, char *id, long long in snd_config_delete(leaf); return err; } - err = snd_config_set_integer64(leaf, integer); - if (err < 0) { - snd_config_delete(leaf); - return err; - } return 0; } @@ -98,7 +88,7 @@ static int snd_config_string_add(snd_config_t *father, const char *id, const cha { int err; snd_config_t *leaf; - err = snd_config_make_string(&leaf, id); + err = snd_config_imake_string(&leaf, id, string); if (err < 0) return err; err = snd_config_add(father, leaf); @@ -106,11 +96,6 @@ static int snd_config_string_add(snd_config_t *father, const char *id, const cha snd_config_delete(leaf); return err; } - err = snd_config_set_string(leaf, string); - if (err < 0) { - snd_config_delete(leaf); - return err; - } return 0; } @@ -1117,6 +1102,7 @@ static int restore_config_value2(snd_ctl_t *handle, snd_ctl_elem_info_t *info, } snd_ctl_elem_value_set_byte(ctl, idx, val); return 1; + break; default: break; } @@ -1403,7 +1389,6 @@ static int set_controls(int card, snd_config_t *top, int doit) snd_ctl_card_info_alloca(&info); sprintf(name, "hw:%d", card); - dbg("device='%s', doit=%i", name, doit); err = snd_ctl_open(&handle, name, 0); if (err < 0) { error("snd_ctl_open error: %s", snd_strerror(err)); @@ -1415,7 +1400,6 @@ static int set_controls(int card, snd_config_t *top, int doit) goto _close; } id = snd_ctl_card_info_get_id(info); - dbg("card-info-id: '%s'", id); err = snd_config_searchv(top, &control, "state", id, "control", 0); if (err < 0) { if (force_restore) { @@ -1441,25 +1425,24 @@ static int set_controls(int card, snd_config_t *top, int doit) goto _close; } - dbg("maxnumid=%i", maxnumid); /* check if we have additional controls in driver */ /* in this case we should go through init procedure */ if (!doit && maxnumid >= 0) { + snd_ctl_elem_id_t *id; snd_ctl_elem_info_t *info; + snd_ctl_elem_id_alloca(&id); snd_ctl_elem_info_alloca(&info); snd_ctl_elem_info_set_numid(info, maxnumid+1); if (snd_ctl_elem_info(handle, info) == 0) { /* not very informative */ /* but value is used for check only */ err = -EAGAIN; - dbg("more controls than maxnumid?"); goto _close; } } _close: snd_ctl_close(handle); - dbg("result code: %i", err); return err; } @@ -1584,9 +1567,9 @@ int load_state(const char *file, const char *initfile, const char *cardname, err = init(initfile, cardname1); if (err < 0) { finalerr = err; - initfailed(card, "init", err); + initfailed(card, "init"); } - initfailed(card, "restore", -ENOENT); + initfailed(card, "restore"); } if (first) finalerr = 0; /* no cards, no error code */ @@ -1619,14 +1602,14 @@ int load_state(const char *file, const char *initfile, const char *cardname, sprintf(cardname1, "%i", card); err = init(initfile, cardname1); if (err < 0) { - initfailed(card, "init", err); + initfailed(card, "init"); finalerr = err; } } if ((err = set_controls(card, config, 1))) { if (!force_restore) finalerr = err; - initfailed(card, "restore", err); + initfailed(card, "restore"); } } } else { @@ -1641,12 +1624,12 @@ int load_state(const char *file, const char *initfile, const char *cardname, if (do_init && set_controls(cardno, config, 0)) { err = init(initfile, cardname); if (err < 0) { - initfailed(cardno, "init", err); - finalerr = err; + initfailed(cardno, "init"); + return err; } } if ((err = set_controls(cardno, config, 1))) { - initfailed(cardno, "restore", err); + initfailed(cardno, "restore"); if (!force_restore) return err; } diff --git a/alsactl/utils.c b/alsactl/utils.c index a27eb6e..ab4dbd4 100644 --- a/alsactl/utils.c +++ b/alsactl/utils.c @@ -79,23 +79,19 @@ size_t line_width(const char *buf, size_t bufsize, size_t pos) return count - pos; } -void initfailed(int cardnumber, const char *reason, int exitcode) +void initfailed(int cardnumber, const char *reason) { int fp; char *str; - char sexitcode[16]; if (statefile == NULL) return; if (snd_card_get_name(cardnumber, &str) < 0) return; - sprintf(sexitcode, "%i", exitcode); fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644); write(fp, str, strlen(str)); write(fp, ":", 1); write(fp, reason, strlen(reason)); - write(fp, ":", 1); - write(fp, sexitcode, strlen(sexitcode)); write(fp, "\n", 1); close(fp); free(str); diff --git a/configure.in b/configure.in index 8bae007..66b785f 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) AC_INIT(aplay/aplay.c) AC_PREFIX_DEFAULT(/usr) -AM_INIT_AUTOMAKE(alsa-utils, 1.0.23) +AM_INIT_AUTOMAKE(alsa-utils, 1.0.22) AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.15]) diff --git a/seq/aconnect/aconnect.c b/seq/aconnect/aconnect.c index 8c66cfd..1a50666 100644 --- a/seq/aconnect/aconnect.c +++ b/seq/aconnect/aconnect.c @@ -192,33 +192,52 @@ static void remove_connection(snd_seq_t *seq, snd_seq_client_info_t *cinfo, snd_seq_port_info_t *pinfo, int count) { snd_seq_query_subscribe_t *query; - snd_seq_port_info_t *port; - snd_seq_port_subscribe_t *subs; snd_seq_query_subscribe_alloca(&query); snd_seq_query_subscribe_set_root(query, snd_seq_port_info_get_addr(pinfo)); + snd_seq_query_subscribe_set_type(query, SND_SEQ_QUERY_SUBS_READ); snd_seq_query_subscribe_set_index(query, 0); - - snd_seq_port_info_alloca(&port); - snd_seq_port_subscribe_alloca(&subs); - - while (snd_seq_query_port_subscribers(seq, query) >= 0) { + for (; snd_seq_query_port_subscribers(seq, query) >= 0; + snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1)) { + snd_seq_port_info_t *port; + snd_seq_port_subscribe_t *subs; const snd_seq_addr_t *sender = snd_seq_query_subscribe_get_root(query); const snd_seq_addr_t *dest = snd_seq_query_subscribe_get_addr(query); - - if (snd_seq_get_any_port_info(seq, dest->client, dest->port, port) < 0 || - !(snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_SUBS_WRITE) || - (snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_NO_EXPORT)) { - snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1); + snd_seq_port_info_alloca(&port); + if (snd_seq_get_any_port_info(seq, dest->client, dest->port, port) < 0) continue; - } + if (!(snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_SUBS_WRITE)) + continue; + if (snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_NO_EXPORT) + continue; + snd_seq_port_subscribe_alloca(&subs); snd_seq_port_subscribe_set_queue(subs, snd_seq_query_subscribe_get_queue(query)); snd_seq_port_subscribe_set_sender(subs, sender); snd_seq_port_subscribe_set_dest(subs, dest); - if (snd_seq_unsubscribe_port(seq, subs) < 0) { - snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1); - } + snd_seq_unsubscribe_port(seq, subs); + } + + snd_seq_query_subscribe_set_type(query, SND_SEQ_QUERY_SUBS_WRITE); + snd_seq_query_subscribe_set_index(query, 0); + for (; snd_seq_query_port_subscribers(seq, query) >= 0; + snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1)) { + snd_seq_port_info_t *port; + snd_seq_port_subscribe_t *subs; + const snd_seq_addr_t *dest = snd_seq_query_subscribe_get_root(query); + const snd_seq_addr_t *sender = snd_seq_query_subscribe_get_addr(query); + snd_seq_port_info_alloca(&port); + if (snd_seq_get_any_port_info(seq, sender->client, sender->port, port) < 0) + continue; + if (!(snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_SUBS_READ)) + continue; + if (snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_NO_EXPORT) + continue; + snd_seq_port_subscribe_alloca(&subs); + snd_seq_port_subscribe_set_queue(subs, snd_seq_query_subscribe_get_queue(query)); + snd_seq_port_subscribe_set_sender(subs, sender); + snd_seq_port_subscribe_set_dest(subs, dest); + snd_seq_unsubscribe_port(seq, subs); } }