From b00a36907c88022a670aba509b1da52372ad441f Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 19 Apr 2016 14:39:31 -0300 Subject: [PATCH] Melhorando sistema de callbacks. --- src/include/lib3270/session.h | 12 ++++++------ src/lib3270/ctlr.c | 21 --------------------- src/lib3270/session.c | 12 ++++++++++++ src/lib3270/telnet.c | 5 +++-- src/pw3270/v3270/widget.c | 58 ++++++++++++++++++++++++++++++++++------------------------ 5 files changed, 55 insertions(+), 53 deletions(-) diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 565d9ef..57f8da6 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -83,8 +83,6 @@ struct lib3270_session_callbacks { - unsigned short sz; - int (*write)(H3270 *hSession, unsigned const char *buf, int len); void (*disconnect)(H3270 *hSession); @@ -119,6 +117,8 @@ }; + LIB3270_EXPORT struct lib3270_session_callbacks * lib3270_get_session_callbacks(H3270 *session, unsigned short sz); + struct _h3270 { unsigned short sz; /**< Struct size */ @@ -182,10 +182,10 @@ struct { - char * current; /**< The hostname part, stripped of qualifiers, luname and port number */ - char * full; /**< The entire string, for use in reconnecting */ - char * srvc; /**< The service name */ - char * qualified; + char * current; /**< The hostname part, stripped of qualifiers, luname and port number */ + char * full; /**< The entire string, for use in reconnecting */ + char * srvc; /**< The service name */ + char * qualified; } host; char * proxy; /**< Proxy server (type:host[:port]) */ diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index a07d6c5..73801db 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -2696,27 +2696,6 @@ void ctlr_scroll(H3270 *hSession) #endif /*]*/ /* - * Note that a particular region of the screen has changed. - */ - -// void changed(H3270 *session, int bstart, int bend) -// { - /* - if(session->first_changed < 0) - { - session->first_changed = bstart; - session->last_changed = bend; - return; - } - if(bstart < session->first_changed) - session->first_changed = bstart; - - if(bend > session->last_changed) - session->last_changed = bend; - */ -// } - -/* * Swap the regular and alternate screen buffers */ void ctlr_altbuffer(H3270 *session, int alt) diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 664e0ec..5334aa7 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -331,3 +331,15 @@ LIB3270_EXPORT void * lib3270_get_user_data(H3270 *h) CHECK_SESSION_HANDLE(h); return h->user_data; } + +struct lib3270_session_callbacks * lib3270_get_session_callbacks(H3270 *session, unsigned short sz) +{ + CHECK_SESSION_HANDLE(session); + + if(sz != sizeof(struct lib3270_session_callbacks)) + return NULL; + + return &session->cbk; +} + + diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 1e1844f..e30edea 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -1866,10 +1866,11 @@ static void process_bind(H3270 *hSession, unsigned char *buf, int buflen) } #endif /*]*/ -static int -process_eor(H3270 *hSession) +static int process_eor(H3270 *hSession) { + trace("%s: syncing=%s",__FUNCTION__,hSession->syncing ? "Yes" : "No"); + if (hSession->syncing || !(hSession->ibptr - hSession->ibuf)) return(0); diff --git a/src/pw3270/v3270/widget.c b/src/pw3270/v3270/widget.c index 4ea38ba..82f6562 100644 --- a/src/pw3270/v3270/widget.c +++ b/src/pw3270/v3270/widget.c @@ -918,7 +918,11 @@ static void release_activity_timer(v3270 *widget) static void v3270_init(v3270 *widget) { - widget->host = lib3270_session_new(""); + struct lib3270_session_callbacks *cbk; + + widget->host = lib3270_session_new(""); + widget->host->user_data = widget; + trace("%s host->sz=%d expected=%d revision=%s expected=%s",__FUNCTION__,widget->host->sz,(int) sizeof(H3270),lib3270_get_revision(),PACKAGE_REVISION); @@ -928,29 +932,35 @@ static void v3270_init(v3270 *widget) return; } - widget->host->user_data = widget; - - widget->host->cbk.update = v3270_update_char; - widget->host->cbk.changed = changed; - widget->host->cbk.set_timer = set_timer; - - widget->host->cbk.set_selection = set_selection; - widget->host->cbk.update_selection = update_selection; - - widget->host->cbk.update_luname = update_luname; - widget->host->cbk.configure = update_screen_size; - widget->host->cbk.update_status = update_message; - widget->host->cbk.update_cursor = v3270_update_cursor; - widget->host->cbk.update_toggle = update_toggle; - widget->host->cbk.update_oia = v3270_update_oia; - widget->host->cbk.cursor = select_cursor; - widget->host->cbk.update_connect = update_connect; - widget->host->cbk.update_model = update_model; - widget->host->cbk.changed = changed; - widget->host->cbk.ctlr_done = ctlr_done; - widget->host->cbk.message = message; - widget->host->cbk.update_ssl = v3270_update_ssl; - widget->host->cbk.print = emit_print_signal; + cbk = lib3270_get_session_callbacks(widget->host,sizeof(struct lib3270_session_callbacks)); + if(!cbk) + { + g_error( _( "Invalid callback table, possible version mismatch in lib3270") ); + return; + } + + + cbk->update = v3270_update_char; + cbk->changed = changed; + cbk->set_timer = set_timer; + + cbk->set_selection = set_selection; + cbk->update_selection = update_selection; + + cbk->update_luname = update_luname; + cbk->configure = update_screen_size; + cbk->update_status = update_message; + cbk->update_cursor = v3270_update_cursor; + cbk->update_toggle = update_toggle; + cbk->update_oia = v3270_update_oia; + cbk->cursor = select_cursor; + cbk->update_connect = update_connect; + cbk->update_model = update_model; + cbk->changed = changed; + cbk->ctlr_done = ctlr_done; + cbk->message = message; + cbk->update_ssl = v3270_update_ssl; + cbk->print = emit_print_signal; // Reset timer -- libgit2 0.21.2