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
# 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
.c.o:
@ -128,7 +128,7 @@ aucat.o: aucat.c aucat.h ../aucat/amsg.h ../aucat/conf.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_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
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

View File

@ -64,10 +64,10 @@ mio_open(const char *str, unsigned mode, int nbio)
if (str == NULL && !issetugid())
str = getenv("MIDIDEVICE");
if (str == NULL) {
hdl = mio_open_thru("0", mode, nbio);
hdl = mio_midithru_open("0", mode, nbio);
if (hdl != NULL)
return hdl;
return mio_open_rmidi("0", mode, nbio);
return mio_rmidi_open("0", mode, nbio);
}
sep = strchr(str, ':');
if (sep == NULL) {
@ -79,19 +79,19 @@ mio_open(const char *str, unsigned mode, int nbio)
return NULL;
}
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;
if (len == (sizeof(prefix_midithru) - 1) &&
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) &&
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) &&
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);
return NULL;
}

View File

@ -33,36 +33,34 @@
#include "bsd-compat.h"
#endif
#define THRU_SOCKET "midithru"
struct thru_hdl {
struct mio_aucat_hdl {
struct mio_hdl mio;
int fd;
};
static void thru_close(struct mio_hdl *);
static size_t thru_read(struct mio_hdl *, void *, size_t);
static size_t thru_write(struct mio_hdl *, const void *, size_t);
static int thru_pollfd(struct mio_hdl *, struct pollfd *, int);
static int thru_revents(struct mio_hdl *, struct pollfd *);
static void mio_aucat_close(struct mio_hdl *);
static size_t mio_aucat_read(struct mio_hdl *, void *, size_t);
static size_t mio_aucat_write(struct mio_hdl *, const void *, size_t);
static int mio_aucat_pollfd(struct mio_hdl *, struct pollfd *, int);
static int mio_aucat_revents(struct mio_hdl *, struct pollfd *);
static struct mio_ops thru_ops = {
thru_close,
thru_write,
thru_read,
thru_pollfd,
thru_revents,
static struct mio_ops mio_aucat_ops = {
mio_aucat_close,
mio_aucat_write,
mio_aucat_read,
mio_aucat_pollfd,
mio_aucat_revents,
};
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;
char unit[4], *sep, *opt;
struct amsg msg;
int s, n, todo;
unsigned char *data;
struct thru_hdl *hdl;
struct mio_aucat_hdl *hdl;
struct sockaddr_un ca;
socklen_t len = sizeof(struct sockaddr_un);
uid_t uid;
@ -74,12 +72,12 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
} else {
opt = sep + 1;
if (sep - str >= sizeof(unit)) {
DPRINTF("thru_open: %s: too long\n", str);
DPRINTF("mio_aucat_open: %s: too long\n", str);
return NULL;
}
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();
if (strchr(str, '/') != 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);
ca.sun_family = AF_UNIX;
hdl = malloc(sizeof(struct thru_hdl));
hdl = malloc(sizeof(struct mio_aucat_hdl));
if (hdl == 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);
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) {
if (errno == EINTR)
continue;
DPERROR("thru_open: connect");
DPERROR("mio_aucat_open: connect");
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat/%s%s", sock, unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
DPERROR("thru_open: connect");
DPERROR("mio_aucat_open: connect");
goto bad_connect;
}
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));
n = write(s, &msg, sizeof(struct amsg));
if (n < 0) {
DPERROR("thru_open");
DPERROR("mio_aucat_open");
goto bad_connect;
}
if (n != sizeof(struct amsg)) {
DPRINTF("thru_open: short write\n");
DPRINTF("mio_aucat_open: short write\n");
goto bad_connect;
}
todo = sizeof(struct amsg);
@ -139,22 +137,22 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
while (todo > 0) {
n = read(s, data, todo);
if (n < 0) {
DPERROR("thru_open");
DPERROR("mio_aucat_open");
goto bad_connect;
}
if (n == 0) {
DPRINTF("thru_open: eof\n");
DPRINTF("mio_aucat_open: eof\n");
goto bad_connect;
}
todo -= n;
data += n;
}
if (msg.cmd != AMSG_ACK) {
DPRINTF("thru_open: proto error\n");
DPRINTF("mio_aucat_open: proto error\n");
goto bad_connect;
}
if (nbio && fcntl(hdl->fd, F_SETFL, O_NONBLOCK) < 0) {
DPERROR("thru_open: fcntl(NONBLOCK)");
DPERROR("mio_aucat_open: fcntl(NONBLOCK)");
goto bad_connect;
}
return (struct mio_hdl *)hdl;
@ -167,21 +165,21 @@ thru_open(const char *str, char *sock, unsigned mode, int nbio)
}
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 *
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
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;
do {
@ -191,22 +189,22 @@ thru_close(struct mio_hdl *sh)
}
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;
while ((n = read(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
DPERROR("thru_read: read");
DPERROR("mio_aucat_read: read");
hdl->mio.eof = 1;
}
return 0;
}
if (n == 0) {
DPRINTF("thru_read: eof\n");
DPRINTF("mio_aucat_read: eof\n");
hdl->mio.eof = 1;
return 0;
}
@ -214,16 +212,16 @@ thru_read(struct mio_hdl *sh, void *buf, size_t len)
}
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;
while ((n = write(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
DPERROR("thru_write: write");
DPERROR("mio_aucat_write: write");
hdl->mio.eof = 1;
}
return 0;
@ -232,9 +230,9 @@ thru_write(struct mio_hdl *sh, const void *buf, size_t len)
}
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->events = events;
@ -242,7 +240,7 @@ thru_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
}
static int
thru_revents(struct mio_hdl *sh, struct pollfd *pfd)
mio_aucat_revents(struct mio_hdl *sh, struct pollfd *pfd)
{
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>
*
@ -57,9 +57,9 @@ struct mio_ops {
int (*revents)(struct mio_hdl *, struct pollfd *);
};
struct mio_hdl *mio_open_rmidi(const char *, unsigned, int);
struct mio_hdl *mio_open_thru(const char *, unsigned, int);
struct mio_hdl *mio_open_aucat(const char *, unsigned, int);
struct mio_hdl *mio_rmidi_open(const char *, unsigned, int);
struct mio_hdl *mio_midithru_open(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_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>
*
@ -29,38 +29,36 @@
#include "mio_priv.h"
#define RMIDI_PATH "/dev/rmidi0"
struct rmidi_hdl {
struct mio_rmidi_hdl {
struct mio_hdl mio;
int fd;
};
static void rmidi_close(struct mio_hdl *);
static size_t rmidi_read(struct mio_hdl *, void *, size_t);
static size_t rmidi_write(struct mio_hdl *, const void *, size_t);
static int rmidi_pollfd(struct mio_hdl *, struct pollfd *, int);
static int rmidi_revents(struct mio_hdl *, struct pollfd *);
static void mio_rmidi_close(struct mio_hdl *);
static size_t mio_rmidi_read(struct mio_hdl *, void *, size_t);
static size_t mio_rmidi_write(struct mio_hdl *, const void *, size_t);
static int mio_rmidi_pollfd(struct mio_hdl *, struct pollfd *, int);
static int mio_rmidi_revents(struct mio_hdl *, struct pollfd *);
static struct mio_ops rmidi_ops = {
rmidi_close,
rmidi_write,
rmidi_read,
rmidi_pollfd,
rmidi_revents,
static struct mio_ops mio_rmidi_ops = {
mio_rmidi_close,
mio_rmidi_write,
mio_rmidi_read,
mio_rmidi_pollfd,
mio_rmidi_revents,
};
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;
struct rmidi_hdl *hdl;
struct mio_rmidi_hdl *hdl;
char path[PATH_MAX];
hdl = malloc(sizeof(struct rmidi_hdl));
hdl = malloc(sizeof(struct mio_rmidi_hdl));
if (hdl == 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);
if (mode == (MIO_OUT | MIO_IN))
@ -90,9 +88,9 @@ mio_open_rmidi(const char *str, unsigned mode, int nbio)
}
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;
do {
@ -102,22 +100,22 @@ rmidi_close(struct mio_hdl *sh)
}
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;
while ((n = read(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
DPERROR("rmidi_read: read");
DPERROR("mio_rmidi_read: read");
hdl->mio.eof = 1;
}
return 0;
}
if (n == 0) {
DPRINTF("rmidi_read: eof\n");
DPRINTF("mio_rmidi_read: eof\n");
hdl->mio.eof = 1;
return 0;
}
@ -125,16 +123,16 @@ rmidi_read(struct mio_hdl *sh, void *buf, size_t len)
}
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;
while ((n = write(hdl->fd, buf, len)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN) {
DPERROR("rmidi_write: write");
DPERROR("mio_rmidi_write: write");
hdl->mio.eof = 1;
}
return 0;
@ -143,9 +141,9 @@ rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
}
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->events = events;
@ -153,7 +151,7 @@ rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
}
static int
rmidi_revents(struct mio_hdl *sh, struct pollfd *pfd)
mio_rmidi_revents(struct mio_hdl *sh, struct pollfd *pfd)
{
return pfd->revents;
}