diff options
Diffstat (limited to 'src/grailbuf.h')
| -rw-r--r-- | src/grailbuf.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/grailbuf.h b/src/grailbuf.h new file mode 100644 index 0000000..b319d24 --- /dev/null +++ b/src/grailbuf.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * grail - Gesture Recognition And Instantiation Library | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Canonical Ltd. | ||
| 6 | * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org> | ||
| 7 | * | ||
| 8 | * This program is free software: you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License as published by the | ||
| 10 | * Free Software Foundation, either version 3 of the License, or (at your | ||
| 11 | * option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, but | ||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License along | ||
| 19 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | * | ||
| 21 | ****************************************************************************/ | ||
| 22 | |||
| 23 | #ifndef _GRAIL_BUFFER_H | ||
| 24 | #define _GRAIL_BUFFER_H | ||
| 25 | |||
| 26 | #include <grail.h> | ||
| 27 | |||
| 28 | #define DIM_GRAIL_EVENTS 512 | ||
| 29 | |||
| 30 | struct grailbuf { | ||
| 31 | int head; | ||
| 32 | int tail; | ||
| 33 | struct grail_event buffer[DIM_GRAIL_EVENTS]; | ||
| 34 | }; | ||
| 35 | |||
| 36 | static inline void grailbuf_clear(struct grailbuf *buf) | ||
| 37 | { | ||
| 38 | buf->head = buf->tail = 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | static inline int grailbuf_empty(const struct grailbuf *buf) | ||
| 42 | { | ||
| 43 | return buf->head == buf->tail; | ||
| 44 | } | ||
| 45 | |||
| 46 | static inline void grailbuf_put(struct grailbuf *buf, | ||
| 47 | const struct grail_event *ev) | ||
| 48 | { | ||
| 49 | buf->buffer[buf->head++] = *ev; | ||
| 50 | buf->head &= DIM_GRAIL_EVENTS - 1; | ||
| 51 | } | ||
| 52 | |||
| 53 | static inline void grailbuf_get(struct grailbuf *buf, | ||
| 54 | struct grail_event *ev) | ||
| 55 | { | ||
| 56 | *ev = buf->buffer[buf->tail++]; | ||
| 57 | buf->tail &= DIM_GRAIL_EVENTS - 1; | ||
| 58 | } | ||
| 59 | |||
| 60 | #endif | ||
