Commit 99986be0b9c540317da421312a0faaf26b34617a

Authored by Perry Werneck
1 parent a26cc869
Exists in master

Incluindo mecanismo para geração de arquivo de trace com as chamadas da API.

@@ -335,6 +335,15 @@ if test "$app_cv_pic" == "yes"; then @@ -335,6 +335,15 @@ if test "$app_cv_pic" == "yes"; then
335 fi 335 fi
336 336
337 dnl --------------------------------------------------------------------------- 337 dnl ---------------------------------------------------------------------------
  338 +dnl Enable/Disable trace file
  339 +dnl ---------------------------------------------------------------------------
  340 +AC_ARG_ENABLE([trace],[AS_HELP_STRING([--enable-trace], [Enable creation of trace file])],[app_cv_trace="$enableval"],[app_cv_trace="no"])
  341 +
  342 +if test "$app_cv_trace" == "yes"; then
  343 + AC_DEFINE(ENABLE_TRACE_TO_FILE)
  344 +fi
  345 +
  346 +dnl ---------------------------------------------------------------------------
338 dnl Output config 347 dnl Output config
339 dnl --------------------------------------------------------------------------- 348 dnl ---------------------------------------------------------------------------
340 349
pw3270-sharp.cbp
@@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
43 <Linker> 43 <Linker>
44 <Add library="pw3270cpp" /> 44 <Add library="pw3270cpp" />
45 </Linker> 45 </Linker>
  46 + <Unit filename="src/include/config.h.in" />
46 <Unit filename="src/native/actions.cc" /> 47 <Unit filename="src/native/actions.cc" />
47 <Unit filename="src/native/get.cc" /> 48 <Unit filename="src/native/get.cc" />
48 <Unit filename="src/native/init.cc" /> 49 <Unit filename="src/native/init.cc" />
src/include/config.h.in
@@ -43,5 +43,12 @@ @@ -43,5 +43,12 @@
43 */ 43 */
44 #undef HAVE_GNUC_VISIBILITY 44 #undef HAVE_GNUC_VISIBILITY
45 45
  46 + /**
  47 + * @brief Ativa trace em um arquivo texto.
  48 + *
  49 + */
  50 + #undef ENABLE_TRACE_TO_FILE
  51 +
  52 +
