1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
/* $Id: async2.c,v 1.2 1998/08/13 06:13:24 boyns Exp $ */
#include <rplay.h>
#include <stdio.h>
static void process_input (int fd);
static void event_callback (int fd, int event, char *line);
static int rptp_fd;
main (int argc, char **argv)
{
char buf[RPTP_MAX_LINE];
rptp_fd = rptp_open (rplay_default_host (), RPTP_PORT, buf, sizeof (buf));
rptp_async_register (0, RPTP_ASYNC_READ, process_input);
rptp_async_notify (rptp_fd, RPTP_EVENT_ALL, event_callback);
rptp_main_loop ();
exit (0);
}
static void
process_input (int fd)
{
char buf[BUFSIZ];
fgets (buf, sizeof (buf), stdin);
buf[strlen (buf) - 1] = '\0';
rptp_async_putline (rptp_fd, NULL, buf);
}
static void
event_callback (int fd, int event, char *line)
{
rptp_parse (line, 0);
switch (event)
{
case RPTP_EVENT_OK:
break;
case RPTP_EVENT_ERROR:
printf ("Error: %s\n", rptp_parse (0, "error"));
break;
case RPTP_EVENT_PLAY:
printf ("[%s] Play %s\n", rptp_parse (0, "id"), rptp_parse (0, "sound"));
break;
case RPTP_EVENT_PAUSE:
printf ("[%s] Pause %s\n", rptp_parse (0, "id"), rptp_parse (0, "sound"));
break;
case RPTP_EVENT_DONE:
printf ("[%s] Done %s\n", rptp_parse (0, "id"), rptp_parse (0, "sound"));
break;
case RPTP_EVENT_CONTINUE:
printf ("[%s] Continue %s\n", rptp_parse (0, "id"), rptp_parse (0, "sound"));
break;
}
}
|