From 36eda0f84d78b45d97dfa488b877d03bdeb437f6 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 21 Nov 2018 11:25:38 -0200 Subject: [PATCH] Moving popup support for session instead of global method. --- lib3270.cbp | 3 --- src/include/lib3270/popup.h | 2 -- src/include/lib3270/session.h | 1 + src/lib3270/private.h | 2 +- src/lib3270/screen.c | 30 +++++++----------------------- src/lib3270/session.c | 18 +++++++++++++++--- 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lib3270.cbp b/lib3270.cbp index f5685c5..d646be1 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -156,9 +156,6 @@ - - diff --git a/src/include/lib3270/popup.h b/src/include/lib3270/popup.h index 644dd3f..9e654ab 100644 --- a/src/include/lib3270/popup.h +++ b/src/include/lib3270/popup.h @@ -51,8 +51,6 @@ LIB3270_NOTIFY_USER /**< Reserved, always the last one */ } LIB3270_NOTIFY; - LIB3270_EXPORT void lib3270_set_popup_handler(int (*popup_handler)(H3270 *, void *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)); - /** * Pop up an error dialog, based on an error number. * diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 83f50d7..e475a14 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -77,6 +77,7 @@ int (*print)(H3270 *session); void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); + void (*popup)(H3270 *session, LIB3270_NOTIFY id, const char *title, const char *msg, const char *fmt, va_list); #ifdef HAVE_LIBSSL void (*set_peer_certificate)(const X509 *cert); diff --git a/src/lib3270/private.h b/src/lib3270/private.h index 2561dbb..44024cf 100644 --- a/src/lib3270/private.h +++ b/src/lib3270/private.h @@ -295,7 +295,7 @@ typedef struct input */ struct _h3270 { - struct lib3270_session_callbacks cbk; // Callback table - Always the first one. + struct lib3270_session_callbacks cbk; // Callback table - Always the first one. // unsigned short sz; /**< Struct size */ diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 80489e3..374295c 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -24,8 +24,6 @@ * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) * */ @@ -74,15 +72,8 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ -static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg); - -static int (*popup_handler)(H3270 *, void *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list) = logpopup; - -// enum ts { TS_AUTO, TS_ON, TS_OFF }; - static void status_connect(H3270 *session, int ignored, void *dunno); static void status_3270_mode(H3270 *session, int ignored, void *dunno); -// static void status_printer(H3270 *session, int on, void *dunno); static unsigned short color_from_fa(H3270 *hSession, unsigned char fa); /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -667,6 +658,7 @@ void status_untiming(H3270 *session) session->cbk.set_timer(session,0); } +/* static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) { #ifdef ANDROID @@ -680,6 +672,7 @@ static int logpopup(H3270 *session, void *widget, LIB3270_NOTIFY type, const cha #endif // ANDROID return 0; } +*/ void Error(H3270 *session, const char *fmt, ...) { @@ -691,7 +684,7 @@ void Error(H3270 *session, const char *fmt, ...) va_start(arg_ptr, fmt); - popup_handler(session,session->user_data,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr); + session->cbk.popup(session,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr); va_end(arg_ptr); @@ -706,7 +699,7 @@ void Warning(H3270 *session, const char *fmt, ...) trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Warning",fmt); va_start(arg_ptr, fmt); - popup_handler(session,session->user_data,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr); + session->cbk.popup(session,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr); va_end(arg_ptr); } @@ -721,7 +714,7 @@ void popup_an_error(H3270 *session, const char *fmt, ...) trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt); va_start(args, fmt); - popup_handler(session,session->user_data,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args); + session->cbk.popup(session,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args); va_end(args); } @@ -735,7 +728,7 @@ void popup_system_error(H3270 *session, const char *title, const char *message, trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message); va_start(args, fmt); - popup_handler(session,session->user_data,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args); + session->cbk.popup(session,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args); va_end(args); } @@ -845,11 +838,6 @@ LIB3270_ACTION( testpattern ) return 0; } -LIB3270_EXPORT void lib3270_set_popup_handler(int (*handler)(H3270 *, void *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)) -{ - popup_handler = handler ? handler : logpopup; -} - LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) { va_list args; @@ -860,12 +848,8 @@ LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , con LIB3270_EXPORT void lib3270_popup_va(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, va_list args) { - CHECK_SESSION_HANDLE(session); - - trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message); - - popup_handler(session,session->user_data,id,title ? title : _( "3270 Error" ), message,fmt,args); + session->cbk.popup(session,id,title ? title : _( "3270 Error" ), message,fmt,args); } LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr) diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 0942520..6f5a4d3 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -34,7 +34,6 @@ #endif // !ANDROID #include "private.h" -// #include "charsetc.h" #include "kybdc.h" #include "ansic.h" #include "togglesc.h" @@ -44,9 +43,7 @@ #include "ftc.h" #include "kybdc.h" #include "3270ds.h" -// #include "tablesc.h" #include "popupsc.h" -//#include "charset.h" /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ @@ -166,6 +163,20 @@ static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const #endif // ANDROID } +static int popup(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) +{ +#ifdef ANDROID + char *mask = xs_buffer("%s\n",fmt); + __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, mask, arg); + lib3270_free(mask); +#else + lib3270_write_log(session,"popup","%s",title); + lib3270_write_log(session,"popup","%s",msg); + lib3270_write_va_log(session,"popup",fmt,arg); +#endif // ANDROID + return 0; +} + static void update_ssl(H3270 *session, LIB3270_SSL_STATE state) { } @@ -222,6 +233,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char hSession->cbk.update_selection = update_selection; hSession->cbk.cursor = set_cursor; hSession->cbk.message = message; + hSession->cbk.popup = popup; hSession->cbk.update_ssl = update_ssl; hSession->cbk.display = screen_disp; hSession->cbk.set_width = nop_int; -- libgit2 0.21.2