From 259b92a30280cdec2b7798df3c14da596c417ef1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 19 Jun 2010 12:10:27 +0200 Subject: 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 --- src/common.h | 1 + src/core.c | 12 +----------- src/evbuf.h | 5 ----- src/iobuf.c | 37 +++++++++++++++++++++++-------------- 4 files changed, 25 insertions(+), 30 deletions(-) (limited to 'src') 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 @@ #define COMMON_H #include +#include #include #include #include diff --git a/src/core.c b/src/core.c index 3df8257..8df2477 100644 --- a/src/core.c +++ b/src/core.c @@ -360,7 +360,7 @@ int mtdev_open(struct mtdev *dev, int fd) return ret; } -void mtdev_put(struct mtdev *dev, const struct input_event *ev) +void mtdev_put_event(struct mtdev *dev, const struct input_event *ev) { struct mtdev_state *state = dev->state; if (ev->type == EV_SYN && ev->code == SYN_REPORT) { @@ -376,16 +376,6 @@ void mtdev_put(struct mtdev *dev, const struct input_event *ev) } } -int mtdev_empty(struct mtdev *dev) -{ - return evbuf_empty(&dev->state->outbuf); -} - -void mtdev_get(struct mtdev *dev, struct input_event* ev) -{ - evbuf_get(&dev->state->outbuf, ev); -} - void mtdev_close(struct mtdev *dev) { 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) return evbuf->head == evbuf->tail; } -static inline int evbuf_full(const struct mtdev_evbuf *evbuf) -{ - return ((evbuf->head + 1) & (DIM_EVENTS - 1)) == evbuf->tail; -} - static inline void evbuf_put(struct mtdev_evbuf *evbuf, const struct input_event *ev) { 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) return buf->head == buf->tail && poll(&fds, 1, ms) <= 0; } -int mtdev_fetch(struct mtdev *dev, int fd, struct input_event *ev) +int mtdev_fetch_event(struct mtdev *dev, int fd, struct input_event *ev) { struct mtdev_iobuf *buf = &dev->state->iobuf; int n = buf->head - buf->tail; @@ -59,21 +59,30 @@ int mtdev_fetch(struct mtdev *dev, int fd, struct input_event *ev) return 1; } -int mtdev_pull(struct mtdev *dev, int fd, int max_events) +int mtdev_empty(struct mtdev *dev) { - struct mtdev_state *state = dev->state; - struct input_event ev; + return evbuf_empty(&dev->state->outbuf); +} + +void mtdev_get_event(struct mtdev *dev, struct input_event* ev) +{ + evbuf_get(&dev->state->outbuf, ev); +} + +int mtdev_get(struct mtdev *dev, int fd, struct input_event* ev, int ev_max) +{ + struct input_event kev; int ret, count = 0; - if (max_events <= 0) - max_events = DIM_EVENTS; - while (max_events-- && !evbuf_full(&state->inbuf)) { - ret = mtdev_fetch(dev, fd, &ev); - if (ret < 0) - return ret; - if (ret == 0) - break; - mtdev_put(dev, &ev); - count++; + while (count < ev_max) { + while (mtdev_empty(dev)) { + ret = mtdev_fetch_event(dev, fd, &kev); + if (ret < 0) + return ret; + if (ret == 0) + return count; + mtdev_put_event(dev, &kev); + } + mtdev_get_event(dev, &ev[count++]); } return count; } -- cgit v1.2.3