From 320b307544747664b83f69c46dc701e75345f731 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 15 Mar 2013 17:40:48 +0000 Subject: [PATCH] Incluindo opção de envio do trace de comunicação e telas para o syslog --- src/lib3270/trace_ds.c | 45 --------------------------------------------- src/oxt/globals.hpp | 6 ++++++ src/oxt/local.cxx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/oxt/main.cxx | 13 +++++++++++++ src/oxt/pw3270.idl | 4 +++- src/oxt/testprogram.cxx | 11 ++++++++--- 6 files changed, 94 insertions(+), 54 deletions(-) diff --git a/src/lib3270/trace_ds.c b/src/lib3270/trace_ds.c index cc283d9..86a2dc9 100644 --- a/src/lib3270/trace_ds.c +++ b/src/lib3270/trace_ds.c @@ -53,70 +53,25 @@ #include #include #include "3270ds.h" -//#include "appres.h" -// #include "objects.h" #include "resources.h" -// #include "ctlr.h" #include "charsetc.h" -// #include "childc.h" #include "ctlrc.h" #include "popupsc.h" -// #include "printc.h" -// #include "savec.h" #include "tablesc.h" #include "telnetc.h" #include "trace_dsc.h" #include "utilc.h" -// #include "w3miscc.h" #include "toggle.h" /* Maximum size of a tracefile header. */ #define MAX_HEADER_SIZE (10*1024) -/* Minimum size of a trace file. */ -// #define MIN_TRACEFILE_SIZE (64*1024) -// #define MIN_TRACEFILE_SIZE_NAME "64K" - -/* System calls which may not be there. */ -// #if !defined(HAVE_FSEEKO) -// #define fseeko(s, o, w) fseek(s, (long)o, w) -// #define ftello(s) (off_t)ftell(s) -// #endif - -// #include /* Statics */ -// static int dscnt = 0; - -/* -#if defined (LIB3270) - HCONSOLE tracewindow_handle = 0; -#elif defined(_WIN32) - static HANDLE tracewindow_handle = NULL; -#else - static int tracewindow_pid = -1; -#endif -*/ - -// static FILE *tracef = NULL; -// static FILE *tracef_pipe = NULL; -// static char *tracef_bufptr = CN; -// static off_t tracef_size = 0; -// static off_t tracef_max = 0; -// static char *tracef_midpoint_header = CN; -// static off_t tracef_midpoint = 0; - static void __vwtrace(H3270 *session, const char *fmt, va_list args); static void wtrace(H3270 *session, const char *fmt, ...); -// static char *create_tracefile_header(const char *mode); -// static void stop_tracing(void); - -/* Globals */ -// struct timeval ds_ts; - static void (*vwtrace)(H3270 *session, const char *fmt, va_list args) = __vwtrace; -// Boolean trace_skipping = False; LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) ) diff --git a/src/oxt/globals.hpp b/src/oxt/globals.hpp index e681665..eee83ba 100644 --- a/src/oxt/globals.hpp +++ b/src/oxt/globals.hpp @@ -57,6 +57,7 @@ virtual char * get_text_at(int row, int col, int len) = 0; virtual int set_text_at(int row, int col, const char *text) = 0; virtual int cmp_text_at(int row, int col, const char *text) = 0; + virtual void set_toggle(LIB3270_TOGGLE toggle, bool state) = 0; virtual int connect(const char *uri) = 0; virtual int disconnect(void) = 0; @@ -99,6 +100,7 @@ virtual int cmp_text_at(int row, int col, const char *text); virtual void mem_free(void *ptr); + virtual void set_toggle(LIB3270_TOGGLE toggle, bool state); private: bool enabled; @@ -121,6 +123,8 @@ int (* _pfkey)(H3270 *, int); int (* _pakey)(H3270 *, int); void * (* _mem_free)(void *); + void (*_set_toggle)(void *h, LIB3270_TOGGLE ix, int value); + }; @@ -156,6 +160,8 @@ virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL hasTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int16 SAL_CALL waitForReady( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int16 SAL_CALL dsTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int16 SAL_CALL screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException); private: diff --git a/src/oxt/local.cxx b/src/oxt/local.cxx index 7320a73..4a088fa 100644 --- a/src/oxt/local.cxx +++ b/src/oxt/local.cxx @@ -31,6 +31,7 @@ #include "globals.hpp" #include + #include #ifdef HAVE_SYSLOG #include @@ -47,14 +48,53 @@ /*---[ Implement ]-----------------------------------------------------------------------------------------*/ -static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) -{ + static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) + { #ifdef HAVE_SYSLOG openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); vsyslog(LOG_INFO,fmt,args); closelog(); #endif // HAVE_SYSLOG -} + } + + static void tracehandler(H3270 *session, const char *fmt, va_list args) + { +#ifdef HAVE_SYSLOG + + #define MAX_LOG_LENGTH 200 + + static char line[MAX_LOG_LENGTH+1]; + char temp[MAX_LOG_LENGTH]; + char * ptr; + size_t len = strlen(line); + + vsnprintf(temp,MAX_LOG_LENGTH-len,fmt,args); + + ptr = strchr(temp,'\n'); + if(!ptr) + { + strncat(line,temp,MAX_LOG_LENGTH); + if(strlen(line) >= MAX_LOG_LENGTH) + { + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); + syslog(LOG_INFO,line); + closelog(); + *line = 0; + } + return; + } + + *ptr = 0; + strncat(line,temp,MAX_LOG_LENGTH); + + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); + syslog(LOG_INFO,line); + closelog(); + + strncpy(line,ptr+1,MAX_LOG_LENGTH); + +#endif // HAVE_SYSLOG + } pw3270::lib3270_session::lib3270_session() { @@ -73,12 +113,14 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f { (void **) & _pakey, "lib3270_pakey" }, { (void **) & _in_tn3270e, "lib3270_in_tn3270e" }, { (void **) & _get_program_message, "lib3270_get_program_message" }, - { (void **) & _mem_free, "lib3270_free" } + { (void **) & _mem_free, "lib3270_free" }, + { (void **) & _set_toggle, "lib3270_set_toggle" } }; H3270 * (*lib3270_new)(const char *); void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); + void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) ); hThread = NULL; hSession = NULL; @@ -89,14 +131,22 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f return; for(int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) + { *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name); + if(!*call[f].entry) + log("Error loading lib3270::%s",call[f].name); + } /* Get lib3270 session handle */ - set_log_handler = (void (*)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list))) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_log_handler"); + set_log_handler = (void (*)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list))) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_log_handler"); + set_trace_handler = (void (*)(void (*handler)(H3270 *session, const char *fmt, va_list args) )) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_trace_handler"); if(set_log_handler) set_log_handler(loghandler); + if(set_trace_handler) + set_trace_handler(tracehandler); + lib3270_new = (H3270 * (*)(const char *)) osl_getAsciiFunctionSymbol(hModule,"lib3270_session_new"); hSession = lib3270_new(""); @@ -193,13 +243,16 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f void (*_iterate)(void *h, int wait) = (void (*)(void *, int)) osl_getAsciiFunctionSymbol(hModule,"lib3270_main_iterate"); + trace("%s starts",__FUNCTION__); _connect(hSession,NULL,1); + trace("%s network loop begin",__FUNCTION__); while(enabled && !_status(hSession)) { osl_yieldThread(); _iterate(hSession,1); } + trace("%s network loop ends",__FUNCTION__); osl_yieldThread(); @@ -272,3 +325,9 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f return false; return _in_tn3270e(hSession) != 0; } + + void pw3270::lib3270_session::set_toggle(LIB3270_TOGGLE toggle, bool state) + { + if(hSession) + _set_toggle(hSession,toggle,(int) state); + } diff --git a/src/oxt/main.cxx b/src/oxt/main.cxx index ca9f1f9..49f3167 100644 --- a/src/oxt/main.cxx +++ b/src/oxt/main.cxx @@ -239,6 +239,19 @@ pw3270::uno_impl::~uno_impl() return 0; } +::sal_Int16 SAL_CALL pw3270::uno_impl::dsTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException) +{ + hSession->log("DS trace is %s",state ? "ON" : "OFF"); + hSession->set_toggle(LIB3270_TOGGLE_DS_TRACE,state); + return 0; +} + +::sal_Int16 SAL_CALL pw3270::uno_impl::screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException) +{ + hSession->log("Screen trace is %s",state ? "ON" : "OFF"); + hSession->set_toggle(LIB3270_TOGGLE_SCREEN_TRACE,state); + return 0; +} pw3270::session::session() { diff --git a/src/oxt/pw3270.idl b/src/oxt/pw3270.idl index fa54edb..79a5363 100644 --- a/src/oxt/pw3270.idl +++ b/src/oxt/pw3270.idl @@ -81,7 +81,9 @@ module br boolean hasTextAt([in] short row, [in] short col, [in] string text); short waitForReady([in] short seconds); // short waitForTextAt(in] short row, [in] short col, [in] string text, [in] short seconds); - boolean isConnected(); + boolean isConnected(); + short dsTrace([in] boolean mode); + short screenTrace([in] boolean mode); }; diff --git a/src/oxt/testprogram.cxx b/src/oxt/testprogram.cxx index 5f16ff8..2ca3ce2 100644 --- a/src/oxt/testprogram.cxx +++ b/src/oxt/testprogram.cxx @@ -104,10 +104,14 @@ int SAL_CALL main(int argc, char **argv) if(srv.is()) { // Wait for commands + char buffer[4096]; OString str; printf("Revision:\t%d\n",srv->getRevision()); + srv->dsTrace(true); + srv->screenTrace(true); + printf("getConnectionState: %d\n", srv->getConnectionState()); printf("Connect(): %d\n" , srv->Connect(OUString::createFromAscii("L:3270.df.bb:9023"))); @@ -136,14 +140,15 @@ int SAL_CALL main(int argc, char **argv) str = OUStringToOString( srv->getScreenContent(),RTL_TEXTENCODING_UTF8); printf("Entire screen:\n%s\n",str.pData->buffer); + + */ + printf("Enter to exit...\n"); fgets(buffer,80,stdin); printf("Disconnect(): %d\n" , srv->Disconnect()); - sleep(5); - - */ + srv->sleep(5); } } -- libgit2 0.21.2