From 981dd162807dd8490849dcc2ae67df9ea9e5cf37 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 22 Feb 2019 10:03:35 -0300 Subject: [PATCH] Refactoring test method. --- Makefile.in | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- src/hllapi/testprogram.c | 169 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/testprograms/hllapi.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/testprograms/ipc3270c.c | 248 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/testprograms/plugin.c | 248 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5 files changed, 485 insertions(+), 432 deletions(-) delete mode 100644 src/hllapi/testprogram.c create mode 100644 src/testprograms/hllapi.c create mode 100644 src/testprograms/ipc3270c.c delete mode 100644 src/testprograms/plugin.c diff --git a/Makefile.in b/Makefile.in index 9e8eaaf..760b6f0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -36,12 +36,25 @@ PLUGIN_SOURCES= \ $(wildcard src/$(PLUGIN_NAME)/@OSNAME@/*.rc) PLUGIN_TEST_SOURCES= \ - src/testprograms/plugin.c + src/testprograms/$(PLUGIN_NAME).c + +#---[ Library configuration ]------------------------------------------------------------ + +LIBRARY_NAME=hllapi + +LIBRARY_SOURCES= \ + $(wildcard src/$(LIBRARY_NAME)/*.c) \ + $(wildcard src/$(LIBRARY_NAME)/@OSNAME@/*.c) \ + $(wildcard src/$(LIBRARY_NAME)/@OSNAME@/*.rc) + +LIBRARY_TEST_SOURCES= \ + src/testprograms/$(LIBRARY_NAME).c #---[ Tools ]---------------------------------------------------------------------------- CC=@CC@ LD=@CC@ +CXX=@CXX@ LN_S=@LN_S@ MKDIR=@MKDIR_P@ INSTALL=@INSTALL@ @@ -190,7 +203,8 @@ all: \ $(POTDIR)/$(PLUGIN_NAME).pot Release: \ - $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@ + $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@ \ + $(BINRLS)/lib$(LIBRARY_NAME)@DLLEXT@ $(BINRLS)/$(PLUGIN_NAME)@DLLEXT@: \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) @@ -240,36 +254,41 @@ run-plugin: \ $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@ -#---[ Debug Targets ]-------------------------------------------------------------------- +run-library: \ + $(BINDBG)/$(LIBRARY_NAME)@DLLEXT@ \ + $(BINDBG)/$(LIBRARY_NAME)@EXEEXT@ -Debug: \ - $(BINDBG)/$(PLUGIN_NAME)@DLLEXT@ \ - $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@ + $(BINDBG)/$(LIBRARY_NAME)@EXEEXT@ -$(BINDBG)/lib$(PLUGIN_NAME).a: \ - $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) +#---[ Debug Targets ]-------------------------------------------------------------------- - @$(MKDIR) $(@D) - @echo $< ... +Debug: \ + Debug-plugin \ + Debug-library - @$(AR) rcs $@ $^ +Debug-plugin: \ + $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@ +Debug-library: \ + $(BINDBG)/$(LIBRARY_NAME)@EXEEXT@ $(BINDBG)/$(PLUGIN_NAME)@EXEEXT@: \ - $(foreach SRC, $(basename $(PLUGIN_TEST_SOURCES)), $(OBJDBG)/$(SRC).o) + $(foreach SRC, $(basename $(PLUGIN_TEST_SOURCES)), $(OBJDBG)/$(SRC).o) \ + $(BINDBG)/$(PLUGIN_NAME)@DLLEXT@ @$(MKDIR) $(@D) @echo $< ... @$(LD) \ -o $@ \ - $^ \ + $(foreach SRC, $(basename $(PLUGIN_TEST_SOURCES)), $(OBJDBG)/$(SRC).o) \ -L$(BINDBG) \ -Wl,-rpath,$(BINDBG) \ $(LDFLAGS) \ $(LIBS) \ $(V3270_LIBS) \ $(GTK_LIBS) \ - $(GLIB_LIBS) + $(GLIB_LIBS) \ + $(DBUS_LIBS) $(BINDBG)/$(PLUGIN_NAME)@DLLEXT@: \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) @@ -279,14 +298,48 @@ $(BINDBG)/$(PLUGIN_NAME)@DLLEXT@: \ @$(LD) \ -shared -Wl,-soname,$(@F) \ -o $@ \ - $(LDFLAGS) \ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ + $(LDFLAGS) \ -L$(BINDBG) \ + $(LIBS) \ $(V3270_LIBS) \ + $(GTK_LIBS) \ + $(GLIB_LIBS) \ + $(DBUS_LIBS) + +$(BINDBG)/$(LIBRARY_NAME)@EXEEXT@: \ + $(foreach SRC, $(basename $(LIBRARY_TEST_SOURCES)), $(OBJDBG)/$(SRC).o) \ + $(BINDBG)/lib$(LIBRARY_NAME)@DLLEXT@ + + @$(MKDIR) $(@D) + @echo $< ... + @$(CXX) \ + -o $@ \ + $(foreach SRC, $(basename $(LIBRARY_TEST_SOURCES)), $(OBJDBG)/$(SRC).o) \ + -Wl,-rpath,$(BINDBG) \ + $(LDFLAGS) \ + -L$(BINDBG) \ + -l$(LIBRARY_NAME) \ $(LIBS) \ + $(V3270_LIBS) \ $(GTK_LIBS) \ + $(GLIB_LIBS) \ $(DBUS_LIBS) +$(BINDBG)/lib$(LIBRARY_NAME)@DLLEXT@: \ + $(foreach SRC, $(basename $(LIBRARY_SOURCES)), $(OBJDBG)/$(SRC).o) + + @$(MKDIR) $(@D) + @echo $< ... + @$(CXX) \ + -shared -Wl,-soname,$(@F) \ + -o $@ \ + $(LDFLAGS) \ + $(foreach SRC, $(basename $(LIBRARY_SOURCES)), $(OBJDBG)/$(SRC).o) \ + -lpw3270cpp \ + -L$(BINDBG) \ + $(LIBS) \ + $(DBUS_LIBS) #---[ Clean Targets ]-------------------------------------------------------------------- diff --git a/src/hllapi/testprogram.c b/src/hllapi/testprogram.c deleted file mode 100644 index d5b1917..0000000 --- a/src/hllapi/testprogram.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA, 02111-1307, USA - * - * Este programa está nomeado como testprogram.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - #include - #include - #include - #include - - #if defined(DEBUG) && defined(_WIN32) - #undef trace - #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } - #endif // DEBUG - - #define MAX_DATA_SIZE 8000 //< Maximum data size for this application. - - static CHAR hllapi_data[MAX_DATA_SIZE]; - -/*---[ Implement ]--------------------------------------------------------------------------------*/ - - static void connect_ps(const char *session) - { - WORD len; - WORD fn = HLLAPI_CMD_CONNECTPS; - WORD rc = 0; - - strncpy(hllapi_data,session,MAX_DATA_SIZE); - - len = strlen(session); - hllapi(&fn,hllapi_data,&len,&rc); - - /* - if(rc) - { - trace("HLLAPI_CMD_CONNECTPS(%s) exits with rc=%d", session, (int) rc); - } - */ - - } - - int main(int numpar, char *param[]) - { - const char *session = "pw3270:A"; - - connect_ps(session); - - /* - - printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); - printf("revision=%d\n",(int) hllapi_get_revision()); - printf("connect=%d\n",(int) hllapi_connect((char *) "fandezhi.efglobe.com:23",1)); - printf("wait_for_ready=%d\n",(int) hllapi_wait_for_ready(10)); - printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); - -// printf("disconnect=%d\n",(int) hllapi_disconnect()); - - - printf("deinit=%d\n",(int) hllapi_deinit()); - - DWORD revision; - int rc; - - rc = hllapi_init(""); - if(rc) - { - printf("Init exits with rc=%d\n",rc); - return rc; - } - - if(!hllapi_get_revision(&revision)) - printf("Library revision is %d\n",(int) revision); - - - printf("Deinit exits with rc=%d\n",rc); - rc = hllapi_deinit(); -*/ - return 0; - } - -/* - int main(int numpar, char *param[]) - { - char buffer[BUFFER_LENGTH]; - unsigned short rc; - unsigned short len; - unsigned long fn; - - static const struct _cmd - { - const char * name; - unsigned short fn; - const char * arg; - } cmd[] = - { - { "GetRevision", HLLAPI_CMD_GETREVISION, " " }, - { "ConnectPS", HLLAPI_CMD_CONNECTPS, "pw3270A" }, - { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, - - }; - - int f; - - - for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) - { - len = strlen(cmd[f].arg); - memcpy(buffer,cmd[f].arg,len); - hllapi((LPWORD) &cmd[f].fn,buffer,&len,&rc); - printf("%s exits with rc=%d\n[%s]\n",cmd[f].name,rc,buffer); - } - - len = 80; - rc = 1040; - fn = HLLAPI_CMD_COPYPSTOSTR; - hllapi((LPWORD) &fn,buffer,&len,&rc); - printf("%s exits with rc=%d\n%s\n","HLLAPI_CMD_COPYPSTOSTR",rc,buffer); - - // Performance - len = strlen(cmd[0].arg); - memcpy(buffer,cmd[0].arg,len); - if(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0) - { - time_t end = time(0) + 5; - int qtd = 0; - do - { - qtd++; - } while(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0 && time(0) + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como testprogram.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + #include + #include + + #if defined(DEBUG) && defined(_WIN32) + #undef trace + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } } + #endif // DEBUG + + #define MAX_DATA_SIZE 8000 //< Maximum data size for this application. + + static CHAR hllapi_data[MAX_DATA_SIZE]; + +/*---[ Implement ]--------------------------------------------------------------------------------*/ + + static void connect_ps(const char *session) + { + WORD len; + WORD fn = HLLAPI_CMD_CONNECTPS; + WORD rc = 0; + + strncpy(hllapi_data,session,MAX_DATA_SIZE); + + len = strlen(session); + hllapi(&fn,hllapi_data,&len,&rc); + + /* + if(rc) + { + trace("HLLAPI_CMD_CONNECTPS(%s) exits with rc=%d", session, (int) rc); + } + */ + + } + + int main(int numpar, char *param[]) + { + const char *session = "pw3270:A"; + + connect_ps(session); + + /* + + printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session)); + printf("revision=%d\n",(int) hllapi_get_revision()); + printf("connect=%d\n",(int) hllapi_connect((char *) "fandezhi.efglobe.com:23",1)); + printf("wait_for_ready=%d\n",(int) hllapi_wait_for_ready(10)); + printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No"); + +// printf("disconnect=%d\n",(int) hllapi_disconnect()); + + + printf("deinit=%d\n",(int) hllapi_deinit()); + + DWORD revision; + int rc; + + rc = hllapi_init(""); + if(rc) + { + printf("Init exits with rc=%d\n",rc); + return rc; + } + + if(!hllapi_get_revision(&revision)) + printf("Library revision is %d\n",(int) revision); + + + printf("Deinit exits with rc=%d\n",rc); + rc = hllapi_deinit(); +*/ + return 0; + } + +/* + int main(int numpar, char *param[]) + { + char buffer[BUFFER_LENGTH]; + unsigned short rc; + unsigned short len; + unsigned long fn; + + static const struct _cmd + { + const char * name; + unsigned short fn; + const char * arg; + } cmd[] = + { + { "GetRevision", HLLAPI_CMD_GETREVISION, " " }, + { "ConnectPS", HLLAPI_CMD_CONNECTPS, "pw3270A" }, + { "InputString", HLLAPI_CMD_INPUTSTRING, "test" }, + + }; + + int f; + + + for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++) + { + len = strlen(cmd[f].arg); + memcpy(buffer,cmd[f].arg,len); + hllapi((LPWORD) &cmd[f].fn,buffer,&len,&rc); + printf("%s exits with rc=%d\n[%s]\n",cmd[f].name,rc,buffer); + } + + len = 80; + rc = 1040; + fn = HLLAPI_CMD_COPYPSTOSTR; + hllapi((LPWORD) &fn,buffer,&len,&rc); + printf("%s exits with rc=%d\n%s\n","HLLAPI_CMD_COPYPSTOSTR",rc,buffer); + + // Performance + len = strlen(cmd[0].arg); + memcpy(buffer,cmd[0].arg,len); + if(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0) + { + time_t end = time(0) + 5; + int qtd = 0; + do + { + qtd++; + } while(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0 && time(0) + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como testprogram.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + + /** + * @brief Test program for pw3270 HLLAPI compatibility plugin. + * + */ + + #include + #include + #include + #include + #include + #include + #include + + /*---[ Globals ]------------------------------------------------------------------------------------*/ + + const gchar * plugin_path = ".bin/Debug"; + const gchar * session_name = "pw3270"; + const gchar * plugin_name = "ipc3270c." G_MODULE_SUFFIX; + + /*---[ Implement ]----------------------------------------------------------------------------------*/ + + static void close_module(GtkWidget *widget, GModule *module) + { + g_message("Closing module %p",module); + + static void (*stop)(GtkWidget *window, GtkWidget *terminal) = NULL; + if(!g_module_symbol(module,"pw3270_plugin_stop",(void **) &stop)) + { + g_message("Can't get stop method from plugin: %s",g_module_error()); + } + else + { + stop(gtk_widget_get_toplevel(widget),widget); + } + + g_module_close(module); + g_message("Module %p was closed",module); + } + + static void toggle_ds_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_DS_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_event_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_EVENT_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_ssl_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_SSL_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_screen_trace(GtkToggleToolButton *button, GtkWidget *terminal) + { + v3270_set_toggle(terminal,LIB3270_TOGGLE_SCREEN_TRACE,gtk_toggle_tool_button_get_active(button)); + } + + static void toggle_started_trace(GtkToggleToolButton *button, GModule *module) + { + if(!module) + return; + + GtkWidget * terminal = GTK_WIDGET(g_object_get_data(G_OBJECT(button),"terminal")); + + const gchar * method_name = (gtk_toggle_tool_button_get_active(button) ? "pw3270_plugin_start" : "pw3270_plugin_stop"); + + static void (*call)(GtkWidget *window, GtkWidget *terminal) = NULL; + if(!g_module_symbol(module,method_name,(void **) &call)) + { + g_message("Can't get method \"%s\": %s",method_name,g_module_error()); + return; + } + + g_message("Calling %s",method_name); + call(gtk_widget_get_toplevel(terminal), GTK_WIDGET(terminal)); + + } + + static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, const gchar *tooltip, GCallback callback) + { + GtkToolItem * item = gtk_toggle_tool_button_new(); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); + + g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); + + if(tooltip) + gtk_widget_set_tooltip_text(GTK_WIDGET(item),tooltip); + + return item; + } + + static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { + + GtkWidget * window = gtk_application_window_new(app); + GtkWidget * terminal = v3270_new(); + GtkWidget * notebook = gtk_notebook_new(); + GModule * module = NULL; + + gtk_widget_set_name(window,session_name); + + // Setup tabs + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new(v3270_get_session_name(terminal))); + + // Load plugin + { + g_autofree gchar * plugin = g_build_filename(plugin_path,plugin_name,NULL); + + g_message("Loading %s",plugin); + + module = g_module_open(plugin,G_MODULE_BIND_LOCAL); + + if(module) + { + g_signal_connect (terminal, "destroy", G_CALLBACK(close_module), module); + } + else + { + g_message("Can't open \"%s\": %s",plugin,g_module_error()); + gtk_main_quit(); + } + + } + // Create trace window + { + GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); + GtkWidget * trace = v3270_trace_new(terminal); + GtkWidget * toolbar = gtk_toolbar_new(); + GtkToolItem * start = gtk_toggle_tool_button_new(); + + gtk_widget_set_sensitive(GTK_WIDGET(start),module != NULL); + + g_object_set_data(G_OBJECT(start),"terminal",terminal); + + gtk_tool_button_set_label(GTK_TOOL_BUTTON(start),"Enable"); + g_signal_connect(GTK_WIDGET(start), "toggled", G_CALLBACK(toggle_started_trace), module); + gtk_widget_set_tooltip_text(GTK_WIDGET(start),"Start/Stop plugin module"); + + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), start, -1); + + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),gtk_separator_tool_item_new(),-1); + + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "DS Trace","Toggle DS Trace",G_CALLBACK(toggle_ds_trace)),-1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Event Trace","Toggle Event Trace",G_CALLBACK(toggle_event_trace)),-1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Screen Trace","Toggle Screen Trace",G_CALLBACK(toggle_screen_trace)),-1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "SSL Trace","Toggle SSL Trace",G_CALLBACK(toggle_ssl_trace)),-1); + + gtk_box_pack_start(GTK_BOX(box),toolbar,FALSE,FALSE,0); + gtk_box_pack_start(GTK_BOX(box),trace,TRUE,TRUE,0); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),box,gtk_label_new("Trace")); + } + + // Setup and show main window + gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); + gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); + gtk_container_add(GTK_CONTAINER(window),notebook); + gtk_widget_show_all (window); + + // Setup title. + const gchar *url = lib3270_get_url(v3270_get_session(terminal)); + if(url) { + + v3270_set_url(terminal,url); + v3270_reconnect(terminal); + + gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url); + gtk_window_set_title(GTK_WINDOW(window), title); + g_free(title); + + } else { + + gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal)); + + } + +} + +int main (int argc, char **argv) { + + /* + GVariantBuilder builder; + + g_variant_builder_init(&builder,G_VARIANT_TYPE("(isi)")); + + g_variant_builder_add(&builder, "i", 10); + g_variant_builder_add(&builder, "s", "teste"); + g_variant_builder_add(&builder, "i", 20); + + GVariant *value = g_variant_builder_end(&builder); + + size_t szPacket = 0; + g_autofree unsigned char * buffer = ipc3270_pack("teste", value, &szPacket); + g_variant_unref(value); + + debug("Package \"%s\" was created with %u bytes", buffer, (unsigned int) szPacket); + + value = ipc3270_unpack(buffer); + + g_variant_unref(value); + */ + + GtkApplication *app; + int status; + + app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); + + g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); + + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + g_message("rc=%d",status); + return status; + +} + diff --git a/src/testprograms/plugin.c b/src/testprograms/plugin.c deleted file mode 100644 index b3918c2..0000000 --- a/src/testprograms/plugin.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob - * o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como testprogram.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - - /** - * @brief Test program for pw3270 HLLAPI compatibility plugin. - * - */ - - #include - #include - #include - #include - #include - #include - #include - - /*---[ Globals ]------------------------------------------------------------------------------------*/ - - const gchar * plugin_path = ".bin/Debug"; - const gchar * session_name = "pw3270"; - const gchar * plugin_name = "ipc3270c." G_MODULE_SUFFIX; - - /*---[ Implement ]----------------------------------------------------------------------------------*/ - - static void close_module(GtkWidget *widget, GModule *module) - { - g_message("Closing module %p",module); - - static void (*stop)(GtkWidget *window, GtkWidget *terminal) = NULL; - if(!g_module_symbol(module,"pw3270_plugin_stop",(void **) &stop)) - { - g_message("Can't get stop method from plugin: %s",g_module_error()); - } - else - { - stop(gtk_widget_get_toplevel(widget),widget); - } - - g_module_close(module); - g_message("Module %p was closed",module); - } - - static void toggle_ds_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_DS_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_event_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_EVENT_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_ssl_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_SSL_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_screen_trace(GtkToggleToolButton *button, GtkWidget *terminal) - { - v3270_set_toggle(terminal,LIB3270_TOGGLE_SCREEN_TRACE,gtk_toggle_tool_button_get_active(button)); - } - - static void toggle_started_trace(GtkToggleToolButton *button, GModule *module) - { - if(!module) - return; - - GtkWidget * terminal = GTK_WIDGET(g_object_get_data(G_OBJECT(button),"terminal")); - - const gchar * method_name = (gtk_toggle_tool_button_get_active(button) ? "pw3270_plugin_start" : "pw3270_plugin_stop"); - - static void (*call)(GtkWidget *window, GtkWidget *terminal) = NULL; - if(!g_module_symbol(module,method_name,(void **) &call)) - { - g_message("Can't get method \"%s\": %s",method_name,g_module_error()); - return; - } - - g_message("Calling %s",method_name); - call(gtk_widget_get_toplevel(terminal), GTK_WIDGET(terminal)); - - } - - static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, const gchar *tooltip, GCallback callback) - { - GtkToolItem * item = gtk_toggle_tool_button_new(); - gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); - - g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); - - if(tooltip) - gtk_widget_set_tooltip_text(GTK_WIDGET(item),tooltip); - - return item; - } - - static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { - - GtkWidget * window = gtk_application_window_new(app); - GtkWidget * terminal = v3270_new(); - GtkWidget * notebook = gtk_notebook_new(); - GModule * module = NULL; - - gtk_widget_set_name(window,session_name); - - // Setup tabs - gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new(v3270_get_session_name(terminal))); - - // Load plugin - { - g_autofree gchar * plugin = g_build_filename(plugin_path,plugin_name,NULL); - - g_message("Loading %s",plugin); - - module = g_module_open(plugin,G_MODULE_BIND_LOCAL); - - if(module) - { - g_signal_connect (terminal, "destroy", G_CALLBACK(close_module), module); - } - else - { - g_message("Can't open \"%s\": %s",plugin,g_module_error()); - gtk_main_quit(); - } - - } - // Create trace window - { - GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); - GtkWidget * trace = v3270_trace_new(terminal); - GtkWidget * toolbar = gtk_toolbar_new(); - GtkToolItem * start = gtk_toggle_tool_button_new(); - - gtk_widget_set_sensitive(GTK_WIDGET(start),module != NULL); - - g_object_set_data(G_OBJECT(start),"terminal",terminal); - - gtk_tool_button_set_label(GTK_TOOL_BUTTON(start),"Enable"); - g_signal_connect(GTK_WIDGET(start), "toggled", G_CALLBACK(toggle_started_trace), module); - gtk_widget_set_tooltip_text(GTK_WIDGET(start),"Start/Stop plugin module"); - - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), start, -1); - - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),gtk_separator_tool_item_new(),-1); - - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "DS Trace","Toggle DS Trace",G_CALLBACK(toggle_ds_trace)),-1); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Event Trace","Toggle Event Trace",G_CALLBACK(toggle_event_trace)),-1); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "Screen Trace","Toggle Screen Trace",G_CALLBACK(toggle_screen_trace)),-1); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar),create_tool_item(terminal, "SSL Trace","Toggle SSL Trace",G_CALLBACK(toggle_ssl_trace)),-1); - - gtk_box_pack_start(GTK_BOX(box),toolbar,FALSE,FALSE,0); - gtk_box_pack_start(GTK_BOX(box),trace,TRUE,TRUE,0); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook),box,gtk_label_new("Trace")); - } - - // Setup and show main window - gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); - gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); - gtk_container_add(GTK_CONTAINER(window),notebook); - gtk_widget_show_all (window); - - // Setup title. - const gchar *url = lib3270_get_url(v3270_get_session(terminal)); - if(url) { - - v3270_set_url(terminal,url); - v3270_reconnect(terminal); - - gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url); - gtk_window_set_title(GTK_WINDOW(window), title); - g_free(title); - - } else { - - gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal)); - - } - -} - -int main (int argc, char **argv) { - - /* - GVariantBuilder builder; - - g_variant_builder_init(&builder,G_VARIANT_TYPE("(isi)")); - - g_variant_builder_add(&builder, "i", 10); - g_variant_builder_add(&builder, "s", "teste"); - g_variant_builder_add(&builder, "i", 20); - - GVariant *value = g_variant_builder_end(&builder); - - size_t szPacket = 0; - g_autofree unsigned char * buffer = ipc3270_pack("teste", value, &szPacket); - g_variant_unref(value); - - debug("Package \"%s\" was created with %u bytes", buffer, (unsigned int) szPacket); - - value = ipc3270_unpack(buffer); - - g_variant_unref(value); - */ - - GtkApplication *app; - int status; - - app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); - - g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); - - status = g_application_run (G_APPLICATION (app), argc, argv); - g_object_unref (app); - - g_message("rc=%d",status); - return status; - -} - -- libgit2 0.21.2