Commit 320b307544747664b83f69c46dc701e75345f731
1 parent
2cd61260
Exists in
master
and in
5 other branches
Incluindo opção de envio do trace de comunicação e telas para o syslog
Showing
6 changed files
with
94 additions
and
54 deletions
Show diff stats
src/lib3270/trace_ds.c
| @@ -53,70 +53,25 @@ | @@ -53,70 +53,25 @@ | ||
| 53 | #include <stdarg.h> | 53 | #include <stdarg.h> |
| 54 | #include <fcntl.h> | 54 | #include <fcntl.h> |
| 55 | #include "3270ds.h" | 55 | #include "3270ds.h" |
| 56 | -//#include "appres.h" | ||
| 57 | -// #include "objects.h" | ||
| 58 | #include "resources.h" | 56 | #include "resources.h" |
| 59 | -// #include "ctlr.h" | ||
| 60 | 57 | ||
| 61 | #include "charsetc.h" | 58 | #include "charsetc.h" |
| 62 | -// #include "childc.h" | ||
| 63 | #include "ctlrc.h" | 59 | #include "ctlrc.h" |
| 64 | #include "popupsc.h" | 60 | #include "popupsc.h" |
| 65 | -// #include "printc.h" | ||
| 66 | -// #include "savec.h" | ||
| 67 | #include "tablesc.h" | 61 | #include "tablesc.h" |
| 68 | #include "telnetc.h" | 62 | #include "telnetc.h" |
| 69 | #include "trace_dsc.h" | 63 | #include "trace_dsc.h" |
| 70 | #include "utilc.h" | 64 | #include "utilc.h" |
| 71 | -// #include "w3miscc.h" | ||
| 72 | #include "toggle.h" | 65 | #include "toggle.h" |
| 73 | 66 | ||
| 74 | /* Maximum size of a tracefile header. */ | 67 | /* Maximum size of a tracefile header. */ |
| 75 | #define MAX_HEADER_SIZE (10*1024) | 68 | #define MAX_HEADER_SIZE (10*1024) |
| 76 | 69 | ||
| 77 | -/* Minimum size of a trace file. */ | ||
| 78 | -// #define MIN_TRACEFILE_SIZE (64*1024) | ||
| 79 | -// #define MIN_TRACEFILE_SIZE_NAME "64K" | ||
| 80 | - | ||
| 81 | -/* System calls which may not be there. */ | ||
| 82 | -// #if !defined(HAVE_FSEEKO) | ||
| 83 | -// #define fseeko(s, o, w) fseek(s, (long)o, w) | ||
| 84 | -// #define ftello(s) (off_t)ftell(s) | ||
| 85 | -// #endif | ||
| 86 | - | ||
| 87 | -// #include <lib3270/api.h> | ||
| 88 | 70 | ||
| 89 | /* Statics */ | 71 | /* Statics */ |
| 90 | -// static int dscnt = 0; | ||
| 91 | - | ||
| 92 | -/* | ||
| 93 | -#if defined (LIB3270) | ||
| 94 | - HCONSOLE tracewindow_handle = 0; | ||
| 95 | -#elif defined(_WIN32) | ||
| 96 | - static HANDLE tracewindow_handle = NULL; | ||
| 97 | -#else | ||
| 98 | - static int tracewindow_pid = -1; | ||
| 99 | -#endif | ||
| 100 | -*/ | ||
| 101 | - | ||
| 102 | -// static FILE *tracef = NULL; | ||
| 103 | -// static FILE *tracef_pipe = NULL; | ||
| 104 | -// static char *tracef_bufptr = CN; | ||
| 105 | -// static off_t tracef_size = 0; | ||
| 106 | -// static off_t tracef_max = 0; | ||
| 107 | -// static char *tracef_midpoint_header = CN; | ||
| 108 | -// static off_t tracef_midpoint = 0; | ||
| 109 | - | ||
| 110 | static void __vwtrace(H3270 *session, const char *fmt, va_list args); | 72 | static void __vwtrace(H3270 *session, const char *fmt, va_list args); |
| 111 | static void wtrace(H3270 *session, const char *fmt, ...); | 73 | static void wtrace(H3270 *session, const char *fmt, ...); |
| 112 | -// static char *create_tracefile_header(const char *mode); | ||
| 113 | -// static void stop_tracing(void); | ||
| 114 | - | ||
| 115 | -/* Globals */ | ||
| 116 | -// struct timeval ds_ts; | ||
| 117 | - | ||
| 118 | static void (*vwtrace)(H3270 *session, const char *fmt, va_list args) = __vwtrace; | 74 | static void (*vwtrace)(H3270 *session, const char *fmt, va_list args) = __vwtrace; |
| 119 | -// Boolean trace_skipping = False; | ||
| 120 | 75 | ||
| 121 | 76 | ||
| 122 | LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) ) | 77 | LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) ) |
src/oxt/globals.hpp
| @@ -57,6 +57,7 @@ | @@ -57,6 +57,7 @@ | ||
| 57 | virtual char * get_text_at(int row, int col, int len) = 0; | 57 | virtual char * get_text_at(int row, int col, int len) = 0; |
| 58 | virtual int set_text_at(int row, int col, const char *text) = 0; | 58 | virtual int set_text_at(int row, int col, const char *text) = 0; |
| 59 | virtual int cmp_text_at(int row, int col, const char *text) = 0; | 59 | virtual int cmp_text_at(int row, int col, const char *text) = 0; |
| 60 | + virtual void set_toggle(LIB3270_TOGGLE toggle, bool state) = 0; | ||
| 60 | 61 | ||
| 61 | virtual int connect(const char *uri) = 0; | 62 | virtual int connect(const char *uri) = 0; |
| 62 | virtual int disconnect(void) = 0; | 63 | virtual int disconnect(void) = 0; |
| @@ -99,6 +100,7 @@ | @@ -99,6 +100,7 @@ | ||
| 99 | virtual int cmp_text_at(int row, int col, const char *text); | 100 | virtual int cmp_text_at(int row, int col, const char *text); |
| 100 | 101 | ||
| 101 | virtual void mem_free(void *ptr); | 102 | virtual void mem_free(void *ptr); |
| 103 | + virtual void set_toggle(LIB3270_TOGGLE toggle, bool state); | ||
| 102 | 104 | ||
| 103 | private: | 105 | private: |
| 104 | bool enabled; | 106 | bool enabled; |
| @@ -121,6 +123,8 @@ | @@ -121,6 +123,8 @@ | ||
| 121 | int (* _pfkey)(H3270 *, int); | 123 | int (* _pfkey)(H3270 *, int); |
| 122 | int (* _pakey)(H3270 *, int); | 124 | int (* _pakey)(H3270 *, int); |
| 123 | void * (* _mem_free)(void *); | 125 | void * (* _mem_free)(void *); |
| 126 | + void (*_set_toggle)(void *h, LIB3270_TOGGLE ix, int value); | ||
| 127 | + | ||
| 124 | 128 | ||
| 125 | }; | 129 | }; |
| 126 | 130 | ||
| @@ -156,6 +160,8 @@ | @@ -156,6 +160,8 @@ | ||
| 156 | virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException); | 160 | virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException); |
| 157 | virtual ::sal_Bool SAL_CALL hasTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException); | 161 | virtual ::sal_Bool SAL_CALL hasTextAt( ::sal_Int16 row, ::sal_Int16 col, const ::rtl::OUString& text ) throw (::com::sun::star::uno::RuntimeException); |
| 158 | virtual ::sal_Int16 SAL_CALL waitForReady( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException); | 162 | virtual ::sal_Int16 SAL_CALL waitForReady( ::sal_Int16 seconds ) throw (::com::sun::star::uno::RuntimeException); |
| 163 | + virtual ::sal_Int16 SAL_CALL dsTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException); | ||
| 164 | + virtual ::sal_Int16 SAL_CALL screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException); | ||
| 159 | 165 | ||
| 160 | private: | 166 | private: |
| 161 | 167 |
src/oxt/local.cxx
| @@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
| 31 | 31 | ||
| 32 | #include "globals.hpp" | 32 | #include "globals.hpp" |
| 33 | #include <errno.h> | 33 | #include <errno.h> |
| 34 | + #include <string.h> | ||
| 34 | 35 | ||
| 35 | #ifdef HAVE_SYSLOG | 36 | #ifdef HAVE_SYSLOG |
| 36 | #include <syslog.h> | 37 | #include <syslog.h> |
| @@ -47,14 +48,53 @@ | @@ -47,14 +48,53 @@ | ||
| 47 | 48 | ||
| 48 | /*---[ Implement ]-----------------------------------------------------------------------------------------*/ | 49 | /*---[ Implement ]-----------------------------------------------------------------------------------------*/ |
| 49 | 50 | ||
| 50 | -static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) | ||
| 51 | -{ | 51 | + static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) |
| 52 | + { | ||
| 52 | #ifdef HAVE_SYSLOG | 53 | #ifdef HAVE_SYSLOG |
| 53 | openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | 54 | openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); |
| 54 | vsyslog(LOG_INFO,fmt,args); | 55 | vsyslog(LOG_INFO,fmt,args); |
| 55 | closelog(); | 56 | closelog(); |
| 56 | #endif // HAVE_SYSLOG | 57 | #endif // HAVE_SYSLOG |
| 57 | -} | 58 | + } |
| 59 | + | ||
| 60 | + static void tracehandler(H3270 *session, const char *fmt, va_list args) | ||
| 61 | + { | ||
| 62 | +#ifdef HAVE_SYSLOG | ||
| 63 | + | ||
| 64 | + #define MAX_LOG_LENGTH 200 | ||
| 65 | + | ||
| 66 | + static char line[MAX_LOG_LENGTH+1]; | ||
| 67 | + char temp[MAX_LOG_LENGTH]; | ||
| 68 | + char * ptr; | ||
| 69 | + size_t len = strlen(line); | ||
| 70 | + | ||
| 71 | + vsnprintf(temp,MAX_LOG_LENGTH-len,fmt,args); | ||
| 72 | + | ||
| 73 | + ptr = strchr(temp,'\n'); | ||
| 74 | + if(!ptr) | ||
| 75 | + { | ||
| 76 | + strncat(line,temp,MAX_LOG_LENGTH); | ||
| 77 | + if(strlen(line) >= MAX_LOG_LENGTH) | ||
| 78 | + { | ||
| 79 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | ||
| 80 | + syslog(LOG_INFO,line); | ||
| 81 | + closelog(); | ||
| 82 | + *line = 0; | ||
| 83 | + } | ||
| 84 | + return; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + *ptr = 0; | ||
| 88 | + strncat(line,temp,MAX_LOG_LENGTH); | ||
| 89 | + | ||
| 90 | + openlog(PACKAGE_NAME, LOG_NDELAY, LOG_USER); | ||
| 91 | + syslog(LOG_INFO,line); | ||
| 92 | + closelog(); | ||
| 93 | + | ||
| 94 | + strncpy(line,ptr+1,MAX_LOG_LENGTH); | ||
| 95 | + | ||
| 96 | +#endif // HAVE_SYSLOG | ||
| 97 | + } | ||
| 58 | 98 | ||
| 59 | pw3270::lib3270_session::lib3270_session() | 99 | pw3270::lib3270_session::lib3270_session() |
| 60 | { | 100 | { |
| @@ -73,12 +113,14 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | @@ -73,12 +113,14 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | ||
| 73 | { (void **) & _pakey, "lib3270_pakey" }, | 113 | { (void **) & _pakey, "lib3270_pakey" }, |
| 74 | { (void **) & _in_tn3270e, "lib3270_in_tn3270e" }, | 114 | { (void **) & _in_tn3270e, "lib3270_in_tn3270e" }, |
| 75 | { (void **) & _get_program_message, "lib3270_get_program_message" }, | 115 | { (void **) & _get_program_message, "lib3270_get_program_message" }, |
| 76 | - { (void **) & _mem_free, "lib3270_free" } | 116 | + { (void **) & _mem_free, "lib3270_free" }, |
| 117 | + { (void **) & _set_toggle, "lib3270_set_toggle" } | ||
| 77 | 118 | ||
| 78 | }; | 119 | }; |
| 79 | 120 | ||
| 80 | H3270 * (*lib3270_new)(const char *); | 121 | H3270 * (*lib3270_new)(const char *); |
| 81 | void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); | 122 | void (*set_log_handler)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); |
| 123 | + void (*set_trace_handler)( void (*handler)(H3270 *session, const char *fmt, va_list args) ); | ||
| 82 | 124 | ||
| 83 | hThread = NULL; | 125 | hThread = NULL; |
| 84 | hSession = NULL; | 126 | hSession = NULL; |
| @@ -89,14 +131,22 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | @@ -89,14 +131,22 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | ||
| 89 | return; | 131 | return; |
| 90 | 132 | ||
| 91 | for(int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) | 133 | for(int f = 0; f < (sizeof (call) / sizeof ((call)[0]));f++) |
| 134 | + { | ||
| 92 | *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name); | 135 | *call[f].entry = (void *) osl_getAsciiFunctionSymbol(hModule,call[f].name); |
| 136 | + if(!*call[f].entry) | ||
| 137 | + log("Error loading lib3270::%s",call[f].name); | ||
| 138 | + } | ||
| 93 | 139 | ||
| 94 | /* Get lib3270 session handle */ | 140 | /* Get lib3270 session handle */ |
| 95 | - set_log_handler = (void (*)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list))) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_log_handler"); | 141 | + set_log_handler = (void (*)(void (*loghandler)(H3270 *, const char *, int, const char *, va_list))) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_log_handler"); |
| 142 | + set_trace_handler = (void (*)(void (*handler)(H3270 *session, const char *fmt, va_list args) )) osl_getAsciiFunctionSymbol(hModule,"lib3270_set_trace_handler"); | ||
| 96 | 143 | ||
| 97 | if(set_log_handler) | 144 | if(set_log_handler) |
| 98 | set_log_handler(loghandler); | 145 | set_log_handler(loghandler); |
| 99 | 146 | ||
| 147 | + if(set_trace_handler) | ||
| 148 | + set_trace_handler(tracehandler); | ||
| 149 | + | ||
| 100 | lib3270_new = (H3270 * (*)(const char *)) osl_getAsciiFunctionSymbol(hModule,"lib3270_session_new"); | 150 | lib3270_new = (H3270 * (*)(const char *)) osl_getAsciiFunctionSymbol(hModule,"lib3270_session_new"); |
| 101 | hSession = lib3270_new(""); | 151 | hSession = lib3270_new(""); |
| 102 | 152 | ||
| @@ -193,13 +243,16 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | @@ -193,13 +243,16 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | ||
| 193 | void (*_iterate)(void *h, int wait) = | 243 | void (*_iterate)(void *h, int wait) = |
| 194 | (void (*)(void *, int)) osl_getAsciiFunctionSymbol(hModule,"lib3270_main_iterate"); | 244 | (void (*)(void *, int)) osl_getAsciiFunctionSymbol(hModule,"lib3270_main_iterate"); |
| 195 | 245 | ||
| 246 | + trace("%s starts",__FUNCTION__); | ||
| 196 | _connect(hSession,NULL,1); | 247 | _connect(hSession,NULL,1); |
| 197 | 248 | ||
| 249 | + trace("%s network loop begin",__FUNCTION__); | ||
| 198 | while(enabled && !_status(hSession)) | 250 | while(enabled && !_status(hSession)) |
| 199 | { | 251 | { |
| 200 | osl_yieldThread(); | 252 | osl_yieldThread(); |
| 201 | _iterate(hSession,1); | 253 | _iterate(hSession,1); |
| 202 | } | 254 | } |
| 255 | + trace("%s network loop ends",__FUNCTION__); | ||
| 203 | 256 | ||
| 204 | osl_yieldThread(); | 257 | osl_yieldThread(); |
| 205 | 258 | ||
| @@ -272,3 +325,9 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | @@ -272,3 +325,9 @@ static void loghandler(H3270 *session, const char *module, int rc, const char *f | ||
| 272 | return false; | 325 | return false; |
| 273 | return _in_tn3270e(hSession) != 0; | 326 | return _in_tn3270e(hSession) != 0; |
| 274 | } | 327 | } |
| 328 | + | ||
| 329 | + void pw3270::lib3270_session::set_toggle(LIB3270_TOGGLE toggle, bool state) | ||
| 330 | + { | ||
| 331 | + if(hSession) | ||
| 332 | + _set_toggle(hSession,toggle,(int) state); | ||
| 333 | + } |
src/oxt/main.cxx
| @@ -239,6 +239,19 @@ pw3270::uno_impl::~uno_impl() | @@ -239,6 +239,19 @@ pw3270::uno_impl::~uno_impl() | ||
| 239 | return 0; | 239 | return 0; |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | +::sal_Int16 SAL_CALL pw3270::uno_impl::dsTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException) | ||
| 243 | +{ | ||
| 244 | + hSession->log("DS trace is %s",state ? "ON" : "OFF"); | ||
| 245 | + hSession->set_toggle(LIB3270_TOGGLE_DS_TRACE,state); | ||
| 246 | + return 0; | ||
| 247 | +} | ||
| 248 | + | ||
| 249 | +::sal_Int16 SAL_CALL pw3270::uno_impl::screenTrace( ::sal_Bool state ) throw (::com::sun::star::uno::RuntimeException) | ||
| 250 | +{ | ||
| 251 | + hSession->log("Screen trace is %s",state ? "ON" : "OFF"); | ||
| 252 | + hSession->set_toggle(LIB3270_TOGGLE_SCREEN_TRACE,state); | ||
| 253 | + return 0; | ||
| 254 | +} | ||
| 242 | 255 | ||
| 243 | pw3270::session::session() | 256 | pw3270::session::session() |
| 244 | { | 257 | { |
src/oxt/pw3270.idl
| @@ -81,7 +81,9 @@ module br | @@ -81,7 +81,9 @@ module br | ||
| 81 | boolean hasTextAt([in] short row, [in] short col, [in] string text); | 81 | boolean hasTextAt([in] short row, [in] short col, [in] string text); |
| 82 | short waitForReady([in] short seconds); | 82 | short waitForReady([in] short seconds); |
| 83 | // short waitForTextAt(in] short row, [in] short col, [in] string text, [in] short seconds); | 83 | // short waitForTextAt(in] short row, [in] short col, [in] string text, [in] short seconds); |
| 84 | - boolean isConnected(); | 84 | + boolean isConnected(); |
| 85 | + short dsTrace([in] boolean mode); | ||
| 86 | + short screenTrace([in] boolean mode); | ||
| 85 | 87 | ||
| 86 | }; | 88 | }; |
| 87 | 89 |
src/oxt/testprogram.cxx
| @@ -104,10 +104,14 @@ int SAL_CALL main(int argc, char **argv) | @@ -104,10 +104,14 @@ int SAL_CALL main(int argc, char **argv) | ||
| 104 | if(srv.is()) | 104 | if(srv.is()) |
| 105 | { | 105 | { |
| 106 | // Wait for commands | 106 | // Wait for commands |
| 107 | + char buffer[4096]; | ||
| 107 | OString str; | 108 | OString str; |
| 108 | 109 | ||
| 109 | printf("Revision:\t%d\n",srv->getRevision()); | 110 | printf("Revision:\t%d\n",srv->getRevision()); |
| 110 | 111 | ||
| 112 | + srv->dsTrace(true); | ||
| 113 | + srv->screenTrace(true); | ||
| 114 | + | ||
| 111 | printf("getConnectionState: %d\n", srv->getConnectionState()); | 115 | printf("getConnectionState: %d\n", srv->getConnectionState()); |
| 112 | printf("Connect(): %d\n" , srv->Connect(OUString::createFromAscii("L:3270.df.bb:9023"))); | 116 | printf("Connect(): %d\n" , srv->Connect(OUString::createFromAscii("L:3270.df.bb:9023"))); |
| 113 | 117 | ||
| @@ -136,14 +140,15 @@ int SAL_CALL main(int argc, char **argv) | @@ -136,14 +140,15 @@ int SAL_CALL main(int argc, char **argv) | ||
| 136 | str = OUStringToOString( srv->getScreenContent(),RTL_TEXTENCODING_UTF8); | 140 | str = OUStringToOString( srv->getScreenContent(),RTL_TEXTENCODING_UTF8); |
| 137 | printf("Entire screen:\n%s\n",str.pData->buffer); | 141 | printf("Entire screen:\n%s\n",str.pData->buffer); |
| 138 | 142 | ||
| 143 | + | ||
| 144 | + */ | ||
| 145 | + | ||
| 139 | printf("Enter to exit...\n"); | 146 | printf("Enter to exit...\n"); |
| 140 | fgets(buffer,80,stdin); | 147 | fgets(buffer,80,stdin); |
| 141 | 148 | ||
| 142 | printf("Disconnect(): %d\n" , srv->Disconnect()); | 149 | printf("Disconnect(): %d\n" , srv->Disconnect()); |
| 143 | 150 | ||
| 144 | - sleep(5); | ||
| 145 | - | ||
| 146 | - */ | 151 | + srv->sleep(5); |
| 147 | 152 | ||
| 148 | } | 153 | } |
| 149 | } | 154 | } |