Commit 1db1fe35a61bf676e0315766ea2d8eaeaa10f8a8

Authored by Perry Werneck
1 parent 442a6928
Exists in master and in 1 other branch develop

Updating IPC modules, working on IPC service.

pw3270-plugin-ipc.cbp
... ... @@ -71,6 +71,9 @@
71 71 <Option compilerVar="CC" />
72 72 </Unit>
73 73 <Unit filename="src/core/linux/gobject.h" />
  74 + <Unit filename="src/core/linux/start.c">
  75 + <Option compilerVar="CC" />
  76 + </Unit>
74 77 <Unit filename="src/core/methods.c">
75 78 <Option compilerVar="CC" />
76 79 </Unit>
... ... @@ -88,6 +91,9 @@
88 91 <Option compilerVar="CC" />
89 92 </Unit>
90 93 <Unit filename="src/core/windows/resources.rc" />
  94 + <Unit filename="src/core/windows/start.c">
  95 + <Option compilerVar="CC" />
  96 + </Unit>
91 97 <Unit filename="src/include/config.h" />
92 98 <Unit filename="src/include/config.h.in" />
93 99 <Unit filename="src/include/lib3270/ipc.h" />
... ...
src/core/linux/gobject.c
... ... @@ -76,73 +76,6 @@ GObject * ipc3270_new() {
76 76 return g_object_new(GLIB_TYPE_IPC3270, NULL);
77 77 }
78 78  
79   -static void
80   - method_call (
81   - G_GNUC_UNUSED GDBusConnection *connection,
82   - G_GNUC_UNUSED const gchar *sender,
83   - G_GNUC_UNUSED const gchar *object_path,
84   - G_GNUC_UNUSED const gchar *interface_name,
85   - const gchar *method_name,
86   - GVariant *parameters,
87   - GDBusMethodInvocation *invocation,
88   - gpointer user_data) {
89   -
90   - g_autoptr (GError) error = NULL;
91   -
92   - GVariant * rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error);
93   -
94   - if(error) {
95   -
96   - if(rc) {
97   - g_variant_unref(rc);
98   - }
99   -
100   - g_dbus_method_invocation_return_gerror(invocation, error);
101   -
102   - } else if(rc) {
103   -
104   - g_dbus_method_invocation_return_value(invocation, rc);
105   -
106   - } else {
107   -
108   - g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call");
109   -
110   - }
111   -
112   -
113   -}
114   -
115   -static GVariant *
116   - get_property (
117   - G_GNUC_UNUSED GDBusConnection *connection,
118   - G_GNUC_UNUSED const gchar *sender,
119   - G_GNUC_UNUSED const gchar *object_path,
120   - G_GNUC_UNUSED const gchar *interface_name,
121   - const gchar *property_name,
122   - GError **error,
123   - gpointer user_data)
124   -{
125   -
126   - return ipc3270_get_property(G_OBJECT(user_data), property_name, error);
127   -
128   -}
129   -
130   -static gboolean
131   - set_property (
132   - G_GNUC_UNUSED GDBusConnection *connection,
133   - G_GNUC_UNUSED const gchar *sender,
134   - G_GNUC_UNUSED const gchar *object_path,
135   - G_GNUC_UNUSED const gchar *interface_name,
136   - const gchar *property_name,
137   - GVariant *value,
138   - GError **error,
139   - gpointer user_data)
140   -{
141   -
142   - return ipc3270_set_property(G_OBJECT(user_data), property_name, value, error);
143   -
144   -}
145   -
146 79 void ipc3270_add_terminal_introspection(GString *introspection) {
147 80  
148 81 size_t ix;
... ... @@ -239,104 +172,11 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
239 172  
240 173 }
241 174  
242   -void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) {
243   -
244   - char id;
245   - int ix;
246   -
247   - static const GDBusInterfaceVTable interface_vtable = {
248   - method_call,
249   - get_property,
250   - set_property
251   - };
  175 +void ipc3270_set_session(GObject *object, H3270 *hSession) {
252 176  
253 177 ipc3270 * ipc = IPC3270(object);
254 178 ipc->hSession = hSession;
255 179  
256   - ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
257   - if(*error) {
258   - g_message("Can't get session bus: %s",(*error)->message);
259   - return;
260   - }
261   -
262   - g_dbus_connection_set_exit_on_close(ipc->connection,FALSE);
263   -
264   - for(id='a'; id < 'z' && !ipc->id && !*error; id++) {
265   -
266   - gchar *object_name = g_strdup_printf("br.com.bb.%s.%c",name,id);
267   -
268   - debug("Requesting \"%s\"",object_name);
269   -
270   - // https://dbus.freedesktop.org/doc/dbus-specification.html
271   - GError *err = NULL;
272   -
273   - GVariant * response =
274   - g_dbus_connection_call_sync (
275   - ipc->connection,
276   - DBUS_SERVICE_DBUS,
277   - DBUS_PATH_DBUS,
278   - DBUS_INTERFACE_DBUS,
279   - "RequestName",
280   - g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE),
281   - NULL,
282   - G_DBUS_CALL_FLAGS_NONE,
283   - -1,
284   - NULL,
285   - &err
286   - );
287   -
288   - if(err) {
289   - g_message("Can't request \"%s\": %s",object_name,err->message);
290   - g_error_free(err);
291   - err = NULL;
292   - }
293   -
294   - if(response) {
295   -
296   - guint32 reply = 0;
297   - g_variant_get(response, "(u)", &reply);
298   - g_variant_unref(response);
299   -
300   - if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
301   -
302   - g_message("Got %s", object_name);
303   -
304   - lib3270_set_session_id(ipc->hSession, id);
305   -
306   - // Introspection data for the service we are exporting
307   - GString * introspection = g_string_new("<node><interface name='br.com.bb.tn3270.session'>");
308   - ipc3270_add_terminal_introspection(introspection);
309   - g_string_append(introspection,"</interface></node>");
310   -
311   - gchar * introspection_xml = g_string_free(introspection,FALSE);
312   -
313   - debug("\n%s\n",introspection_xml);
314   -
315   - GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
316   -
317   - // Register object-id
318   - ipc->id = g_dbus_connection_register_object (
319   - ipc->connection,
320   - "/br/com/bb/tn3270",
321   - introspection_data->interfaces[0],
322   - &interface_vtable,
323   - ipc,
324   - NULL,
325   - error
326   - );
327   -
328   - g_dbus_node_info_unref(introspection_data);
329   - g_free(introspection_xml);
330   -
331   - break;
332   - }
333   -
334   - }
335   -
336   - g_free(object_name);
337   -
338   - }
339   -
340 180 }
341 181  
342 182 const gchar * ipc3270_get_display_charset(GObject *object) {
... ...
src/core/linux/start.c 0 → 100644
... ... @@ -0,0 +1,206 @@
  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.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como main.c e possui - linhas de código.
  22 + *
  23 + * Referências:
  24 + *
  25 + * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c
  26 + * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c
  27 + *
  28 + * Contatos:
  29 + *
  30 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  31 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  32 + *
  33 + */
  34 +
  35 +#include "gobject.h"
  36 +#include <lib3270.h>
  37 +#include <lib3270/ipc.h>
  38 +
  39 +#include <dbus/dbus-glib.h>
  40 +#include <dbus/dbus-glib-bindings.h>
  41 +
  42 +static void
  43 + method_call (
  44 + G_GNUC_UNUSED GDBusConnection *connection,
  45 + G_GNUC_UNUSED const gchar *sender,
  46 + G_GNUC_UNUSED const gchar *object_path,
  47 + G_GNUC_UNUSED const gchar *interface_name,
  48 + const gchar *method_name,
  49 + GVariant *parameters,
  50 + GDBusMethodInvocation *invocation,
  51 + gpointer user_data) {
  52 +
  53 + g_autoptr (GError) error = NULL;
  54 +
  55 + GVariant * rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error);
  56 +
  57 + if(error) {
  58 +
  59 + if(rc) {
  60 + g_variant_unref(rc);
  61 + }
  62 +
  63 + g_dbus_method_invocation_return_gerror(invocation, error);
  64 +
  65 + } else if(rc) {
  66 +
  67 + g_dbus_method_invocation_return_value(invocation, rc);
  68 +
  69 + } else {
  70 +
  71 + g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call");
  72 +
  73 + }
  74 +
  75 +
  76 +}
  77 +
  78 +static GVariant *
  79 + get_property (
  80 + G_GNUC_UNUSED GDBusConnection *connection,
  81 + G_GNUC_UNUSED const gchar *sender,
  82 + G_GNUC_UNUSED const gchar *object_path,
  83 + G_GNUC_UNUSED const gchar *interface_name,
  84 + const gchar *property_name,
  85 + GError **error,
  86 + gpointer user_data)
  87 +{
  88 +
  89 + return ipc3270_get_property(G_OBJECT(user_data), property_name, error);
  90 +
  91 +}
  92 +
  93 +static gboolean
  94 + set_property (
  95 + G_GNUC_UNUSED GDBusConnection *connection,
  96 + G_GNUC_UNUSED const gchar *sender,
  97 + G_GNUC_UNUSED const gchar *object_path,
  98 + G_GNUC_UNUSED const gchar *interface_name,
  99 + const gchar *property_name,
  100 + GVariant *value,
  101 + GError **error,
  102 + gpointer user_data)
  103 +{
  104 +
  105 + return ipc3270_set_property(G_OBJECT(user_data), property_name, value, error);
  106 +
  107 +}
  108 +
  109 +void ipc3270_export_object(GObject *object, const char *name, GError **error) {
  110 +
  111 + char id;
  112 +
  113 + #pragma GCC diagnostic push
  114 + #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
  115 + static const GDBusInterfaceVTable interface_vtable = {
  116 + method_call,
  117 + get_property,
  118 + set_property
  119 + };
  120 + #pragma GCC diagnostic pop
  121 +
  122 + ipc3270 * ipc = IPC3270(object);
  123 +
  124 + ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
  125 + if(*error) {
  126 + g_message("Can't get session bus: %s",(*error)->message);
  127 + return;
  128 + }
  129 +
  130 + g_dbus_connection_set_exit_on_close(ipc->connection,FALSE);
  131 +
  132 + for(id='a'; id < 'z' && !ipc->id && !*error; id++) {
  133 +
  134 + g_autofree gchar *object_name = g_strdup_printf(PW3270_IPC_SESSION_BUS_NAME,name,id);
  135 +
  136 + debug("Requesting \"%s\"",object_name);
  137 +
  138 + // https://dbus.freedesktop.org/doc/dbus-specification.html
  139 + GError *err = NULL;
  140 +
  141 + GVariant * response =
  142 + g_dbus_connection_call_sync (
  143 + ipc->connection,
  144 + DBUS_SERVICE_DBUS,
  145 + DBUS_PATH_DBUS,
  146 + DBUS_INTERFACE_DBUS,
  147 + "RequestName",
  148 + g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE),
  149 + NULL,
  150 + G_DBUS_CALL_FLAGS_NONE,
  151 + -1,
  152 + NULL,
  153 + &err
  154 + );
  155 +
  156 + if(err) {
  157 +
  158 + g_message("Can't request \"%s\": %s",object_name,err->message);
  159 + g_error_free(err);
  160 + err = NULL;
  161 +
  162 + } else if(response) {
  163 +
  164 + guint32 reply = 0;
  165 + g_variant_get(response, "(u)", &reply);
  166 + g_variant_unref(response);
  167 +
  168 + if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
  169 +
  170 + g_message("Got %s", object_name);
  171 +
  172 + lib3270_set_session_id(ipc->hSession, id);
  173 +
  174 + // Introspection data for the service we are exporting
  175 + GString * introspection = g_string_new("<node><interface name='" PW3270_IPC_SESSION_INTERFACE_NAME "'>");
  176 + ipc3270_add_terminal_introspection(introspection);
  177 + g_string_append(introspection,"</interface></node>");
  178 +
  179 + gchar * introspection_xml = g_string_free(introspection,FALSE);
  180 +
  181 + debug("\n%s\n",introspection_xml);
  182 +
  183 + GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
  184 +
  185 + // Register object-id
  186 + ipc->id = g_dbus_connection_register_object (
  187 + ipc->connection,
  188 + PW3270_IPC_SESSION_OBJECT_PATH,
  189 + introspection_data->interfaces[0],
  190 + &interface_vtable,
  191 + ipc,
  192 + NULL,
  193 + error
  194 + );
  195 +
  196 + g_dbus_node_info_unref(introspection_data);
  197 + g_free(introspection_xml);
  198 +
  199 + return;
  200 + }
  201 +
  202 + }
  203 +
  204 + }
  205 +
  206 +}
