Clean up function naming: use mio_<backend>_ prefix for private

midi-related functions and put them in files named mio_<backend>.c
No behaviour changes.
This commit is contained in:
Alexandre Ratchov 2011-04-12 11:24:49 +02:00
parent 1be9a4da0b
commit 7fa1603c83
5 changed files with 83 additions and 87 deletions

View File

@ -97,7 +97,7 @@ clean:
# object files, sorted following dependencies to allow the # object files, sorted following dependencies to allow the
# loader to determine dependencies in a single pass # loader to determine dependencies in a single pass
# #
OBJS = mio.o mio_rmidi.o mio_thru.o sio.o sio_alsa.o sio_aucat.o sio_sun.o \ OBJS = mio.o mio_rmidi.o mio_aucat.o sio.o sio_alsa.o sio_aucat.o sio_sun.o \
aucat.o getpeereid.o issetugid.o strlcpy.o strtonum.o aucat.o getpeereid.o issetugid.o strlcpy.o strtonum.o
.c.o: .c.o:
@ -128,7 +128,7 @@ aucat.o: aucat.c aucat.h ../aucat/amsg.h ../aucat/conf.h \
../bsd-compat/bsd-compat.h ../bsd-compat/bsd-compat.h
mio.o: mio.c mio_priv.h sndio.h ../bsd-compat/bsd-compat.h mio.o: mio.c mio_priv.h sndio.h ../bsd-compat/bsd-compat.h
mio_rmidi.o: mio_rmidi.c mio_priv.h sndio.h mio_rmidi.o: mio_rmidi.c mio_priv.h sndio.h
mio_thru.o: mio_thru.c ../aucat/amsg.h ../aucat/conf.h mio_priv.h \ mio_aucat.o: mio_aucat.c ../aucat/amsg.h ../aucat/conf.h mio_priv.h \
sndio.h ../bsd-compat/bsd-compat.h sndio.h ../bsd-compat/bsd-compat.h
sio.o: sio.c sio_priv.h sndio.h ../bsd-compat/bsd-compat.h sio.o: sio.c sio_priv.h sndio.h ../bsd-compat/bsd-compat.h
sio_alsa.o: sio_alsa.c sio_priv.h sndio.h sio_alsa.o: sio_alsa.c sio_priv.h sndio.h

View File

@ -64,10 +64,10 @@ mio_open(const char *str, unsigned mode, int nbio)
if (str == NULL && !issetugid()) if (str == NULL && !issetugid())
str = getenv("MIDIDEVICE"); str = getenv("MIDIDEVICE");
if (str == NULL) { if (str == NULL) {
hdl = mio_open_thru("0", mode, nbio); hdl = mio_midithru_open("0", mode, nbio);
if (hdl != NULL) if (hdl != NULL)
return hdl; return hdl;
return mio_open_rmidi("0", mode, nbio); return mio_rmidi_open("0", mode, nbio);
} }
sep = strchr(str, ':'); sep = strchr(str, ':');
if (sep == NULL) { if (sep == NULL) {
@ -79,19 +79,19 @@ mio_open(const char *str, unsigned mode, int nbio)
return NULL; return NULL;
} }
snprintf(buf, sizeof(buf), "%u", minor(sb.st_rdev)); snprintf(buf, sizeof(buf), "%u", minor(sb.st_rdev));
return mio_open_rmidi(buf, mode, nbio); return mio_rmidi_open(buf, mode, nbio);
} }
len = sep - str; len = sep - str;
if (len == (sizeof(prefix_midithru) - 1) && if (len == (sizeof(prefix_midithru) - 1) &&
memcmp(str, prefix_midithru, len) == 0) memcmp(str, prefix_midithru, len) == 0)
return mio_open_thru(sep + 1, mode, nbio); return mio_midithru_open(sep + 1, mode, nbio);
if (len == (sizeof(prefix_aucat) - 1) && if (len == (sizeof(prefix_aucat) - 1) &&
memcmp(str, prefix_aucat, len) == 0) memcmp(str, prefix_aucat, len) == 0)
return mio_open_aucat(sep + 1, mode, nbio); return mio_aucat_open(sep + 1, mode, nbio);
if (len == (sizeof(prefix_rmidi) - 1) && if (len == (sizeof(prefix_rmidi) - 1) &&
memcmp(str, prefix_rmidi, len) == 0) memcmp(str, prefix_rmidi, len) == 0)
return mio_open_rmidi(sep + 1, mode, nbio); return mio_rmidi_open(sep + 1, mode, nbio);
DPRINTF("mio_open: %s: unknown device type\n", str); DPRINTF("mio_open: %s: unknown device type\n", str);
return NULL; return NULL;
} }

