Commit dd5922c82396098f937a8b8e88bf7e772d460bb2

Authored by perry.werneck@gmail.com
1 parent 9a120c29

Trabalhando no novo mecanismo de trace

Showing 1 changed file with 45 additions and 12 deletions   Show diff stats
trace_ds.c
... ... @@ -74,14 +74,14 @@
74 74 #define MAX_HEADER_SIZE (10*1024)
75 75  
76 76 /* Minimum size of a trace file. */
77   -#define MIN_TRACEFILE_SIZE (64*1024)
78   -#define MIN_TRACEFILE_SIZE_NAME "64K"
  77 +// #define MIN_TRACEFILE_SIZE (64*1024)
  78 +// #define MIN_TRACEFILE_SIZE_NAME "64K"
79 79  
80 80 /* System calls which may not be there. */
81   -#if !defined(HAVE_FSEEKO) /*[*/
82   -#define fseeko(s, o, w) fseek(s, (long)o, w)
83   -#define ftello(s) (off_t)ftell(s)
84   -#endif /*]*/
  81 +// #if !defined(HAVE_FSEEKO)
  82 +// #define fseeko(s, o, w) fseek(s, (long)o, w)
  83 +// #define ftello(s) (off_t)ftell(s)
  84 +// #endif
85 85  
86 86 // #include <lib3270/api.h>
87 87  
... ... @@ -106,16 +106,22 @@ static int dscnt = 0;
106 106 // static char *tracef_midpoint_header = CN;
107 107 // static off_t tracef_midpoint = 0;
108 108  
109   -static void __vwtrace(const char *fmt, va_list args);
  109 +static void __vwtrace(H3270 *session, const char *fmt, va_list args);
110 110 static void wtrace(const char *fmt, ...);
111 111 // static char *create_tracefile_header(const char *mode);
112 112 static void stop_tracing(void);
113 113  
114 114 /* Globals */
115 115 struct timeval ds_ts;
116   -static void (*vwtrace)(const char *fmt, va_list args) = __vwtrace;
  116 +static void (*vwtrace)(H3270 *session, const char *fmt, va_list args) = __vwtrace;
117 117 Boolean trace_skipping = False;
118 118  
  119 +
  120 +LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) )
  121 +{
  122 + vwtrace = handler ? handler : __vwtrace;
  123 +}
  124 +
119 125 /* display a (row,col) */
120 126 const char *
121 127 rcba(int baddr)
... ... @@ -217,7 +223,7 @@ trace_event(const char *fmt, ...)
217 223  
218 224 /* print out message */
219 225 va_start(args, fmt);
220   - vwtrace(fmt, args);
  226 + vwtrace(&h3270,fmt, args);
221 227 va_end(args);
222 228 }
223 229  
... ... @@ -232,7 +238,7 @@ trace_dsn(const char *fmt, ...)
232 238  
233 239 /* print out message */
234 240 va_start(args, fmt);
235   - vwtrace(fmt, args);
  241 + vwtrace(&h3270,fmt, args);
236 242 va_end(args);
237 243 }
238 244  
... ... @@ -241,9 +247,10 @@ trace_dsn(const char *fmt, ...)
241 247 * This is the only function that actually does output to the trace file --
242 248 * all others are wrappers around this function.
243 249 */
244   -static void __vwtrace(const char *fmt, va_list args)
  250 +static void __vwtrace(H3270 *session, const char *fmt, va_list args)
245 251 {
246 252 vfprintf(stdout,fmt,args);
  253 + fflush(stdout);
247 254 }
248 255  
249 256 /*
... ... @@ -272,10 +279,36 @@ static void wtrace(const char *fmt, ...)
272 279 {
273 280 va_list args;
274 281 va_start(args, fmt);
275   - vwtrace(fmt, args);
  282 + vwtrace(&h3270,fmt, args);
276 283 va_end(args);
277 284 }
278 285  
  286 +LIB3270_EXPORT void lib3270_write_dstrace(H3270 *session, const char *fmt, ...)
  287 +{
  288 + va_list args;
  289 +
  290 + if(!lib3270_get_toggle(session,LIB3270_TOGGLE_DS_TRACE))
  291 + return;
  292 +
  293 + va_start(args, fmt);
  294 + vwtrace(session,fmt, args);
  295 + va_end(args);
  296 +}
  297 +
  298 +LIB3270_EXPORT void lib3270_trace_event(H3270 *session, const char *fmt, ...)
  299 +{
  300 + va_list args;
  301 +
  302 + if(!lib3270_get_toggle(session,LIB3270_TOGGLE_EVENT_TRACE))
  303 + return;
  304 +
  305 + va_start(args, fmt);
  306 + vwtrace(session,fmt, args);
  307 + va_end(args);
  308 +}
  309 +
  310 +
  311 +
279 312 /*
280 313 static void stop_tracing(void)
281 314 {
... ...