summaryrefslogtreecommitdiff
path: root/package/libtapi/src/tapidemo.c
blob: 63098b89cf7e28123f26a1a38e54bd6eee962361 (plain)
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

#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <poll.h>

#include <linux/input.h>
/*#include <sys/timerfd.h>*/
#include "timerfd.h"
#include "dialdetector.h"

#include "tapi-ioctl.h"

#include "tapi-device.h"
#include "tapi-port.h"

static struct tapi_device dev;
static struct tapi_port ports[2];

void dial_callback(struct tapi_port *port, size_t num_digits, const unsigned char *digits)
{
	unsigned int link;

	if (num_digits != 1)
		return;
	if (port->id == digits[0] || digits[0] > 1)
		return;

	tapi_port_set_ring(&ports[digits[0]], true);

	tapi_session_alloc(&dev, port, &ports[digits[0]]);
}

int main(int argc, char *argv[])
{
	struct dialdetector *dd, *dd2;
	unsigned int link;
	unsigned char buf[1024];
	int ret;

	tapi_device_open(0, &dev);
	tapi_port_open(0, 0, &ports[0]);
	tapi_port_open(0, 1, &ports[1]);

	dd = dialdetector_alloc(&ports[0]);
	dd->dial_callback = dial_callback;
	dd2 = dialdetector_alloc(&ports[1]);
	dd2->dial_callback = dial_callback;

	tapi_mainloop();

	return 0;
}