46 53
47 #endif // CONFIG_H_INCLUDED 54 #endif // CONFIG_H_INCLUDED
src/native/Makefile.in
@@ -67,7 +67,7 @@ CC=@CC@ @@ -67,7 +67,7 @@ CC=@CC@
67 LD=@CXX@ 67 LD=@CXX@
68 68
69 LIBS=-lpw3270cpp @LIBS@ @LIBICONV@ 69 LIBS=-lpw3270cpp @LIBS@ @LIBICONV@
70 -CFLAGS=@CFLAGS@ 70 +CFLAGS=-I../include @CFLAGS@
71 LDFLAGS=@LDFLAGS@ 71 LDFLAGS=@LDFLAGS@
72 72
73 #---[ Rules ]---------------------------------------------------------------------------- 73 #---[ Rules ]----------------------------------------------------------------------------
src/native/get.cc
@@ -63,6 +63,8 @@ @@ -63,6 +63,8 @@
63 63
64 int tn3270_get_cstate(h3270::session *ses) { 64 int tn3270_get_cstate(h3270::session *ses) {
65 65
  66 + trace_to_file("%s: %d",__FUNCTION__,(int) ses->get_cstate());
  67 +
66 try { 68 try {
67 return (int) ses->get_cstate(); 69 return (int) ses->get_cstate();
68 } catch(std::exception &e) { 70 } catch(std::exception &e) {
src/native/init.cc
@@ -42,6 +42,9 @@ @@ -42,6 +42,9 @@
42 * 42 *
43 */ 43 */
44 h3270::session * tn3270_create_session(const char *name) { 44 h3270::session * tn3270_create_session(const char *name) {
  45 +
  46 + trace_to_file("%s(%s)",__FUNCTION__,name ? name : "");
  47 +
45 try { 48 try {
46 return h3270::session::create(name); 49 return h3270::session::create(name);
47 } catch(std::exception &e) { 50 } catch(std::exception &e) {
@@ -55,6 +58,9 @@ @@ -55,6 +58,9 @@
55 * 58 *
56 */ 59 */
57 int tn3270_destroy_session(h3270::session *ses) { 60 int tn3270_destroy_session(h3270::session *ses) {
  61 +
  62 + trace_to_file("%s",__FUNCTION__);
  63 +
58 try { 64 try {
59 delete ses; 65 delete ses;
60 } catch(std::exception &e) { 66 } catch(std::exception &e) {
@@ -64,3 +70,23 @@ @@ -64,3 +70,23 @@
64 return 0; 70 return 0;
65 } 71 }
66 72
  73 +#ifdef ENABLE_TRACE_TO_FILE
  74 + void write_trace(const char *fmt, ...) {
  75 +
  76 + FILE *trace = fopen(PACKAGE_NAME ".trace","a");
  77 + if(trace) {
  78 + va_list arg_ptr;
  79 + va_start(arg_ptr, fmt);
  80 + vfprintf(trace, fmt, arg_ptr);
  81 + fprintf(trace,"\n");
  82 + va_end(arg_ptr);
  83 + fclose(trace);
  84 + }
  85 +#ifdef DEBUG
  86 + else {
  87 + perror(PACKAGE_NAME ".trace");
  88 + }
  89 +#endif // DEBUG
  90 +
  91 + }
  92 +#endif // ENABLE_TRACE_TO_FILE
src/native/private.h
@@ -35,6 +35,8 @@ @@ -35,6 +35,8 @@
35 35
36 #define PRIVATE_H_INCLUDED 36 #define PRIVATE_H_INCLUDED
37 37
  38 + #include <config.h>
  39 +
38 #if defined(_WIN32) 40 #if defined(_WIN32)
39 41
40 #include <windows.h> 42 #include <windows.h>
@@ -63,6 +65,13 @@ @@ -63,6 +65,13 @@
63 #define debug( fmt, ... ) /* */ 65 #define debug( fmt, ... ) /* */
64 #endif // DEBUG 66 #endif // DEBUG
65 67
  68 + #ifdef ENABLE_TRACE_TO_FILE
  69 + DLL_PRIVATE void write_trace(const char *fmt, ...);
  70 + #define trace_to_file( ... ) write_trace(__VA_ARGS__)
  71 + #else
  72 + #define trace( ... ) /* */
  73 + #endif // ENABLE_TRACE_TO_FILE
  74 +
66 #include <pw3270cpp.h> 75 #include <pw3270cpp.h>
67 #include <cerrno> 76 #include <cerrno>
68 #include <cstring> 77 #include <cstring>
src/native/screen.cc
@@ -70,6 +70,7 @@ int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int s @@ -70,6 +70,7 @@ int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int s
70 try { 70 try {
71 memset(str,0,sz+1); 71 memset(str,0,sz+1);
72 strncpy(str,ses->get_string_at(row,col,sz).c_str(),sz); 72 strncpy(str,ses->get_string_at(row,col,sz).c_str(),sz);
  73 + trace_to_file("%s(%d,%d,%d):\n%s\n",__FUNCTION__,row,col,sz,str);
73 } catch(std::exception &e) { 74 } catch(std::exception &e) {
74 tn3270_lasterror = e.what(); 75 tn3270_lasterror = e.what();
75 return -1; 76 return -1;
@@ -79,6 +80,7 @@ int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int s @@ -79,6 +80,7 @@ int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int s
79 80
80 int tn3270_set_string_at(h3270::session *ses, int row, int col, const char* str) { 81 int tn3270_set_string_at(h3270::session *ses, int row, int col, const char* str) {
81 try { 82 try {
  83 + trace_to_file("%s(%d,%d):\n%s\n",__FUNCTION__,row,col,str);
82 debug("%s(%d,%d,\"%s\")",__FUNCTION__,row,col,str); 84 debug("%s(%d,%d,\"%s\")",__FUNCTION__,row,col,str);
83 ses->set_string_at(row,col,str); 85 ses->set_string_at(row,col,str);
84 } catch(std::exception &e) { 86 } catch(std::exception &e) {
src/native/set.cc
@@ -63,6 +63,7 @@ int tn3270_set_cursor_addr(h3270::session *ses, int addr) { @@ -63,6 +63,7 @@ int tn3270_set_cursor_addr(h3270::session *ses, int addr) {
63 63
64 int tn3270_set_charset(h3270::session *ses, const char* str) { 64 int tn3270_set_charset(h3270::session *ses, const char* str) {
65 try { 65 try {
  66 + trace_to_file("%s: \"%s\" -> \"%s\"",__FUNCTION__,ses->get_display_charset().c_str(),str);
66 ses->set_display_charset(NULL, str); 67 ses->set_display_charset(NULL, str);
67 } catch(std::exception &e) { 68 } catch(std::exception &e) {
68 tn3270_lasterror = e.what(); 69 tn3270_lasterror = e.what();