Revert wrong parts of "alsactl: use snd_config_imake* functions"

This reverts the parts of commit e509df69a5
that accidentally reverted a bunch of earlier commits.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
This commit is contained in:
Clemens Ladisch 2010-05-26 10:37:58 +02:00
parent bd15b1e5ea
commit b4ff58b685
5 changed files with 38 additions and 51 deletions

View file

@ -34,16 +34,16 @@ extern char *statefile;
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
#define cerror(cond, ...) do {\ #define cerror(cond, ...) do {\
if (cond) { \ if (cond || debugflag) { \
fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, __VA_ARGS__); \
putc('\n', stderr); \ putc('\n', stderr); \
} \ } \
} while (0) } while (0)
#else #else
#define cerror(cond, args...) do {\ #define cerror(cond, args...) do {\
if (cond) { \ if (cond || debugflag) { \
fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \
fprintf(stderr, ##args); \ fprintf(stderr, ##args); \
putc('\n', stderr); \ putc('\n', stderr); \
} \ } \
@ -78,7 +78,7 @@ int generate_names(const char *cfgfile);
int file_map(const char *filename, char **buf, size_t *bufsize); int file_map(const char *filename, char **buf, size_t *bufsize);
void file_unmap(void *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); size_t line_width(const char *buf, size_t bufsize, size_t pos);
void initfailed(int cardnumber, const char *reason); void initfailed(int cardnumber, const char *reason, int exitcode);
static inline int hextodigit(int c) static inline int hextodigit(int c)
{ {

View file

@ -1131,7 +1131,6 @@ static int restore_config_value2(snd_ctl_t *handle, snd_ctl_elem_info_t *info,
} }
snd_ctl_elem_value_set_byte(ctl, idx, val); snd_ctl_elem_value_set_byte(ctl, idx, val);
return 1; return 1;
break;
default: default:
break; break;
} }
@ -1418,6 +1417,7 @@ static int set_controls(int card, snd_config_t *top, int doit)
snd_ctl_card_info_alloca(&info); snd_ctl_card_info_alloca(&info);
sprintf(name, "hw:%d", card); sprintf(name, "hw:%d", card);
dbg("device='%s', doit=%i", name, doit);
err = snd_ctl_open(&handle, name, 0); err = snd_ctl_open(&handle, name, 0);
if (err < 0) { if (err < 0) {
error("snd_ctl_open error: %s", snd_strerror(err)); error("snd_ctl_open error: %s", snd_strerror(err));
@ -1429,6 +1429,7 @@ static int set_controls(int card, snd_config_t *top, int doit)
goto _close; goto _close;
} }
id = snd_ctl_card_info_get_id(info); id = snd_ctl_card_info_get_id(info);
dbg("card-info-id: '%s'", id);
err = snd_config_searchv(top, &control, "state", id, "control", 0); err = snd_config_searchv(top, &control, "state", id, "control", 0);
if (err < 0) { if (err < 0) {
if (force_restore) { if (force_restore) {
@ -1454,24 +1455,25 @@ static int set_controls(int card, snd_config_t *top, int doit)
goto _close; goto _close;
} }
dbg("maxnumid=%i", maxnumid);
/* check if we have additional controls in driver */ /* check if we have additional controls in driver */
/* in this case we should go through init procedure */ /* in this case we should go through init procedure */
if (!doit && maxnumid >= 0) { if (!doit && maxnumid >= 0) {
snd_ctl_elem_id_t *id;
snd_ctl_elem_info_t *info; snd_ctl_elem_info_t *info;
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_info_alloca(&info); snd_ctl_elem_info_alloca(&info);
snd_ctl_elem_info_set_numid(info, maxnumid+1); snd_ctl_elem_info_set_numid(info, maxnumid+1);
if (snd_ctl_elem_info(handle, info) == 0) { if (snd_ctl_elem_info(handle, info) == 0) {
/* not very informative */ /* not very informative */
/* but value is used for check only */ /* but value is used for check only */
err = -EAGAIN; err = -EAGAIN;
dbg("more controls than maxnumid?");
goto _close; goto _close;
} }
} }
_close: _close:
snd_ctl_close(handle); snd_ctl_close(handle);
dbg("result code: %i", err);
return err; return err;
} }
@ -1596,9 +1598,9 @@ int load_state(const char *file, const char *initfile, const char *cardname,
err = init(initfile, cardname1); err = init(initfile, cardname1);
if (err < 0) { if (err < 0) {
finalerr = err; finalerr = err;
initfailed(card, "init"); initfailed(card, "init", err);
} }
initfailed(card, "restore"); initfailed(card, "restore", -ENOENT);
} }
if (first) if (first)
finalerr = 0; /* no cards, no error code */ finalerr = 0; /* no cards, no error code */
@ -1631,14 +1633,14 @@ int load_state(const char *file, const char *initfile, const char *cardname,
sprintf(cardname1, "%i", card); sprintf(cardname1, "%i", card);
err = init(initfile, cardname1); err = init(initfile, cardname1);
if (err < 0) { if (err < 0) {
initfailed(card, "init"); initfailed(card, "init", err);
finalerr = err; finalerr = err;
} }
} }
if ((err = set_controls(card, config, 1))) { if ((err = set_controls(card, config, 1))) {
if (!force_restore) if (!force_restore)
finalerr = err; finalerr = err;
initfailed(card, "restore"); initfailed(card, "restore", err);
} }
} }
} else { } else {
@ -1653,12 +1655,12 @@ int load_state(const char *file, const char *initfile, const char *cardname,
if (do_init && set_controls(cardno, config, 0)) { if (do_init && set_controls(cardno, config, 0)) {
err = init(initfile, cardname); err = init(initfile, cardname);
if (err < 0) { if (err < 0) {
initfailed(cardno, "init"); initfailed(cardno, "init", err);
return err; finalerr = err;
} }
} }
if ((err = set_controls(cardno, config, 1))) { if ((err = set_controls(cardno, config, 1))) {
initfailed(cardno, "restore"); initfailed(cardno, "restore", err);
if (!force_restore) if (!force_restore)
return err; return err;
} }

View file

@ -79,19 +79,23 @@ size_t line_width(const char *buf, size_t bufsize, size_t pos)
return count - pos; return count - pos;
} }
void initfailed(int cardnumber, const char *reason) void initfailed(int cardnumber, const char *reason, int exitcode)
{ {
int fp; int fp;
char *str; char *str;
char sexitcode[16];
if (statefile == NULL) if (statefile == NULL)
return; return;
if (snd_card_get_name(cardnumber, &str) < 0) if (snd_card_get_name(cardnumber, &str) < 0)
return; return;
sprintf(sexitcode, "%i", exitcode);
fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644); fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644);
write(fp, str, strlen(str)); write(fp, str, strlen(str));
write(fp, ":", 1); write(fp, ":", 1);
write(fp, reason, strlen(reason)); write(fp, reason, strlen(reason));
write(fp, ":", 1);
write(fp, sexitcode, strlen(sexitcode));
write(fp, "\n", 1); write(fp, "\n", 1);
close(fp); close(fp);
free(str); free(str);