... ...
src/core/windows/gobject.c
... ... @@ -63,59 +63,11 @@ GObject * ipc3270_new() {
63 63 return g_object_new(GLIB_TYPE_IPC3270, NULL);
64 64 }
65 65  
66   -void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) {
67   -
68   - char id;
  66 +void ipc3270_set_session(GObject *object, H3270 *hSession) {
69 67  
70 68 ipc3270 * ipc = IPC3270(object);
71 69 ipc->hSession = hSession;
72 70  
73   - for(id='A';id < 'Z';id++) {
74   -
75   - gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s\\%c",name,id);
76   - gchar * ptr;
77   - HANDLE hPipe;
78   -
79   - for(ptr=pipename;*ptr;ptr++)
80   - *ptr = g_ascii_tolower(*ptr);
81   -
82   - hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
83   - PIPE_ACCESS_DUPLEX | // read/write access
84   - FILE_FLAG_OVERLAPPED, // overlapped mode
85   - PIPE_TYPE_MESSAGE | // pipe type
86   - PIPE_READMODE_MESSAGE | // pipe mode
87   - PIPE_WAIT, // blocking mode
88   - 1, // number of instances
89   - PIPE_BUFFER_LENGTH, // output buffer size
90   - PIPE_BUFFER_LENGTH, // input buffer size
91   - NMPWAIT_USE_DEFAULT_WAIT, // client time-out
92   - NULL); // default security attributes
93   -
94   - debug("%s = %p",pipename,hPipe);
95   - g_free(pipename);
96   -
97   - if(hPipe != INVALID_HANDLE_VALUE) {
98   -
99   - ipc->source = (IPC3270_PIPE_SOURCE *) g_source_new(&ipc3270_source_funcs,sizeof(IPC3270_PIPE_SOURCE));
100   -
101   - lib3270_set_session_id(ipc->hSession, id);
102   -
103   - ipc->source->hPipe = hPipe;
104   - ipc->source->object = object;
105   - ipc->source->state = PIPE_STATE_WAITING;
106   - ipc->source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
107   -
108   - g_source_attach((GSource *) ipc->source,NULL);
109   -
110   - // IO_accept(source);
111   - ipc3270_wait_for_client(ipc->source);
112   -
113   - break;
114   - }
115   -
116   - }
117   -
118   -
119 71 }
120 72  
121 73 const gchar * ipc3270_get_display_charset(GObject *object) {
... ...
src/core/windows/start.c 0 → 100644
... ... @@ -0,0 +1,99 @@
  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.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como gobject.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +#include "gobject.h"
  31 +#include <lib3270.h>
  32 +#include <lib3270/actions.h>
  33 +#include <lib3270/properties.h>
  34 +
  35 +void ipc3270_export_object(GObject *object, const char *name, GError **error) {
  36 +
  37 + char id;
  38 +
  39 + ipc3270 * ipc = IPC3270(object);
  40 +
  41 + for(id='A';id < 'Z';id++) {
  42 +
  43 + gchar * pipename = g_strdup_printf(PW3270_IPC_SESSION_BUS_NAME,name,id);
  44 + gchar * ptr;
  45 + HANDLE hPipe;
  46 +
  47 + for(ptr=pipename;*ptr;ptr++)
  48 + *ptr = g_ascii_tolower(*ptr);
  49 +
  50 + hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
  51 + PIPE_ACCESS_DUPLEX | // read/write access
  52 + FILE_FLAG_OVERLAPPED, // overlapped mode
  53 + PIPE_TYPE_MESSAGE | // pipe type
  54 + PIPE_READMODE_MESSAGE | // pipe mode
  55 + PIPE_WAIT, // blocking mode
  56 + 1, // number of instances
  57 + PIPE_BUFFER_LENGTH, // output buffer size
  58 + PIPE_BUFFER_LENGTH, // input buffer size
  59 + NMPWAIT_USE_DEFAULT_WAIT, // client time-out
  60 + NULL); // default security attributes
  61 +
  62 + debug("%s = %p",pipename,hPipe);
  63 + g_free(pipename);
  64 +
  65 + if(hPipe != INVALID_HANDLE_VALUE) {
  66 +
  67 + ipc->source = (IPC3270_PIPE_SOURCE *) g_source_new(&ipc3270_source_funcs,sizeof(IPC3270_PIPE_SOURCE));
  68 +
  69 + lib3270_set_session_id(ipc->hSession, id);
  70 +
  71 + ipc->source->hPipe = hPipe;
  72 + ipc->source->object = object;
  73 + ipc->source->state = PIPE_STATE_WAITING;
  74 + ipc->source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
  75 +
  76 + g_source_attach((GSource *) ipc->source,NULL);
  77 +
  78 + // IO_accept(source);
  79 + ipc3270_wait_for_client(ipc->source);
  80 +
  81 + break;
  82 + }
  83 +
  84 + }
  85 +
  86 +}
  87 +
  88 +const gchar * ipc3270_get_display_charset(GObject *object) {
  89 + return lib3270_get_display_charset(IPC3270(object)->hSession);
  90 +}
  91 +
  92 +H3270 * ipc3270_get_session(GObject *object) {
  93 + return IPC3270(object)->hSession;
  94 +}
  95 +
  96 +void ipc3270_set_error(GObject *object, int errcode, GError **error) {
  97 + g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode));
  98 +}
  99 +
