From 9edc9bc36aec96d83f963d90a017cc661c96f41f Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 11 Jan 2019 10:39:21 -0200 Subject: [PATCH] Reactivating spinner spliting linux & windows I/O calls. --- configure.ac | 6 ++++++ src/include/config.h.in | 1 + src/v3270/iocallback.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/v3270/linux/iosource.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ src/v3270/oia.c | 2 ++ src/v3270/private.h | 6 +----- src/v3270/widget.c | 2 +- src/v3270/windows/iosource.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- v3270.cbp | 8 +++++++- 9 files changed, 284 insertions(+), 29 deletions(-) create mode 100644 src/v3270/iocallback.c diff --git a/configure.ac b/configure.ac index 27d14f1..77ad245 100644 --- a/configure.ac +++ b/configure.ac @@ -169,6 +169,12 @@ AC_SUBST(SCCS_USER,$USER) AC_SUBST(SCCS_DATE,$sccs_date) dnl --------------------------------------------------------------------------- +dnl Check for libm (Required for spinner) +dnl --------------------------------------------------------------------------- + +AC_SEARCH_LIBS( [sin], [m], AC_DEFINE(HAVE_LIBM), AC_MSG_ERROR([libm not present.])) + +dnl --------------------------------------------------------------------------- dnl Check for libintl dnl --------------------------------------------------------------------------- diff --git a/src/include/config.h.in b/src/include/config.h.in index ca153ed..856bad0 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -35,6 +35,7 @@ #undef PACKAGE_VERSION #undef PACKAGE_RELEASE + #undef HAVE_LIBM #undef HAVE_GNOME #undef HAVE_GTKMAC diff --git a/src/v3270/iocallback.c b/src/v3270/iocallback.c new file mode 100644 index 0000000..22f28ae --- /dev/null +++ b/src/v3270/iocallback.c @@ -0,0 +1,154 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include +#include +#include "private.h" + +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata); +static void static_RemoveSource(H3270 *session, void *id); + +static void * static_AddTimeOut(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session)); +static void static_RemoveTimeOut(H3270 *session, void * timer); +static int static_Sleep(H3270 *hSession, int seconds); +static int static_RunPendingEvents(H3270 *hSession, int wait); + +/*---[ Structs ]-------------------------------------------------------------------------------------------*/ + + typedef struct _timer + { + unsigned char remove; + void * userdata; + void (*call)(H3270 *session); + H3270 * session; + } TIMER; + +/*---[ Implement ]-----------------------------------------------------------------------------------------*/ + +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) +{ + return (void *) IO_source_new(session, fd, flag, call, userdata); +} + +static void static_RemoveSource(G_GNUC_UNUSED H3270 *session, void *id) +{ + if(id) + g_source_destroy((GSource *) id); +} + +static gboolean do_timer(TIMER *t) +{ + if(!t->remove) + t->call(t->session); + return FALSE; +} + +static void * static_AddTimeOut(H3270 *session, unsigned long interval, void (*call)(H3270 *session)) +{ + TIMER *t = g_malloc0(sizeof(TIMER)); + + t->call = call; + t->session = session; + + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free); + + return t; +} + +static void static_RemoveTimeOut(G_GNUC_UNUSED H3270 *session, void * timer) +{ + ((TIMER *) timer)->remove++; +} + +/* +struct bgParameter +{ + gboolean running; + H3270 *session; + int rc; + int(*callback)(H3270 *session, void *); + void *parm; + +}; +*/ + +static int static_Sleep(G_GNUC_UNUSED H3270 *hSession, int seconds) +{ + time_t end = time(0) + seconds; + + while(time(0) < end) + gtk_main_iteration(); + + return 0; +} + +static int static_RunPendingEvents(G_GNUC_UNUSED H3270 *hSession, int wait) +{ + int rc = 0; + while(gtk_events_pending()) + { + rc = 1; + gtk_main_iteration(); + } + + if(wait) + gtk_main_iteration(); + + return rc; +} + +static void beep(G_GNUC_UNUSED H3270 *session) +{ + gdk_display_beep(gdk_display_get_default()); +} + +void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls) +{ + static const struct lib3270_callbacks hdl = + { + sizeof(struct lib3270_callbacks), + + static_AddTimeOut, + static_RemoveTimeOut, + + static_AddSource, + static_RemoveSource, + + static_Sleep, + static_RunPendingEvents, + beep + + }; + + if(lib3270_register_handlers(&hdl)) + { + g_error("%s",_( "Can't set lib3270 I/O handlers" ) ); + } + +} diff --git a/src/v3270/linux/iosource.c b/src/v3270/linux/iosource.c index cec7506..e08b7d8 100644 --- a/src/v3270/linux/iosource.c +++ b/src/v3270/linux/iosource.c @@ -28,6 +28,7 @@ */ #include + #include #include "../private.h" /*---[ Structs ]-------------------------------------------------------------------------------------------*/ @@ -43,8 +44,50 @@ void * userdata; } IO_Source; +static gboolean IO_prepare(GSource *source, gint *timeout); +static gboolean IO_check(GSource *source); +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); +static void IO_finalize(GSource *source); /* Can be NULL */ +static gboolean IO_closure(gpointer data); + /*---[ Implement ]-----------------------------------------------------------------------------------------*/ +GSource * IO_source_new(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) +{ + static GSourceFuncs IOSources = + { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL + }; + + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); + + src->fd = fd; + src->enabled = TRUE; + src->call = call; + src->userdata = userdata; + src->session = session; + + src->poll.fd = (int) fd; + src->poll.events = G_IO_HUP|G_IO_ERR; + + if(flag & LIB3270_IO_FLAG_READ) + src->poll.events |= G_IO_IN; + + if(flag & LIB3270_IO_FLAG_WRITE) + src->poll.events |= G_IO_OUT; + + g_source_attach((GSource *) src,NULL); + g_source_add_poll((GSource *) src,&src->poll); + + return (GSource *) src; +} + + gboolean IO_prepare(G_GNUC_UNUSED GSource *source, G_GNUC_UNUSED gint *timeout) { /* @@ -72,15 +115,18 @@ gboolean IO_check(GSource *source) * function was called, so the source should be checked again here. * */ - struct pollfd fds; + if(((IO_Source *) source)->enabled) + { + struct pollfd fds; - memset(&fds,0,sizeof(fds)); + memset(&fds,0,sizeof(fds)); - fds.fd = ((IO_Source *) source)->poll.fd; - fds.events = ((IO_Source *) source)->poll.events; + fds.fd = ((IO_Source *) source)->poll.fd; + fds.events = ((IO_Source *) source)->poll.events; - if(poll(&fds,1,0) > 0) - return TRUE; + if(poll(&fds,1,0) > 0) + return TRUE; + } return FALSE; } diff --git a/src/v3270/oia.c b/src/v3270/oia.c index de62853..ae87067 100644 --- a/src/v3270/oia.c +++ b/src/v3270/oia.c @@ -104,6 +104,8 @@ static gint draw_spinner(cairo_t *cr, GdkRectangle *r, GdkRGBA *color, gint step step++; step %= num_steps; + debug("%s step=%d",__FUNCTION__,step); + for (i = 0; i < num_steps; i++) { gint inset = 0.7 * radius; diff --git a/src/v3270/private.h b/src/v3270/private.h index af56378..639fb05 100644 --- a/src/v3270/private.h +++ b/src/v3270/private.h @@ -336,10 +336,6 @@ G_GNUC_INTERNAL gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll * G_GNUC_INTERNAL const struct v3270_ssl_status_msg * v3270_get_ssl_status_msg(GtkWidget *widget); // I/O Callbacks -G_GNUC_INTERNAL gboolean IO_prepare(GSource *source, gint *timeout); -G_GNUC_INTERNAL gboolean IO_check(GSource *source); -G_GNUC_INTERNAL gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); -G_GNUC_INTERNAL void IO_finalize(GSource *source); /* Can be NULL */ -G_GNUC_INTERNAL gboolean IO_closure(gpointer data); +G_GNUC_INTERNAL GSource * IO_source_new(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata); G_END_DECLS diff --git a/src/v3270/widget.c b/src/v3270/widget.c index 88fea20..0142de6 100644 --- a/src/v3270/widget.c +++ b/src/v3270/widget.c @@ -940,7 +940,7 @@ static void popup_handler(H3270 *session, LIB3270_NOTIFY type, const char *title cbk->update = v3270_update_char; - cbk->changed = changed; + cbk->changed = changed; cbk->set_timer = set_timer; cbk->set_selection = set_selection; diff --git a/src/v3270/windows/iosource.c b/src/v3270/windows/iosource.c index 462750f..8fa10f6 100644 --- a/src/v3270/windows/iosource.c +++ b/src/v3270/windows/iosource.c @@ -43,8 +43,49 @@ void * userdata; } IO_Source; +static gboolean IO_prepare(GSource *source, gint *timeout); +static gboolean IO_check(GSource *source); +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); +static void IO_finalize(GSource *source); /* Can be NULL */ +static gboolean IO_closure(gpointer data); + /*---[ Implement ]-----------------------------------------------------------------------------------------*/ +GSource * IO_source_new(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) +{ + static GSourceFuncs IOSources = + { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL + }; + + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); + + src->fd = fd; + src->enabled = TRUE; + src->call = call; + src->userdata = userdata; + src->session = session; + + src->poll.fd = (int) fd; + src->poll.events = G_IO_HUP|G_IO_ERR; + + if(flag & LIB3270_IO_FLAG_READ) + src->poll.events |= G_IO_IN; + + if(flag & LIB3270_IO_FLAG_WRITE) + src->poll.events |= G_IO_OUT; + + g_source_attach((GSource *) src,NULL); + g_source_add_poll((GSource *) src,&src->poll); + + return (GSource *) src; +} + static gboolean IO_prepare(G_GNUC_UNUSED GSource *source, G_GNUC_UNUSED gint *timeout) { /* @@ -72,27 +113,30 @@ static gboolean IO_check(GSource *source) * function was called, so the source should be checked again here. * */ - fd_set rfds, wfds; - struct timeval tm; + if(((IO_Source *) source)->enabled) + { + fd_set rfds, wfds; + struct timeval tm; - memset(&tm,0,sizeof(tm)); + memset(&tm,0,sizeof(tm)); - FD_ZERO(&rfds); - FD_ZERO(&wfds); -// FD_ZERO(&xfds); + FD_ZERO(&rfds); + FD_ZERO(&wfds); + // FD_ZERO(&xfds); - if(((IO_Source *) source)->poll.events & G_IO_IN) - { - FD_SET(((IO_Source *) source)->poll.fd, &rfds); - } + if(((IO_Source *) source)->poll.events & G_IO_IN) + { + FD_SET(((IO_Source *) source)->poll.fd, &rfds); + } - if(((IO_Source *) source)->poll.events & G_IO_OUT) - { - FD_SET(((IO_Source *) source)->poll.fd, &wfds); - } + if(((IO_Source *) source)->poll.events & G_IO_OUT) + { + FD_SET(((IO_Source *) source)->poll.fd, &wfds); + } - if(select(((IO_Source *) source)->poll.fd+1, &rfds, &wfds, NULL, &tm) > 0) - return TRUE; + if(select(((IO_Source *) source)->poll.fd+1, &rfds, &wfds, NULL, &tm) > 0) + return TRUE; + } return FALSE; } diff --git a/v3270.cbp b/v3270.cbp index 100f37b..3200726 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -47,6 +47,7 @@ + @@ -69,6 +70,9 @@ + + @@ -88,10 +92,12 @@ - + + -- libgit2 0.21.2