hdjd/hdjd.c

70 lines
1013 B
C
Raw Normal View History

#include <signal.h>
2012-06-26 23:29:48 -06:00
#include <stdio.h>
#include <stdint.h>
2013-05-06 23:06:13 -06:00
#include <sys/select.h>
2013-05-27 22:11:48 -06:00
#include "alsa.h"
#include "usb.h"
2013-05-06 23:06:13 -06:00
#include "dump.h"
2012-06-26 23:29:48 -06:00
static volatile int keepRunning = 1;
void intHandler(int dummy) {
keepRunning = 0;
usb_interrupting();
alsa_interrupting();
}
2013-05-27 22:11:48 -06:00
int
setup()
2013-05-06 23:06:13 -06:00
{
2013-05-27 22:11:48 -06:00
char name[100];
2013-05-06 23:06:13 -06:00
2013-05-27 22:11:48 -06:00
if (usb_setup(name, sizeof(name)) < 0) {
usb_finish();
2013-05-27 22:11:48 -06:00
return -1;
2013-05-06 23:06:13 -06:00
}
2013-05-27 22:11:48 -06:00
if (alsa_setup(name) < 0) {
alsa_close();
2013-05-27 22:11:48 -06:00
return -1;
2013-05-27 14:54:27 -06:00
}
2013-05-27 22:11:48 -06:00
return 0;
}
2012-06-26 23:29:48 -06:00
int
2013-05-27 22:11:48 -06:00
main(int argc, char *argv[])
2012-06-26 23:29:48 -06:00
{
2013-05-27 22:11:48 -06:00
if (setup() < 0) {
2013-04-12 11:18:58 -06:00
return 69;
}
signal(SIGINT, intHandler);
while (keepRunning) {
2013-05-27 22:11:48 -06:00
fd_set rfds;
fd_set wfds;
int nfds = 0;
int ret;
2013-05-27 22:11:48 -06:00
FD_ZERO(&rfds);
FD_ZERO(&wfds);
2013-05-27 22:11:48 -06:00
alsa_fd_setup(&nfds, &rfds, &wfds);
usb_fd_setup(&nfds, &rfds, &wfds);
ret = select(nfds + 1, &rfds, &wfds, NULL, NULL);
if (-1 == ret) {
DUMP();
}
alsa_check_fds(&rfds, &wfds);
usb_check_fds(&rfds, &wfds);
2013-04-12 11:18:58 -06:00
}
printf("Exiting...\n");
usb_finish();
alsa_close();
2012-06-26 23:29:48 -06:00
2013-04-12 11:18:58 -06:00
return 0;
2012-06-26 23:29:48 -06:00
}