Commit 9b0f78c1ce95306e893ee676bb2e13570e281e3d
1 parent
61e7ae84
Exists in
master
and in
1 other branch
Adding method to get/set tn3270 properties from D-Bus
Showing
7 changed files
with
238 additions
and
74 deletions
Show diff stats
pw3270-plugin-ipc.cbp
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | <Option compiler="gcc" /> | 8 | <Option compiler="gcc" /> |
| 9 | <Build> | 9 | <Build> |
| 10 | <Target title="Debug"> | 10 | <Target title="Debug"> |
| 11 | - <Option output=".bin/Debug/pw3270ipc" prefix_auto="1" extension_auto="1" /> | 11 | + <Option output=".bin/Debug/ipc3270" prefix_auto="1" extension_auto="1" /> |
| 12 | <Option object_output=".obj/Debug/" /> | 12 | <Option object_output=".obj/Debug/" /> |
| 13 | <Option type="1" /> | 13 | <Option type="1" /> |
| 14 | <Option compiler="gcc" /> | 14 | <Option compiler="gcc" /> |
| @@ -40,10 +40,19 @@ | @@ -40,10 +40,19 @@ | ||
| 40 | </Linker> | 40 | </Linker> |
| 41 | <Unit filename="src/include/config.h.in" /> | 41 | <Unit filename="src/include/config.h.in" /> |
| 42 | <Unit filename="src/include/lib3270/ipc.h" /> | 42 | <Unit filename="src/include/lib3270/ipc.h" /> |
| 43 | + <Unit filename="src/linux/getproperties.c"> | ||
| 44 | + <Option compilerVar="CC" /> | ||
| 45 | + </Unit> | ||
| 43 | <Unit filename="src/linux/gobject.c"> | 46 | <Unit filename="src/linux/gobject.c"> |
| 44 | <Option compilerVar="CC" /> | 47 | <Option compilerVar="CC" /> |
| 45 | </Unit> | 48 | </Unit> |
| 46 | <Unit filename="src/linux/gobject.h" /> | 49 | <Unit filename="src/linux/gobject.h" /> |
| 50 | + <Unit filename="src/linux/methods.c"> | ||
| 51 | + <Option compilerVar="CC" /> | ||
| 52 | + </Unit> | ||
| 53 | + <Unit filename="src/linux/setproperties.c"> | ||
| 54 | + <Option compilerVar="CC" /> | ||
| 55 | + </Unit> | ||
| 47 | <Unit filename="src/plugin/private.h" /> | 56 | <Unit filename="src/plugin/private.h" /> |
| 48 | <Unit filename="src/plugin/start.c"> | 57 | <Unit filename="src/plugin/start.c"> |
| 49 | <Option compilerVar="CC" /> | 58 | <Option compilerVar="CC" /> |
| @@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
| 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 <v3270.h> | ||
| 37 | + | ||
| 38 | +#include <dbus/dbus-glib.h> | ||
| 39 | +#include <dbus/dbus-glib-bindings.h> | ||
| 40 | + | ||
| 41 | +GVariant * | ||
| 42 | +ipc3270_get_property (GDBusConnection *connection, | ||
| 43 | + const gchar *sender, | ||
| 44 | + const gchar *object_path, | ||
| 45 | + const gchar *interface_name, | ||
| 46 | + const gchar *property_name, | ||
| 47 | + GError **error, | ||
| 48 | + gpointer user_data) | ||
| 49 | +{ | ||
| 50 | + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(property_name); | ||
| 51 | + | ||
| 52 | + debug("%s: toggle(%s)=%d", __FUNCTION__, property_name,(int) toggle); | ||
| 53 | + if(toggle != (LIB3270_TOGGLE) -1) { | ||
| 54 | + | ||
| 55 | + // Is a Tn3270 toggle, get it! | ||
| 56 | + return g_variant_new_int16((gint16) lib3270_get_toggle(IPC3270(user_data)->hSession,toggle)); | ||
| 57 | + | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + g_set_error (error, | ||
| 62 | + G_IO_ERROR, | ||
| 63 | + G_IO_ERROR_NOT_FOUND, | ||
| 64 | + "Can't find any property named %s", property_name | ||
| 65 | + ); | ||
| 66 | + | ||
| 67 | + return NULL; | ||
| 68 | +} | ||
| 69 | + |
src/linux/gobject.c
| @@ -38,16 +38,6 @@ | @@ -38,16 +38,6 @@ | ||
| 38 | #include <dbus/dbus-glib.h> | 38 | #include <dbus/dbus-glib.h> |
| 39 | #include <dbus/dbus-glib-bindings.h> | 39 | #include <dbus/dbus-glib-bindings.h> |
| 40 | 40 | ||
| 41 | -/* Introspection data for the service we are exporting */ | ||
| 42 | -static const gchar introspection_xml[] = | ||
| 43 | - "<node>" | ||
| 44 | - " <interface name='br.com.bb.tn3270'>" | ||
| 45 | - " <method name='about'>" | ||
| 46 | - " <arg type='s' name='revision' direction='out'/>" | ||
| 47 | - " </method>" | ||
| 48 | - " </interface>" | ||
| 49 | - "</node>"; | ||
| 50 | - | ||
| 51 | G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT) | 41 | G_DEFINE_TYPE(ipc3270, ipc3270, G_TYPE_OBJECT) |
| 52 | 42 | ||
| 53 | static void ipc3270_finalize(GObject *object) { | 43 | static void ipc3270_finalize(GObject *object) { |
| @@ -79,67 +69,6 @@ static void ipc3270_init(ipc3270 *object) { | @@ -79,67 +69,6 @@ static void ipc3270_init(ipc3270 *object) { | ||
| 79 | 69 | ||
| 80 | } | 70 | } |
| 81 | 71 | ||
| 82 | -void | ||
| 83 | -ipc3270_method_call (GDBusConnection *connection, | ||
| 84 | - const gchar *sender, | ||
| 85 | - const gchar *object_path, | ||
| 86 | - const gchar *interface_name, | ||
| 87 | - const gchar *method_name, | ||
| 88 | - GVariant *parameters, | ||
| 89 | - GDBusMethodInvocation *invocation, | ||
| 90 | - gpointer user_data) | ||
| 91 | -{ | ||
| 92 | - | ||
| 93 | - | ||
| 94 | - g_dbus_method_invocation_return_error ( | ||
| 95 | - invocation, | ||
| 96 | - G_DBUS_ERROR, | ||
| 97 | - G_DBUS_ERROR_UNKNOWN_METHOD, | ||
| 98 | - "Invalid or unexpected method call"); | ||
| 99 | - | ||
| 100 | -} | ||
| 101 | - | ||
| 102 | -GVariant * | ||
| 103 | -ipc3270_get_property (GDBusConnection *connection, | ||
| 104 | - const gchar *sender, | ||
| 105 | - const gchar *object_path, | ||
| 106 | - const gchar *interface_name, | ||
| 107 | - const gchar *property_name, | ||
| 108 | - GError **error, | ||
| 109 | - gpointer user_data) | ||
| 110 | -{ | ||
| 111 | - GVariant *ret = NULL; | ||
| 112 | - | ||
| 113 | - g_set_error (error, | ||
| 114 | - G_IO_ERROR, | ||
| 115 | - G_IO_ERROR_NOT_FOUND, | ||
| 116 | - "There's no %s propriety", property_name | ||
| 117 | - ); | ||
| 118 | - | ||
| 119 | - return ret; | ||
| 120 | -} | ||
| 121 | - | ||
| 122 | -gboolean | ||
| 123 | -ipc3270_set_property (GDBusConnection *connection, | ||
| 124 | - const gchar *sender, | ||
| 125 | - const gchar *object_path, | ||
| 126 | - const gchar *interface_name, | ||
| 127 | - const gchar *property_name, | ||
| 128 | - GVariant *value, | ||
| 129 | - GError **error, | ||
| 130 | - gpointer user_data) | ||
| 131 | -{ | ||
| 132 | - | ||
| 133 | - | ||
| 134 | - g_set_error (error, | ||
| 135 | - G_IO_ERROR, | ||
| 136 | - G_IO_ERROR_NOT_FOUND, | ||
| 137 | - "There's no %s propriety", property_name | ||
| 138 | - ); | ||
| 139 | - | ||
| 140 | - return *error == NULL; | ||
| 141 | -} | ||
| 142 | - | ||
| 143 | GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | 72 | GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { |
| 144 | 73 | ||
| 145 | static const GDBusInterfaceVTable interface_vtable = { | 74 | static const GDBusInterfaceVTable interface_vtable = { |
| @@ -151,9 +80,10 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | @@ -151,9 +80,10 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | ||
| 151 | ipc3270 * object = IPC3270(g_object_new(GLIB_TYPE_IPC3270, NULL)); | 80 | ipc3270 * object = IPC3270(g_object_new(GLIB_TYPE_IPC3270, NULL)); |
| 152 | 81 | ||
| 153 | GError * error = NULL; | 82 | GError * error = NULL; |
| 154 | - int id; | 83 | + int id, ix; |
| 155 | 84 | ||
| 156 | - object->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); | 85 | + object->hSession = v3270_get_session(terminal); |
| 86 | + object->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); | ||
| 157 | 87 | ||
| 158 | if(error) { | 88 | if(error) { |
| 159 | GtkWidget *dialog = gtk_message_dialog_new( | 89 | GtkWidget *dialog = gtk_message_dialog_new( |
| @@ -217,6 +147,27 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | @@ -217,6 +147,27 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | ||
| 217 | 147 | ||
| 218 | g_message("Got %s - %s", name, v3270_get_session_name(terminal)); | 148 | g_message("Got %s - %s", name, v3270_get_session_name(terminal)); |
| 219 | 149 | ||
| 150 | + // Introspection data for the service we are exporting | ||
| 151 | + GString * introspection = g_string_new( | ||
| 152 | + "<node>\n" | ||
| 153 | + " <interface name='br.com.bb.tn3270'>" | ||
| 154 | + " <method name='connect'>" | ||
| 155 | + " <arg type='s' name='url' direction='in'/>" | ||
| 156 | + " </method>" | ||
| 157 | + " <property type='i' name='Revision' access='read'/>" | ||
| 158 | + " <property type='s' name='Version' access='read'/>" | ||
| 159 | + ); | ||
| 160 | + | ||
| 161 | + for(ix = 0; ix < (int) LIB3270_TOGGLE_COUNT; ix++) { | ||
| 162 | + g_string_append_printf(introspection, " <property type='i' name='%s' access='readwrite'/>", lib3270_get_toggle_name((LIB3270_TOGGLE) ix)); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + g_string_append(introspection, | ||
| 166 | + " </interface>" | ||
| 167 | + "</node>" | ||
| 168 | + ); | ||
| 169 | + | ||
| 170 | + gchar * introspection_xml = g_string_free(introspection,FALSE); | ||
| 220 | GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); | 171 | GDBusNodeInfo * introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); |
| 221 | 172 | ||
| 222 | // Register object-id | 173 | // Register object-id |
| @@ -231,6 +182,7 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | @@ -231,6 +182,7 @@ GObject * ipc3270_new(GtkWidget *window, GtkWidget *terminal) { | ||
| 231 | ); | 182 | ); |
| 232 | 183 | ||
| 233 | g_dbus_node_info_unref(introspection_data); | 184 | g_dbus_node_info_unref(introspection_data); |
| 185 | + g_free(introspection_xml); | ||
| 234 | 186 | ||
| 235 | break; | 187 | break; |
| 236 | } | 188 | } |
src/linux/gobject.h
| @@ -46,6 +46,7 @@ | @@ -46,6 +46,7 @@ | ||
| 46 | #include <glib/gi18n.h> | 46 | #include <glib/gi18n.h> |
| 47 | #include <gio/gio.h> | 47 | #include <gio/gio.h> |
| 48 | 48 | ||
| 49 | + #include <lib3270.h> | ||
| 49 | #include <lib3270/ipc.h> | 50 | #include <lib3270/ipc.h> |
| 50 | 51 | ||
| 51 | G_BEGIN_DECLS | 52 | G_BEGIN_DECLS |
| @@ -57,6 +58,7 @@ | @@ -57,6 +58,7 @@ | ||
| 57 | GObject parent; | 58 | GObject parent; |
| 58 | GDBusConnection * connection; | 59 | GDBusConnection * connection; |
| 59 | guint id; | 60 | guint id; |
| 61 | + GtkWidget * hSession; | ||
| 60 | }; | 62 | }; |
| 61 | 63 | ||
| 62 | struct _ipc3270Class { | 64 | struct _ipc3270Class { |
| @@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
| 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 <v3270.h> | ||
| 37 | + | ||
| 38 | +#include <dbus/dbus-glib.h> | ||
| 39 | +#include <dbus/dbus-glib-bindings.h> | ||
| 40 | + | ||
| 41 | +void | ||
| 42 | +ipc3270_method_call (GDBusConnection *connection, | ||
| 43 | + const gchar *sender, | ||
| 44 | + const gchar *object_path, | ||
| 45 | + const gchar *interface_name, | ||
| 46 | + const gchar *method_name, | ||
| 47 | + GVariant *parameters, | ||
| 48 | + GDBusMethodInvocation *invocation, | ||
| 49 | + gpointer user_data) | ||
| 50 | +{ | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + g_dbus_method_invocation_return_error ( | ||
| 54 | + invocation, | ||
| 55 | + G_DBUS_ERROR, | ||
| 56 | + G_DBUS_ERROR_UNKNOWN_METHOD, | ||
| 57 | + "Invalid or unexpected method call"); | ||
| 58 | + | ||
| 59 | +} |
| @@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
| 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 <v3270.h> | ||
| 37 | + | ||
| 38 | +#include <dbus/dbus-glib.h> | ||
| 39 | +#include <dbus/dbus-glib-bindings.h> | ||
| 40 | + | ||
| 41 | +gboolean | ||
| 42 | +ipc3270_set_property (GDBusConnection *connection, | ||
| 43 | + const gchar *sender, | ||
| 44 | + const gchar *object_path, | ||
| 45 | + const gchar *interface_name, | ||
| 46 | + const gchar *property_name, | ||
| 47 | + GVariant *value, | ||
| 48 | + GError **error, | ||
| 49 | + gpointer user_data) | ||
| 50 | +{ | ||
| 51 | + | ||
| 52 | + g_set_error (error, | ||
| 53 | + G_IO_ERROR, | ||
| 54 | + G_IO_ERROR_NOT_FOUND, | ||
| 55 | + "Can't find any property named %s", property_name | ||
| 56 | + ); | ||
| 57 | + | ||
| 58 | + return *error == NULL; | ||
| 59 | +} |
| @@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
| 1 | +#!/bin/bash | ||
| 2 | +# | ||
| 3 | +# https://stackoverflow.com/questions/48648952/set-get-property-using-dbus-send | ||
| 4 | +# | ||
| 5 | + | ||
| 6 | +dbus-send \ | ||
| 7 | + --session \ | ||
| 8 | + --dest=br.com.bb.pw3270.a\ | ||
| 9 | + --print-reply \ | ||
| 10 | + "/br/com/bb/tn3270" \ | ||
| 11 | + "org.freedesktop.DBus.Properties.Get" \ | ||
| 12 | + string:br.com.bb.tn3270 \ | ||
| 13 | + string:${1} | ||
| 14 | + |