Commit b9822c0d8eead0386c63dbf1538931484fc3646d

Authored by Perry Werneck
1 parent 4a8d41f5
Exists in master and in 1 other branch develop

Coding the new IPC interface with common code for windows and linux.

pw3270-plugin-ipc.cbp
@@ -32,11 +32,15 @@ @@ -32,11 +32,15 @@
32 </Build> 32 </Build>
33 <Compiler> 33 <Compiler>
34 <Add option="-Wall" /> 34 <Add option="-Wall" />
35 - <Add option="`pkg-config --cflags gtk+-3.0 lib3270 v3270`" /> 35 + <Add option="`pkg-config --cflags gtk+-3.0 lib3270 v3270 gio-2.0`" />
36 </Compiler> 36 </Compiler>
37 <Linker> 37 <Linker>
38 - <Add option="`pkg-config --libs gtk+-3.0 lib3270 v3270`" /> 38 + <Add option="`pkg-config --libs gtk+-3.0 lib3270 v3270 gio-2.0 dbus-1 dbus-glib-1`" />
39 </Linker> 39 </Linker>
  40 + <Unit filename="src/linux/start.c">
  41 + <Option compilerVar="CC" />
  42 + </Unit>
  43 + <Unit filename="src/private.h" />
40 <Unit filename="src/testprogram/testprogram.c"> 44 <Unit filename="src/testprogram/testprogram.c">
41 <Option compilerVar="CC" /> 45 <Option compilerVar="CC" />
42 </Unit> 46 </Unit>
src/linux/start.c 0 → 100644
@@ -0,0 +1,178 @@ @@ -0,0 +1,178 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob
  5 + * o nome G3270.
  6 + *
  7 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  8 + *
  9 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  10 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  11 + * Free Software Foundation.
  12 + *
  13 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  14 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  15 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  16 + * obter mais detalhes.
  17 + *
  18 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  19 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  20 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  21 + *
  22 + * Este programa está nomeado como testprogram.c e possui - linhas de código.
  23 + *
  24 + * Contatos:
  25 + *
  26 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  27 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  28 + *
  29 + */
  30 +
  31 +
  32 + /**
  33 + * @brief Plugin startup/stop for linux.
  34 + *
  35 + */
  36 +
  37 + #include "../private.h"
  38 +
  39 + #ifndef _WIN32
  40 +
  41 + #include <dbus/dbus-glib.h>
  42 + #include <dbus/dbus-glib-bindings.h>
  43 +
  44 + static void pw3270_dbus_cleanup(struct DBusSession * dBus) {
  45 +
  46 + if(dBus->proxy) {
  47 + g_object_unref(dBus);
  48 + }
  49 +
  50 + }
  51 +
  52 + int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) {
  53 +
  54 + struct DBusSession * dBus = g_new0(struct DBusSession,1);
  55 + GError * error = NULL;
  56 + int id;
  57 +
  58 + g_object_set_data_full(G_OBJECT(terminal), "dbus-session-info", dBus, (GDestroyNotify) pw3270_dbus_cleanup);
  59 +
  60 + dBus->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
  61 +
  62 + if(error) {
  63 + GtkWidget *dialog = gtk_message_dialog_new(
  64 + GTK_WINDOW(window),
  65 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  66 + GTK_MESSAGE_ERROR,
  67 + GTK_BUTTONS_OK,
  68 + _( "Can't get D-Bus connection" ));
  69 +
  70 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
  71 + g_error_free(error);
  72 +
  73 + gtk_dialog_run(GTK_DIALOG(dialog));
  74 + gtk_widget_destroy(dialog);
  75 +
  76 + return -1;
  77 + }
  78 +
  79 + g_dbus_connection_set_exit_on_close(dBus->connection,FALSE);
  80 +
  81 + /*
  82 + dBus->proxy = g_dbus_proxy_new_sync(
  83 + dBus->connection,
  84 + G_DBUS_PROXY_FLAGS_NONE,
  85 + NULL, // GDBusInterfaceInfo
  86 + "br.com.bb." PACKAGE_NAME, // name
  87 + "/br/com/bb/" PACKAGE_NAME "/terminal", // object path
  88 + "br.com.bb." PACKAGE_NAME ".terminal", // interface
  89 + NULL, // GCancellable
  90 + &error );
  91 +
  92 + if(error) {
  93 +
  94 + GtkWidget *dialog = gtk_message_dialog_new(
  95 + GTK_WINDOW(window),
  96 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  97 + GTK_MESSAGE_ERROR,
  98 + GTK_BUTTONS_OK,
  99 + _( "Can't get D-Bus proxy object" ));
  100 +
  101 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
  102 + g_error_free(error);
  103 +
  104 + gtk_dialog_run(GTK_DIALOG(dialog));
  105 + gtk_widget_destroy(dialog);
  106 +
  107 + return -1;
  108 + }
  109 + */
  110 +
  111 + for(id='a'; id < 'z' && !error && !dBus->proxy; id++) {
  112 +
  113 + gchar *name = g_strdup_printf("br.com.bb.%s.%c",gtk_widget_get_name(window),id);
  114 +
  115 + debug("Requesting \"%s\"",name);
  116 +
  117 + // https://dbus.freedesktop.org/doc/dbus-specification.html
  118 + GVariant * response =
  119 + g_dbus_connection_call_sync (
  120 + dBus->connection,
  121 + DBUS_SERVICE_DBUS,
  122 + DBUS_PATH_DBUS,
  123 + DBUS_INTERFACE_DBUS,
  124 + "RequestName",
  125 + g_variant_new ("(su)", name, DBUS_NAME_FLAG_DO_NOT_QUEUE),
  126 + NULL,
  127 + G_DBUS_CALL_FLAGS_NONE,
  128 + -1,
  129 + NULL,
  130 + &error
  131 + );
  132 +
  133 + if(error) {
  134 + g_message("Can't request \"%s\": %s",name,error->message);
  135 + g_error_free(error);
  136 + error = NULL;
  137 + }
  138 +
  139 + if(response) {
  140 +
  141 + guint32 reply = 0;
  142 + g_variant_get(response, "(u)", &reply);
  143 + g_variant_unref(response);
  144 +
  145 + if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
  146 +
  147 + dBus->proxy = g_dbus_proxy_new_sync(
  148 + dBus->connection,
  149 + G_DBUS_PROXY_FLAGS_NONE,
  150 + NULL, // GDBusInterfaceInfo
  151 + name, // name
  152 + "/br/com/bb/" PACKAGE_NAME "/terminal", // object path
  153 + "br.com.bb." PACKAGE_NAME ".terminal", // interface
  154 + NULL, // GCancellable
  155 + &error );
  156 +
  157 + gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id);
  158 + v3270_set_session_name(terminal, widget_name);
  159 + g_free(widget_name);
  160 +
  161 + g_message("Got %s - %s", name, v3270_get_session_name(terminal));
  162 +
  163 + }
  164 +
  165 + }
  166 +
  167 + g_free(name);
  168 +
  169 + }
  170 +
  171 +
  172 + return 0;
  173 +
  174 + }
  175 +
  176 + #endif // !_WIN32
  177 +
  178 +
