diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common.h | 1 | ||||
| -rw-r--r-- | src/core.c | 12 | ||||
| -rw-r--r-- | src/evbuf.h | 5 | ||||
| -rw-r--r-- | src/iobuf.c | 37 |
4 files changed, 25 insertions, 30 deletions
diff --git a/src/common.h b/src/common.h index 03bc7bd..57d47a0 100644 --- a/src/common.h +++ b/src/common.h | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | #define COMMON_H | 30 | #define COMMON_H |
| 31 | 31 | ||
| 32 | #include <mtdev-mapping.h> | 32 | #include <mtdev-mapping.h> |
| 33 | #include <mtdev-plumbing.h> | ||
| 33 | #include <malloc.h> | 34 | #include <malloc.h> |
| 34 | #include <string.h> | 35 | #include <string.h> |
| 35 | #include <errno.h> | 36 | #include <errno.h> |
| @@ -360,7 +360,7 @@ int mtdev_open(struct mtdev *dev, int fd) | |||
| 360 | return ret; | 360 | return ret; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | void mtdev_put(struct mtdev *dev, const struct input_event *ev) | 363 | void mtdev_put_event(struct mtdev *dev, const struct input_event *ev) |
| 364 | { | 364 | { |
| 365 | struct mtdev_state *state = dev->state; | 365 | struct mtdev_state *state = dev->state; |
| 366 | if (ev->type == EV_SYN && ev->code == SYN_REPORT) { | 366 | if (ev->type == EV_SYN && ev->code == SYN_REPORT) { |
| @@ -376,16 +376,6 @@ void mtdev_put(struct mtdev *dev, const struct input_event *ev) | |||
| 376 | } | 376 | } |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | int mtdev_empty(struct mtdev *dev) | ||
| 380 | { | ||
| 381 | return evbuf_empty(&dev->state->outbuf); | ||
| 382 | } | ||
| 383 | |||
| 384 | void mtdev_get(struct mtdev *dev, struct input_event* ev) | ||
| 385 | { | ||
| 386 | evbuf_get(&dev->state->outbuf, ev); | ||
| 387 | } | ||
| 388 | |||
| 389 | void mtdev_close(struct mtdev *dev) | 379 | void mtdev_close(struct mtdev *dev) |
| 390 | { | 380 | { |
| 391 | free(dev->state); | 381 | free(dev->state); |
diff --git a/src/evbuf.h b/src/evbuf.h index ba61cd5..1afd9f5 100644 --- a/src/evbuf.h +++ b/src/evbuf.h | |||
| @@ -42,11 +42,6 @@ static inline int evbuf_empty(const struct mtdev_evbuf *evbuf) | |||
| 42 | return evbuf->head == evbuf->tail; | 42 | return evbuf->head == evbuf->tail; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static inline int evbuf_full(const struct mtdev_evbuf *evbuf) | ||
| 46 | { | ||
| 47 | return ((evbuf->head + 1) & (DIM_EVENTS - 1)) == evbuf->tail; | ||
| 48 | } | ||
| 49 | |||
| 50 | static inline void evbuf_put(struct mtdev_evbuf *evbuf, | 45 | static inline void evbuf_put(struct mtdev_evbuf *evbuf, |
| 51 | const struct input_event *ev) | 46 | const struct input_event *ev) |
| 52 | { | 47 | { |
diff --git a/src/iobuf.c b/src/iobuf.c index 050f2ed..85a9f19 100644 --- a/src/iobuf.c +++ b/src/iobuf.c | |||
| @@ -37,7 +37,7 @@ int mtdev_idle(struct mtdev *dev, int fd, int ms) | |||
| 37 | return buf->head == buf->tail && poll(&fds, 1, ms) <= 0; | 37 | return buf->head == buf->tail && poll(&fds, 1, ms) <= 0; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | int mtdev_fetch(struct mtdev *dev, int fd, struct input_event *ev) | 40 | int mtdev_fetch_event(struct mtdev *dev, int fd, struct input_event *ev) |
| 41 | { | 41 | { |
| 42 | struct mtdev_iobuf *buf = &dev->state->iobuf; | 42 | struct mtdev_iobuf *buf = &dev->state->iobuf; |
| 43 | int n = buf->head - buf->tail; | 43 | int n = buf->head - buf->tail; |
| @@ -59,21 +59,30 @@ int mtdev_fetch(struct mtdev *dev, int fd, struct input_event *ev) | |||
| 59 | return 1; | 59 | return 1; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | int mtdev_pull(struct mtdev *dev, int fd, int max_events) | 62 | int mtdev_empty(struct mtdev *dev) |
| 63 | { | 63 | { |
| 64 | struct mtdev_state *state = dev->state; | 64 | return evbuf_empty(&dev->state->outbuf); |
| 65 | struct input_event ev; | 65 | } |
| 66 | |||
| 67 | void mtdev_get_event(struct mtdev *dev, struct input_event* ev) | ||
| 68 | { | ||
| 69 | evbuf_get(&dev->state->outbuf, ev); | ||
| 70 | } | ||
| 71 | |||
| 72 | int mtdev_get(struct mtdev *dev, int fd, struct input_event* ev, int ev_max) | ||
| 73 | { | ||
| 74 | struct input_event kev; | ||
| 66 | int ret, count = 0; | 75 | int ret, count = 0; |
| 67 | if (max_events <= 0) | 76 | while (count < ev_max) { |
| 68 | max_events = DIM_EVENTS; | 77 | while (mtdev_empty(dev)) { |
| 69 | while (max_events-- && !evbuf_full(&state->inbuf)) { | 78 | ret = mtdev_fetch_event(dev, fd, &kev); |
| 70 | ret = mtdev_fetch(dev, fd, &ev); | 79 | if (ret < 0) |
| 71 | if (ret < 0) | 80 | return ret; |
| 72 | return ret; | 81 | if (ret == 0) |
| 73 | if (ret == 0) | 82 | return count; |
| 74 | break; | 83 | mtdev_put_event(dev, &kev); |
| 75 | mtdev_put(dev, &ev); | 84 | } |
| 76 | count++; | 85 | mtdev_get_event(dev, &ev[count++]); |
| 77 | } | 86 | } |
| 78 | return count; | 87 | return count; |
| 79 | } | 88 | } |
