mirror of https://github.com/ericonr/sndio.git
rename STATE_ macros
This commit is contained in:
parent
936815ff03
commit
93c71ca1df
|
@ -59,7 +59,7 @@ aucat_rmsg(struct aucat *hdl, int *eof)
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
|
|
||||||
if (hdl->rstate != STATE_RMSG) {
|
if (hdl->rstate != RSTATE_MSG) {
|
||||||
DPRINTF("aucat_rmsg: bad state\n");
|
DPRINTF("aucat_rmsg: bad state\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
@ -84,10 +84,10 @@ aucat_rmsg(struct aucat *hdl, int *eof)
|
||||||
}
|
}
|
||||||
if (hdl->rmsg.cmd == AMSG_DATA) {
|
if (hdl->rmsg.cmd == AMSG_DATA) {
|
||||||
hdl->rtodo = hdl->rmsg.u.data.size;
|
hdl->rtodo = hdl->rmsg.u.data.size;
|
||||||
hdl->rstate = STATE_RDATA;
|
hdl->rstate = RSTATE_DATA;
|
||||||
} else {
|
} else {
|
||||||
hdl->rtodo = sizeof(struct amsg);
|
hdl->rtodo = sizeof(struct amsg);
|
||||||
hdl->rstate = STATE_RMSG;
|
hdl->rstate = RSTATE_MSG;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -101,10 +101,10 @@ aucat_wmsg(struct aucat *hdl, int *eof)
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
|
|
||||||
if (hdl->wstate == STATE_WIDLE)
|
if (hdl->wstate == WSTATE_IDLE)
|
||||||
hdl->wstate = STATE_WMSG;
|
hdl->wstate = WSTATE_MSG;
|
||||||
hdl->wtodo = sizeof(struct amsg);
|
hdl->wtodo = sizeof(struct amsg);
|
||||||
if (hdl->wstate != STATE_WMSG) {
|
if (hdl->wstate != WSTATE_MSG) {
|
||||||
DPRINTF("aucat_wmsg: bad state\n");
|
DPRINTF("aucat_wmsg: bad state\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
@ -124,10 +124,10 @@ aucat_wmsg(struct aucat *hdl, int *eof)
|
||||||
}
|
}
|
||||||
if (hdl->wmsg.cmd == AMSG_DATA) {
|
if (hdl->wmsg.cmd == AMSG_DATA) {
|
||||||
hdl->wtodo = hdl->wmsg.u.data.size;
|
hdl->wtodo = hdl->wmsg.u.data.size;
|
||||||
hdl->wstate = STATE_WDATA;
|
hdl->wstate = WSTATE_DATA;
|
||||||
} else {
|
} else {
|
||||||
hdl->wtodo = 0xdeadbeef;
|
hdl->wtodo = 0xdeadbeef;
|
||||||
hdl->wstate = STATE_WIDLE;
|
hdl->wstate = WSTATE_IDLE;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ aucat_rdata(struct aucat *hdl, void *buf, size_t len, int *eof)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
if (hdl->rstate != STATE_RDATA) {
|
if (hdl->rstate != RSTATE_DATA) {
|
||||||
DPRINTF("aucat_rdata: bad state\n");
|
DPRINTF("aucat_rdata: bad state\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ aucat_rdata(struct aucat *hdl, void *buf, size_t len, int *eof)
|
||||||
}
|
}
|
||||||
hdl->rtodo -= n;
|
hdl->rtodo -= n;
|
||||||
if (hdl->rtodo == 0) {
|
if (hdl->rtodo == 0) {
|
||||||
hdl->rstate = STATE_RMSG;
|
hdl->rstate = RSTATE_MSG;
|
||||||
hdl->rtodo = sizeof(struct amsg);
|
hdl->rtodo = sizeof(struct amsg);
|
||||||
}
|
}
|
||||||
DPRINTF("aucat_rdata: read: n = %zd\n", n);
|
DPRINTF("aucat_rdata: read: n = %zd\n", n);
|
||||||
|
@ -172,7 +172,7 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
switch (hdl->wstate) {
|
switch (hdl->wstate) {
|
||||||
case STATE_WIDLE:
|
case WSTATE_IDLE:
|
||||||
if (len > AMSG_DATAMAX)
|
if (len > AMSG_DATAMAX)
|
||||||
len = AMSG_DATAMAX;
|
len = AMSG_DATAMAX;
|
||||||
len -= len % wbpf;
|
len -= len % wbpf;
|
||||||
|
@ -181,9 +181,9 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
|
||||||
hdl->wmsg.cmd = AMSG_DATA;
|
hdl->wmsg.cmd = AMSG_DATA;
|
||||||
hdl->wmsg.u.data.size = len;
|
hdl->wmsg.u.data.size = len;
|
||||||
hdl->wtodo = sizeof(struct amsg);
|
hdl->wtodo = sizeof(struct amsg);
|
||||||
hdl->wstate = STATE_WMSG;
|
hdl->wstate = WSTATE_MSG;
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case STATE_WMSG:
|
case WSTATE_MSG:
|
||||||
if (!aucat_wmsg(hdl, eof))
|
if (!aucat_wmsg(hdl, eof))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
|
||||||
DPRINTF("aucat_wdata: write: n = %zd\n", n);
|
DPRINTF("aucat_wdata: write: n = %zd\n", n);
|
||||||
hdl->wtodo -= n;
|
hdl->wtodo -= n;
|
||||||
if (hdl->wtodo == 0) {
|
if (hdl->wtodo == 0) {
|
||||||
hdl->wstate = STATE_WIDLE;
|
hdl->wstate = WSTATE_IDLE;
|
||||||
hdl->wtodo = 0xdeadbeef;
|
hdl->wtodo = 0xdeadbeef;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
|
@ -268,9 +268,9 @@ aucat_open(struct aucat *hdl, const char *str, char *sock, unsigned mode, int nb
|
||||||
goto bad_connect;
|
goto bad_connect;
|
||||||
}
|
}
|
||||||
hdl->fd = s;
|
hdl->fd = s;
|
||||||
hdl->rstate = STATE_RMSG;
|
hdl->rstate = RSTATE_MSG;
|
||||||
hdl->rtodo = sizeof(struct amsg);
|
hdl->rtodo = sizeof(struct amsg);
|
||||||
hdl->wstate = STATE_WIDLE;
|
hdl->wstate = WSTATE_IDLE;
|
||||||
hdl->wtodo = 0xdeadbeef;
|
hdl->wtodo = 0xdeadbeef;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -326,7 +326,7 @@ aucat_close(struct aucat *hdl, int eof)
|
||||||
int
|
int
|
||||||
aucat_pollfd(struct aucat *hdl, struct pollfd *pfd, int events)
|
aucat_pollfd(struct aucat *hdl, struct pollfd *pfd, int events)
|
||||||
{
|
{
|
||||||
if (hdl->rstate == STATE_RMSG)
|
if (hdl->rstate == RSTATE_MSG)
|
||||||
events |= POLLIN;
|
events |= POLLIN;
|
||||||
pfd->fd = hdl->fd;
|
pfd->fd = hdl->fd;
|
||||||
pfd->events = events;
|
pfd->events = events;
|
||||||
|
|
|
@ -10,12 +10,12 @@ struct aucat {
|
||||||
int fd; /* socket */
|
int fd; /* socket */
|
||||||
struct amsg rmsg, wmsg; /* temporary messages */
|
struct amsg rmsg, wmsg; /* temporary messages */
|
||||||
size_t wtodo, rtodo; /* bytes to complete the packet */
|
size_t wtodo, rtodo; /* bytes to complete the packet */
|
||||||
#define STATE_RMSG 0 /* message being received */
|
#define RSTATE_MSG 0 /* message being received */
|
||||||
#define STATE_RDATA 1 /* data being received */
|
#define RSTATE_DATA 1 /* data being received */
|
||||||
unsigned rstate; /* one of above */
|
unsigned rstate; /* one of above */
|
||||||
#define STATE_WIDLE 2 /* nothing to do */
|
#define WSTATE_IDLE 2 /* nothing to do */
|
||||||
#define STATE_WMSG 3 /* message being transferred */
|
#define WSTATE_MSG 3 /* message being transferred */
|
||||||
#define STATE_WDATA 4 /* data being transferred */
|
#define WSTATE_DATA 4 /* data being transferred */
|
||||||
unsigned wstate; /* one of above */
|
unsigned wstate; /* one of above */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ struct sio_aucat_hdl {
|
||||||
int events; /* events the user requested */
|
int events; /* events the user requested */
|
||||||
unsigned curvol, reqvol; /* current and requested volume */
|
unsigned curvol, reqvol; /* current and requested volume */
|
||||||
int delta; /* some of received deltas */
|
int delta; /* some of received deltas */
|
||||||
#define STATE_INIT 0
|
#define PSTATE_INIT 0
|
||||||
#define STATE_RUN 1
|
#define RSTATE_UN 1
|
||||||
int pstate;
|
int pstate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,14 +114,14 @@ sio_aucat_runmsg(struct sio_aucat_hdl *hdl)
|
||||||
sio_onvol_cb(&hdl->sio, hdl->curvol);
|
sio_onvol_cb(&hdl->sio, hdl->curvol);
|
||||||
break;
|
break;
|
||||||
case AMSG_STOP:
|
case AMSG_STOP:
|
||||||
hdl->pstate = STATE_INIT;
|
hdl->pstate = PSTATE_INIT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DPRINTF("sio_aucat_runmsg: unhandled message %u\n", hdl->aucat.rmsg.cmd);
|
DPRINTF("sio_aucat_runmsg: unhandled message %u\n", hdl->aucat.rmsg.cmd);
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hdl->aucat.rstate = STATE_RMSG;
|
hdl->aucat.rstate = RSTATE_MSG;
|
||||||
hdl->aucat.rtodo = sizeof(struct amsg);
|
hdl->aucat.rtodo = sizeof(struct amsg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ static int
|
||||||
sio_aucat_buildmsg(struct sio_aucat_hdl *hdl)
|
sio_aucat_buildmsg(struct sio_aucat_hdl *hdl)
|
||||||
{
|
{
|
||||||
if (hdl->curvol != hdl->reqvol) {
|
if (hdl->curvol != hdl->reqvol) {
|
||||||
hdl->aucat.wstate = STATE_WMSG;
|
hdl->aucat.wstate = WSTATE_MSG;
|
||||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||||
hdl->aucat.wmsg.cmd = AMSG_SETVOL;
|
hdl->aucat.wmsg.cmd = AMSG_SETVOL;
|
||||||
hdl->aucat.wmsg.u.vol.ctl = hdl->reqvol;
|
hdl->aucat.wmsg.u.vol.ctl = hdl->reqvol;
|
||||||
|
@ -155,7 +155,7 @@ sio_aucat_open(const char *str, unsigned mode, int nbio)
|
||||||
sio_create(&hdl->sio, &sio_aucat_ops, mode, nbio);
|
sio_create(&hdl->sio, &sio_aucat_ops, mode, nbio);
|
||||||
hdl->curvol = SIO_MAXVOL;
|
hdl->curvol = SIO_MAXVOL;
|
||||||
hdl->reqvol = SIO_MAXVOL;
|
hdl->reqvol = SIO_MAXVOL;
|
||||||
hdl->pstate = STATE_INIT;
|
hdl->pstate = PSTATE_INIT;
|
||||||
return (struct sio_hdl *)hdl;
|
return (struct sio_hdl *)hdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,14 +192,14 @@ sio_aucat_start(struct sio_hdl *sh)
|
||||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||||
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
||||||
return 0;
|
return 0;
|
||||||
hdl->aucat.rstate = STATE_RMSG;
|
hdl->aucat.rstate = RSTATE_MSG;
|
||||||
hdl->aucat.rtodo = sizeof(struct amsg);
|
hdl->aucat.rtodo = sizeof(struct amsg);
|
||||||
if (fcntl(hdl->aucat.fd, F_SETFL, O_NONBLOCK) < 0) {
|
if (fcntl(hdl->aucat.fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||||
DPERROR("sio_aucat_start: fcntl(0)");
|
DPERROR("sio_aucat_start: fcntl(0)");
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hdl->pstate = STATE_RUN;
|
hdl->pstate = RSTATE_UN;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,13 +220,13 @@ sio_aucat_stop(struct sio_hdl *sh)
|
||||||
/*
|
/*
|
||||||
* complete message or data block in progress
|
* complete message or data block in progress
|
||||||
*/
|
*/
|
||||||
if (hdl->aucat.wstate == STATE_WMSG) {
|
if (hdl->aucat.wstate == WSTATE_MSG) {
|
||||||
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (hdl->aucat.wstate == STATE_WDATA) {
|
if (hdl->aucat.wstate == WSTATE_DATA) {
|
||||||
hdl->maxwrite = hdl->aucat.wtodo;
|
hdl->maxwrite = hdl->aucat.wtodo;
|
||||||
while (hdl->aucat.wstate != STATE_WIDLE) {
|
while (hdl->aucat.wstate != WSTATE_IDLE) {
|
||||||
count = hdl->aucat.wtodo;
|
count = hdl->aucat.wtodo;
|
||||||
if (count > ZERO_MAX)
|
if (count > ZERO_MAX)
|
||||||
count = ZERO_MAX;
|
count = ZERO_MAX;
|
||||||
|
@ -248,13 +248,13 @@ sio_aucat_stop(struct sio_hdl *sh)
|
||||||
/*
|
/*
|
||||||
* wait for the STOP ACK
|
* wait for the STOP ACK
|
||||||
*/
|
*/
|
||||||
while (hdl->pstate != STATE_INIT) {
|
while (hdl->pstate != PSTATE_INIT) {
|
||||||
switch (hdl->aucat.rstate) {
|
switch (hdl->aucat.rstate) {
|
||||||
case STATE_RMSG:
|
case RSTATE_MSG:
|
||||||
if (!sio_aucat_runmsg(hdl))
|
if (!sio_aucat_runmsg(hdl))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case STATE_RDATA:
|
case RSTATE_DATA:
|
||||||
if (!sio_aucat_read(&hdl->sio, zero, ZERO_MAX))
|
if (!sio_aucat_read(&hdl->sio, zero, ZERO_MAX))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
|
@ -416,7 +416,7 @@ sio_aucat_read(struct sio_hdl *sh, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
|
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
|
||||||
|
|
||||||
while (hdl->aucat.rstate == STATE_RMSG) {
|
while (hdl->aucat.rstate == RSTATE_MSG) {
|
||||||
if (!sio_aucat_runmsg(hdl))
|
if (!sio_aucat_runmsg(hdl))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,7 @@ sio_aucat_write(struct sio_hdl *sh, const void *buf, size_t len)
|
||||||
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
|
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
while (hdl->aucat.wstate == STATE_WIDLE) {
|
while (hdl->aucat.wstate == WSTATE_IDLE) {
|
||||||
if (!sio_aucat_buildmsg(hdl))
|
if (!sio_aucat_buildmsg(hdl))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -466,11 +466,11 @@ sio_aucat_revents(struct sio_hdl *sh, struct pollfd *pfd)
|
||||||
int revents = pfd->revents;
|
int revents = pfd->revents;
|
||||||
|
|
||||||
if (revents & POLLIN) {
|
if (revents & POLLIN) {
|
||||||
while (hdl->aucat.rstate == STATE_RMSG) {
|
while (hdl->aucat.rstate == RSTATE_MSG) {
|
||||||
if (!sio_aucat_runmsg(hdl))
|
if (!sio_aucat_runmsg(hdl))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (hdl->aucat.rstate != STATE_RDATA)
|
if (hdl->aucat.rstate != RSTATE_DATA)
|
||||||
revents &= ~POLLIN;
|
revents &= ~POLLIN;
|
||||||
}
|
}
|
||||||
if (revents & POLLOUT) {
|
if (revents & POLLOUT) {
|
||||||
|
|
Loading…
Reference in New Issue