... ...
src/include/lib3270/ipc.h
... ... @@ -37,6 +37,23 @@
37 37  
38 38 #define PW3270_IPC_H_INCLUDED
39 39  
  40 + #ifdef _WIN32
  41 +
  42 + #define PW3270_IPC_SESSION_BUS_NAME "\\\\.\\pipe\\%s\\%c"
  43 +
  44 + #else
  45 +
  46 + #define PW3270_IPC_SESSION_BUS_NAME "br.com.bb.%s.%c"
  47 + #define PW3270_IPC_SESSION_INTERFACE_NAME "br.com.bb.tn3270.session"
  48 + #define PW3270_IPC_SESSION_OBJECT_PATH "/br/com/bb/tn3270/session"
  49 +
  50 + #define PW3270_IPC_SERVICE_BUS_NAME "br.com.bb.tn3270.service"
  51 + #define PW3270_IPC_SERVICE_INTERFACE_NAME "br.com.bb.tn3270.service"
  52 + #define PW3270_IPC_SERVICE_OBJECT_PATH "/br/com/bb/tn3270/service"
  53 +
  54 + #endif // _WIN32
  55 +
  56 +
40 57 #include <gtk/gtk.h>
41 58 #include <lib3270.h>
42 59  
... ... @@ -52,29 +69,31 @@
52 69 typedef struct _ipc3270 ipc3270;
53 70 typedef struct _ipc3270Class ipc3270Class;
54 71  
55   - GObject * ipc3270_new();
56   - GType ipc3270_get_type(void);
57   - void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error);
  72 + GObject * ipc3270_new();
  73 + GType ipc3270_get_type(void);
  74 + void ipc3270_set_session(GObject *object, H3270 *hSession);
  75 + void ipc3270_export_object(GObject *object, const char *name, GError **error);
