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 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 \ 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 dsp.o: dsp.c defs.h dsp.h utils.h
file.o: file.c defs.h file.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 \ 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 \ siofile.o: siofile.c abuf.h defs.h dev.h dsp.h siofile.h file.h \
utils.h utils.h
sndiod.o: sndiod.c ../libsndio/amsg.h defs.h dev.h abuf.h dsp.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 \ siofile.h file.h listen.h midi.h miofile.h opt.h sock.h \
../bsd-compat/bsd-compat.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 \ 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 utils.o: utils.c utils.h

View File

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

View File

@ -436,8 +436,7 @@ port_del(struct port *c)
int int
port_open(struct port *c) port_open(struct port *c)
{ {
c->mio = miofile_new(c); if (!port_mio_open(c)) {
if (c->mio == NULL) {
if (log_level >= 1) { if (log_level >= 1) {
port_log(c); port_log(c);
log_puts(": "); log_puts(": ");
@ -453,8 +452,15 @@ port_open(struct port *c)
int int
port_close(struct port *c) port_close(struct port *c)
{ {
miofile_del(c->mio); #ifdef DEBUG
c->mio = NULL; 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; c->state = PORT_CFG;
return 1; return 1;
} }

View File

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

View File

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