Commit 941b5a97de989a3e1cc87eddbbae5399cfb5a7d2
1 parent
2b535dc5
Exists in
master
and in
1 other branch
Releasing object name on stop.
Showing
5 changed files
with
134 additions
and
16 deletions
Show diff stats
pw3270-plugin-ipc.cbp
| ... | ... | @@ -74,6 +74,9 @@ |
| 74 | 74 | <Unit filename="src/core/linux/start.c"> |
| 75 | 75 | <Option compilerVar="CC" /> |
| 76 | 76 | </Unit> |
| 77 | + <Unit filename="src/core/linux/stop.c"> | |
| 78 | + <Option compilerVar="CC" /> | |
| 79 | + </Unit> | |
| 77 | 80 | <Unit filename="src/core/methods.c"> |
| 78 | 81 | <Option compilerVar="CC" /> |
| 79 | 82 | </Unit> | ... | ... |
src/core/linux/gobject.c
| ... | ... | @@ -50,11 +50,7 @@ static void ipc3270_finalize(GObject *object) { |
| 50 | 50 | |
| 51 | 51 | debug("ipc3270::%s(%p)",__FUNCTION__,object); |
| 52 | 52 | |
| 53 | - ipc3270 * ipc = IPC3270(object); | |
| 54 | - | |
| 55 | - if(ipc->id) { | |
| 56 | - g_dbus_connection_unregister_object(ipc->connection,ipc->id); | |
| 57 | - } | |
| 53 | + ipc3270_release_object(IPC3270(object)); | |
| 58 | 54 | |
| 59 | 55 | G_OBJECT_CLASS(ipc3270_parent_class)->finalize(object); |
| 60 | 56 | } |
| ... | ... | @@ -155,7 +151,7 @@ void ipc3270_add_terminal_introspection(GString *introspection) { |
| 155 | 151 | // Boolean properties |
| 156 | 152 | const LIB3270_INT_PROPERTY * bol_props = lib3270_get_boolean_properties_list(); |
| 157 | 153 | for(ix = 0; bol_props[ix].name; ix++) { |
| 158 | - debug("Boolean(%s)",bol_props[ix].name); | |
| 154 | +// debug("Boolean(%s)",bol_props[ix].name); | |
| 159 | 155 | g_string_append_printf(introspection, " <property type='b' name='%s' access='%s'/>", |
| 160 | 156 | bol_props[ix].name, |
| 161 | 157 | ((bol_props[ix].set == NULL) ? "read" : "readwrite") | ... | ... |
src/core/linux/gobject.h
| ... | ... | @@ -56,8 +56,13 @@ |
| 56 | 56 | |
| 57 | 57 | struct _ipc3270 { |
| 58 | 58 | GObject parent; |
| 59 | - GDBusConnection * connection; | |
| 60 | - guint id; | |
| 59 | + | |
| 60 | + struct { | |
| 61 | + gchar * name; | |
| 62 | + GDBusConnection * connection; | |
| 63 | + guint id; | |
| 64 | + } dbus; | |
| 65 | + | |
| 61 | 66 | H3270 * hSession; |
| 62 | 67 | GQuark error_domain; |
| 63 | 68 | }; |
| ... | ... | @@ -66,6 +71,8 @@ |
| 66 | 71 | GObjectClass parent; |
| 67 | 72 | }; |
| 68 | 73 | |
| 74 | + G_GNUC_INTERNAL void ipc3270_release_object(ipc3270 *object); | |
| 75 | + | |
| 69 | 76 | G_END_DECLS |
| 70 | 77 | |
| 71 | 78 | #endif // LINUX_GOBJECT_H_INCLUDED | ... | ... |
src/core/linux/start.c
| ... | ... | @@ -121,15 +121,15 @@ void ipc3270_export_object(GObject *object, const char *name, GError **error) { |
| 121 | 121 | |
| 122 | 122 | ipc3270 * ipc = IPC3270(object); |
| 123 | 123 | |
| 124 | - ipc->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error); | |
| 124 | + ipc->dbus.connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error); | |
| 125 | 125 | if(*error) { |
| 126 | 126 | g_message("Can't get session bus: %s",(*error)->message); |
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - g_dbus_connection_set_exit_on_close(ipc->connection,FALSE); | |
| 130 | + g_dbus_connection_set_exit_on_close(ipc->dbus.connection,FALSE); | |
| 131 | 131 | |
| 132 | - for(id='a'; id < 'z' && !ipc->id && !*error; id++) { | |
| 132 | + for(id='a'; id < 'z' && !ipc->dbus.id && !*error; id++) { | |
| 133 | 133 | |
| 134 | 134 | g_autofree gchar *object_name = g_strdup_printf(PW3270_IPC_SESSION_BUS_NAME,name,id); |
| 135 | 135 | |
| ... | ... | @@ -140,7 +140,7 @@ void ipc3270_export_object(GObject *object, const char *name, GError **error) { |
| 140 | 140 | |
| 141 | 141 | GVariant * response = |
| 142 | 142 | g_dbus_connection_call_sync ( |
| 143 | - ipc->connection, | |
| 143 | + ipc->dbus.connection, | |
| 144 | 144 | DBUS_SERVICE_DBUS, |
| 145 | 145 | DBUS_PATH_DBUS, |
| 146 | 146 | DBUS_INTERFACE_DBUS, |
| ... | ... | @@ -167,7 +167,8 @@ void ipc3270_export_object(GObject *object, const char *name, GError **error) { |
| 167 | 167 | |
| 168 | 168 | if(reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { |
| 169 | 169 | |
| 170 | - g_message("Got %s", object_name); | |
| 170 | + ipc->dbus.name = g_strdup(object_name); | |
| 171 | + g_message("Got %s", ipc->dbus.name); | |
| 171 | 172 | |
| 172 | 173 | lib3270_set_session_id(ipc->hSession, id); |
| 173 | 174 | |
| ... | ... | @@ -178,13 +179,13 @@ void ipc3270_export_object(GObject *object, const char *name, GError **error) { |
| 178 | 179 | |
| 179 | 180 | gchar * introspection_xml = g_string_free(introspection,FALSE); |
| 180 | 181 | |
| 181 | - debug("\n%s\n",introspection_xml); | |
| 182 | + // debug("\n%s\n",introspection_xml); | |
| 182 | 183 | |
| 183 | 184 | GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); |
| 184 | 185 | |
| 185 | 186 | // Register object-id |
| 186 | - ipc->id = g_dbus_connection_register_object ( | |
| 187 | - ipc->connection, | |
| 187 | + ipc->dbus.id = g_dbus_connection_register_object ( | |
| 188 | + ipc->dbus.connection, | |
| 188 | 189 | PW3270_IPC_SESSION_OBJECT_PATH, |
| 189 | 190 | introspection_data->interfaces[0], |
| 190 | 191 | &interface_vtable, | ... | ... |
| ... | ... | @@ -0,0 +1,111 @@ |
| 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 | +void ipc3270_release_object(ipc3270 *object) { | |
| 43 | + | |
| 44 | + if(object->dbus.id) { | |
| 45 | + g_dbus_connection_unregister_object(object->dbus.connection,object->dbus.id); | |
| 46 | + } | |
| 47 | + | |
| 48 | + if(object->dbus.name) { | |
| 49 | + | |
| 50 | + debug("Releasing %s",object->dbus.name); | |
| 51 | + | |
| 52 | + // https://dbus.freedesktop.org/doc/dbus-specification.html | |
| 53 | + GError *err = NULL; | |
| 54 | + | |
| 55 | + GVariant * response = | |
| 56 | + g_dbus_connection_call_sync ( | |
| 57 | + object->dbus.connection, | |
| 58 | + DBUS_SERVICE_DBUS, | |
| 59 | + DBUS_PATH_DBUS, | |
| 60 | + DBUS_INTERFACE_DBUS, | |
| 61 | + "ReleaseName", | |
| 62 | + g_variant_new ("(s)", object->dbus.name), | |
| 63 | + NULL, | |
| 64 | + G_DBUS_CALL_FLAGS_NONE, | |
| 65 | + -1, | |
| 66 | + NULL, | |
| 67 | + &err | |
| 68 | + ); | |
| 69 | + | |
| 70 | + if(err) { | |
| 71 | + | |
| 72 | + g_message("Can't release \"%s\": %s",object->dbus.name,err->message); | |
| 73 | + g_error_free(err); | |
| 74 | + err = NULL; | |
| 75 | + | |
| 76 | + } else if(response) { | |
| 77 | + | |
| 78 | + guint32 reply = 0; | |
| 79 | + g_variant_get(response, "(u)", &reply); | |
| 80 | + g_variant_unref(response); | |
| 81 | + | |
| 82 | + switch(reply) | |
| 83 | + { | |
| 84 | + case DBUS_RELEASE_NAME_REPLY_RELEASED: | |
| 85 | + // The caller has released his claim on the given name. | |
| 86 | + // Either the caller was the primary owner of the name, and the name is | |
| 87 | + // now unused or taken by somebody waiting in the queue for the name, | |
| 88 | + // or the caller was waiting in the queue for the name and has now been removed from the queue. | |
| 89 | + g_message("%s released",object->dbus.name); | |
| 90 | + break; | |
| 91 | + | |
| 92 | + case DBUS_RELEASE_NAME_REPLY_NON_EXISTENT: | |
| 93 | + // The given name does not exist on this bus. | |
| 94 | + g_message("%s does not exist on this bus",object->dbus.name); | |
| 95 | + break; | |
| 96 | + | |
| 97 | + case DBUS_RELEASE_NAME_REPLY_NOT_OWNER: | |
| 98 | + // The caller was not the primary owner of this name, and was also not waiting in the queue to own this name. | |
| 99 | + g_message("%s does not exist on this bus", object->dbus.name); | |
| 100 | + break; | |
| 101 | + | |
| 102 | + default: | |
| 103 | + g_message("Unexpected response %u when removing %s",(unsigned int) reply, object->dbus.name); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + g_free(object->dbus.name); | |
| 108 | + object->dbus.name = NULL; | |
| 109 | + } | |
| 110 | + | |
| 111 | +} | ... | ... |