58 76  
59   - gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error);
60   - gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error);
61   - GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error);
  77 + gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error);
  78 + gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error);
  79 + GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error);
62 80  
63   - void ipc3270_add_terminal_introspection(GString *string);
  81 + void ipc3270_add_terminal_introspection(GString *string);
64 82  
65   - const gchar * ipc3270_get_display_charset(GObject *object);
66   - H3270 * ipc3270_get_session(GObject *object);
  83 + const gchar * ipc3270_get_display_charset(GObject *object);
  84 + H3270 * ipc3270_get_session(GObject *object);
67 85  
68   - void ipc3270_set_error(GObject *object, int errcode, GError **error);
  86 + void ipc3270_set_error(GObject *object, int errcode, GError **error);
69 87  
70   - GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error);
71   - gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
72   - GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
  88 + GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error);
  89 + gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
  90 + GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
73 91  
74   - // TODO: Move for windows private.h
75   - unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket);
76   - unsigned char * ipc3270_pack_error(const GError *error, size_t * szPacket);
77   - GVariant * ipc3270_unpack(const unsigned char *packet, int *id);
  92 + #ifdef _WIN32
  93 + unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket);
  94 + unsigned char * ipc3270_pack_error(const GError *error, size_t * szPacket);
  95 + GVariant * ipc3270_unpack(const unsigned char *packet, int *id);
  96 + #endif // _WIN32
