diff --git a/pw3270-plugin-ipc.cbp b/pw3270-plugin-ipc.cbp
index 71579cb..dc17da6 100644
--- a/pw3270-plugin-ipc.cbp
+++ b/pw3270-plugin-ipc.cbp
@@ -71,6 +71,9 @@
+
+
+
@@ -88,6 +91,9 @@
+
+
+
diff --git a/src/core/linux/gobject.c b/src/core/linux/gobject.c
index 64408c0..ee77271 100644
--- a/src/core/linux/gobject.c
+++ b/src/core/linux/gobject.c
@@ -76,73 +76,6 @@ GObject * ipc3270_new() {
return g_object_new(GLIB_TYPE_IPC3270, NULL);
}
-static void
- method_call (
- G_GNUC_UNUSED GDBusConnection *connection,
- G_GNUC_UNUSED const gchar *sender,
- G_GNUC_UNUSED const gchar *object_path,
- G_GNUC_UNUSED const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data) {
-
- g_autoptr (GError) error = NULL;
-
- GVariant * rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error);
-
- if(error) {
-
- if(rc) {
- g_variant_unref(rc);
- }
-
- g_dbus_method_invocation_return_gerror(invocation, error);
-
- } else if(rc) {
-
- g_dbus_method_invocation_return_value(invocation, rc);
-
- } else {
-
- g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call");
-
- }
-
-
-}
-
-static GVariant *
- get_property (
- G_GNUC_UNUSED GDBusConnection *connection,
- G_GNUC_UNUSED const gchar *sender,
- G_GNUC_UNUSED const gchar *object_path,
- G_GNUC_UNUSED const gchar *interface_name,
- const gchar *property_name,
- GError **error,
- gpointer user_data)
-{
-
- return ipc3270_get_property(G_OBJECT(user_data), property_name, error);
-
-}
-
-static gboolean
- set_property (
- G_GNUC_UNUSED GDBusConnection *connection,
- G_GNUC_UNUSED const gchar *sender,
- G_GNUC_UNUSED const gchar *object_path,
- G_GNUC_UNUSED const gchar *interface_name,
- const gchar *property_name,
- GVariant *value,
- GError **error,
- gpointer user_data)
-{
-
- return ipc3270_set_property(G_OBJECT(user_data), property_name, value, error);
-
-}
-
void ipc3270_add_terminal_introspection(GString *introspection) {
size_t ix;
@@ -239,104 +172,11 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
}
-void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) {
-
- char id;
- int ix;
-
- static const GDBusInterfaceVTable interface_vtable = {
- method_call,
- get_property,
- set_property
- };
+void ipc3270_set_session(GObject *object, H3270 *hSession) {
ipc3270 * ipc = IPC3270(object);
ipc->hSession = hSession;
- ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
- if(*error) {
- g_message("Can't get session bus: %s",(*error)->message);
- return;
- }
-
- g_dbus_connection_set_exit_on_close(ipc->connection,FALSE);
-
- for(id='a'; id < 'z' && !ipc->id && !*error; id++) {
-
- gchar *object_name = g_strdup_printf("br.com.bb.%s.%c",name,id);
-
- debug("Requesting \"%s\"",object_name);
-
- // https://dbus.freedesktop.org/doc/dbus-specification.html
- GError *err = NULL;
-
- GVariant * response =
- g_dbus_connection_call_sync (
- ipc->connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "RequestName",
- g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE),
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &err
- );
-
- if(err) {
- g_message("Can't request \"%s\": %s",object_name,err->message);
- g_error_free(err);
- err = NULL;
- }
-
- if(response) {
-
- guint32 reply = 0;
- g_variant_get(response, "(u)", &reply);
- g_variant_unref(response);
-
- if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
-
- g_message("Got %s", object_name);
-
- lib3270_set_session_id(ipc->hSession, id);
-
- // Introspection data for the service we are exporting
- GString * introspection = g_string_new("");
- ipc3270_add_terminal_introspection(introspection);
- g_string_append(introspection,"");
-
- gchar * introspection_xml = g_string_free(introspection,FALSE);
-
- debug("\n%s\n",introspection_xml);
-
- GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
-
- // Register object-id
- ipc->id = g_dbus_connection_register_object (
- ipc->connection,
- "/br/com/bb/tn3270",
- introspection_data->interfaces[0],
- &interface_vtable,
- ipc,
- NULL,
- error
- );
-
- g_dbus_node_info_unref(introspection_data);
- g_free(introspection_xml);
-
- break;
- }
-
- }
-
- g_free(object_name);
-
- }
-
}
const gchar * ipc3270_get_display_charset(GObject *object) {
diff --git a/src/core/linux/start.c b/src/core/linux/start.c
new file mode 100644
index 0000000..743ddfb
--- /dev/null
+++ b/src/core/linux/start.c
@@ -0,0 +1,206 @@
+/*
+ * "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., 51 Franklin
+ * St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Este programa está nomeado como main.c e possui - linhas de código.
+ *
+ * Referências:
+ *
+ * https://github.com/joprietoe/gdbus/blob/master/gdbus-example-server.c
+ * https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-export.c
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
+ *
+ */
+
+#include "gobject.h"
+#include
+#include
+
+#include
+#include
+
+static void
+ method_call (
+ G_GNUC_UNUSED GDBusConnection *connection,
+ G_GNUC_UNUSED const gchar *sender,
+ G_GNUC_UNUSED const gchar *object_path,
+ G_GNUC_UNUSED const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data) {
+
+ g_autoptr (GError) error = NULL;
+
+ GVariant * rc = ipc3270_method_call(G_OBJECT(user_data), method_name, parameters, &error);
+
+ if(error) {
+
+ if(rc) {
+ g_variant_unref(rc);
+ }
+
+ g_dbus_method_invocation_return_gerror(invocation, error);
+
+ } else if(rc) {
+
+ g_dbus_method_invocation_return_value(invocation, rc);
+
+ } else {
+
+ g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Invalid or unexpected method call");
+
+ }
+
+
+}
+
+static GVariant *
+ get_property (
+ G_GNUC_UNUSED GDBusConnection *connection,
+ G_GNUC_UNUSED const gchar *sender,
+ G_GNUC_UNUSED const gchar *object_path,
+ G_GNUC_UNUSED const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data)
+{
+
+ return ipc3270_get_property(G_OBJECT(user_data), property_name, error);
+
+}
+
+static gboolean
+ set_property (
+ G_GNUC_UNUSED GDBusConnection *connection,
+ G_GNUC_UNUSED const gchar *sender,
+ G_GNUC_UNUSED const gchar *object_path,
+ G_GNUC_UNUSED const gchar *interface_name,
+ const gchar *property_name,
+ GVariant *value,
+ GError **error,
+ gpointer user_data)
+{
+
+ return ipc3270_set_property(G_OBJECT(user_data), property_name, value, error);
+
+}
+
+void ipc3270_export_object(GObject *object, const char *name, GError **error) {
+
+ char id;
+
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+ static const GDBusInterfaceVTable interface_vtable = {
+ method_call,
+ get_property,
+ set_property
+ };
+ #pragma GCC diagnostic pop
+
+ ipc3270 * ipc = IPC3270(object);
+
+ ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
+ if(*error) {
+ g_message("Can't get session bus: %s",(*error)->message);
+ return;
+ }
+
+ g_dbus_connection_set_exit_on_close(ipc->connection,FALSE);
+
+ for(id='a'; id < 'z' && !ipc->id && !*error; id++) {
+
+ g_autofree gchar *object_name = g_strdup_printf(PW3270_IPC_SESSION_BUS_NAME,name,id);
+
+ debug("Requesting \"%s\"",object_name);
+
+ // https://dbus.freedesktop.org/doc/dbus-specification.html
+ GError *err = NULL;
+
+ GVariant * response =
+ g_dbus_connection_call_sync (
+ ipc->connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "RequestName",
+ g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err
+ );
+
+ if(err) {
+
+ g_message("Can't request \"%s\": %s",object_name,err->message);
+ g_error_free(err);
+ err = NULL;
+
+ } else if(response) {
+
+ guint32 reply = 0;
+ g_variant_get(response, "(u)", &reply);
+ g_variant_unref(response);
+
+ if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+
+ g_message("Got %s", object_name);
+
+ lib3270_set_session_id(ipc->hSession, id);
+
+ // Introspection data for the service we are exporting
+ GString * introspection = g_string_new("");
+ ipc3270_add_terminal_introspection(introspection);
+ g_string_append(introspection,"");
+
+ gchar * introspection_xml = g_string_free(introspection,FALSE);
+
+ debug("\n%s\n",introspection_xml);
+
+ GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+
+ // Register object-id
+ ipc->id = g_dbus_connection_register_object (
+ ipc->connection,
+ PW3270_IPC_SESSION_OBJECT_PATH,
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ ipc,
+ NULL,
+ error
+ );
+
+ g_dbus_node_info_unref(introspection_data);
+ g_free(introspection_xml);
+
+ return;
+ }
+
+ }
+
+ }
+
+}
diff --git a/src/core/windows/gobject.c b/src/core/windows/gobject.c
index f775b73..e01c6a1 100644
--- a/src/core/windows/gobject.c
+++ b/src/core/windows/gobject.c
@@ -63,59 +63,11 @@ GObject * ipc3270_new() {
return g_object_new(GLIB_TYPE_IPC3270, NULL);
}
-void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) {
-
- char id;
+void ipc3270_set_session(GObject *object, H3270 *hSession) {
ipc3270 * ipc = IPC3270(object);
ipc->hSession = hSession;
- for(id='A';id < 'Z';id++) {
-
- gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s\\%c",name,id);
- gchar * ptr;
- HANDLE hPipe;
-
- for(ptr=pipename;*ptr;ptr++)
- *ptr = g_ascii_tolower(*ptr);
-
- hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
- PIPE_ACCESS_DUPLEX | // read/write access
- FILE_FLAG_OVERLAPPED, // overlapped mode
- PIPE_TYPE_MESSAGE | // pipe type
- PIPE_READMODE_MESSAGE | // pipe mode
- PIPE_WAIT, // blocking mode
- 1, // number of instances
- PIPE_BUFFER_LENGTH, // output buffer size
- PIPE_BUFFER_LENGTH, // input buffer size
- NMPWAIT_USE_DEFAULT_WAIT, // client time-out
- NULL); // default security attributes
-
- debug("%s = %p",pipename,hPipe);
- g_free(pipename);
-
- if(hPipe != INVALID_HANDLE_VALUE) {
-
- ipc->source = (IPC3270_PIPE_SOURCE *) g_source_new(&ipc3270_source_funcs,sizeof(IPC3270_PIPE_SOURCE));
-
- lib3270_set_session_id(ipc->hSession, id);
-
- ipc->source->hPipe = hPipe;
- ipc->source->object = object;
- ipc->source->state = PIPE_STATE_WAITING;
- ipc->source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
-
- g_source_attach((GSource *) ipc->source,NULL);
-
- // IO_accept(source);
- ipc3270_wait_for_client(ipc->source);
-
- break;
- }
-
- }
-
-
}
const gchar * ipc3270_get_display_charset(GObject *object) {
diff --git a/src/core/windows/start.c b/src/core/windows/start.c
new file mode 100644
index 0000000..e829041
--- /dev/null
+++ b/src/core/windows/start.c
@@ -0,0 +1,99 @@
+/*
+ * "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., 51 Franklin
+ * St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Este programa está nomeado como gobject.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 "gobject.h"
+#include
+#include
+#include
+
+void ipc3270_export_object(GObject *object, const char *name, GError **error) {
+
+ char id;
+
+ ipc3270 * ipc = IPC3270(object);
+
+ for(id='A';id < 'Z';id++) {
+
+ gchar * pipename = g_strdup_printf(PW3270_IPC_SESSION_BUS_NAME,name,id);
+ gchar * ptr;
+ HANDLE hPipe;
+
+ for(ptr=pipename;*ptr;ptr++)
+ *ptr = g_ascii_tolower(*ptr);
+
+ hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
+ PIPE_ACCESS_DUPLEX | // read/write access
+ FILE_FLAG_OVERLAPPED, // overlapped mode
+ PIPE_TYPE_MESSAGE | // pipe type
+ PIPE_READMODE_MESSAGE | // pipe mode
+ PIPE_WAIT, // blocking mode
+ 1, // number of instances
+ PIPE_BUFFER_LENGTH, // output buffer size
+ PIPE_BUFFER_LENGTH, // input buffer size
+ NMPWAIT_USE_DEFAULT_WAIT, // client time-out
+ NULL); // default security attributes
+
+ debug("%s = %p",pipename,hPipe);
+ g_free(pipename);
+
+ if(hPipe != INVALID_HANDLE_VALUE) {
+
+ ipc->source = (IPC3270_PIPE_SOURCE *) g_source_new(&ipc3270_source_funcs,sizeof(IPC3270_PIPE_SOURCE));
+
+ lib3270_set_session_id(ipc->hSession, id);
+
+ ipc->source->hPipe = hPipe;
+ ipc->source->object = object;
+ ipc->source->state = PIPE_STATE_WAITING;
+ ipc->source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
+
+ g_source_attach((GSource *) ipc->source,NULL);
+
+ // IO_accept(source);
+ ipc3270_wait_for_client(ipc->source);
+
+ break;
+ }
+
+ }
+
+}
+
+const gchar * ipc3270_get_display_charset(GObject *object) {
+ return lib3270_get_display_charset(IPC3270(object)->hSession);
+}
+
+H3270 * ipc3270_get_session(GObject *object) {
+ return IPC3270(object)->hSession;
+}
+
+void ipc3270_set_error(GObject *object, int errcode, GError **error) {
+ g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode));
+}
+
diff --git a/src/include/lib3270/ipc.h b/src/include/lib3270/ipc.h
index 40f0c5f..fd39aca 100644
--- a/src/include/lib3270/ipc.h
+++ b/src/include/lib3270/ipc.h
@@ -37,6 +37,23 @@
#define PW3270_IPC_H_INCLUDED
+ #ifdef _WIN32
+
+ #define PW3270_IPC_SESSION_BUS_NAME "\\\\.\\pipe\\%s\\%c"
+
+ #else
+
+ #define PW3270_IPC_SESSION_BUS_NAME "br.com.bb.%s.%c"
+ #define PW3270_IPC_SESSION_INTERFACE_NAME "br.com.bb.tn3270.session"
+ #define PW3270_IPC_SESSION_OBJECT_PATH "/br/com/bb/tn3270/session"
+
+ #define PW3270_IPC_SERVICE_BUS_NAME "br.com.bb.tn3270.service"
+ #define PW3270_IPC_SERVICE_INTERFACE_NAME "br.com.bb.tn3270.service"
+ #define PW3270_IPC_SERVICE_OBJECT_PATH "/br/com/bb/tn3270/service"
+
+ #endif // _WIN32
+
+
#include
#include
@@ -52,29 +69,31 @@
typedef struct _ipc3270 ipc3270;
typedef struct _ipc3270Class ipc3270Class;
- GObject * ipc3270_new();
- GType ipc3270_get_type(void);
- void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error);
+ GObject * ipc3270_new();
+ GType ipc3270_get_type(void);
+ void ipc3270_set_session(GObject *object, H3270 *hSession);
+ void ipc3270_export_object(GObject *object, const char *name, GError **error);
- gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error);
- gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error);
- GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error);
+ gchar * ipc3270_convert_output_string(GObject *object, const gchar *string, GError **error);
+ gchar * ipc3270_convert_input_string(GObject *object, const gchar *string, GError **error);
+ GVariant * ipc3270_GVariant_from_input_string(GObject *object, char *string, GError **error);
- void ipc3270_add_terminal_introspection(GString *string);
+ void ipc3270_add_terminal_introspection(GString *string);
- const gchar * ipc3270_get_display_charset(GObject *object);
- H3270 * ipc3270_get_session(GObject *object);
+ const gchar * ipc3270_get_display_charset(GObject *object);
+ H3270 * ipc3270_get_session(GObject *object);
- void ipc3270_set_error(GObject *object, int errcode, GError **error);
+ void ipc3270_set_error(GObject *object, int errcode, GError **error);
- GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error);
- gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
- GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
+ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error);
+ gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error);
+ GVariant * ipc3270_get_property(GObject *object, const gchar *property_name, GError **error);
- // TODO: Move for windows private.h
- unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket);
- unsigned char * ipc3270_pack_error(const GError *error, size_t * szPacket);
- GVariant * ipc3270_unpack(const unsigned char *packet, int *id);
+ #ifdef _WIN32
+ unsigned char * ipc3270_pack(const gchar *name, int id, GVariant *values, size_t * szPacket);
+ unsigned char * ipc3270_pack_error(const GError *error, size_t * szPacket);
+ GVariant * ipc3270_unpack(const unsigned char *packet, int *id);
+ #endif // _WIN32
G_END_DECLS
diff --git a/src/plugin/plugin.c b/src/plugin/plugin.c
new file mode 100644
index 0000000..3eb60c9
--- /dev/null
+++ b/src/plugin/plugin.c
@@ -0,0 +1,90 @@
+/*
+ * "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 - 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 Plugin startup/stop for linux.
+ *
+ */
+
+ #define ENABLE_NLS
+ #define GETTEXT_PACKAGE PACKAGE_NAME
+
+ #include
+ #include
+ #include
+
+ #include "private.h"
+ #include
+ #include
+
+ int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) {
+
+ // Creates IPC, associate it with the terminal window
+ GObject * ipc = ipc3270_new();
+ g_object_set_data_full(G_OBJECT(terminal), "ipc-object-info", ipc, g_object_unref);
+
+ debug("Name: \"%s\"",gtk_widget_get_name(window));
+
+ // Set session handle, this starts the IPC communication.
+ GError * error = NULL;
+ ipc3270_set_session(ipc,v3270_get_session(terminal));
+ ipc3270_export_object(ipc,gtk_widget_get_name(window),&error);
+
+ if(error) {
+
+ GtkWidget *dialog = gtk_message_dialog_new(
+ GTK_WINDOW(window),
+ GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _( "Can't start IPC Module" ));
+
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
+ g_error_free(error);
+
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ return 0;
+
+ }
+
+ char id = lib3270_get_session_id(v3270_get_session(terminal));
+ if(id) {
+ gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id);
+ v3270_set_session_name(terminal, widget_name);
+ g_free(widget_name);
+ }
+
+ return 0;
+ }
+
+
+
diff --git a/src/plugin/start.c b/src/plugin/start.c
deleted file mode 100644
index d0e1af9..0000000
--- a/src/plugin/start.c
+++ /dev/null
@@ -1,90 +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 - 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 Plugin startup/stop for linux.
- *
- */
-
- #define ENABLE_NLS
- #define GETTEXT_PACKAGE PACKAGE_NAME
-
- #include
- #include
- #include
-
- #include "private.h"
- #include
- #include
-
- int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) {
-
- // Creates IPC, associate it with the terminal window
- GObject * ipc = ipc3270_new();
- g_object_set_data_full(G_OBJECT(terminal), "ipc-object-info", ipc, g_object_unref);
-
-
- debug("Name: \"%s\"",gtk_widget_get_name(window));
-
- // Set session handle, this starts the IPC communication.
- GError * error = NULL;
- ipc3270_set_session(ipc,v3270_get_session(terminal),gtk_widget_get_name(window),&error);
-
- if(error) {
-
- GtkWidget *dialog = gtk_message_dialog_new(
- GTK_WINDOW(window),
- GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _( "Can't start IPC Module" ));
-
- gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
- g_error_free(error);
-
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- return 0;
-
- }
-
- char id = lib3270_get_session_id(v3270_get_session(terminal));
- if(id) {
- gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id);
- v3270_set_session_name(terminal, widget_name);
- g_free(widget_name);
- }
-
- return 0;
- }
-
-
-
diff --git a/src/service/linux/start.c b/src/service/linux/start.c
index 46456a4..1608da7 100644
--- a/src/service/linux/start.c
+++ b/src/service/linux/start.c
@@ -35,10 +35,6 @@
#include
#include "../private.h"
-#define PW3270_SERVICE_DBUS_SERVICE_PATH "/br/com/bb/tn3270/service"
-#define PW3270_SERVICE_DBUS_SERVICE "br.com.bb.tn3270.service"
-#define PW3270_SERVICE_DBUS_SERVICE_INTERFACE "br.com.bb.tn3270.service"
-
static GDBusNodeInfo *introspection_data = NULL;
static guint owner_id = 0;
static gchar * introspection_xml = NULL;
@@ -125,10 +121,10 @@ static void on_bus_acquired (GDBusConnection *connection, const gchar *name, gpo
guint registration_id;
- g_message("Registering object %s",PW3270_SERVICE_DBUS_SERVICE_PATH);
+ g_message("Registering object %s",PW3270_IPC_SERVICE_OBJECT_PATH);
registration_id = g_dbus_connection_register_object (connection,
- PW3270_SERVICE_DBUS_SERVICE_PATH,
+ PW3270_IPC_SERVICE_OBJECT_PATH,
introspection_data->interfaces[0],
&interface_vtable,
NULL, /* user_data */
@@ -154,7 +150,7 @@ void service_start(void) {
GString * introspection = g_string_new("\n");
g_string_append(introspection,
- " "
+ " "
" "
" "
" "
@@ -177,7 +173,7 @@ void service_start(void) {
introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
- PW3270_SERVICE_DBUS_SERVICE,
+ PW3270_IPC_SERVICE_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_bus_acquired,
on_name_acquired,
diff --git a/src/service/service.c b/src/service/service.c
index f6e9eca..030402c 100644
--- a/src/service/service.c
+++ b/src/service/service.c
@@ -32,6 +32,10 @@
#include
#include
+#ifndef _WIN32
+ #include
+#endif // !_WIN32
+
GMainLoop * main_loop = NULL;
#ifdef DEBUG
@@ -40,6 +44,13 @@ GMainLoop * main_loop = NULL;
static gchar * pidfile = "/var/run/" PACKAGE_NAME ".pid";
#endif // DEBUG
+#ifndef _WIN32
+static void on_sigterm(int signal) {
+ g_message("Stopping by termination request\n");
+ g_main_loop_quit(main_loop);
+}
+#endif // !_WIN32
+
#if defined( HAVE_SYSLOG )
static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
{
@@ -121,7 +132,9 @@ int main(int argc, char *argv[]) {
// Verifica argumentos
static const GOptionEntry app_options[] = {
{ "pidfile", 'p', 0, G_OPTION_ARG_STRING, &pidfile, "Path to pidfile" , NULL },
+#ifndef _WIN32
{ "daemon", 'd', 0, G_OPTION_ARG_NONE, &asDaemon, "Run as daemon", NULL },
+#endif // !_WIN32
{ NULL }
};
@@ -146,18 +159,24 @@ int main(int argc, char *argv[]) {
}
}
+ service_start();
+
+ g_print("%s starts\n",argv[0]);
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+
#ifndef _WIN32
+
if(asDaemon && daemon(0,0)) {
g_print("%s can't start: %s\n",argv[0],strerror(errno));
return -1;
}
-#endif // _WIN32
- service_start();
+ signal(SIGTERM,on_sigterm);
+ signal(SIGINT,on_sigterm);
- g_print("%s starts\n",argv[0]);
+#endif // !_WIN32
- main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
g_print("%s ends\n",argv[0]);
diff --git a/src/service/session.c b/src/service/session.c
index 86e3831..079cb88 100644
--- a/src/service/session.c
+++ b/src/service/session.c
@@ -42,13 +42,19 @@ struct _sessionClass {
GObjectClass parent;
};
+static GList * session_list = NULL;
+
G_DEFINE_TYPE(session, session, GLIB_TYPE_IPC3270)
static void session_finalize(GObject *object) {
+ session_list = g_list_remove(session_list, object);
+
lib3270_session_free(ipc3270_get_session(object));
G_OBJECT_CLASS(session_parent_class)->finalize(object);
+ debug("%s(%p)",__FUNCTION__,(void *) object);
+
}
static void session_class_init(sessionClass *klass) {
@@ -63,8 +69,13 @@ static void session_class_init(sessionClass *klass) {
static void session_init(session *object) {
- debug("%s",__FUNCTION__);
- ipc3270_set_session(&object->parent,lib3270_session_new(""),PACKAGE_NAME,NULL);
+ debug("%s(%p)",__FUNCTION__,(void *) object);
+
+ H3270 * hSession = lib3270_session_new("");
+ lib3270_set_user_data(hSession,object);
+ ipc3270_set_session(&object->parent,hSession);
+
+ session_list = g_list_prepend(session_list, object);
}
--
libgit2 0.21.2