Debian Codegraph @

examples/async2.c

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