Commit f0d7d344c9fe63639c629318d5535506e0f10dc2
1 parent
a370c560
Exists in
master
and in
5 other branches
Implementando janela de trace
Showing
10 changed files
with
113 additions
and
23 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -308,6 +308,7 @@ install-sdk: |
| 308 | 308 | @$(INSTALL_DATA) src/include/lib3270/popup.h $(DESTDIR)/$(includedir)/lib3270 |
| 309 | 309 | @$(INSTALL_DATA) src/include/lib3270/actions.h $(DESTDIR)/$(includedir)/lib3270 |
| 310 | 310 | @$(INSTALL_DATA) src/include/lib3270/action_table.h $(DESTDIR)/$(includedir)/lib3270 |
| 311 | + @$(INSTALL_DATA) src/include/lib3270/trace.h $(DESTDIR)/$(includedir)/lib3270 | |
| 311 | 312 | |
| 312 | 313 | @$(MKDIR) $(DESTDIR)$(includedir)/pw3270 |
| 313 | 314 | @$(INSTALL_DATA) src/include/pw3270/v3270.h $(DESTDIR)/$(includedir)/pw3270 | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -1007,10 +1007,6 @@ |
| 1007 | 1007 | |
| 1008 | 1008 | LIB3270_EXPORT int lib3270_clear_operator_error(H3270 *hSession); |
| 1009 | 1009 | |
| 1010 | - LIB3270_EXPORT void lib3270_trace_event(H3270 *session, const char *fmt, ...) LIB3270_GNUC_FORMAT(2,3); | |
| 1011 | - LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) ); | |
| 1012 | - LIB3270_EXPORT void lib3270_write_dstrace(H3270 *session, const char *fmt, ...) LIB3270_GNUC_FORMAT(2,3); | |
| 1013 | - | |
| 1014 | 1010 | LIB3270_EXPORT LIB3270_OPTION lib3270_get_options(H3270 *hSession); |
| 1015 | 1011 | LIB3270_EXPORT void lib3270_set_options(H3270 *hSession, LIB3270_OPTION opt); |
| 1016 | 1012 | LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, unsigned short colortype); | ... | ... |
src/include/lib3270/trace.h
| ... | ... | @@ -33,13 +33,18 @@ |
| 33 | 33 | |
| 34 | 34 | #define LIB3270_TRACE_H_INCLUDED 1 |
| 35 | 35 | |
| 36 | + typedef void (*LIB3270_TRACE_HANDLER)(H3270 *, const char *, va_list); | |
| 37 | + | |
| 38 | + | |
| 36 | 39 | /** |
| 37 | 40 | * Set trace handle callback. |
| 38 | 41 | * |
| 39 | - * @param handle Callback to write in trace file or show trace window (NULL send all trace to stdout). | |
| 42 | + * @param handle Callback to write in trace file or show trace window (NULL send all trace to stdout/syslog). | |
| 43 | + * @param data User data to pass to the trace handler. | |
| 40 | 44 | * |
| 45 | + * @return Current trace handler | |
| 41 | 46 | */ |
| 42 | - LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) ); | |
| 47 | + LIB3270_EXPORT LIB3270_TRACE_HANDLER lib3270_set_trace_handler( LIB3270_TRACE_HANDLER handler); | |
| 43 | 48 | |
| 44 | 49 | /** |
| 45 | 50 | * Write on trace file. | ... | ... |
src/lib3270/ft.c
src/lib3270/kybd.c
src/lib3270/trace_ds.c
| ... | ... | @@ -38,6 +38,7 @@ |
| 38 | 38 | */ |
| 39 | 39 | |
| 40 | 40 | #include "globals.h" |
| 41 | +#include <lib3270/trace.h> | |
| 41 | 42 | |
| 42 | 43 | #if defined(X3270_TRACE) /*[*/ |
| 43 | 44 | |
| ... | ... | @@ -74,9 +75,11 @@ static void wtrace(H3270 *session, const char *fmt, ...); |
| 74 | 75 | static void (*vwtrace)(H3270 *session, const char *fmt, va_list args) = __vwtrace; |
| 75 | 76 | |
| 76 | 77 | |
| 77 | -LIB3270_EXPORT void lib3270_set_trace_handler( void (*handler)(H3270 *session, const char *fmt, va_list args) ) | |
| 78 | +LIB3270_EXPORT LIB3270_TRACE_HANDLER lib3270_set_trace_handler( LIB3270_TRACE_HANDLER handler ) | |
| 78 | 79 | { |
| 80 | + void (*ret)(H3270 *session, const char *fmt, va_list args) = vwtrace; | |
| 79 | 81 | vwtrace = handler ? handler : __vwtrace; |
| 82 | + return ret; | |
| 80 | 83 | } |
| 81 | 84 | |
| 82 | 85 | /* display a (row,col) */ |
| ... | ... | @@ -88,10 +91,6 @@ const char * rcba(H3270 *hSession, int baddr) |
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | /* Data Stream trace print, handles line wraps */ |
| 91 | - | |
| 92 | -// static char *tdsbuf = CN; | |
| 93 | -// #define TDS_LEN 75 | |
| 94 | - | |
| 95 | 94 | static void trace_ds_s(H3270 *hSession, char *s, Boolean can_break) |
| 96 | 95 | { |
| 97 | 96 | static int dscnt = 0; | ... | ... |
src/plugins/rx3270/pluginmain.cc
| ... | ... | @@ -48,6 +48,7 @@ |
| 48 | 48 | #include <pw3270/trace.h> |
| 49 | 49 | #include <lib3270/actions.h> |
| 50 | 50 | #include <lib3270/log.h> |
| 51 | + #include <lib3270/trace.h> | |
| 51 | 52 | #include <pw3270/class.h> |
| 52 | 53 | |
| 53 | 54 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ | ... | ... |
src/pw3270/main.c
| ... | ... | @@ -40,6 +40,8 @@ |
| 40 | 40 | #include <pw3270/v3270.h> |
| 41 | 41 | #include <pw3270/plugin.h> |
| 42 | 42 | #include "v3270/accessible.h" |
| 43 | +#include <lib3270/trace.h> | |
| 44 | +#include <pw3270/trace.h> | |
| 43 | 45 | #include <stdlib.h> |
| 44 | 46 | |
| 45 | 47 | #if defined( HAVE_SYSLOG ) |
| ... | ... | @@ -51,11 +53,13 @@ |
| 51 | 53 | /*--[ Statics ]--------------------------------------------------------------------------------------*/ |
| 52 | 54 | |
| 53 | 55 | static GtkWidget * toplevel = NULL; |
| 56 | + static GtkWidget * trace_window = NULL; | |
| 54 | 57 | static unsigned int syscolors = 16; |
| 55 | 58 | static const gchar * systype = NULL; |
| 56 | 59 | static const gchar * toggleset = NULL; |
| 57 | 60 | static const gchar * togglereset = NULL; |
| 58 | 61 | static const gchar * logfile = NULL; |
| 62 | + static const gchar * tracefile = NULL; | |
| 59 | 63 | |
| 60 | 64 | #ifdef HAVE_GTKMAC |
| 61 | 65 | GtkOSXApplication * osxapp = NULL; |
| ... | ... | @@ -255,6 +259,72 @@ static void g_logfile(const gchar *log_domain,GLogLevelFlags log_level,const gch |
| 255 | 259 | } |
| 256 | 260 | } |
| 257 | 261 | |
| 262 | +static void trace_window_destroy(GtkWidget *widget, H3270 *hSession) | |
| 263 | +{ | |
| 264 | + trace("%s",__FUNCTION__); | |
| 265 | + lib3270_set_toggle(hSession,LIB3270_TOGGLE_DS_TRACE,0); | |
| 266 | + lib3270_set_toggle(hSession,LIB3270_TOGGLE_SCREEN_TRACE,0); | |
| 267 | + lib3270_set_toggle(hSession,LIB3270_TOGGLE_EVENT_TRACE,0); | |
| 268 | + trace_window = NULL; | |
| 269 | +} | |
| 270 | + | |
| 271 | +static void g_trace(H3270 *hSession, const char *fmt, va_list args) | |
| 272 | +{ | |
| 273 | + gchar *ptr = g_strdup_vprintf(fmt,args); | |
| 274 | + | |
| 275 | + if(tracefile) | |
| 276 | + { | |
| 277 | + // Has trace file, use it | |
| 278 | + int err; | |
| 279 | + | |
| 280 | + FILE *out = fopen(tracefile,"a"); | |
| 281 | + err = errno; | |
| 282 | + | |
| 283 | + if(!out) | |
| 284 | + { | |
| 285 | + // Error opening trace file, notify user and disable it | |
| 286 | + GtkWidget *popup = gtk_message_dialog_new_with_markup( | |
| 287 | + GTK_WINDOW(pw3270_get_toplevel()), | |
| 288 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 289 | + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, | |
| 290 | + _( "Can't save trace data to file %s" ),tracefile); | |
| 291 | + | |
| 292 | + gtk_window_set_title(GTK_WINDOW(popup),_("Can't open file")); | |
| 293 | + | |
| 294 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",strerror(err)); | |
| 295 | + | |
| 296 | + gtk_dialog_run(GTK_DIALOG(popup)); | |
| 297 | + gtk_widget_destroy(popup); | |
| 298 | + | |
| 299 | + tracefile = NULL; | |
| 300 | + } | |
| 301 | + else | |
| 302 | + { | |
| 303 | + fprintf(out,"%s",ptr); | |
| 304 | + fclose(out); | |
| 305 | + } | |
| 306 | + } | |
| 307 | + else | |
| 308 | + { | |
| 309 | + // No trace file, open standard window | |
| 310 | + gchar * utftext = g_convert_with_fallback(ptr,-1,"UTF-8",lib3270_get_charset(hSession),"?",NULL,NULL,NULL); | |
| 311 | + | |
| 312 | + if(!trace_window) | |
| 313 | + { | |
| 314 | + trace_window = pw3270_trace_new(); | |
| 315 | + pw3270_trace_set_destroy_on_close(trace_window,TRUE); | |
| 316 | + g_signal_connect(trace_window, "destroy", G_CALLBACK(trace_window_destroy), hSession); | |
| 317 | + gtk_window_set_default_size(GTK_WINDOW(trace_window),590,430); | |
| 318 | + gtk_window_set_attached_to(GTK_WINDOW(trace_window),toplevel); | |
| 319 | + gtk_widget_show(trace_window); | |
| 320 | + } | |
| 321 | + pw3270_trace_printf(trace_window,"%s",utftext); | |
| 322 | + g_free(utftext); | |
| 323 | + } | |
| 324 | + | |
| 325 | + g_free(ptr); | |
| 326 | +} | |
| 327 | + | |
| 258 | 328 | int main(int argc, char *argv[]) |
| 259 | 329 | { |
| 260 | 330 | static const gchar * session_name = PACKAGE_NAME; |
| ... | ... | @@ -333,7 +403,8 @@ int main(int argc, char *argv[]) |
| 333 | 403 | #if defined( HAVE_SYSLOG ) |
| 334 | 404 | { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL }, |
| 335 | 405 | #endif |
| 336 | - { "log", 'L', 0, G_OPTION_ARG_STRING, &logfile, N_( "Log to file" ), NULL }, | |
| 406 | + { "tracefile", 'T', 0, G_OPTION_ARG_FILENAME, &tracefile, N_( "Set trace filename" ), NULL }, | |
| 407 | + { "log", 'L', 0, G_OPTION_ARG_FILENAME, &logfile, N_( "Log to file" ), NULL }, | |
| 337 | 408 | |
| 338 | 409 | { NULL } |
| 339 | 410 | }; |
| ... | ... | @@ -388,6 +459,8 @@ int main(int argc, char *argv[]) |
| 388 | 459 | g_log_set_default_handler(g_logfile,NULL); |
| 389 | 460 | } |
| 390 | 461 | |
| 462 | + lib3270_set_trace_handler(g_trace); | |
| 463 | + | |
| 391 | 464 | } |
| 392 | 465 | |
| 393 | 466 | { |
| ... | ... | @@ -482,6 +555,9 @@ int main(int argc, char *argv[]) |
| 482 | 555 | |
| 483 | 556 | gtk_main(); |
| 484 | 557 | |
| 558 | + if(trace_window) | |
| 559 | + gtk_widget_destroy(trace_window); | |
| 560 | + | |
| 485 | 561 | pw3270_stop_plugins(toplevel); |
| 486 | 562 | pw3270_deinit_plugins(); |
| 487 | 563 | ... | ... |
src/pw3270/trace.c
| ... | ... | @@ -36,7 +36,7 @@ |
| 36 | 36 | #include <glib/gi18n.h> |
| 37 | 37 | |
| 38 | 38 | #include <pw3270/trace.h> |
| 39 | - #include <lib3270/log.h> | |
| 39 | + #include "common/common.h" | |
| 40 | 40 | |
| 41 | 41 | #if defined( HAVE_SYSLOG ) |
| 42 | 42 | #include <syslog.h> |
| ... | ... | @@ -119,12 +119,6 @@ static void destroy(GtkObject *widget) |
| 119 | 119 | if(hwnd->enabled) |
| 120 | 120 | *hwnd->enabled = FALSE; |
| 121 | 121 | |
| 122 | -#if GTK_CHECK_VERSION(3,0,0) | |
| 123 | - GTK_WIDGET_CLASS(pw3270_trace_parent_class)->destroy(widget); | |
| 124 | -#else | |
| 125 | - GTK_OBJECT_CLASS(pw3270_trace_parent_class)->destroy(widget); | |
| 126 | -#endif // GTK3 | |
| 127 | - | |
| 128 | 122 | } |
| 129 | 123 | |
| 130 | 124 | static gboolean delete_event(GtkWidget *widget, GdkEventAny *event) |
| ... | ... | @@ -327,9 +321,13 @@ static void destroy(GtkObject *widget) |
| 327 | 321 | |
| 328 | 322 | static void pw3270_trace_init(pw3270_trace *window) |
| 329 | 323 | { |
| 330 | - GtkWidget *widget; | |
| 331 | - GtkWidget *view; | |
| 332 | - GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); | |
| 324 | + GtkWidget * widget; | |
| 325 | + GtkWidget * view; | |
| 326 | + GtkWidget * vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); | |
| 327 | + gchar * fontname = get_string_from_config("trace", "fontname", "Monospace 8"); | |
| 328 | + PangoFontDescription * fontdesc = pango_font_description_from_string("Monospace 8"); | |
| 329 | + | |
| 330 | + g_free(fontname); | |
| 333 | 331 | |
| 334 | 332 | // Top menu |
| 335 | 333 | { |
| ... | ... | @@ -353,8 +351,16 @@ static void destroy(GtkObject *widget) |
| 353 | 351 | window->scroll = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(widget)); |
| 354 | 352 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); |
| 355 | 353 | view = gtk_text_view_new(); |
| 356 | - window->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); | |
| 354 | + | |
| 355 | +#if GTK_CHECK_VERSION(3,0,0) | |
| 356 | + gtk_widget_override_font(GTK_WIDGET(view), fontdesc); | |
| 357 | +#else | |
| 358 | + gtk_widget_modify_font(GTK_WIDGET(view), fontdesc); | |
| 359 | +#endif // GTK_CHECK_VERSION | |
| 360 | + | |
| 361 | + window->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); | |
| 357 | 362 | gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE); |
| 363 | + | |
| 358 | 364 | #if GTK_CHECK_VERSION(3,8,0) |
| 359 | 365 | gtk_container_add(GTK_CONTAINER(widget),view); |
| 360 | 366 | #else |
| ... | ... | @@ -383,6 +389,8 @@ static void destroy(GtkObject *widget) |
| 383 | 389 | |
| 384 | 390 | gtk_container_add(GTK_CONTAINER(window),vbox); |
| 385 | 391 | |
| 392 | + pango_font_description_free(fontdesc); | |
| 393 | + | |
| 386 | 394 | window->log_handler = g_log_set_handler(NULL,G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,(GLogFunc) glog,window); |
| 387 | 395 | trace("Log handler set to %d",window->log_handler); |
| 388 | 396 | ... | ... |
src/pw3270/v3270/mouse.c