summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-06-19 12:10:27 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-06-19 14:01:40 +0200
commit259b92a30280cdec2b7798df3c14da596c417ef1 (patch)
treebb1f7138cb2e2c7be18975cb3cd0cc9a07d8c44f /src
parent8087ac3d655c2b2835cf61e7a69611d81d4f303e (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')
-rw-r--r--src/common.h1
-rw-r--r--src/core.c12
-rw-r--r--src/evbuf.h5
-rw-r--r--src/iobuf.c37
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>
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)
360 return ret; 360 return ret;
361} 361}
362 362
363void mtdev_put(struct mtdev *dev, const struct input_event *ev) 363void 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
379int mtdev_empty(struct mtdev *dev)
380{
381 return evbuf_empty(&dev->state->outbuf);
382}
383
384void mtdev_get(struct mtdev *dev, struct input_event* ev)
385{
386 evbuf_get(&dev->state->outbuf, ev);
387}
388
389void mtdev_close(struct mtdev *dev) 379void 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
45static inline int evbuf_full(const struct mtdev_evbuf *evbuf)
46{
47 return ((evbuf->head + 1) & (DIM_EVENTS - 1)) == evbuf->tail;
48}
49
50static inline void evbuf_put(struct mtdev_evbuf *evbuf, 45static 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
40int mtdev_fetch(struct mtdev *dev, int fd, struct input_event *ev) 40int 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
62int mtdev_pull(struct mtdev *dev, int fd, int max_events) 62int 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
67void mtdev_get_event(struct mtdev *dev, struct input_event* ev)
68{
69 evbuf_get(&dev->state->outbuf, ev);
70}
71
72int 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}