JosepMaJAZ
·
2017-01-16
hdjd.c
1#include <signal.h>
2#include <stdio.h>
3#include <stdint.h>
4#include <sys/select.h>
5#include "alsa.h"
6#include "usb.h"
7#include "dump.h"
8
9
10static volatile int keepRunning = 1;
11
12void intHandler(int dummy) {
13 keepRunning = 0;
14 usb_interrupting();
15 alsa_interrupting();
16}
17
18int
19setup()
20{
21 char name[100];
22
23 if (usb_setup(name, sizeof(name)) < 0) {
24 usb_finish();
25 return -1;
26 }
27
28 if (alsa_setup(name) < 0) {
29 alsa_close();
30 return -1;
31 }
32
33 return 0;
34}
35
36
37int
38main(int argc, char *argv[])
39{
40 if (setup() < 0) {
41 return 69;
42 }
43 signal(SIGINT, intHandler);
44 while (keepRunning) {
45 fd_set rfds;
46 fd_set wfds;
47 int nfds = 0;
48 int ret;
49
50 FD_ZERO(&rfds);
51 FD_ZERO(&wfds);
52
53 alsa_fd_setup(&nfds, &rfds, &wfds);
54 usb_fd_setup(&nfds, &rfds, &wfds);
55
56 ret = select(nfds + 1, &rfds, &wfds, NULL, NULL);
57 if (-1 == ret) {
58 DUMP();
59 }
60
61 alsa_check_fds(&rfds, &wfds);
62 usb_check_fds(&rfds, &wfds);
63 }
64 printf("Exiting...\n");
65 usb_finish();
66 alsa_close();
67
68 return 0;
69}