Commit df0d7fe9928cc8fa3757b925f4876e0d8ba85bfa

Authored by Perry Werneck
1 parent 4e98bbf4
Exists in master and in 1 other branch develop

Refactoring IPC module.

server/src/core/linux/gobject.c
... ... @@ -136,7 +136,7 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
136 136 " <method name= 'getStringAt'>" \
137 137 " <arg type='u' name='row' direction='in' />" \
138 138 " <arg type='u' name='col' direction='in' />" \
139   - " <arg type='u' name='len' direction='in' />" \
  139 + " <arg type='i' name='len' direction='in' />" \
140 140 " <arg type='y' name='lf' direction='in' />" \
141 141 " <arg type='s' name='text' direction='out' />" \
142 142 " </method>" \
... ... @@ -169,8 +169,8 @@ void ipc3270_add_terminal_introspection(GString *introspection) {
169 169 " <arg type='s' name='text' direction='out' />" \
170 170 " </method>" \
171 171 " <method name= 'getFieldAttributeAt'>" \
172   - " <arg type='u' name='row' direction='in' />" \
173   - " <arg type='u' name='col' direction='in' />" \
  172 + " <arg type='i' name='row' direction='in' />" \
  173 + " <arg type='i' name='col' direction='in' />" \
174 174 " <arg type='u' name='attribute' direction='out' />" \
175 175 " </method>" \
176 176 " <method name= 'getFieldAttributeAtAddress'>" \
... ...
server/src/core/linux/response.c 0 → 100644
... ... @@ -0,0 +1,139 @@
  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 - 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/actions.h>
  38 +#include <lib3270/properties.h>
  39 +#include <lib3270/toggle.h>
  40 +#include <v3270.h>
  41 +
  42 +#include <dbus/dbus-glib.h>
  43 +#include <dbus/dbus-glib-bindings.h>
  44 +
  45 +/*--[ Widget definition ]----------------------------------------------------------------------------*/
  46 +
  47 +struct _ipc3270Response {
  48 + GObject parent;
  49 + GVariant * value;
  50 +};
  51 +
  52 +struct _ipc3270ResponseClass {
  53 +
  54 + GObjectClass parent;
  55 + int dummy;
  56 +
  57 +};
  58 +
  59 +
  60 +G_DEFINE_TYPE(ipc3270Response, ipc3270Response, G_TYPE_OBJECT)
  61 +
  62 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  63 +
  64 +static void ipc3270Response_finalize(GObject *object) {
  65 +
  66 + ipc3270Response * response = IPC3270_RESPONSE(object);
  67 +
  68 + debug("%s value=%p",__FUNCTION__,response->value);
  69 +
  70 + if(response->value)
  71 + g_variant_unref(response->value);
  72 +
  73 +}
  74 +
  75 +
  76 +static void ipc3270Response_class_init(ipc3270ResponseClass *klass) {
  77 +
  78 + debug("%s",__FUNCTION__);
  79 +
  80 + GObjectClass *object_class;
  81 + object_class = G_OBJECT_CLASS (klass);
  82 + object_class->finalize = ipc3270Response_finalize;
  83 +
  84 +}
  85 +
  86 +static void ipc3270Response_init(ipc3270Response *object) {
  87 +
  88 + object->value = NULL;
  89 +
  90 +}
  91 +
  92 +GObject * ipc3270_response_new() {
  93 + return g_object_new(GLIB_TYPE_IPC3270_RESPONSE, NULL);
  94 +}
  95 +
  96 +void ipc3270_response_append_int32(GObject *object, gint32 value) {
  97 +
  98 + ipc3270Response * response = IPC3270_RESPONSE(object);
  99 +
  100 + if(response->value)
  101 + g_variant_unref(response->value);
  102 +
  103 + response->value = g_variant_new_int32(value);
  104 +}
  105 +
  106 +void ipc3270_response_append_uint32(GObject *object, guint32 value) {
  107 +
  108 + ipc3270Response * response = IPC3270_RESPONSE(object);
  109 +
  110 + if(response->value)
  111 + g_variant_unref(response->value);
  112 +
  113 + response->value = g_variant_new_uint32(value);
  114 +}
  115 +
  116 +void ipc3270_response_append_string(GObject *object, const gchar *text) {
  117 +
  118 + ipc3270Response * response = IPC3270_RESPONSE(object);
  119 +
  120 + if(response->value)
  121 + g_variant_unref(response->value);
  122 +
  123 + response->value = g_variant_new_string(text);
  124 +
  125 +}
  126 +
  127 +GVariant * ipc3270_response_steal_value(GObject *object) {
  128 +
  129 + ipc3270Response * response = IPC3270_RESPONSE(object);
  130 +
  131 + GVariant * value = response->value;
  132 + response->value = NULL;
  133 +
  134 + return value;
  135 +}
  136 +
  137 +gboolean ipc3270_response_has_values(GObject *object) {
  138 + return IPC3270_RESPONSE(object)->value != NULL;
  139 +}
... ...
server/src/core/methods/field.c 0 → 100644
... ... @@ -0,0 +1,38 @@
  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 - 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 "private.h"
  31 +
  32 +int ipc3270_method_get_field_attribute(GObject *session, GVariant *request, GObject *response, GError **error) {
  33 +
  34 + debug("%s childs=%u",__FUNCTION__,(unsigned int) g_variant_n_children(request));
  35 +
  36 + return ENOTSUP;
  37 +}
  38 +
... ...
server/src/core/methods/get.c
... ... @@ -38,15 +38,14 @@ int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *resp
38 38 switch(g_variant_n_children(request)) {
39 39 case 0: // No arguments
40 40 {
41   -
  41 + text = lib3270_get_string_at_address(hSession, 0, -1, '\n');
42 42 }
43 43 break;
44 44  
45 45 case 3: // address, length, line-delimiter
46 46 {
47   - gint addr;
48   - guint len;
49   - guchar lf;
  47 + gint addr = 0, len = -1;
  48 + guchar lf = 0;
50 49  
51 50 g_variant_get(request, "(iiy)", &addr, &len, &lf);
52 51  
... ... @@ -57,9 +56,11 @@ int ipc3270_method_get_string(GObject *session, GVariant *request, GObject *resp
57 56  
58 57 case 4: // row, col, length, line-delimiter
59 58 {
60   - guint row,col,len;
61   - guchar lf;
62   - g_variant_get(request, "(uuuy)", &row, &col, &len, &lf);
  59 + guint row = 0, col = 0;
  60 + gint len = -1;
  61 + guchar lf = 0;
  62 +
  63 + g_variant_get(request, "(uuiy)", &row, &col, &len, &lf);
63 64  
64 65 text = lib3270_get_string_at(hSession, row, col, len, lf);
65 66  
... ...
server/src/core/methods/set.c 0 → 100644
... ... @@ -0,0 +1,105 @@
  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 - 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 "private.h"
  31 +
  32 +int ipc3270_method_set_string(GObject *session, GVariant *request, GObject *response, GError **error) {
  33 +
  34 + H3270 *hSession = ipc3270_get_session(session);
  35 +
  36 + gchar *text = NULL;
  37 + g_variant_get(request, "(&s)", &text);
  38 +
  39 +
  40 + if(*error)
  41 + return 0;
  42 +
  43 + switch(g_variant_n_children(request)) {
  44 + case 1: // Just text
  45 + {
  46 + gchar *text = NULL;
  47 + g_variant_get(request, "(&s)", &text);
  48 +
  49 + if(text) {
  50 +
  51 + g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);
  52 +
  53 + if(!lib3270_input_string(hSession,(const unsigned char *) converted, -1))
  54 + return errno;
  55 + }
  56 +
  57 + }
  58 +
  59 + break;
  60 +
  61 + case 2: // Address and text
  62 + {
  63 + gint addr;
  64 + gchar *text = NULL;
  65 + g_variant_get(request, "(i&s)", &addr, &text);
  66 +
  67 + if(text) {
  68 +
  69 + g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);
  70 +
  71 + if(lib3270_set_string_at_address(hSession,addr,(unsigned char *) converted, -1) < 0)
  72 + return errno;
  73 +
  74 + }
  75 +
  76 + }
  77 + break;
  78 +
  79 + case 3: // Row, col & text
  80 + {
  81 + guint row, col;
  82 + gchar *text = NULL;
  83 + g_variant_get(request, "(uu&s)", &row, &col, &text);
  84 +
  85 + if(text) {
  86 +
  87 + g_autofree gchar * converted = ipc3270_convert_to_3270(session,text,error);
  88 +
  89 + if(lib3270_set_string_at(hSession, row, col, (unsigned char *) converted) < 0)
  90 + return errno;
  91 +
  92 + }
  93 +
  94 + }
  95 + break;
  96 +
  97 + default:
  98 + return EINVAL;
  99 + }
  100 +
  101 + ipc3270_response_append_uint32(response, 0);
  102 +
  103 + return 0;
  104 +}
  105 +
... ...
server/testscripts/getstringat.sh 0 → 100755
... ... @@ -0,0 +1,15 @@
  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/session" \
  11 + "br.com.bb.tn3270.session.getStringAtAddress" \
  12 + int32:0 \
  13 + int32:-1 \
  14 + byte:0
  15 +
... ...