From 14a453006047f0dd6658d515709d85b323c48d6f Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Tue, 26 Jun 2018 07:12:36 +0000 Subject: Replace the gloal opt list with per-device lists. --- usr.bin/sndiod/dev.c | 6 +++++- usr.bin/sndiod/dev.h | 15 ++++++++++++++- usr.bin/sndiod/opt.c | 27 ++++++++++++--------------- usr.bin/sndiod/opt.h | 23 ++++------------------- usr.bin/sndiod/sndiod.c | 8 +++----- usr.bin/sndiod/sock.c | 11 +++++++---- 6 files changed, 45 insertions(+), 45 deletions(-) (limited to 'usr.bin/sndiod') diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index bf394d9597a..fd1b610f62f 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.35 2018/06/26 07:11:39 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.36 2018/06/26 07:12:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -23,6 +23,7 @@ #include "dsp.h" #include "siofile.h" #include "midi.h" +#include "opt.h" #include "sysex.h" #include "utils.h" @@ -971,6 +972,7 @@ dev_new(char *path, struct aparams *par, d = xmalloc(sizeof(struct dev)); d->path = xstrdup(path); d->num = dev_sndnum++; + d->opt_list = NULL; /* * XXX: below, we allocate a midi input buffer, since we don't @@ -1238,6 +1240,8 @@ dev_del(struct dev *d) log_puts(": deleting\n"); } #endif + while (d->opt_list != NULL) + opt_del(d, d->opt_list); if (d->pstate != DEV_CFG) dev_close(d); for (p = &dev_list; *p != d; p = &(*p)->next) { diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index 15e2809dce0..cfde2ac0f32 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.11 2016/03/23 06:16:35 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.12 2018/06/26 07:12:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -95,12 +95,25 @@ struct slot { unsigned int tstate; /* mmc state */ }; +struct opt { + struct opt *next; +#define OPT_NAMEMAX 11 + char name[OPT_NAMEMAX + 1]; + int maxweight; /* max dynamic range for clients */ + int pmin, pmax; /* play channels */ + int rmin, rmax; /* recording channels */ + int mmc; /* true if MMC control enabled */ + int dup; /* true if join/expand enabled */ + int mode; /* bitmap of MODE_XXX */ +}; + /* * audio device with plenty of slots */ struct dev { struct dev *next; struct slot *slot_list; /* audio streams attached */ + struct opt *opt_list; struct midi *midi; /* diff --git a/usr.bin/sndiod/opt.c b/usr.bin/sndiod/opt.c index 1c533118fc6..9f5477c38ac 100644 --- a/usr.bin/sndiod/opt.c +++ b/usr.bin/sndiod/opt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.c,v 1.3 2016/01/08 10:54:07 ratchov Exp $ */ +/* $OpenBSD: opt.c,v 1.4 2018/06/26 07:12:35 ratchov Exp $ */ /* * Copyright (c) 2008-2011 Alexandre Ratchov * @@ -20,13 +20,11 @@ #include "opt.h" #include "utils.h" -struct opt *opt_list = NULL; - /* * create a new audio sub-device "configuration" */ struct opt * -opt_new(char *name, struct dev *dev, +opt_new(struct dev *d, char *name, int pmin, int pmax, int rmin, int rmax, int maxweight, int mmc, int dup, unsigned int mode) { @@ -34,7 +32,9 @@ opt_new(char *name, struct dev *dev, unsigned int len; char c; - if (opt_byname(name, dev->num)) { + if (opt_byname(d, name)) { + dev_log(d); + log_puts("."); log_puts(name); log_puts(": already defined\n"); return NULL; @@ -66,12 +66,11 @@ opt_new(char *name, struct dev *dev, o->mmc = mmc; o->dup = dup; o->mode = mode; - o->dev = dev; memcpy(o->name, name, len + 1); - o->next = opt_list; - opt_list = o; + o->next = d->opt_list; + d->opt_list = o; if (log_level >= 2) { - dev_log(o->dev); + dev_log(d); log_puts("."); log_puts(o->name); log_puts(":"); @@ -107,13 +106,11 @@ opt_new(char *name, struct dev *dev, } struct opt * -opt_byname(char *name, unsigned int num) +opt_byname(struct dev *d, char *name) { struct opt *o; - for (o = opt_list; o != NULL; o = o->next) { - if (o->dev->num != num) - continue; + for (o = d->opt_list; o != NULL; o = o->next) { if (strcmp(name, o->name) == 0) return o; } @@ -121,11 +118,11 @@ opt_byname(char *name, unsigned int num) } void -opt_del(struct opt *o) +opt_del(struct dev *d, struct opt *o) { struct opt **po; - for (po = &opt_list; *po != o; po = &(*po)->next) { + for (po = &d->opt_list; *po != o; po = &(*po)->next) { #ifdef DEBUG if (*po == NULL) { log_puts("opt_del: not on list\n"); diff --git a/usr.bin/sndiod/opt.h b/usr.bin/sndiod/opt.h index 49c185b8e73..31dcce25e61 100644 --- a/usr.bin/sndiod/opt.h +++ b/usr.bin/sndiod/opt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.h,v 1.1 2012/11/23 07:03:28 ratchov Exp $ */ +/* $OpenBSD: opt.h,v 1.2 2018/06/26 07:12:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -19,24 +19,9 @@ struct dev; -struct opt { - struct opt *next; -#define OPT_NAMEMAX 11 - char name[OPT_NAMEMAX + 1]; - int maxweight; /* max dynamic range for clients */ - int pmin, pmax; /* play channels */ - int rmin, rmax; /* recording channels */ - int mmc; /* true if MMC control enabled */ - int dup; /* true if join/expand enabled */ - int mode; /* bitmap of MODE_XXX */ - struct dev *dev; /* device to which we're attached */ -}; - -extern struct opt *opt_list; - -struct opt *opt_new(char *, struct dev *, int, int, int, int, +struct opt *opt_new(struct dev *, char *, int, int, int, int, int, int, int, unsigned int); -void opt_del(struct opt *); -struct opt *opt_byname(char *, unsigned int); +void opt_del(struct dev *, struct opt *); +struct opt *opt_byname(struct dev *, char *); #endif /* !defined(OPT_H) */ diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c index dbdb44cba0e..bd43f4f7fc3 100644 --- a/usr.bin/sndiod/sndiod.c +++ b/usr.bin/sndiod/sndiod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sndiod.c,v 1.32 2016/10/20 05:48:50 ratchov Exp $ */ +/* $OpenBSD: sndiod.c,v 1.33 2018/06/26 07:12:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -332,7 +332,7 @@ mkopt(char *path, struct dev *d, { struct opt *o; - o = opt_new(path, d, pmin, pmax, rmin, rmax, + o = opt_new(d, path, pmin, pmax, rmin, rmax, MIDI_TO_ADATA(vol), mmc, dup, mode); if (o == NULL) return NULL; @@ -531,7 +531,7 @@ main(int argc, char **argv) if (dev_list == NULL) mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate, hold, autovol); for (d = dev_list; d != NULL; d = d->next) { - if (opt_byname("default", d->num)) + if (opt_byname(d, "default")) continue; if (mkopt("default", d, pmin, pmax, rmin, rmax, mode, vol, mmc, dup) == NULL) @@ -614,8 +614,6 @@ main(int argc, char **argv) ; /* nothing */ midi_done(); - while (opt_list != NULL) - opt_del(opt_list); while (dev_list) dev_del(dev_list); while (port_list) diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index b22b7322772..d9db6158c1c 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.21 2018/01/10 09:05:48 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.22 2018/06/26 07:12:35 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -842,14 +842,17 @@ sock_hello(struct sock *f) return 0; return 1; } - f->opt = opt_byname(p->opt, p->devnum); + d = dev_bynum(p->devnum); + if (d == NULL) + return 0; + f->opt = opt_byname(d, p->opt); if (f->opt == NULL) return 0; #ifdef DEBUG if (log_level >= 3) { sock_log(f); log_puts(": using "); - dev_log(f->opt->dev); + dev_log(d); log_puts("."); log_puts(f->opt->name); log_puts(", mode = "); @@ -868,7 +871,7 @@ sock_hello(struct sock *f) } return 0; } - s = slot_new(f->opt->dev, p->who, &sock_slotops, f, mode); + s = slot_new(d, p->who, &sock_slotops, f, mode); if (s == NULL) return 0; f->midi = NULL; -- cgit v1.2.3