78 97  
79 98 G_END_DECLS
80 99  
... ...
src/plugin/plugin.c 0 → 100644
... ... @@ -0,0 +1,90 @@
  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 + /**
  33 + * @brief Plugin startup/stop for linux.
  34 + *
  35 + */
  36 +
  37 + #define ENABLE_NLS
  38 + #define GETTEXT_PACKAGE PACKAGE_NAME
  39 +
  40 + #include <libintl.h>
  41 + #include <glib/gi18n.h>
  42 + #include <gio/gio.h>
  43 +
  44 + #include "private.h"
  45 + #include <v3270.h>
  46 + #include <lib3270/ipc.h>
  47 +
  48 + int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) {
  49 +
  50 + // Creates IPC, associate it with the terminal window
  51 + GObject * ipc = ipc3270_new();
  52 + g_object_set_data_full(G_OBJECT(terminal), "ipc-object-info", ipc, g_object_unref);
  53 +
  54 + debug("Name: \"%s\"",gtk_widget_get_name(window));
  55 +
  56 + // Set session handle, this starts the IPC communication.
  57 + GError * error = NULL;
  58 + ipc3270_set_session(ipc,v3270_get_session(terminal));
  59 + ipc3270_export_object(ipc,gtk_widget_get_name(window),&error);
  60 +
  61 + if(error) {
  62 +
  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 start IPC Module" ));
  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 + return 0;
  76 +
  77 + }
  78 +
  79 + char id = lib3270_get_session_id(v3270_get_session(terminal));
  80 + if(id) {
  81 + gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id);
  82 + v3270_set_session_name(terminal, widget_name);
  83 + g_free(widget_name);
  84 + }
  85 +
  86 + return 0;
  87 + }
  88 +
  89 +
  90 +
