From 7afaf12a38e0c4b551cc9964e6b25aa01bafd90d Mon Sep 17 00:00:00 2001 From: Julien Date: Sat, 29 Oct 2011 15:36:03 +0200 Subject: [PATCH] Finalizing swig binding for python, and works, see https://github.com/JulienPalard/ashttp --- Makefile | 3 +-- README.rst | 9 +++++++++ hl_vt100.i | 1 + src/hl_vt100.c | 21 ++++++--------------- src/hl_vt100.h | 2 ++ src/lw_terminal_vt100.c | 4 ++++ src/lw_terminal_vt100.h | 2 ++ 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 3131578..a3cf6de 100644 --- a/Makefile +++ b/Makefile @@ -32,8 +32,7 @@ test: $(OBJ_TEST) $(CC) $(OBJ_TEST) -L . -l$(NAME) -o test python_module: - swig -python *.i - python setup.py build_ext --inplace + swig -python -threads *.i all: @make $(NAME) diff --git a/README.rst b/README.rst index 1528bfd..517f52c 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,12 @@ +INSTALL +======= + +Python module +------------- + +Run : +$ make python_module && su -c 'python setup.py install' + Overview ======== diff --git a/hl_vt100.i b/hl_vt100.i index f6f1492..b13ea6f 100644 --- a/hl_vt100.i +++ b/hl_vt100.i @@ -56,5 +56,6 @@ struct vt100_headless void fork(const char *progname, char **argv); char **getlines(); int main_loop(); + void stop(); } }; diff --git a/src/hl_vt100.c b/src/hl_vt100.c index 836d25d..b6b76ce 100644 --- a/src/hl_vt100.c +++ b/src/hl_vt100.c @@ -33,20 +33,6 @@ static void restore_termios(struct vt100_headless *this, int fd) ioctl(fd, TCSETS, &this->backup); } -/* static void debug(struct vt100_headless *this, char *title) */ -/* { */ -/* unsigned int argc; */ - -/* fprintf(stderr, "%s ", title); */ -/* for (argc = 0; argc < this->term->argc; ++argc) */ -/* { */ -/* fprintf(stderr, "%d", this->term->argv[argc]); */ -/* if (argc != this->term->argc - 1) */ -/* fprintf(stderr, ", "); */ -/* } */ -/* fprintf(stderr, "\n"); */ -/* } */ - #ifndef NDEBUG static void strdump(char *str) { @@ -62,6 +48,11 @@ static void strdump(char *str) } #endif +void vt100_headless_stop(struct vt100_headless *this) +{ + this->should_quit = 1; +} + int vt100_headless_main_loop(struct vt100_headless *this) { char buffer[4096]; @@ -69,7 +60,7 @@ int vt100_headless_main_loop(struct vt100_headless *this) int retval; ssize_t read_size; - while (42) + while (!this->should_quit) { FD_ZERO(&rfds); FD_SET(this->master, &rfds); diff --git a/src/hl_vt100.h b/src/hl_vt100.h index ecc783a..5e2796b 100644 --- a/src/hl_vt100.h +++ b/src/hl_vt100.h @@ -14,6 +14,7 @@ struct vt100_headless int master; struct termios backup; struct lw_terminal_vt100 *term; + int should_quit; void (*changed)(struct vt100_headless *this); }; @@ -23,5 +24,6 @@ int vt100_headless_main_loop(struct vt100_headless *this); void delete_vt100_headless(struct vt100_headless *this); struct vt100_headless *new_vt100_headless(void); const char **vt100_headless_getlines(struct vt100_headless *this); +void vt100_headless_stop(struct vt100_headless *this); #endif diff --git a/src/lw_terminal_vt100.c b/src/lw_terminal_vt100.c index 2f90f36..6cb3264 100644 --- a/src/lw_terminal_vt100.c +++ b/src/lw_terminal_vt100.c @@ -887,11 +887,13 @@ const char **lw_terminal_vt100_getlines(struct lw_terminal_vt100 *vt100) { unsigned int y; + pthread_mutex_lock(&vt100->mutex); for (y = 0; y < vt100->height; ++y) if (y < vt100->margin_top || y > vt100->margin_bottom) vt100->lines[y] = vt100->frozen_screen + FROZEN_SCREEN_PTR(vt100, 0, y); else vt100->lines[y] = vt100->screen + SCREEN_PTR(vt100, 0, y); + pthread_mutex_unlock(&vt100->mutex); return (const char **)vt100->lines; } @@ -967,7 +969,9 @@ free_this: void lw_terminal_vt100_read_str(struct lw_terminal_vt100 *this, char *buffer) { + pthread_mutex_lock(&this->mutex); lw_terminal_parser_read_str(this->lw_terminal, buffer); + pthread_mutex_unlock(&this->mutex); } void lw_terminal_vt100_destroy(struct lw_terminal_vt100 *this) diff --git a/src/lw_terminal_vt100.h b/src/lw_terminal_vt100.h index 8cffb84..f4ea91f 100644 --- a/src/lw_terminal_vt100.h +++ b/src/lw_terminal_vt100.h @@ -1,6 +1,7 @@ #ifndef __LW_TERMINAL_VT100_H__ #define __LW_TERMINAL_VT100_H__ +#include #include "lw_terminal_parser.h" /* @@ -64,6 +65,7 @@ struct lw_terminal_vt100 char *lines[80]; void (*master_write)(void *user_data, void *buffer, size_t len); void *user_data; + pthread_mutex_t mutex; }; struct lw_terminal_vt100 *lw_terminal_vt100_init(void *user_data,