diff options
Diffstat (limited to 'mtdev/iobuf.c')
| -rw-r--r-- | mtdev/iobuf.c | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/mtdev/iobuf.c b/mtdev/iobuf.c deleted file mode 100644 index 65c33f6..0000000 --- a/mtdev/iobuf.c +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * Multitouch X driver | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | * | ||
| 20 | **************************************************************************/ | ||
| 21 | |||
| 22 | #include <mtdev-iobuf.h> | ||
| 23 | #include <sys/poll.h> | ||
| 24 | |||
| 25 | void init_iobuf(struct IOBuffer *buf) | ||
| 26 | { | ||
| 27 | memset(buf, 0, sizeof(struct IOBuffer)); | ||
| 28 | buf->at = buf->begin; | ||
| 29 | buf->top = buf->at; | ||
| 30 | buf->end = buf->begin + DIM_BUFFER; | ||
| 31 | } | ||
| 32 | |||
| 33 | const struct input_event *get_iobuf_event(struct IOBuffer *buf, int fd) | ||
| 34 | { | ||
| 35 | const struct input_event *ev; | ||
| 36 | int n = buf->top - buf->at; | ||
| 37 | if (n < EVENT_SIZE) { | ||
| 38 | /* partial event is available: save it */ | ||
| 39 | if (buf->at != buf->begin && n > 0) | ||
| 40 | memmove(buf->begin, buf->at, n); | ||
| 41 | /* start from the beginning */ | ||
| 42 | buf->at = buf->begin; | ||
| 43 | buf->top = buf->at + n; | ||
| 44 | /* read more data */ | ||
| 45 | SYSCALL(n = read(fd, buf->top, buf->end - buf->top)); | ||
| 46 | if (n <= 0) | ||
| 47 | return NULL; | ||
| 48 | buf->top += n; | ||
| 49 | } | ||
| 50 | if (buf->top - buf->at < EVENT_SIZE) | ||
| 51 | return NULL; | ||
| 52 | ev = (const struct input_event *)buf->at; | ||
| 53 | buf->at += EVENT_SIZE; | ||
| 54 | return ev; | ||
| 55 | } | ||
| 56 | |||
| 57 | int poll_iobuf(struct IOBuffer *buf, int fd, int ms) | ||
| 58 | { | ||
| 59 | struct pollfd fds = { fd, POLLIN, 0 }; | ||
| 60 | if (buf->top != buf->at) | ||
| 61 | return 1; | ||
| 62 | return poll(&fds, 1, ms); | ||
| 63 | } | ||
