Commit 07b2fcd8a41df1d8f023d4ed011f8ce864fcd6bf
1 parent
3b3fb738
Exists in
master
and in
1 other branch
Working on IPC module.
Showing
3 changed files
with
77 additions
and
60 deletions
Show diff stats
src/include/lib3270/ipc.h
| ... | ... | @@ -38,6 +38,7 @@ |
| 38 | 38 | #define PW3270_IPC_H_INCLUDED |
| 39 | 39 | |
| 40 | 40 | #include <gtk/gtk.h> |
| 41 | + #include <lib3270.h> | |
| 41 | 42 | |
| 42 | 43 | G_BEGIN_DECLS |
| 43 | 44 | |
| ... | ... | @@ -51,8 +52,9 @@ |
| 51 | 52 | typedef struct _ipc3270 ipc3270; |
| 52 | 53 | typedef struct _ipc3270Class ipc3270Class; |
| 53 | 54 | |
| 54 | - GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal); | |
| 55 | + GObject * ipc3270_new(); | |
| 55 | 56 | GType ipc3270_get_type(void); |
| 57 | + void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error); | |
| 56 | 58 | |
| 57 | 59 | G_END_DECLS |
| 58 | 60 | ... | ... |
src/linux/gobject.c
| ... | ... | @@ -71,6 +71,13 @@ static void ipc3270_init(ipc3270 *object) { |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { |
| 74 | + return g_object_new(GLIB_TYPE_IPC3270, NULL); | |
| 75 | +} | |
| 76 | + | |
| 77 | +void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GError **error) { | |
| 78 | + | |
| 79 | + char id; | |
| 80 | + int ix; | |
| 74 | 81 | |
| 75 | 82 | static const GDBusInterfaceVTable interface_vtable = { |
| 76 | 83 | ipc3270_method_call, |
| ... | ... | @@ -78,60 +85,45 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { |
| 78 | 85 | ipc3270_set_property |
| 79 | 86 | }; |
| 80 | 87 | |
| 81 | - ipc3270 * object = IPC3270(g_object_new(GLIB_TYPE_IPC3270, NULL)); | |
| 82 | - | |
| 83 | - GError * error = NULL; | |
| 84 | - int id, ix; | |
| 85 | - | |
| 86 | - object->hSession = v3270_get_session(terminal); | |
| 87 | - object->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); | |
| 88 | - | |
| 89 | - if(error) { | |
| 90 | - GtkWidget *dialog = gtk_message_dialog_new( | |
| 91 | - GTK_WINDOW(window), | |
| 92 | - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 93 | - GTK_MESSAGE_ERROR, | |
| 94 | - GTK_BUTTONS_OK, | |
| 95 | - _( "Can't get D-Bus connection" )); | |
| 96 | - | |
| 97 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); | |
| 98 | - g_error_free(error); | |
| 99 | - | |
| 100 | - gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 101 | - gtk_widget_destroy(dialog); | |
| 102 | - | |
| 103 | - return G_OBJECT(object); | |
| 88 | + ipc3270 * ipc = IPC3270(object); | |
| 89 | + ipc->hSession = hSession; | |
| 104 | 90 | |
| 91 | + ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error); | |
| 92 | + if(*error) { | |
| 93 | + g_message("Can't get session bus: %s",(*error)->message); | |
| 94 | + return; | |
| 105 | 95 | } |
| 106 | 96 | |
| 107 | - g_dbus_connection_set_exit_on_close(object->connection,FALSE); | |
| 97 | + g_dbus_connection_set_exit_on_close(ipc->connection,FALSE); | |
| 108 | 98 | |
| 109 | - for(id='a'; id < 'z' && !object->id && !error; id++) { | |
| 99 | + for(id='a'; id < 'z' && !ipc->id && !*error; id++) { | |
| 110 | 100 | |
| 111 | - gchar *name = g_strdup_printf("br.com.bb.%s.%c",gtk_widget_get_name(window),id); | |
| 101 | + gchar *object_name = g_strdup_printf("br.com.bb.%s.%c",name,id); | |
| 112 | 102 | |
| 113 | - debug("Requesting \"%s\"",name); | |
| 103 | + debug("Requesting \"%s\"",object_name); | |
| 114 | 104 | |
| 115 | 105 | // https://dbus.freedesktop.org/doc/dbus-specification.html |
| 106 | + GError *err = NULL; | |
| 107 | + | |
| 116 | 108 | GVariant * response = |
| 117 | 109 | g_dbus_connection_call_sync ( |
| 118 | - object->connection, | |
| 110 | + ipc->connection, | |
| 119 | 111 | DBUS_SERVICE_DBUS, |
| 120 | 112 | DBUS_PATH_DBUS, |
| 121 | 113 | DBUS_INTERFACE_DBUS, |
| 122 | 114 | "RequestName", |
| 123 | - g_variant_new ("(su)", name, DBUS_NAME_FLAG_DO_NOT_QUEUE), | |
| 115 | + g_variant_new ("(su)", object_name, DBUS_NAME_FLAG_DO_NOT_QUEUE), | |
| 124 | 116 | NULL, |
| 125 | 117 | G_DBUS_CALL_FLAGS_NONE, |
| 126 | 118 | -1, |
| 127 | 119 | NULL, |
| 128 | - &error | |
| 120 | + &err | |
| 129 | 121 | ); |
| 130 | 122 | |
| 131 | - if(error) { | |
| 132 | - g_message("Can't request \"%s\": %s",name,error->message); | |
| 133 | - g_error_free(error); | |
| 134 | - error = NULL; | |
| 123 | + if(err) { | |
| 124 | + g_message("Can't request \"%s\": %s",object_name,err->message); | |
| 125 | + g_error_free(err); | |
| 126 | + err = NULL; | |
| 135 | 127 | } |
| 136 | 128 | |
| 137 | 129 | if(response) { |
| ... | ... | @@ -142,11 +134,15 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { |
| 142 | 134 | |
| 143 | 135 | if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { |
| 144 | 136 | |
| 137 | + g_message("Got %s", object_name); | |
| 138 | + | |
| 139 | + /* | |
| 145 | 140 | gchar * widget_name = g_strdup_printf("%s:%c",gtk_widget_get_name(window),id); |
| 146 | 141 | v3270_set_session_name(terminal, widget_name); |
| 147 | 142 | g_free(widget_name); |
| 148 | 143 | |
| 149 | 144 | g_message("Got %s - %s", name, v3270_get_session_name(terminal)); |
| 145 | + */ | |
| 150 | 146 | |
| 151 | 147 | // Introspection data for the service we are exporting |
| 152 | 148 | GString * introspection = g_string_new( |
| ... | ... | @@ -180,14 +176,14 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { |
| 180 | 176 | GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); |
| 181 | 177 | |
| 182 | 178 | // Register object-id |
| 183 | - object->id = g_dbus_connection_register_object ( | |
| 184 | - object->connection, | |
| 179 | + ipc->id = g_dbus_connection_register_object ( | |
| 180 | + ipc->connection, | |
| 185 | 181 | "/br/com/bb/tn3270", |
| 186 | 182 | introspection_data->interfaces[0], |
| 187 | 183 | &interface_vtable, |
| 188 | - object, | |
| 184 | + ipc, | |
| 189 | 185 | NULL, |
| 190 | - &error | |
| 186 | + error | |
| 191 | 187 | ); |
| 192 | 188 | |
| 193 | 189 | g_dbus_node_info_unref(introspection_data); |
| ... | ... | @@ -198,29 +194,11 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { |
| 198 | 194 | |
| 199 | 195 | } |
| 200 | 196 | |
| 201 | - g_free(name); | |
| 197 | + g_free(object_name); | |
| 202 | 198 | |
| 203 | 199 | } |
| 204 | 200 | |
| 205 | - if(error) { | |
| 206 | - | |
| 207 | - GtkWidget *dialog = gtk_message_dialog_new( | |
| 208 | - GTK_WINDOW(window), | |
| 209 | - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 210 | - GTK_MESSAGE_ERROR, | |
| 211 | - GTK_BUTTONS_OK, | |
| 212 | - _( "Can't register D-Bus Object" )); | |
| 213 | - | |
| 214 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); | |
| 215 | - g_error_free(error); | |
| 216 | - | |
| 217 | - gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 218 | - gtk_widget_destroy(dialog); | |
| 219 | - | |
| 220 | - return G_OBJECT(object); | |
| 201 | +} | |
| 221 | 202 | |
| 222 | - } | |
| 223 | 203 | |
| 224 | - return G_OBJECT(object); | |
| 225 | 204 | |
| 226 | -} | ... | ... |
src/plugin/start.c
| ... | ... | @@ -34,10 +34,47 @@ |
| 34 | 34 | * |
| 35 | 35 | */ |
| 36 | 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 | + | |
| 37 | 44 | #include "private.h" |
| 45 | + #include <v3270.h> | |
| 46 | + #include <lib3270/ipc.h> | |
| 38 | 47 | |
| 39 | 48 | int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) { |
| 40 | - g_object_set_data_full(G_OBJECT(terminal), "ipc-object-info", ipc3270_new(window,terminal), g_object_unref); | |
| 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 | + | |
| 76 | + } | |
| 77 | + | |
| 41 | 78 | return 0; |
| 42 | 79 | } |
| 43 | 80 | ... | ... |