diff options
| -rw-r--r-- | include/mtdev.h | 11 | ||||
| -rw-r--r-- | src/iobuf.c | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/mtdev.h b/include/mtdev.h index 5f2f6a3..e2fdc9d 100644 --- a/include/mtdev.h +++ b/include/mtdev.h | |||
| @@ -146,6 +146,17 @@ int mtdev_configure(struct mtdev *dev, int fd); | |||
| 146 | int mtdev_open(struct mtdev *dev, int fd); | 146 | int mtdev_open(struct mtdev *dev, int fd); |
| 147 | 147 | ||
| 148 | /** | 148 | /** |
| 149 | * mtdev_idle - check state of kernel device | ||
| 150 | * @dev: the mtdev in use | ||
| 151 | * @fd: file descriptor of the kernel device | ||
| 152 | * @ms: number of milliseconds to wait for activity | ||
| 153 | * | ||
| 154 | * Returns true if the device is idle, i.e., there are no buffered | ||
| 155 | * events and there is nothing to fetch from the kernel device. | ||
| 156 | */ | ||
| 157 | int mtdev_idle(struct mtdev *dev, int fd, int ms); | ||
| 158 | |||
| 159 | /** | ||
| 149 | * mtdev_fetch - fetch an event from the kernel device | 160 | * mtdev_fetch - fetch an event from the kernel device |
| 150 | * @dev: the mtdev in use | 161 | * @dev: the mtdev in use |
| 151 | * @ev: the kernel input event to fill | 162 | * @ev: the kernel input event to fill |
diff --git a/src/iobuf.c b/src/iobuf.c index 6d238ec..83e531a 100644 --- a/src/iobuf.c +++ b/src/iobuf.c | |||
| @@ -28,6 +28,18 @@ | |||
| 28 | 28 | ||
| 29 | #include "iobuf.h" | 29 | #include "iobuf.h" |
| 30 | #include "state.h" | 30 | #include "state.h" |
| 31 | #include <poll.h> | ||
| 32 | |||
| 33 | int mtdev_idle(struct mtdev *dev, int fd, int ms) | ||
| 34 | { | ||
| 35 | struct mtdev_state *state = dev->state; | ||
| 36 | struct mtdev_iobuf *buf = &state->iobuf; | ||
| 37 | struct pollfd fds = { fd, POLLIN, 0 }; | ||
| 38 | return evbuf_empty(&state->outbuf) && | ||
| 39 | evbuf_empty(&state->inbuf) && | ||
| 40 | buf->head == buf->tail && | ||
| 41 | poll(&fds, 1, ms) <= 0; | ||
| 42 | } | ||
| 31 | 43 | ||
| 32 | int mtdev_fetch(struct mtdev *dev, struct input_event *ev, int fd) | 44 | int mtdev_fetch(struct mtdev *dev, struct input_event *ev, int fd) |
| 33 | { | 45 | { |