View File

@ -33,36 +33,34 @@
#include "bsd-compat.h" #include "bsd-compat.h"
#endif #endif
#define THRU_SOCKET "midithru" struct mio_aucat_hdl {
struct thru_hdl {
struct mio_hdl mio; struct mio_hdl mio;
int fd; int fd;
}; };
static void thru_close(struct mio_hdl *); static void mio_aucat_close(struct mio_hdl *);
static size_t thru_read(struct mio_hdl *, void *, size_t); static size_t mio_aucat_read(struct mio_hdl *, void *, size_t);
static size_t thru_write(struct mio_hdl *, const void *, size_t); static size_t mio_aucat_write(struct mio_hdl *, const void *, size_t);
static int thru_pollfd(struct mio_hdl *, struct pollfd *, int); static int mio_aucat_pollfd(struct mio_hdl *, struct pollfd *, int);
static int thru_revents(struct mio_hdl *, struct pollfd *); static int mio_aucat_revents(struct mio_hdl *, struct pollfd *);
static struct mio_ops thru_ops = { static struct mio_ops mio_aucat_ops = {
thru_close, mio_aucat_close,
thru_write, mio_aucat_write,
thru_read, mio_aucat_read,
thru_pollfd, mio_aucat_pollfd,
thru_revents, mio_aucat_revents,
}; };
static struct mio_hdl * static struct mio_hdl *
thru_open(const char *str, char *sock, unsigned mode, int nbio) mio_xxx_open(const char *str, char *sock, unsigned mode, int nbio)
{ {
extern char *__progname; extern char *__progname;
char unit[4], *sep, *opt; char unit[4], *sep, *opt;
struct amsg msg; struct amsg msg;
int s, n, todo; int s, n, todo;
unsigned char *data; unsigned char *data;
struct thru_hdl *hdl; struct mio_aucat_hdl *hdl;
struct sockaddr_un ca; struct sockaddr_un ca;
socklen_t len = sizeof(struct sockaddr_un); socklen_t len = sizeof(struct sockaddr_un);
uid_t uid; uid_t uid;
@ -74,12 +72,12 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
} else { } else {
opt = sep + 1; opt = sep + 1;
if (sep - str >= sizeof(unit)) { if (sep - str >= sizeof(unit)) {
DPRINTF("thru_open: %s: too long\n", str); DPRINTF("mio_aucat_open: %s: too long\n", str);
return NULL; return NULL;
} }
strlcpy(unit, str, opt - str); strlcpy(unit, str, opt - str);
} }
DPRINTF("thru_open: trying %s -> %s.%s\n", str, unit, opt); DPRINTF("mio_aucat_open: trying %s -> %s.%s\n", str, unit, opt);
uid = geteuid(); uid = geteuid();
if (strchr(str, '/') != NULL) if (strchr(str, '/') != NULL)
return NULL; return NULL;
@ -87,10 +85,10 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
"/tmp/aucat-%u/%s%s", uid, sock, unit); "/tmp/aucat-%u/%s%s", uid, sock, unit);
ca.sun_family = AF_UNIX; ca.sun_family = AF_UNIX;
hdl = malloc(sizeof(struct thru_hdl)); hdl = malloc(sizeof(struct mio_aucat_hdl));
if (hdl == NULL) if (hdl == NULL)
return NULL; return NULL;
mio_create(&hdl->mio, &thru_ops, mode, nbio); mio_create(&hdl->mio, &mio_aucat_ops, mode, nbio);
s = socket(AF_UNIX, SOCK_STREAM, 0); s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0) if (s < 0)
@ -98,14 +96,14 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
while (connect(s, (struct sockaddr *)&ca, len) < 0) { while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
DPERROR("thru_open: connect"); DPERROR("mio_aucat_open: connect");
/* try shared server */ /* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path), snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat/%s%s", sock, unit); "/tmp/aucat/%s%s", sock, unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) { while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
DPERROR("thru_open: connect"); DPERROR("mio_aucat_open: connect");
goto bad_connect; goto bad_connect;
} }
break; break;
@ -127,11 +125,11 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
strlcpy(msg.u.hello.who, __progname, sizeof(msg.u.hello.who)); strlcpy(msg.u.hello.who, __progname, sizeof(msg.u.hello.who));
n = write(s, &msg, sizeof(struct amsg)); n = write(s, &msg, sizeof(struct amsg));
if (n < 0) { if (n < 0) {
DPERROR("thru_open"); DPERROR("mio_aucat_open");
goto bad_connect; goto bad_connect;
} }
if (n != sizeof(struct amsg)) { if (n != sizeof(struct amsg)) {
DPRINTF("thru_open: short write\n"); DPRINTF("mio_aucat_open: short write\n");
goto bad_connect; goto bad_connect;
} }
todo = sizeof(struct amsg); todo = sizeof(struct amsg);
@ -139,22 +137,22 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
while (todo > 0) { while (todo > 0) {
n = read(s, data, todo); n = read(s, data, todo);
if (n < 0) { if (n < 0) {
DPERROR("thru_open"); DPERROR("mio_aucat_open");
goto bad_connect; goto bad_connect;
} }
if (n == 0) { if (n == 0) {
DPRINTF("thru_open: eof\n"); DPRINTF("mio_aucat_open: eof\n");
goto bad_connect; goto bad_connect;
} }
todo -= n; todo -= n;
data += n; data += n;
} }
if (msg.cmd != AMSG_ACK) { if (msg.cmd != AMSG_ACK) {
DPRINTF("thru_open: proto error\n"); DPRINTF("mio_aucat_open: proto error\n");
goto bad_connect; goto bad_connect;
} }
if (nbio && fcntl(hdl->fd, F_SETFL, O_NONBLOCK) < 0) { if (nbio && fcntl(hdl->fd, F_SETFL, O_NONBLOCK) < 0) {
DPERROR("thru_open: fcntl(NONBLOCK)"); DPERROR("mio_aucat_open: fcntl(NONBLOCK)");
goto bad_connect; goto bad_connect;
} }
return (struct mio_hdl *)hdl; return (struct mio_hdl *)hdl;
@ -167,21 +165,21 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
} }
struct mio_hdl * struct mio_hdl *
mio_open_thru(const char *str, unsigned mode, int nbio) mio_midithru_open(const char *str, unsigned mode, int nbio)
{ {
return thru_open(str, "midithru", mode, nbio); return mio_xxx_open(str, "midithru", mode, nbio);
} }
struct mio_hdl * struct mio_hdl *
mio_open_aucat(const char *str, unsigned mode, int nbio) mio_aucat_open(const char *str, unsigned mode, int nbio)
{ {
return thru_open(str, "softaudio", mode, nbio); return mio_xxx_open(str, "softaudio", mode, nbio);
} }
static void static void
thru_close(struct mio_hdl *sh) mio_aucat_close(struct mio_hdl *sh)
{ {
struct thru_hdl *hdl = (struct thru_hdl *)sh; struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
int rc; int rc;
do { do {
@ -191,22 +189,22 @@ thru_close(struct mio_hdl *sh)
} }
static size_t static size_t
thru_read(struct mio_hdl *sh, void *buf, size_t len) mio_aucat_read(struct mio_hdl *sh, void *buf, size_t len)
{ {
struct thru_hdl *hdl = (struct thru_hdl *)sh; struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
ssize_t n; ssize_t n;
while ((n = read(hdl->fd, buf, len)) < 0) { while ((n = read(hdl->fd, buf, len)) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
if (errno != EAGAIN) { if (errno != EAGAIN) {
DPERROR("thru_read: read"); DPERROR("mio_aucat_read: read");
hdl->mio.eof = 1; hdl->mio.eof = 1;
} }
return 0; return 0;
} }
if (n == 0) { if (n == 0) {
DPRINTF("thru_read: eof\n"); DPRINTF("mio_aucat_read: eof\n");
hdl->mio.eof = 1; hdl->mio.eof = 1;
return 0; return 0;
} }
@ -214,16 +212,16 @@ thru_read(struct mio_hdl *sh, void *buf, size_t len)
} }
static size_t static size_t
thru_write(struct mio_hdl *sh, const void *buf, size_t len) mio_aucat_write(struct mio_hdl *sh, const void *buf, size_t len)
{ {
struct thru_hdl *hdl = (struct thru_hdl *)sh; struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
ssize_t n; ssize_t n;
while ((n = write(hdl->fd, buf, len)) < 0) { while ((n = write(hdl->fd, buf, len)) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
if (errno != EAGAIN) { if (errno != EAGAIN) {
DPERROR("thru_write: write"); DPERROR("mio_aucat_write: write");
hdl->mio.eof = 1; hdl->mio.eof = 1;
} }
return 0; return 0;
@ -232,9 +230,9 @@ thru_write(struct mio_hdl *sh, const void *buf, size_t len)
} }
static int static int
thru_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events) mio_aucat_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
{ {
struct thru_hdl *hdl = (struct thru_hdl *)sh; struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
pfd->fd = hdl->fd; pfd->fd = hdl->fd;
pfd->events = events; pfd->events = events;
@ -242,7 +240,7 @@ thru_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
} }
static int static int
thru_revents(struct mio_hdl *sh, struct pollfd *pfd) mio_aucat_revents(struct mio_hdl *sh, struct pollfd *pfd)
{ {
return pfd->revents; return pfd->revents;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mio_priv.h,v 1.4 2009/08/21 16:48:03 ratchov Exp $ */ /* $OpenBSD$ */
/* /*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
* *
@ -57,9 +57,9 @@ struct mio_ops {
int (*revents)(struct mio_hdl *, struct pollfd *); int (*revents)(struct mio_hdl *, struct pollfd *);
}; };
struct mio_hdl *mio_open_rmidi(const char *, unsigned, int); struct mio_hdl *mio_rmidi_open(const char *, unsigned, int);
struct mio_hdl *mio_open_thru(const char *, unsigned, int); struct mio_hdl *mio_midithru_open(const char *, unsigned, int);
struct mio_hdl *mio_open_aucat(const char *, unsigned, int); struct mio_hdl *mio_aucat_open(const char *, unsigned, int);
void mio_create(struct mio_hdl *, struct mio_ops *, unsigned, int); void mio_create(struct mio_hdl *, struct mio_ops *, unsigned, int);
void mio_destroy(struct mio_hdl *); void mio_destroy(struct mio_hdl *);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mio_rmidi.c,v 1.7 2010/07/21 23:00:16 ratchov Exp $ */ /* $OpenBSD$ */
/* /*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
* *
@ -29,38 +29,36 @@
#include "mio_priv.h" #include "mio_priv.h"
#define RMIDI_PATH "/dev/rmidi0" struct mio_rmidi_hdl {
struct rmidi_hdl {
struct mio_hdl mio; struct mio_hdl mio;
int fd; int fd;
}; };
static void rmidi_close(struct mio_hdl *); static void mio_rmidi_close(struct mio_hdl *);
static size_t rmidi_read(struct mio_hdl *, void *, size_t); static size_t mio_rmidi_read(struct mio_hdl *, void *, size_t);
static size_t rmidi_write(struct mio_hdl *, const void *, size_t); static size_t mio_rmidi_write(struct mio_hdl *, const void *, size_t);
static int rmidi_pollfd(struct mio_hdl *, struct pollfd *, int); static int mio_rmidi_pollfd(struct mio_hdl *, struct pollfd *, int);
static int rmidi_revents(struct mio_hdl *, struct pollfd *); static int mio_rmidi_revents(struct mio_hdl *, struct pollfd *);
static struct mio_ops rmidi_ops = { static struct mio_ops mio_rmidi_ops = {
rmidi_close, mio_rmidi_close,
rmidi_write, mio_rmidi_write,
rmidi_read, mio_rmidi_read,
rmidi_pollfd, mio_rmidi_pollfd,
rmidi_revents, mio_rmidi_revents,
}; };
struct mio_hdl * struct mio_hdl *
mio_open_rmidi(const char *str, unsigned mode, int nbio) mio_rmidi_open(const char *str, unsigned mode, int nbio)
{ {
int fd, flags; int fd, flags;
struct rmidi_hdl *hdl; struct mio_rmidi_hdl *hdl;
char path[PATH_MAX]; char path[PATH_MAX];
hdl = malloc(sizeof(struct rmidi_hdl)); hdl = malloc(sizeof(struct mio_rmidi_hdl));
if (hdl == NULL) if (hdl == NULL)
return NULL; return NULL;
mio_create(&hdl->mio, &rmidi_ops, mode, nbio); mio_create(&hdl->mio, &mio_rmidi_ops, mode, nbio);
snprintf(path, sizeof(path), "/dev/rmidi%s", str); snprintf(path, sizeof(path), "/dev/rmidi%s", str);
if (mode == (MIO_OUT | MIO_IN)) if (mode == (MIO_OUT | MIO_IN))
@ -90,9 +88,9 @@ mio_open_rmidi(const char *str, unsigned mode, int nbio)
} }
static void static void
rmidi_close(struct mio_hdl *sh) mio_rmidi_close(struct mio_hdl *sh)
{ {
struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh; struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
int rc; int rc;
do { do {
@ -102,22 +100,22 @@ rmidi_close(struct mio_hdl *sh)
} }
static size_t static size_t
rmidi_read(struct mio_hdl *sh, void *buf, size_t len) mio_rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
{ {
struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh; struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
ssize_t n; ssize_t n;
while ((n = read(hdl->fd, buf, len)) < 0) { while ((n = read(hdl->fd, buf, len)) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
if (errno != EAGAIN) { if (errno != EAGAIN) {
DPERROR("rmidi_read: read"); DPERROR("mio_rmidi_read: read");
hdl->mio.eof = 1; hdl->mio.eof = 1;
} }
return 0; return 0;
} }
if (n == 0) { if (n == 0) {
DPRINTF("rmidi_read: eof\n"); DPRINTF("mio_rmidi_read: eof\n");
hdl->mio.eof = 1; hdl->mio.eof = 1;
return 0; return 0;
} }
@ -125,16 +123,16 @@ rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
} }
static size_t static size_t
rmidi_write(struct mio_hdl *sh, const void *buf, size_t len) mio_rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
{ {
struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh; struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
ssize_t n; ssize_t n;
while ((n = write(hdl->fd, buf, len)) < 0) { while ((n = write(hdl->fd, buf, len)) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
if (errno != EAGAIN) { if (errno != EAGAIN) {
DPERROR("rmidi_write: write"); DPERROR("mio_rmidi_write: write");
hdl->mio.eof = 1; hdl->mio.eof = 1;
} }
return 0; return 0;
@ -143,9 +141,9 @@ rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
} }
static int static int
rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events) mio_rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
{ {
struct rmidi_hdl *hdl = (struct rmidi_hdl *)sh; struct mio_rmidi_hdl *hdl = (struct mio_rmidi_hdl *)sh;
pfd->fd = hdl->fd; pfd->fd = hdl->fd;
pfd->events = events; pfd->events = events;
@ -153,7 +151,7 @@ rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
} }
static int static int
rmidi_revents(struct mio_hdl *sh, struct pollfd *pfd) mio_rmidi_revents(struct mio_hdl *sh, struct pollfd *pfd)
{ {
return pfd->revents; return pfd->revents;
} }