miofile -> port_mio

This commit is contained in:
Alexandre Ratchov 2012-11-02 15:58:34 +01:00
parent 8bdc288d6b
commit fc38a92505
6 changed files with 63 additions and 65 deletions

View File

@ -55,7 +55,7 @@ sndiod: ${OBJS}
abuf.o: abuf.c abuf.h defs.h utils.h
dev.o: dev.c ../bsd-compat/bsd-compat.h abuf.h defs.h dev.h \
dsp.h siofile.h miofile.h midi.h opt.h sysex.h utils.h
dsp.h siofile.h midi.h miofile.h opt.h sysex.h utils.h
dsp.o: dsp.c defs.h dsp.h utils.h
file.o: file.c defs.h file.h utils.h
listen.o: listen.c listen.h file.h sock.h ../libsndio/amsg.h \
@ -67,8 +67,8 @@ opt.o: opt.c dev.h abuf.h dsp.h defs.h siofile.h opt.h utils.h
siofile.o: siofile.c abuf.h defs.h dev.h dsp.h siofile.h file.h \
utils.h
sndiod.o: sndiod.c ../libsndio/amsg.h defs.h dev.h abuf.h dsp.h \
siofile.h file.h listen.h midi.h opt.h sock.h utils.h \
../bsd-compat/bsd-compat.h
siofile.h file.h listen.h midi.h miofile.h opt.h sock.h \
utils.h ../bsd-compat/bsd-compat.h
sock.o: sock.c abuf.h defs.h dev.h dsp.h siofile.h file.h midi.h \
opt.h sock.h ../libsndio/amsg.h utils.h
miofile.h opt.h sock.h ../libsndio/amsg.h utils.h
utils.o: utils.c utils.h

View File

@ -22,7 +22,6 @@
#include "defs.h"
#include "dev.h"
#include "dsp.h"
#include "miofile.h"
#include "siofile.h"
#include "midi.h"
#include "opt.h"

View File

