player: pass callback directly to sync_update

sync_update is the only code-path that can end up calling any of the
callbacks, so there's no need to store it in the device.

This is a breaking change, so all users needs to update their code
accordingly.
This commit is contained in:
Erik Faye-Lund 2010-09-13 20:17:20 +02:00
parent a3da5fe361
commit 5bfd04f55b
4 changed files with 9 additions and 19 deletions

View File

@ -164,7 +164,6 @@ int main(int argc, char *argv[])
die("out of memory?");
#ifndef SYNC_PLAYER
sync_set_callbacks(rocket, &bass_cb, (void *)stream);
if (sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT))
die("failed to connect to host");
#endif
@ -184,7 +183,7 @@ int main(int argc, char *argv[])
while (!done) {
double row = bass_get_row(stream);
#ifndef SYNC_PLAYER
if (sync_update(rocket, (int)floor(row)))
if (sync_update(rocket, (int)floor(row), &bass_cb, (void *)stream))
sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT);
#endif

View File

@ -88,7 +88,6 @@ struct sync_device *sync_create_device(const char *base)
d->data.num_tracks = 0;
#ifndef SYNC_PLAYER
d->cb = d->cb_param = NULL;
d->row = -1;
d->sock = INVALID_SOCKET;
#endif
@ -130,12 +129,6 @@ static int load_track_data(struct sync_track *t, const char *path)
#else
void sync_set_callbacks(struct sync_device *d, struct sync_cb *cb, void *cb_param)
{
d->cb = cb;
d->cb_param = cb_param;
}
static int save_track(const struct sync_track *t, const char *path)
{
int i;
@ -248,7 +241,8 @@ int sync_connect(struct sync_device *d, const char *host, unsigned short port)
return purge_and_rerequest(d);
}
int sync_update(struct sync_device *d, int row)
int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
void *cb_param)
{
if (d->sock == INVALID_SOCKET)
return 1;
@ -272,14 +266,14 @@ int sync_update(struct sync_device *d, int row)
case SET_ROW:
if (xrecv(d->sock, (char *)&row, sizeof(row), 0))
goto sockerr;
if (d->cb && d->cb->set_row)
d->cb->set_row(d->cb_param, ntohl(row));
if (cb && cb->set_row)
cb->set_row(cb_param, ntohl(row));
break;
case PAUSE:
if (xrecv(d->sock, (char *)&flag, 1, 0))
goto sockerr;
if (d->cb && d->cb->pause)
d->cb->pause(d->cb_param, flag);
if (cb && cb->pause)
cb->pause(cb_param, flag);
break;
case SAVE_TRACKS:
sync_save_tracks(d);
@ -290,7 +284,7 @@ int sync_update(struct sync_device *d, int row)
}
}
if (d->cb && d->cb->is_playing && d->cb->is_playing(d->cb_param)) {
if (cb && cb->is_playing && cb->is_playing(cb_param)) {
if (d->row != row && d->sock != INVALID_SOCKET) {
unsigned char cmd = SET_ROW;
uint32_t nrow = htonl(row);

View File

@ -13,8 +13,6 @@ struct sync_device {
struct sync_data data;
#ifndef SYNC_PLAYER
struct sync_cb *cb;
void *cb_param;
int row;
SOCKET sock;
#endif

View File

@ -21,10 +21,9 @@ struct sync_cb {
void (*set_row)(void *, int);
int (*is_playing)(void *);
};
void sync_set_callbacks(struct sync_device *, struct sync_cb *, void *);
#define SYNC_DEFAULT_PORT 1338
int sync_connect(struct sync_device *, const char *, unsigned short);
int sync_update(struct sync_device *, int);
int sync_update(struct sync_device *, int, struct sync_cb *, void *);
void sync_save_tracks(const struct sync_device *);
#endif /* !defined(SYNC_PLAYER) */