summaryrefslogtreecommitdiff
path: root/test/evlink.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-07-26 13:51:34 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-08-05 22:48:38 +0200
commitb76660d71e2ea77752025089bd71deffad64e325 (patch)
treec19adf132087edcdc1e721446d4975f37899239e /test/evlink.c
parenteb896e11aacab5f53e3915a8d19ffffd92ce8e10 (diff)
Test implementation of grail api
This patch introduces the grail API, and a program to test it (evlink). Signed-off-by: Henrik Rydberg <rydberg@bitmath.org>
Diffstat (limited to 'test/evlink.c')
-rw-r--r--test/evlink.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/test/evlink.c b/test/evlink.c
new file mode 100644
index 0000000..bef5e22
--- /dev/null
+++ b/test/evlink.c
@@ -0,0 +1,96 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#include <grail.h>
26#include <string.h>
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31static int tp_get_clients(int x, int y, int screen,
32 grail_clientid_t *clients, int nclients)
33{
34 return 0;
35}
36
37static void tp_event(struct grail *ge, const struct input_event *ev)
38{
39 fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value);
40}
41
42static void tp_gesture(struct grail *ge, const struct grail_event *ev)
43{
44 fprintf(stderr, "gesture %d %d\n", ev->type, ev->id);
45}
46
47static void loop_device(struct grail *ge, int fd)
48{
49 while (!grail_idle(ge, fd, 5000))
50 grail_pull(ge, fd);
51}
52
53#if 0
54void grail_add_client(struct grail *ge, grail_clientid_t id,
55 const int *types, const int *priority, int ntypes);
56void grail_remove_client(struct grail *ge, grail_clientid_t id);
57
58#endif
59
60
61int main(int argc, char *argv[])
62{
63 struct grail ge;
64 int fd;
65
66 if (argc < 2) {
67 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
68 return -1;
69 }
70
71 memset(&ge, 0, sizeof(ge));
72 ge.get_clients = tp_get_clients;
73 ge.event = tp_event;
74 ge.gesture = tp_gesture;
75
76 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
77 if (fd < 0) {
78 fprintf(stderr, "error: could not open device\n");
79 return -1;
80 }
81 if (ioctl(fd, EVIOCGRAB, 1)) {
82 fprintf(stderr, "error: could not grab the device\n");
83 return -1;
84 }
85
86 if (grail_open(&ge, fd)) {
87 fprintf(stderr, "error: could not open touch device\n");
88 return -1;
89 }
90 loop_device(&ge, fd);
91 grail_close(&ge, fd);
92
93 ioctl(fd, EVIOCGRAB, 0);
94 close(fd);
95 return 0;
96}