src/private.h 0 → 100644
@@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270. Registro no INPI sob
  5 + * o nome G3270.
  6 + *
  7 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  8 + *
  9 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  10 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  11 + * Free Software Foundation.
  12 + *
  13 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  14 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  15 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  16 + * obter mais detalhes.
  17 + *
  18 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  19 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  20 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  21 + *
  22 + * Este programa está nomeado como - e possui - linhas de código.
  23 + *
  24 + * Contatos:
  25 + *
  26 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  27 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  28 + *
  29 + */
  30 +
  31 + /**
  32 + * @brief Private definitions for pw3270 IPC plugin.
  33 + *
  34 + */
  35 +
  36 +#ifndef PRIVATE_H_INCLUDED
  37 +
  38 + #define PRIVATE_H_INCLUDED
  39 +
  40 + #define PACKAGE_NAME "pw3270"
  41 +
  42 + #include <libintl.h>
  43 + #include <glib/gi18n.h>
  44 + #include <gtk/gtk.h>
  45 + #include <gio/gio.h>
  46 +
  47 + #include <v3270.h>
  48 +
  49 + #ifdef _WIN32
  50 +
  51 + #include <windows.h>
  52 +
  53 + #else
  54 +
  55 + G_GNUC_INTERNAL struct DBusSession {
  56 + GDBusConnection * connection;
  57 + GDBusProxy * proxy;
  58 + } dBus;
  59 +
  60 + #endif // _WIN32
  61 +
  62 + #ifdef DEBUG
  63 + #define debug( fmt, ... ) fprintf(stderr,"%s(%d) " fmt "\n", __FILE__, (int) __LINE__, __VA_ARGS__ ); fflush(stderr);
  64 + #else
  65 + #define debug(...) /* __VA_ARGS */
  66 + #endif
  67 +
  68 +
  69 + int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal);
  70 + int pw3270_plugin_stop(GtkWidget *window, GtkWidget *terminal);
  71 +
  72 +#endif // PRIVATE_H_INCLUDED
src/testprogram/testprogram.c
@@ -28,9 +28,13 @@ @@ -28,9 +28,13 @@
28 * 28 *
29 */ 29 */
30 30
31 - #include <v3270.h>  
32 - #include <v3270/filetransfer.h>  
33 - #include <v3270/ftprogress.h> 31 +
  32 + /**
  33 + * @brief Test program for pw3270 IPC plugin.
  34 + *
  35 + */
  36 +
  37 + #include "../private.h"
34 #include <stdlib.h> 38 #include <stdlib.h>
35 39
36 /*---[ Implement ]----------------------------------------------------------------------------------*/ 40 /*---[ Implement ]----------------------------------------------------------------------------------*/
@@ -39,7 +43,16 @@ static void activate(GtkApplication* app, gpointer user_data) { @@ -39,7 +43,16 @@ static void activate(GtkApplication* app, gpointer user_data) {
39 43
40 GtkWidget * window = gtk_application_window_new(app); 44 GtkWidget * window = gtk_application_window_new(app);
41 GtkWidget * terminal = v3270_new(); 45 GtkWidget * terminal = v3270_new();
42 - gchar * filename = NULL; 46 +
  47 + gtk_widget_set_name(window,"pw3270");
  48 +
  49 + // Setup and show window
  50 + gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  51 + gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);
  52 + gtk_container_add(GTK_CONTAINER(window),terminal);
  53 + gtk_widget_show_all (window);
  54 +
  55 + pw3270_plugin_start(window, terminal);
43 56
44 const gchar *url = getenv("LIB3270_DEFAULT_HOST"); 57 const gchar *url = getenv("LIB3270_DEFAULT_HOST");
45 if(url) { 58 if(url) {
@@ -56,12 +69,6 @@ static void activate(GtkApplication* app, gpointer user_data) { @@ -56,12 +69,6 @@ static void activate(GtkApplication* app, gpointer user_data) {
56 69
57 } 70 }
58 71
59 - // Setup and show window  
60 - gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);  
61 - gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);  
62 - gtk_container_add(GTK_CONTAINER(window),terminal);  
63 - gtk_widget_show_all (window);  
64 -  
65 } 72 }
66 73
67 int main (int argc, char **argv) { 74 int main (int argc, char **argv) {