diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-06-19 12:10:27 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-06-19 14:01:40 +0200 |
| commit | 259b92a30280cdec2b7798df3c14da596c417ef1 (patch) | |
| tree | bb1f7138cb2e2c7be18975cb3cd0cc9a07d8c44f /src/iobuf.c | |
| parent | 8087ac3d655c2b2835cf61e7a69611d81d4f303e (diff) | |
Restructure mtdev api
Split the api into plumbing and porcelain layers and move the
plumbing part to its own optional header file.
The main usecase is to fetch events from the device, route them
through the converter and extract the processed events. To simplify
the API, replace the intermediate mtdev_pull() function by the
higher-level mtdev_get(). This function does all the required steps,
and has the same semantics as read().
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/iobuf.c')
| -rw-r--r-- | src/iobuf.c | 37 |
1 files changed, 23 insertions, 14 deletions
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 | } |