View file

@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59) AC_PREREQ(2.59)
AC_INIT(aplay/aplay.c) AC_INIT(aplay/aplay.c)
AC_PREFIX_DEFAULT(/usr) AC_PREFIX_DEFAULT(/usr)
AM_INIT_AUTOMAKE(alsa-utils, 1.0.22) AM_INIT_AUTOMAKE(alsa-utils, 1.0.23)
AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.15]) AM_GNU_GETTEXT_VERSION([0.15])

View file

@ -192,52 +192,33 @@ static void remove_connection(snd_seq_t *seq, snd_seq_client_info_t *cinfo,
snd_seq_port_info_t *pinfo, int count) snd_seq_port_info_t *pinfo, int count)
{ {
snd_seq_query_subscribe_t *query; 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_alloca(&query);
snd_seq_query_subscribe_set_root(query, snd_seq_port_info_get_addr(pinfo)); 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_type(query, SND_SEQ_QUERY_SUBS_READ);
snd_seq_query_subscribe_set_index(query, 0); 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_alloca(&port);
snd_seq_port_info_t *port; snd_seq_port_subscribe_alloca(&subs);
snd_seq_port_subscribe_t *subs;
while (snd_seq_query_port_subscribers(seq, query) >= 0) {
const snd_seq_addr_t *sender = snd_seq_query_subscribe_get_root(query); 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); 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);
}
snd_seq_query_subscribe_set_type(query, SND_SEQ_QUERY_SUBS_WRITE); if (snd_seq_get_any_port_info(seq, dest->client, dest->port, port) < 0 ||
snd_seq_query_subscribe_set_index(query, 0); !(snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_SUBS_WRITE) ||
for (; snd_seq_query_port_subscribers(seq, query) >= 0; (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_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; 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_queue(subs, snd_seq_query_subscribe_get_queue(query));
snd_seq_port_subscribe_set_sender(subs, sender); snd_seq_port_subscribe_set_sender(subs, sender);
snd_seq_port_subscribe_set_dest(subs, dest); snd_seq_port_subscribe_set_dest(subs, dest);
snd_seq_unsubscribe_port(seq, subs); if (snd_seq_unsubscribe_port(seq, subs) < 0) {
snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1);
}
} }
} }