]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl: use snd_config_imake* functions
authorClemens Ladisch <clemens@ladisch.de>
Wed, 26 May 2010 08:07:47 +0000 (10:07 +0200)
committerClemens Ladisch <clemens@ladisch.de>
Wed, 26 May 2010 08:07:47 +0000 (10:07 +0200)
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 <clemens@ladisch.de>
alsactl/alsactl.h
alsactl/state.c
alsactl/utils.c
configure.in
seq/aconnect/aconnect.c

index be90efb5d9c2dc1ad4e3e5c008be867f78523541..89ad295ae3ceeab361d5f1e6538ff2d7dba56372 100644 (file)
@@ -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)
 {
index e70c6f92c01165dfa2e9da62167976ea14538d76..a9ffeea5b43cd05ea4905dc02d5e351b494ee091 100644 (file)
@@ -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;
                }
index a27eb6ebeb31805358e887b25b1faf0abd47fdbb..ab4dbd49d626adf31676a15bb262297571ef5993 100644 (file)
@@ -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);
index 8bae0079d301facd48e19d3ecc347f81039c35d3..66b785f1628efd119043badc2f4e0f970f02f299 100644 (file)
@@ -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])
index 8c66cfd306400585e5951a071c761d4ef53cf612..1a50666966e98f459655b6ad4970f67991f443f3 100644 (file)
@@ -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);
+               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);
+               snd_seq_unsubscribe_port(seq, subs);
+       }
 
-               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_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);
-               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);
        }
 }