diff options
| -rw-r--r-- | include/grail-touch.h | 3 | ||||
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/grail-api.c | 70 | ||||
| -rw-r--r-- | src/touch-dev.c | 35 | ||||
| -rw-r--r-- | test/grail-gesture.c | 4 | ||||
| -rw-r--r-- | test/grail-touch.c | 6 |
6 files changed, 9 insertions, 111 deletions
diff --git a/include/grail-touch.h b/include/grail-touch.h index 5bf0034..5c2fab0 100644 --- a/include/grail-touch.h +++ b/include/grail-touch.h | |||
| @@ -92,8 +92,7 @@ struct touch_engine { | |||
| 92 | 92 | ||
| 93 | int touch_dev_open(struct touch_dev *dev, int fd); | 93 | int touch_dev_open(struct touch_dev *dev, int fd); |
| 94 | int touch_dev_idle(struct touch_dev *dev, int fd, int ms); | 94 | int touch_dev_idle(struct touch_dev *dev, int fd, int ms); |
| 95 | int touch_dev_fetch(struct touch_dev *dev, int fd); | 95 | int touch_dev_pull(struct touch_dev *dev, int fd); |
| 96 | int touch_dev_process(struct touch_dev *dev); | ||
| 97 | void touch_dev_close(struct touch_dev *dev, int fd); | 96 | void touch_dev_close(struct touch_dev *dev, int fd); |
| 98 | 97 | ||
| 99 | void touch_engine_init(struct touch_engine *engine, | 98 | void touch_engine_init(struct touch_engine *engine, |
diff --git a/src/Makefile.am b/src/Makefile.am index 932c8ae..3b001b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -23,7 +23,7 @@ libgrail_la_SOURCES = \ | |||
| 23 | grail-recognizer.h \ | 23 | grail-recognizer.h \ |
| 24 | grail-api.c | 24 | grail-api.c |
| 25 | 25 | ||
| 26 | AM_CFLAGS = $(CWARNFLAGS) -pthread | 26 | AM_CFLAGS = $(CWARNFLAGS) |
| 27 | 27 | ||
| 28 | INCLUDES = -I$(top_srcdir)/include/ | 28 | INCLUDES = -I$(top_srcdir)/include/ |
| 29 | 29 | ||
diff --git a/src/grail-api.c b/src/grail-api.c index 2c6c438..9ceb1e7 100644 --- a/src/grail-api.c +++ b/src/grail-api.c | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | #include "grail-inserter.h" | 1 | #include "grail-inserter.h" |
| 2 | #include "grail-recognizer.h" | 2 | #include "grail-recognizer.h" |
| 3 | #include <grail.h> | 3 | #include <grail.h> |
| 4 | #include <pthread.h> | ||
| 5 | #include <signal.h> | ||
| 6 | #include <string.h> | 4 | #include <string.h> |
| 7 | #include <stdio.h> | 5 | #include <stdio.h> |
| 8 | #include <unistd.h> | 6 | #include <unistd.h> |
| @@ -11,48 +9,12 @@ | |||
| 11 | #include <errno.h> | 9 | #include <errno.h> |
| 12 | #include "evbuf.h" | 10 | #include "evbuf.h" |
| 13 | 11 | ||
| 14 | static const pthread_mutex_t c_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 15 | static const pthread_cond_t c_wait = PTHREAD_COND_INITIALIZER; | ||
| 16 | |||
| 17 | struct grail_impl { | 12 | struct grail_impl { |
| 18 | struct touch_dev dev; | 13 | struct touch_dev dev; |
| 19 | struct touch_engine engine; | 14 | struct touch_engine engine; |
| 20 | struct evbuf evbuf; | 15 | struct evbuf evbuf; |
| 21 | int fd; | ||
| 22 | int pull, finished; | ||
| 23 | pthread_mutex_t mutex; | ||
| 24 | pthread_cond_t wait; | ||
| 25 | pthread_t thread; | ||
| 26 | }; | 16 | }; |
| 27 | 17 | ||
| 28 | /* | ||
| 29 | * While not finished, lock, wait for condition, extract the running | ||
| 30 | * state, unlock, then process the event queue. | ||
| 31 | * | ||
| 32 | * The processing may in principle take seconds to complete without | ||
| 33 | * locking up the writer side. | ||
| 34 | */ | ||
| 35 | static void *grail_thread(void *priv) | ||
| 36 | { | ||
| 37 | struct grail_impl *x = priv; | ||
| 38 | int pull, finished = 0; | ||
| 39 | sigset_t block; | ||
| 40 | sigemptyset(&block); | ||
| 41 | sigaddset(&block, SIGIO); | ||
| 42 | pthread_sigmask(SIG_BLOCK, &block, NULL); | ||
| 43 | while (!finished) { | ||
| 44 | pthread_mutex_lock(&x->mutex); | ||
| 45 | pthread_cond_wait(&x->wait, &x->mutex); | ||
| 46 | pull = x->pull; | ||
| 47 | finished = x->finished; | ||
| 48 | x->pull = 0; | ||
| 49 | if (!finished && pull) | ||
| 50 | touch_dev_process(&x->dev); | ||
| 51 | pthread_mutex_unlock(&x->mutex); | ||
| 52 | } | ||
| 53 | pthread_exit(NULL); | ||
| 54 | } | ||
| 55 | |||
| 56 | static void tp_event(struct touch_engine *engine, | 18 | static void tp_event(struct touch_engine *engine, |
| 57 | const struct input_event *ev) | 19 | const struct input_event *ev) |
| 58 | { | 20 | { |
| @@ -105,17 +67,9 @@ int grail_open(struct grail *ge, int fd) | |||
| 105 | ret = gru_init(ge); | 67 | ret = gru_init(ge); |
| 106 | if (ret) | 68 | if (ret) |
| 107 | goto freedev; | 69 | goto freedev; |
| 108 | x->fd = fd; | ||
| 109 | x->mutex = c_mutex; | ||
| 110 | x->wait = c_wait; | ||
| 111 | ret = pthread_create(&x->thread, NULL, grail_thread, x); | ||
| 112 | if (ret) | ||
| 113 | goto freegru; | ||
| 114 | touch_engine_init(&x->engine, tp_event, tp_sync, ge); | 70 | touch_engine_init(&x->engine, tp_event, tp_sync, ge); |
| 115 | touch_engine_attach(&x->engine, &x->dev); | 71 | touch_engine_attach(&x->engine, &x->dev); |
| 116 | return 0; | 72 | return 0; |
| 117 | freegru: | ||
| 118 | gru_destroy(ge); | ||
| 119 | freedev: | 73 | freedev: |
| 120 | touch_dev_close(&x->dev, fd); | 74 | touch_dev_close(&x->dev, fd); |
| 121 | freegin: | 75 | freegin: |
| @@ -130,10 +84,6 @@ void grail_close(struct grail *ge, int fd) | |||
| 130 | { | 84 | { |
| 131 | struct grail_impl *x = ge->impl; | 85 | struct grail_impl *x = ge->impl; |
| 132 | void *status; | 86 | void *status; |
| 133 | pthread_mutex_lock(&x->mutex); | ||
| 134 | x->finished = 1; | ||
| 135 | pthread_cond_signal (&x->wait); | ||
| 136 | pthread_mutex_unlock(&x->mutex); | ||
| 137 | touch_engine_detach(&x->engine, &x->dev); | 87 | touch_engine_detach(&x->engine, &x->dev); |
| 138 | gru_destroy(ge); | 88 | gru_destroy(ge); |
| 139 | touch_dev_close(&x->dev, fd); | 89 | touch_dev_close(&x->dev, fd); |
| @@ -145,29 +95,13 @@ void grail_close(struct grail *ge, int fd) | |||
| 145 | int grail_idle(struct grail *ge, int fd, int ms) | 95 | int grail_idle(struct grail *ge, int fd, int ms) |
| 146 | { | 96 | { |
| 147 | struct grail_impl *x = ge->impl; | 97 | struct grail_impl *x = ge->impl; |
| 148 | int ret; | 98 | return touch_dev_idle(&x->dev, fd, ms); |
| 149 | pthread_mutex_lock(&x->mutex); | ||
| 150 | ret = touch_dev_idle(&x->dev, fd, ms); | ||
| 151 | pthread_mutex_unlock(&x->mutex); | ||
| 152 | return ret; | ||
| 153 | } | 99 | } |
| 154 | 100 | ||
| 155 | /* | ||
| 156 | * First extract all input events to a lockless circular buffer, then, | ||
| 157 | * under lock, signal the worker thread. | ||
| 158 | * | ||
| 159 | * This function only blocks temporarily while signalling the worker | ||
| 160 | * thread. | ||
| 161 | */ | ||
| 162 | int grail_pull(struct grail *ge, int fd) | 101 | int grail_pull(struct grail *ge, int fd) |
| 163 | { | 102 | { |
| 164 | struct grail_impl *x = ge->impl; | 103 | struct grail_impl *x = ge->impl; |
| 165 | pthread_mutex_lock(&x->mutex); | 104 | return touch_dev_pull(&x->dev, fd); |
| 166 | x->pull = 1; | ||
| 167 | x->finished = touch_dev_fetch(&x->dev, fd) < 0; | ||
| 168 | pthread_cond_signal(&x->wait); | ||
| 169 | pthread_mutex_unlock(&x->mutex); | ||
| 170 | return 1; | ||
| 171 | } | 105 | } |
| 172 | 106 | ||
| 173 | void grail_get_units(struct grail_coord *min, struct grail_coord *max, | 107 | void grail_get_units(struct grail_coord *min, struct grail_coord *max, |
diff --git a/src/touch-dev.c b/src/touch-dev.c index b327266..4cc8d55 100644 --- a/src/touch-dev.c +++ b/src/touch-dev.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | #include <malloc.h> | 26 | #include <malloc.h> |
| 27 | #include <string.h> | 27 | #include <string.h> |
| 28 | #include <errno.h> | 28 | #include <errno.h> |
| 29 | #include "evbuf.h" | ||
| 30 | 29 | ||
| 31 | /* from mtdev-mapping.h */ | 30 | /* from mtdev-mapping.h */ |
| 32 | #define MT_TOUCH_MAJOR 0 | 31 | #define MT_TOUCH_MAJOR 0 |
| @@ -50,7 +49,6 @@ struct touch_dev_impl { | |||
| 50 | int status; | 49 | int status; |
| 51 | grail_mask_t mask[DIM_TOUCH_BYTES]; | 50 | grail_mask_t mask[DIM_TOUCH_BYTES]; |
| 52 | touch_prop_t prop[DIM_TOUCH_PROP]; | 51 | touch_prop_t prop[DIM_TOUCH_PROP]; |
| 53 | struct evbuf evbuf; | ||
| 54 | struct mtdev mtdev; | 52 | struct mtdev mtdev; |
| 55 | }; | 53 | }; |
| 56 | 54 | ||
| @@ -82,23 +80,6 @@ static void set_caps(struct touch_dev_caps *caps, | |||
| 82 | set_info(caps, TP_PRESSURE, &mtcaps->abs[MT_PRESSURE]); | 80 | set_info(caps, TP_PRESSURE, &mtcaps->abs[MT_PRESSURE]); |
| 83 | } | 81 | } |
| 84 | 82 | ||
| 85 | static int touch_get_fetched(struct touch_dev_impl *x, | ||
| 86 | struct input_event* ev, int ev_max) | ||
| 87 | { | ||
| 88 | struct input_event kev; | ||
| 89 | int count = 0; | ||
| 90 | while (count < ev_max) { | ||
| 91 | while (mtdev_empty(&x->mtdev)) { | ||
| 92 | if (evbuf_empty(&x->evbuf)) | ||
| 93 | return count; | ||
| 94 | evbuf_get(&x->evbuf, &kev); | ||
| 95 | mtdev_put_event(&x->mtdev, &kev); | ||
| 96 | } | ||
| 97 | mtdev_get_event(&x->mtdev, &ev[count++]); | ||
| 98 | } | ||
| 99 | return count; | ||
| 100 | } | ||
| 101 | |||
| 102 | static inline void set_prop(struct touch_dev_impl *x, int code, int value) | 83 | static inline void set_prop(struct touch_dev_impl *x, int code, int value) |
| 103 | { | 84 | { |
| 104 | grail_mask_set(x->mask, code); | 85 | grail_mask_set(x->mask, code); |
| @@ -207,24 +188,12 @@ int touch_dev_idle(struct touch_dev *dev, int fd, int ms) | |||
| 207 | return mtdev_idle(&dev->impl->mtdev, fd, ms); | 188 | return mtdev_idle(&dev->impl->mtdev, fd, ms); |
| 208 | } | 189 | } |
| 209 | 190 | ||
| 210 | int touch_dev_fetch(struct touch_dev *dev, int fd) | 191 | int touch_dev_pull(struct touch_dev *dev, int fd) |
| 211 | { | ||
| 212 | struct touch_dev_impl *x = dev->impl; | ||
| 213 | struct input_event ev; | ||
| 214 | int ret, count = 0; | ||
| 215 | while ((ret = mtdev_fetch_event(&x->mtdev, fd, &ev)) > 0) { | ||
| 216 | evbuf_put(&x->evbuf, &ev); | ||
| 217 | count++; | ||
| 218 | } | ||
| 219 | return count > 0 ? count : ret; | ||
| 220 | } | ||
| 221 | |||
| 222 | int touch_dev_process(struct touch_dev *dev) | ||
| 223 | { | 192 | { |
| 224 | struct touch_dev_impl *x = dev->impl; | 193 | struct touch_dev_impl *x = dev->impl; |
| 225 | struct input_event ev; | 194 | struct input_event ev; |
| 226 | int ret, count = 0, consumed; | 195 | int ret, count = 0, consumed; |
| 227 | while ((ret = touch_get_fetched(x, &ev, 1)) > 0) { | 196 | while ((ret = mtdev_get(&x->mtdev, fd, &ev, 1)) > 0) { |
| 228 | consumed = 0; | 197 | consumed = 0; |
| 229 | if (ev.type == EV_SYN) { | 198 | if (ev.type == EV_SYN) { |
| 230 | if (ev.code == SYN_REPORT) | 199 | if (ev.code == SYN_REPORT) |
diff --git a/test/grail-gesture.c b/test/grail-gesture.c index 18c50c3..16b33ac 100644 --- a/test/grail-gesture.c +++ b/test/grail-gesture.c | |||
| @@ -64,10 +64,8 @@ static void tp_gesture(struct grail *ge, const struct grail_event *ev) | |||
| 64 | 64 | ||
| 65 | static void loop_device(struct grail *ge, int fd) | 65 | static void loop_device(struct grail *ge, int fd) |
| 66 | { | 66 | { |
| 67 | while (!grail_idle(ge, fd, 5000)) { | 67 | while (!grail_idle(ge, fd, 5000)) |
| 68 | grail_pull(ge, fd); | 68 | grail_pull(ge, fd); |
| 69 | fprintf(stderr, "\r"); | ||
| 70 | } | ||
| 71 | } | 69 | } |
| 72 | 70 | ||
| 73 | int main(int argc, char *argv[]) | 71 | int main(int argc, char *argv[]) |
diff --git a/test/grail-touch.c b/test/grail-touch.c index 8893c0d..bed31c3 100644 --- a/test/grail-touch.c +++ b/test/grail-touch.c | |||
| @@ -54,10 +54,8 @@ static void loop_device(struct touch_dev *dev, int fd) | |||
| 54 | struct touch_engine engine; | 54 | struct touch_engine engine; |
| 55 | touch_engine_init(&engine, tp_event, tp_sync, 0); | 55 | touch_engine_init(&engine, tp_event, tp_sync, 0); |
| 56 | touch_engine_attach(&engine, dev); | 56 | touch_engine_attach(&engine, dev); |
| 57 | while (!touch_dev_idle(dev, fd, 5000)) { | 57 | while (!touch_dev_idle(dev, fd, 5000)) |
| 58 | touch_dev_fetch(dev, fd); | 58 | touch_dev_pull(dev, fd); |
| 59 | touch_dev_process(dev); | ||
| 60 | } | ||
| 61 | touch_engine_detach(&engine, dev); | 59 | touch_engine_detach(&engine, dev); |
| 62 | } | 60 | } |
| 63 | 61 | ||