@ -436,8 +436,7 @@ port_del(struct port *c)
int
port_open(struct port *c)
{
c->mio = miofile_new(c);
if (c->mio == NULL) {
if (!port_mio_open(c)) {
if (log_level >= 1) {
port_log(c);
log_puts(": ");
@ -453,8 +452,15 @@ port_open(struct port *c)
int
port_close(struct port *c)
{
miofile_del(c->mio);
c->mio = NULL;
#ifdef DEBUG
if (c->state == PORT_CFG) {
port_log(c);
log_puts(": ");
log_puts(c->path);
log_puts(": failed to open midi port\n");
}
#endif
port_mio_close(c);
c->state = PORT_CFG;
return 1;
}

View File

@ -18,6 +18,7 @@
#define MIDI_H
#include "abuf.h"
#include "miofile.h"
/*
* masks to extract command and channel of status byte
@ -81,7 +82,7 @@ struct midi {
*/
struct port {
struct port *next;
struct miofile *mio;
struct port_mio mio;
#define PORT_CFG 0
#define PORT_INIT 1
#define PORT_DRAIN 2
@ -106,6 +107,7 @@ void midi_out(struct midi *, unsigned char *, int);
void midi_send(struct midi *, unsigned char *, int);
void midi_tag(struct midi *, unsigned int);
void midi_untag(struct midi *, unsigned int);
struct port *port_new(char *, unsigned int);
void port_del(struct port *);
int port_init(struct port *);

View File

@ -29,78 +29,65 @@
#include "miofile.h"
#include "utils.h"
struct miofile {
struct mio_hdl *hdl;
struct port *port;
struct file *file;
};
int port_mio_pollfd(void *, struct pollfd *);
int port_mio_revents(void *, struct pollfd *);
void port_mio_in(void *);
void port_mio_out(void *);
void port_mio_hup(void *);
int miofile_pollfd(void *, struct pollfd *);
int miofile_revents(void *, struct pollfd *);
void miofile_in(void *);
void miofile_out(void *);
void miofile_hup(void *);
struct fileops miofile_ops = {
struct fileops port_mio_ops = {
"mio",
miofile_pollfd,
miofile_revents,
miofile_in,
miofile_out,
miofile_hup
port_mio_pollfd,
port_mio_revents,
port_mio_in,
port_mio_out,
port_mio_hup
};
struct miofile *
miofile_new(struct port *p)
int
port_mio_open(struct port *p)
{
struct mio_hdl *hdl;
struct miofile *f;
hdl = mio_open(p->path, p->midi->mode, 1);
if (hdl == NULL)
return NULL;
f = xmalloc(sizeof(struct miofile));
f->port = p;
f->hdl = hdl;
f->file = file_new(&miofile_ops, f, p->path, mio_nfds(f->hdl));
return f;
p->mio.hdl = mio_open(p->path, p->midi->mode, 1);
if (p->mio.hdl == NULL)
return 0;
p->mio.file = file_new(&port_mio_ops, p, p->path, mio_nfds(p->mio.hdl));
return 1;
}
void
miofile_del(struct miofile *f)
port_mio_close(struct port *p)
{
file_del(f->file);
mio_close(f->hdl);
xfree(f);
file_del(p->mio.file);
mio_close(p->mio.hdl);
}
int
miofile_pollfd(void *addr, struct pollfd *pfd)
port_mio_pollfd(void *addr, struct pollfd *pfd)
{
struct miofile *f = addr;
struct midi *ep = f->port->midi;
struct port *p = addr;
struct midi *ep = p->midi;
int events = 0;
if ((ep->mode & MODE_MIDIIN) && ep->ibuf.used < ep->ibuf.len)
events |= POLLIN;
if ((ep->mode & MODE_MIDIOUT) && ep->obuf.used > 0)
events |= POLLOUT;
return mio_pollfd(f->hdl, pfd, events);
return mio_pollfd(p->mio.hdl, pfd, events);
}
int
miofile_revents(void *addr, struct pollfd *pfd)
port_mio_revents(void *addr, struct pollfd *pfd)
{
struct miofile *f = addr;
struct port *p = addr;
return mio_revents(f->hdl, pfd);
return mio_revents(p->mio.hdl, pfd);
}
void
miofile_in(void *arg)
port_mio_in(void *arg)
{
struct miofile *f = arg;
struct midi *ep = f->port->midi;
struct port *p = arg;
struct midi *ep = p->midi;
unsigned char *data;
int n, count;
@ -108,7 +95,7 @@ miofile_in(void *arg)
data = abuf_wgetblk(&ep->ibuf, &count);
if (count == 0)
break;
n = mio_read(f->hdl, data, count);
n = mio_read(p->mio.hdl, data, count);
if (n == 0)
break;
abuf_wcommit(&ep->ibuf, n);
@ -119,10 +106,10 @@ miofile_in(void *arg)
}
void
miofile_out(void *arg)
port_mio_out(void *arg)
{
struct miofile *f = arg;
struct midi *ep = f->port->midi;
struct port *p = arg;
struct midi *ep = p->midi;
unsigned char *data;
int n, count;
@ -130,7 +117,7 @@ miofile_out(void *arg)
data = abuf_rgetblk(&ep->obuf, &count);
if (count == 0)
break;
n = mio_write(f->hdl, data, count);
n = mio_write(p->mio.hdl, data, count);
if (n == 0)
break;
abuf_rdiscard(&ep->obuf, n);
@ -140,9 +127,9 @@ miofile_out(void *arg)
}
void
miofile_hup(void *arg)
port_mio_hup(void *arg)
{
struct miofile *f = arg;
struct port *p = arg;
port_close(f->port);
port_close(p);
}

View File

@ -18,9 +18,13 @@
#define MIOFILE_H
struct port;
struct miofile;
struct miofile *miofile_new(struct port *);
void miofile_del(struct miofile *);
struct port_mio {
struct mio_hdl *hdl;
struct file *file;
};
int port_mio_open(struct port *);
void port_mio_close(struct port *);
#endif /* !defined(MIOFILE_H) */