... ...
src/plugin/start.c
... ... @@ -1,90 +0,0 @@
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   - /**
33   - * @brief Plugin startup/stop for linux.
34   - *
35   - */
36   -
37   - #define ENABLE_NLS
38   - #define GETTEXT_PACKAGE PACKAGE_NAME
39   -
40   - #include <libintl.h>
41   - #include <glib/gi18n.h>
42   - #include <gio/gio.h>
43   -
44   - #include "private.h"
45   - #include <v3270.h>
46   - #include <lib3270/ipc.h>
47   -
48   - int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) {
49   -
50   - // Creates IPC, associate it with the terminal window
51   - GObject * ipc = ipc3270_new();
52   - g_object_set_data_full(G_OBJECT(terminal), "ipc-object-info", ipc, g_object_unref);
53   -
54   -
55   - debug("Name: \"%s\"",gtk_widget_get_name(window));
56   -
57   - // Set session handle, this starts the IPC communication.
58   - GError * error = NULL;
59   - ipc3270_set_session(ipc,v3270_get_session(terminal),gtk_widget_get_name(window),&error);
60   -
61   - if(error) {
62   -
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 start IPC Module" ));
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   - return 0;
76   -
77   - }
78   -
79   - char id = lib3270_get_session_id(v3270_get_session(terminal));
80   - if(id) {
81   - gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id);
82   - v3270_set_session_name(terminal, widget_name);
83   - g_free(widget_name);
84   - }
85   -
86   - return 0;
87   - }
88   -
89   -
90   -
src/service/linux/start.c
... ... @@ -35,10 +35,6 @@
35 35 #include <lib3270/ipc.h>
36 36 #include "../private.h"
37 37  
38   -#define PW3270_SERVICE_DBUS_SERVICE_PATH "/br/com/bb/tn3270/service"
39   -#define PW3270_SERVICE_DBUS_SERVICE "br.com.bb.tn3270.service"
40   -#define PW3270_SERVICE_DBUS_SERVICE_INTERFACE "br.com.bb.tn3270.service"
41   -
42 38 static GDBusNodeInfo *introspection_data = NULL;
43 39 static guint owner_id = 0;
44 40 static gchar * introspection_xml = NULL;
... ... @@ -125,10 +121,10 @@ static void on_bus_acquired (GDBusConnection *connection, const gchar *name, gpo
125 121  
126 122 guint registration_id;
127 123  
128   - g_message("Registering object %s",PW3270_SERVICE_DBUS_SERVICE_PATH);
  124 + g_message("Registering object %s",PW3270_IPC_SERVICE_OBJECT_PATH);
129 125  
130 126 registration_id = g_dbus_connection_register_object (connection,
131   - PW3270_SERVICE_DBUS_SERVICE_PATH,
  127 + PW3270_IPC_SERVICE_OBJECT_PATH,
132 128 introspection_data->interfaces[0],
133 129 &interface_vtable,
134 130 NULL, /* user_data */
... ... @@ -154,7 +150,7 @@ void service_start(void) {
154 150 GString * introspection = g_string_new("<node>\n");
155 151  
156 152 g_string_append(introspection,
157   - " <interface name='" PW3270_SERVICE_DBUS_SERVICE_INTERFACE "'>"
  153 + " <interface name='" PW3270_IPC_SERVICE_INTERFACE_NAME "'>"
158 154 " <method name='createSession'>"
159 155 " <arg type='s' name='id' direction='out' />"
160 156 " </method>"
... ... @@ -177,7 +173,7 @@ void service_start(void) {
177 173 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
178 174  
179 175 owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
180   - PW3270_SERVICE_DBUS_SERVICE,
  176 + PW3270_IPC_SERVICE_BUS_NAME,
181 177 G_BUS_NAME_OWNER_FLAGS_NONE,
182 178 on_bus_acquired,
183 179 on_name_acquired,
... ...
src/service/service.c
... ... @@ -32,6 +32,10 @@
32 32 #include <stdlib.h>
33 33 #include <lib3270/ipc.h>
34 34  
  35 +#ifndef _WIN32
  36 + #include <signal.h>
  37 +#endif // !_WIN32
  38 +
35 39 GMainLoop * main_loop = NULL;
36 40  
37 41 #ifdef DEBUG
... ... @@ -40,6 +44,13 @@ GMainLoop * main_loop = NULL;
40 44 static gchar * pidfile = "/var/run/" PACKAGE_NAME ".pid";
41 45 #endif // DEBUG
42 46  
  47 +#ifndef _WIN32
  48 +static void on_sigterm(int signal) {
  49 + g_message("Stopping by termination request\n");
  50 + g_main_loop_quit(main_loop);
  51 +}
  52 +#endif // !_WIN32
  53 +
43 54 #if defined( HAVE_SYSLOG )
44 55 static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
45 56 {
... ... @@ -121,7 +132,9 @@ int main(int argc, char *argv[]) {
121 132 // Verifica argumentos
122 133 static const GOptionEntry app_options[] = {
123 134 { "pidfile", 'p', 0, G_OPTION_ARG_STRING, &pidfile, "Path to pidfile" , NULL },
  135 +#ifndef _WIN32
124 136 { "daemon", 'd', 0, G_OPTION_ARG_NONE, &asDaemon, "Run as daemon", NULL },
  137 +#endif // !_WIN32
125 138 { NULL }
126 139 };
127 140  
... ... @@ -146,18 +159,24 @@ int main(int argc, char *argv[]) {
146 159 }
147 160 }
148 161  
  162 + service_start();
  163 +
  164 + g_print("%s starts\n",argv[0]);
  165 +
  166 + main_loop = g_main_loop_new(NULL, FALSE);
  167 +
149 168 #ifndef _WIN32
  169 +
150 170 if(asDaemon && daemon(0,0)) {
151 171 g_print("%s can't start: %s\n",argv[0],strerror(errno));
152 172 return -1;
153 173 }
154   -#endif // _WIN32
155 174  
156   - service_start();
  175 + signal(SIGTERM,on_sigterm);
  176 + signal(SIGINT,on_sigterm);
157 177  
158   - g_print("%s starts\n",argv[0]);
  178 +#endif // !_WIN32
159 179  
160   - main_loop = g_main_loop_new(NULL, FALSE);
161 180 g_main_loop_run(main_loop);
162 181  
163 182 g_print("%s ends\n",argv[0]);
... ...
src/service/session.c
... ... @@ -42,13 +42,19 @@ struct _sessionClass {
42 42 GObjectClass parent;
43 43 };
44 44  
  45 +static GList * session_list = NULL;
  46 +
45 47 G_DEFINE_TYPE(session, session, GLIB_TYPE_IPC3270)
46 48  
47 49 static void session_finalize(GObject *object) {
48 50  
  51 + session_list = g_list_remove(session_list, object);
  52 +
49 53 lib3270_session_free(ipc3270_get_session(object));
50 54 G_OBJECT_CLASS(session_parent_class)->finalize(object);
51 55  
  56 + debug("%s(%p)",__FUNCTION__,(void *) object);
  57 +
52 58 }
53 59  
54 60 static void session_class_init(sessionClass *klass) {
... ... @@ -63,8 +69,13 @@ static void session_class_init(sessionClass *klass) {
63 69  
64 70 static void session_init(session *object) {
65 71  
66   - debug("%s",__FUNCTION__);
67   - ipc3270_set_session(&object->parent,lib3270_session_new(""),PACKAGE_NAME,NULL);
  72 + debug("%s(%p)",__FUNCTION__,(void *) object);
  73 +
  74 + H3270 * hSession = lib3270_session_new("");
  75 + lib3270_set_user_data(hSession,object);
  76 + ipc3270_set_session(&object->parent,hSession);
  77 +
  78 + session_list = g_list_prepend(session_list, object);
68 79  
69 80 }
70 81  
... ...