diff --git a/libsndio/aucat.c b/libsndio/aucat.c index da33c8c..dd5d2a4 100644 --- a/libsndio/aucat.c +++ b/libsndio/aucat.c @@ -59,7 +59,7 @@ aucat_rmsg(struct aucat *hdl, int *eof) ssize_t n; unsigned char *data; - if (hdl->rstate != STATE_RMSG) { + if (hdl->rstate != RSTATE_MSG) { DPRINTF("aucat_rmsg: bad state\n"); abort(); } @@ -84,10 +84,10 @@ aucat_rmsg(struct aucat *hdl, int *eof) } if (hdl->rmsg.cmd == AMSG_DATA) { hdl->rtodo = hdl->rmsg.u.data.size; - hdl->rstate = STATE_RDATA; + hdl->rstate = RSTATE_DATA; } else { hdl->rtodo = sizeof(struct amsg); - hdl->rstate = STATE_RMSG; + hdl->rstate = RSTATE_MSG; } return 1; } @@ -101,10 +101,10 @@ aucat_wmsg(struct aucat *hdl, int *eof) ssize_t n; unsigned char *data; - if (hdl->wstate == STATE_WIDLE) - hdl->wstate = STATE_WMSG; + if (hdl->wstate == WSTATE_IDLE) + hdl->wstate = WSTATE_MSG; hdl->wtodo = sizeof(struct amsg); - if (hdl->wstate != STATE_WMSG) { + if (hdl->wstate != WSTATE_MSG) { DPRINTF("aucat_wmsg: bad state\n"); abort(); } @@ -124,10 +124,10 @@ aucat_wmsg(struct aucat *hdl, int *eof) } if (hdl->wmsg.cmd == AMSG_DATA) { hdl->wtodo = hdl->wmsg.u.data.size; - hdl->wstate = STATE_WDATA; + hdl->wstate = WSTATE_DATA; } else { hdl->wtodo = 0xdeadbeef; - hdl->wstate = STATE_WIDLE; + hdl->wstate = WSTATE_IDLE; } return 1; } @@ -137,7 +137,7 @@ aucat_rdata(struct aucat *hdl, void *buf, size_t len, int *eof) { ssize_t n; - if (hdl->rstate != STATE_RDATA) { + if (hdl->rstate != RSTATE_DATA) { DPRINTF("aucat_rdata: bad state\n"); abort(); } @@ -159,7 +159,7 @@ aucat_rdata(struct aucat *hdl, void *buf, size_t len, int *eof) } hdl->rtodo -= n; if (hdl->rtodo == 0) { - hdl->rstate = STATE_RMSG; + hdl->rstate = RSTATE_MSG; hdl->rtodo = sizeof(struct amsg); } 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; switch (hdl->wstate) { - case STATE_WIDLE: + case WSTATE_IDLE: if (len > AMSG_DATAMAX) len = AMSG_DATAMAX; 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.u.data.size = len; hdl->wtodo = sizeof(struct amsg); - hdl->wstate = STATE_WMSG; + hdl->wstate = WSTATE_MSG; /* FALLTHROUGH */ - case STATE_WMSG: + case WSTATE_MSG: if (!aucat_wmsg(hdl, eof)) 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); hdl->wtodo -= n; if (hdl->wtodo == 0) { - hdl->wstate = STATE_WIDLE; + hdl->wstate = WSTATE_IDLE; hdl->wtodo = 0xdeadbeef; } return n; @@ -268,9 +268,9 @@ aucat_open(struct aucat *hdl, const char *str, char *sock, unsigned mode, int nb goto bad_connect; } hdl->fd = s; - hdl->rstate = STATE_RMSG; + hdl->rstate = RSTATE_MSG; hdl->rtodo = sizeof(struct amsg); - hdl->wstate = STATE_WIDLE; + hdl->wstate = WSTATE_IDLE; hdl->wtodo = 0xdeadbeef; /* @@ -326,7 +326,7 @@ aucat_close(struct aucat *hdl, int eof) int aucat_pollfd(struct aucat *hdl, struct pollfd *pfd, int events) { - if (hdl->rstate == STATE_RMSG) + if (hdl->rstate == RSTATE_MSG) events |= POLLIN; pfd->fd = hdl->fd; pfd->events = events; diff --git a/libsndio/aucat.h b/libsndio/aucat.h index a959090..8321a8f 100644 --- a/libsndio/aucat.h +++ b/libsndio/aucat.h @@ -10,12 +10,12 @@ struct aucat { int fd; /* socket */ struct amsg rmsg, wmsg; /* temporary messages */ size_t wtodo, rtodo; /* bytes to complete the packet */ -#define STATE_RMSG 0 /* message being received */ -#define STATE_RDATA 1 /* data being received */ +#define RSTATE_MSG 0 /* message being received */ +#define RSTATE_DATA 1 /* data being received */ unsigned rstate; /* one of above */ -#define STATE_WIDLE 2 /* nothing to do */ -#define STATE_WMSG 3 /* message being transferred */ -#define STATE_WDATA 4 /* data being transferred */ +#define WSTATE_IDLE 2 /* nothing to do */ +#define WSTATE_MSG 3 /* message being transferred */ +#define WSTATE_DATA 4 /* data being transferred */ unsigned wstate; /* one of above */ }; diff --git a/libsndio/sio_aucat.c b/libsndio/sio_aucat.c index 7517b62..ca15269 100644 --- a/libsndio/sio_aucat.c +++ b/libsndio/sio_aucat.c @@ -41,8 +41,8 @@ struct sio_aucat_hdl { int events; /* events the user requested */ unsigned curvol, reqvol; /* current and requested volume */ int delta; /* some of received deltas */ -#define STATE_INIT 0 -#define STATE_RUN 1 +#define PSTATE_INIT 0 +#define RSTATE_UN 1 int pstate; }; @@ -114,14 +114,14 @@ sio_aucat_runmsg(struct sio_aucat_hdl *hdl) sio_onvol_cb(&hdl->sio, hdl->curvol); break; case AMSG_STOP: - hdl->pstate = STATE_INIT; + hdl->pstate = PSTATE_INIT; break; default: DPRINTF("sio_aucat_runmsg: unhandled message %u\n", hdl->aucat.rmsg.cmd); hdl->sio.eof = 1; return 0; } - hdl->aucat.rstate = STATE_RMSG; + hdl->aucat.rstate = RSTATE_MSG; hdl->aucat.rtodo = sizeof(struct amsg); return 1; } @@ -130,7 +130,7 @@ static int sio_aucat_buildmsg(struct sio_aucat_hdl *hdl) { if (hdl->curvol != hdl->reqvol) { - hdl->aucat.wstate = STATE_WMSG; + hdl->aucat.wstate = WSTATE_MSG; hdl->aucat.wtodo = sizeof(struct amsg); hdl->aucat.wmsg.cmd = AMSG_SETVOL; 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); hdl->curvol = SIO_MAXVOL; hdl->reqvol = SIO_MAXVOL; - hdl->pstate = STATE_INIT; + hdl->pstate = PSTATE_INIT; return (struct sio_hdl *)hdl; } @@ -192,14 +192,14 @@ sio_aucat_start(struct sio_hdl *sh) hdl->aucat.wtodo = sizeof(struct amsg); if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof)) return 0; - hdl->aucat.rstate = STATE_RMSG; + hdl->aucat.rstate = RSTATE_MSG; hdl->aucat.rtodo = sizeof(struct amsg); if (fcntl(hdl->aucat.fd, F_SETFL, O_NONBLOCK) < 0) { DPERROR("sio_aucat_start: fcntl(0)"); hdl->sio.eof = 1; return 0; } - hdl->pstate = STATE_RUN; + hdl->pstate = RSTATE_UN; return 1; } @@ -220,13 +220,13 @@ sio_aucat_stop(struct sio_hdl *sh) /* * 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)) return 0; } - if (hdl->aucat.wstate == STATE_WDATA) { + if (hdl->aucat.wstate == WSTATE_DATA) { hdl->maxwrite = hdl->aucat.wtodo; - while (hdl->aucat.wstate != STATE_WIDLE) { + while (hdl->aucat.wstate != WSTATE_IDLE) { count = hdl->aucat.wtodo; if (count > ZERO_MAX) count = ZERO_MAX; @@ -248,13 +248,13 @@ sio_aucat_stop(struct sio_hdl *sh) /* * wait for the STOP ACK */ - while (hdl->pstate != STATE_INIT) { + while (hdl->pstate != PSTATE_INIT) { switch (hdl->aucat.rstate) { - case STATE_RMSG: + case RSTATE_MSG: if (!sio_aucat_runmsg(hdl)) return 0; break; - case STATE_RDATA: + case RSTATE_DATA: if (!sio_aucat_read(&hdl->sio, zero, ZERO_MAX)) return 0; 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; - while (hdl->aucat.rstate == STATE_RMSG) { + while (hdl->aucat.rstate == RSTATE_MSG) { if (!sio_aucat_runmsg(hdl)) 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; size_t n; - while (hdl->aucat.wstate == STATE_WIDLE) { + while (hdl->aucat.wstate == WSTATE_IDLE) { if (!sio_aucat_buildmsg(hdl)) break; } @@ -466,11 +466,11 @@ sio_aucat_revents(struct sio_hdl *sh, struct pollfd *pfd) int revents = pfd->revents; if (revents & POLLIN) { - while (hdl->aucat.rstate == STATE_RMSG) { + while (hdl->aucat.rstate == RSTATE_MSG) { if (!sio_aucat_runmsg(hdl)) break; } - if (hdl->aucat.rstate != STATE_RDATA) + if (hdl->aucat.rstate != RSTATE_DATA) revents &= ~POLLIN; } if (revents & POLLOUT) {