Commit 0f190dc53aced37a3bb6112dae861edb60bccbef

Authored by Perry Werneck
0 parents
Exists in master and in 1 other branch develop

Splitting old HLLAPI module to his own repository.

src/dbus3270/Makefile.in 0 → 100644
  1 +++ a/src/dbus3270/Makefile.in
... ... @@ -0,0 +1,221 @@
  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., 59 Temple
  19 +# Place, Suite 330, Boston, MA, 02111-1307, USA
  20 +#
  21 +# Contatos:
  22 +#
  23 +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  24 +# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça)
  25 +#
  26 +
  27 +MODULE_NAME=dbus3270
  28 +
  29 +SOURCES=main.c gobject.c misc.c
  30 +# DAEMON_SRC=daemon.c gobject.c iocallback.c misc.c
  31 +
  32 +#---[ Configuration values ]-------------------------------------------------------------
  33 +
  34 +PACKAGE_NAME=@PACKAGE_NAME@
  35 +PACKAGE_VERSION=@PACKAGE_VERSION@
  36 +PACKAGE_TARNAME=@PACKAGE_TARNAME@
  37 +
  38 +prefix=@prefix@
  39 +exec_prefix=@exec_prefix@
  40 +bindir=@bindir@
  41 +sbindir=@sbindir@
  42 +libdir=@libdir@
  43 +
  44 +BASEDIR=@BASEDIR@
  45 +SRCDIR=$(BASEDIR)/.src/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/src/plugins/$(MODULE_NAME)
  46 +POTDIR=$(BASEDIR)/.pot/plugins/$(MODULE_NAME)
  47 +
  48 +OBJDIR=$(BASEDIR)/.obj/plugins/$(MODULE_NAME)
  49 +OBJDBG=$(OBJDIR)/Debug
  50 +OBJRLS=$(OBJDIR)/Release
  51 +
  52 +BINDIR=$(BASEDIR)/.bin
  53 +BINDBG=$(BINDIR)/Debug/plugins
  54 +BINRLS=$(BINDIR)/Release/plugins
  55 +
  56 +MKDIR=@MKDIR_P@
  57 +CC=@CC@
  58 +LD=@CC@
  59 +AR=@AR@
  60 +DBUSBINDINGTOOL=@DBUSBINDINGTOOL@
  61 +XGETTEXT=@XGETTEXT@
  62 +MSGCAT=@MSGCAT@
  63 +INSTALL=@INSTALL@
  64 +INSTALL_DATA=@INSTALL_DATA@
  65 +INSTALL_PROGRAM=@INSTALL_PROGRAM@
  66 +
  67 +CFLAGS= \
  68 + @CFLAGS@ \
  69 + @LIB3270_CFLAGS@ \
  70 + @LIBV3270_CFLAGS@ \
  71 + @PW3270_CFLAGS@ \
  72 + @GTK_CFLAGS@ \
  73 + @DBUS_CFLAGS@
  74 +
  75 +LIBS= \
  76 + @LIBS@ \
  77 + @GTK_LIBS@ \
  78 + @GLIB_LIBS@ \
  79 + @GDBUS_LIBS@ \
  80 + @LIB3270_LIBS@ \
  81 + @LIBV3270_LIBS@ \
  82 + @PW3270_LIBS@
  83 +
  84 +#---[ Rules ]----------------------------------------------------------------------------
  85 +
  86 +DEPENDS=dbus-glue.h globals.h service.h Makefile
  87 +
  88 +$(OBJDBG)/%.o: \
  89 + %.c \
  90 + $(DEPENDS)
  91 +
  92 + @echo $< ...
  93 + @$(MKDIR) `dirname $@`
  94 + @$(CC) $(CFLAGS) \
  95 + @DBG_CFLAGS@ \
  96 + -DBUILD_DATE=`date +"0x%Y%m%d"`\
  97 + -o $@ -c $<
  98 +
  99 +$(OBJRLS)/%.o: \
  100 + %.c \
  101 + $(DEPENDS)
  102 +
  103 + @echo $< ...
  104 + @$(MKDIR) `dirname $@`
  105 + @$(CC) $(CFLAGS) \
  106 + @RLS_CFLAGS@ \
  107 + -DBUILD_DATE=`date +"0x%Y%m%d"` \
  108 + -o $@ -c $<
  109 +
  110 +$(POTDIR)/%.pot: %.c
  111 +
  112 + @echo $(notdir $@) ...
  113 + @$(MKDIR) `dirname $@`
  114 + @$(XGETTEXT) \
  115 + --default-domain=$(PACKAGE) \
  116 + --language=C \
  117 + --keyword=_ \
  118 + --keyword=N_ \
  119 + --keyword=MSG_:2 \
  120 + --output=$@ \
  121 + $<
  122 +
  123 + @touch $@
  124 +
  125 +dbus-glue.h: \
  126 + pw3270dbus.xml
  127 +
  128 + @echo $@ ...
  129 + @$(DBUSBINDINGTOOL) \
  130 + --mode=glib-server \
  131 + --output=$@ \
  132 + --prefix=pw3270_dbus $^
  133 +
  134 +
  135 +#---[ Release Targets ]------------------------------------------------------------------
  136 +
  137 +Release: \
  138 + $(BINRLS)/$(MODULE_NAME)@DLLEXT@
  139 +
  140 +install: \
  141 + $(BINRLS)/$(MODULE_NAME)@DLLEXT@
  142 +
  143 + @echo $@ ...
  144 + @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins
  145 + @$(INSTALL_PROGRAM) $(BINRLS)/$(MODULE_NAME)@DLLEXT@ $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins/$(MODULE_NAME)@DLLEXT@
  146 +
  147 +$(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins/$(MODULE_NAME)@DLLEXT@: \
  148 + $(BINRLS)/$(MODULE_NAME)@DLLEXT@
  149 +
  150 + @echo $@ ...
  151 + @$(MKDIR) `dirname $@`
  152 + @$(INSTALL_PROGRAM) $(BINRLS)/$(MODULE_NAME)@DLLEXT@ $@
  153 +
  154 +
  155 +$(BINRLS)/$(MODULE_NAME)@DLLEXT@: \
  156 + $(foreach SRC, $(basename $(SOURCES)), $(OBJRLS)/$(SRC).o)
  157 +
  158 + @echo $@ ...
  159 + @$(MKDIR) `dirname $@`
  160 + @$(LD) \
  161 + -shared \
  162 + -L$(BASEDIR)/.bin/Release \
  163 + -o $@ $^ \
  164 + $(LIBS)
  165 +
  166 +pot: \
  167 + $(BASEDIR)/.pot/plugins/$(MODULE_NAME).pot
  168 +
  169 +$(BASEDIR)/.pot/plugins/$(MODULE_NAME).pot: \
  170 + $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(SRC).pot)
  171 +
  172 + @rm -f $@
  173 + @mkdir -p `dirname $@`
  174 + @$(MSGCAT) --sort-output $^ > $@
  175 +
  176 +$(SRCDIR): \
  177 + clean
  178 +
  179 + @$(MKDIR) $@
  180 + @$(INSTALL_DATA) *.c *.h *.in *.xml *.cbp $@
  181 +
  182 +
  183 +#---[ Debug Targets ]--------------------------------------------------------------------
  184 +
  185 +Debug: \
  186 + $(BINDBG)/$(MODULE_NAME)@DLLEXT@
  187 +
  188 +$(BINDBG)/$(MODULE_NAME)@DLLEXT@: \
  189 + $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).o)
  190 +
  191 + @echo $@ ...
  192 + @$(MKDIR) `dirname $@`
  193 + @$(LD) \
  194 + -shared \
  195 + -Wl,-soname,`basename $@`,--rpath,$(BASEDIR)/.bin/Debug \
  196 + -L$(BASEDIR)/.bin/Debug \
  197 + -o $@ $^ \
  198 + $(LIBS)
  199 +
  200 +
  201 +#---[ Clean Targets]---------------------------------------------------------------------
  202 +
  203 +cleanDebug:
  204 +
  205 + @rm -fr $(BINDBG)/$(MODULE_NAME)@DLLEXT@ \
  206 + $(OBJDBG) \
  207 + dbus-glue.h
  208 +
  209 +cleanRelease:
  210 +
  211 + @rm -fr $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \
  212 + $(OBJRLS) \
  213 + dbus-glue.h
  214 +
  215 + @rm -fr $(POTDIR)
  216 +
  217 +clean: \
  218 + cleanDebug \
  219 + cleanRelease
  220 +
  221 +
... ...
src/dbus3270/daemon.c 0 → 100644
  1 +++ a/src/dbus3270/daemon.c
... ... @@ -0,0 +1,122 @@
  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 daemon.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + * Referencias:
  31 + *
  32 + * https://live.gnome.org/DBusGlibBindings
  33 + *
  34 + */
  35 +
  36 +#include <glib.h>
  37 +#include <dbus/dbus.h>
  38 +#include <dbus/dbus-glib-lowlevel.h>
  39 +#include <dbus/dbus-glib.h>
  40 +
  41 +#include "daemon.h"
  42 +#include "dbus-glue.h"
  43 +
  44 +#define PW3270_DBUS_SERVICE_PATH "/br/com/bb/pw3270"
  45 +#define PW3270_DBUS_SERVICE "br.com.bb.pw3270"
  46 +
  47 +
  48 +/*---[ Globals ]---------------------------------------------------------------------------------*/
  49 +
  50 + static DBusGConnection * connection = NULL;
  51 + static DBusGProxy * proxy = NULL;
  52 + static H3270 * hSession = NULL;
  53 +
  54 + GMainLoop * main_loop = NULL;
  55 +
  56 +
  57 +/*---[ Implement ]-------------------------------------------------------------------------------*/
  58 +
  59 +static int initialize(void)
  60 +{
  61 + GError * error = NULL;
  62 + guint result;
  63 +
  64 + connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error);
  65 + if(error)
  66 + {
  67 + g_message("Error \"%s\" getting session dbus",error->message);
  68 + g_error_free(error);
  69 + return -1;
  70 + }
  71 +
  72 + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);
  73 +
  74 + org_freedesktop_DBus_request_name(proxy, PW3270_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);
  75 +
  76 + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,PW3270_DBUS_SERVICE_PATH);
  77 +
  78 + return 0;
  79 +}
  80 +
  81 +static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args)
  82 +{
  83 + g_logv(module,rc ? G_LOG_LEVEL_WARNING : G_LOG_LEVEL_MESSAGE, fmt, args);
  84 +}
  85 +
  86 +int main(int numpar, char *param[])
  87 +{
  88 + g_type_init ();
  89 +
  90 + if (!g_thread_supported ())
  91 + g_thread_init (NULL);
  92 +
  93 + dbus_g_thread_init ();
  94 +
  95 + lib3270_set_log_handler(loghandler);
  96 + pw3270_dbus_register_io_handlers();
  97 +
  98 + hSession = lib3270_session_new("");
  99 +
  100 + main_loop = g_main_loop_new (NULL, FALSE);
  101 +
  102 + if(initialize())
  103 + return -1;
  104 +
  105 + g_main_loop_run(main_loop);
  106 +
  107 + lib3270_session_free(hSession);
  108 +
  109 + return 0;
  110 +}
  111 +
  112 +void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context)
  113 +{
  114 + g_main_loop_quit(main_loop);
  115 + dbus_g_method_return(context,0);
  116 +}
  117 +
  118 +H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object)
  119 +{
  120 + return hSession;
  121 +}
  122 +
... ...
src/dbus3270/daemon.h 0 → 100644
  1 +++ a/src/dbus3270/daemon.h
... ... @@ -0,0 +1,46 @@
  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 daemon.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + * Referencias:
  31 + *
  32 + * https://live.gnome.org/DBusGlibBindings
  33 + *
  34 + */
  35 +
  36 + #include "service.h"
  37 +
  38 +/*---[ Globals ]---------------------------------------------------------------------------------*/
  39 +
  40 + G_GNUC_INTERNAL GMainLoop * main_loop;
  41 +
  42 +
  43 +/*---[ Prototipes ]------------------------------------------------------------------------------*/
  44 +
  45 + G_GNUC_INTERNAL void pw3270_dbus_register_io_handlers(void);
  46 +
... ...
src/dbus3270/globals.h 0 → 100644
  1 +++ a/src/dbus3270/globals.h
... ... @@ -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 globals.h 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + */
  31 +
  32 +#ifndef PW3270_DBUS_GLOBALS_H_INCLUDED
  33 +
  34 + #define PW3270_DBUS_GLOBALS_H_INCLUDED 1
  35 +
  36 + #include <libintl.h>
  37 + #include <glib/gi18n.h>
  38 +
  39 + #include <errno.h>
  40 + #include <lib3270.h>
  41 + #include <lib3270/log.h>
  42 + #include <glib.h>
  43 +
  44 + //
  45 + // Disabling warning on unused-function defined in dbus-glib-bindings.h
  46 + // warning: 'org_freedesktop_DBus_reload_config' defined but not used [-Wunused-function] ...
  47 + //
  48 + #pragma GCC diagnostic ignored "-Wunused-function"
  49 +
  50 + #include <dbus/dbus-glib.h>
  51 + #include <dbus/dbus-glib-bindings.h>
  52 + #include <dbus/dbus-glib-lowlevel.h>
  53 +
  54 + #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS")
  55 +
  56 + G_GNUC_INTERNAL gpointer pw3270_dbus_register_object (DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path);
  57 +
  58 +
  59 +#endif // PW3270_DBUS_GLOBALS_H_INCLUDED
... ...
src/dbus3270/gobject.c 0 → 100644
  1 +++ a/src/dbus3270/gobject.c
... ... @@ -0,0 +1,622 @@
  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 gobject.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + * Referencias:
  31 + *
  32 + * https://live.gnome.org/DBusGlibBindings
  33 + *
  34 + */
  35 +
  36 +#include <glib.h>
  37 +#include <gtk/gtk.h>
  38 +#include <dbus/dbus.h>
  39 +#include <dbus/dbus-glib-lowlevel.h>
  40 +#include <dbus/dbus-glib.h>
  41 +
  42 +#include <config.h>
  43 +#include <lib3270.h>
  44 +#include <pw3270.h>
  45 +#include <v3270.h>
  46 +#include <lib3270/actions.h>
  47 +#include <lib3270/charset.h>
  48 +
  49 +#include "service.h"
  50 +
  51 +/*---[ Globals ]---------------------------------------------------------------------------------*/
  52 +
  53 +
  54 +/*---[ Implement ]-------------------------------------------------------------------------------*/
  55 +
  56 +G_DEFINE_TYPE(PW3270Dbus, pw3270_dbus, G_TYPE_OBJECT)
  57 +
  58 +static void pw3270_dbus_finalize(GObject *object)
  59 +{
  60 + G_OBJECT_CLASS(pw3270_dbus_parent_class)->finalize (object);
  61 +}
  62 +
  63 +
  64 +static void pw3270_dbus_class_init(PW3270DbusClass *klass)
  65 +{
  66 + GObjectClass *object_class;
  67 + object_class = G_OBJECT_CLASS (klass);
  68 + object_class->finalize = pw3270_dbus_finalize;
  69 +}
  70 +
  71 +static void pw3270_dbus_init(PW3270Dbus *object)
  72 +{
  73 +
  74 +}
  75 +
  76 +PW3270Dbus * pw3270_dbus_new(void)
  77 +{
  78 + return g_object_new(PW3270_TYPE_DBUS, NULL);
  79 +}
  80 +
  81 +void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context)
  82 +{
  83 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  84 +#ifdef PACKAGE_REVISION
  85 + dbus_g_method_return(context,PACKAGE_REVISION);
  86 +#else
  87 + dbus_g_method_return(context,BUILD_DATE);
  88 +#endif
  89 +}
  90 +
  91 +void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context)
  92 +{
  93 + H3270 *hSession = pw3270_dbus_get_session_handle(PW3270_DBUS(object));
  94 +
  95 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  96 +
  97 + if(uri && *uri)
  98 + {
  99 + lib3270_set_url(hSession,uri);
  100 + g_message("Connecting to \"%s\" by remote request",lib3270_get_url(hSession));
  101 + }
  102 + else
  103 + {
  104 + g_message("%s","Connecting by remote request");
  105 + }
  106 +
  107 + dbus_g_method_return(context,lib3270_reconnect(hSession,0));
  108 +}
  109 +
  110 +void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context)
  111 +{
  112 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  113 +
  114 + g_message("Changing host to \"%s\" by remote request",uri);
  115 +
  116 + dbus_g_method_return(context,lib3270_set_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri) != 0);
  117 +}
  118 +
  119 +void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context)
  120 +{
  121 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  122 + dbus_g_method_return(context,lib3270_get_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object))));
  123 +}
  124 +
  125 +
  126 +void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context)
  127 +{
  128 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  129 +
  130 + g_message("Disconnecting by remote request");
  131 + lib3270_disconnect(pw3270_dbus_get_session_handle(object));
  132 + dbus_g_method_return(context,0);
  133 +}
  134 +
  135 +void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context)
  136 +{
  137 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  138 + dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object)));
  139 +}
  140 +
  141 +void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context)
  142 +{
  143 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  144 + dbus_g_method_return(context,lib3270_get_connection_state(pw3270_dbus_get_session_handle(object)));
  145 +}
  146 +
  147 +void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context)
  148 +{
  149 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  150 + dbus_g_method_return(context,lib3270_get_secure(pw3270_dbus_get_session_handle(object)));
  151 +}
  152 +
  153 +GError * pw3270_dbus_get_error_from_errno(int code)
  154 +{
  155 + return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code));
  156 +}
  157 +
  158 +int pw3270_dbus_check_valid_state(PW3270Dbus *object, DBusGMethodInvocation *context)
  159 +{
  160 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  161 + GError * error = NULL;
  162 +
  163 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  164 +
  165 + if(!lib3270_is_connected(hSession))
  166 + {
  167 + error = pw3270_dbus_get_error_from_errno(ENOTCONN);
  168 + }
  169 + else
  170 + {
  171 + LIB3270_MESSAGE state = lib3270_get_program_message(hSession);
  172 +
  173 + switch(state)
  174 + {
  175 + case LIB3270_MESSAGE_NONE:
  176 + return 0;
  177 +
  178 + case LIB3270_MESSAGE_DISCONNECTED:
  179 + error = pw3270_dbus_get_error_from_errno(ENOTCONN);
  180 + break;
  181 +
  182 + case LIB3270_MESSAGE_MINUS:
  183 + case LIB3270_MESSAGE_PROTECTED:
  184 + case LIB3270_MESSAGE_NUMERIC:
  185 + case LIB3270_MESSAGE_OVERFLOW:
  186 + case LIB3270_MESSAGE_INHIBIT:
  187 + case LIB3270_MESSAGE_KYBDLOCK:
  188 + case LIB3270_MESSAGE_X:
  189 + error = g_error_new(ERROR_DOMAIN,-1,_( "State %04d can't accept requests" ),state);
  190 + break;
  191 +
  192 + case LIB3270_MESSAGE_SYSWAIT:
  193 + case LIB3270_MESSAGE_TWAIT:
  194 + case LIB3270_MESSAGE_CONNECTED:
  195 + case LIB3270_MESSAGE_AWAITING_FIRST:
  196 + error = pw3270_dbus_get_error_from_errno(EBUSY);
  197 + break;
  198 +
  199 + case LIB3270_MESSAGE_RESOLVING:
  200 + case LIB3270_MESSAGE_CONNECTING:
  201 + error = g_error_new(ERROR_DOMAIN,EINPROGRESS,_( "Connecting to host" ));
  202 +
  203 + case LIB3270_MESSAGE_USER:
  204 + error = g_error_new(ERROR_DOMAIN,-1,_( "Unexpected state %04d" ),state);
  205 + }
  206 + }
  207 +
  208 + if(error)
  209 + {
  210 + dbus_g_method_return_error(context,error);
  211 + g_error_free(error);
  212 + return -1;
  213 + }
  214 +
  215 + return 0;
  216 +}
  217 +
  218 +void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context)
  219 +{
  220 + char * text;
  221 + gchar * utftext;
  222 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  223 +
  224 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  225 +
  226 + if(pw3270_dbus_check_valid_state(object,context))
  227 + return;
  228 +
  229 + text = lib3270_get_string_at_address(hSession,0,-1,'\n');
  230 +
  231 + utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL);
  232 +
  233 + lib3270_free(text);
  234 +
  235 + dbus_g_method_return(context,utftext);
  236 +
  237 + g_free(utftext);
  238 +
  239 +}
  240 +
  241 +void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context)
  242 +{
  243 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  244 + if(pw3270_dbus_check_valid_state(object,context))
  245 + return;
  246 + dbus_g_method_return(context,lib3270_enter(pw3270_dbus_get_session_handle(object)));
  247 +}
  248 +
  249 +void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, DBusGMethodInvocation *context)
  250 +{
  251 + gchar * text;
  252 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  253 +
  254 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  255 + if(pw3270_dbus_check_valid_state(object,context))
  256 + return;
  257 +
  258 + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL);
  259 +
  260 + int sz = lib3270_set_string_at(hSession,row,col,(const unsigned char *) text);
  261 +
  262 + trace("%s returns %d",__FUNCTION__,sz);
  263 + dbus_g_method_return(context,sz);
  264 +
  265 + g_free(text);
  266 +}
  267 +
  268 +void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context)
  269 +{
  270 + gchar * text;
  271 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  272 +
  273 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  274 + if(pw3270_dbus_check_valid_state(object,context))
  275 + return;
  276 +
  277 + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL);
  278 +
  279 + dbus_g_method_return(context,lib3270_emulate_input(hSession,(const char *) text,-1,1));
  280 +
  281 + g_free(text);
  282 +}
  283 +
  284 +
  285 +void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context)
  286 +{
  287 + gchar * text;
  288 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  289 +
  290 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  291 + if(pw3270_dbus_check_valid_state(object,context))
  292 + return;
  293 +
  294 + text = lib3270_get_string_at(hSession, row, col, len, lf);
  295 + if(!text)
  296 + {
  297 + GError *error = pw3270_dbus_get_error_from_errno(errno);
  298 + dbus_g_method_return_error(context,error);
  299 + g_error_free(error);
  300 + }
  301 + else
  302 + {
  303 + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL);
  304 +
  305 + lib3270_free(text);
  306 +
  307 + dbus_g_method_return(context,utftext);
  308 +
  309 + g_free(utftext);
  310 + }
  311 + }
  312 +
  313 + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context)
  314 + {
  315 + gchar * text;
  316 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  317 +
  318 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  319 + if(pw3270_dbus_check_valid_state(object,context))
  320 + return;
  321 +
  322 + if(len < 0) {
  323 + len = lib3270_get_length(hSession);
  324 + }
  325 +
  326 + text = lib3270_get_string_at_address(hSession,offset,len,lf);
  327 + if(!text)
  328 + {
  329 + GError *error = pw3270_dbus_get_error_from_errno(errno);
  330 + dbus_g_method_return_error(context,error);
  331 + g_error_free(error);
  332 + }
  333 + else
  334 + {
  335 + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL);
  336 +
  337 + lib3270_free(text);
  338 +
  339 + debug("\n%s\n",utftext);
  340 +
  341 + dbus_g_method_return(context,utftext);
  342 +
  343 + g_free(utftext);
  344 + }
  345 +
  346 + }
  347 +
  348 + void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context)
  349 + {
  350 + trace("%s object=%p context=%p connected=%s",__FUNCTION__,object,context, lib3270_is_connected(pw3270_dbus_get_session_handle(object)) ? "Yes" : "No");
  351 + dbus_g_method_return(context,lib3270_is_connected(pw3270_dbus_get_session_handle(object)));
  352 + }
  353 +
  354 + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context)
  355 + {
  356 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  357 + dbus_g_method_return(context,lib3270_is_ready(pw3270_dbus_get_session_handle(object)));
  358 + }
  359 +
  360 + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context)
  361 + {
  362 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  363 + dbus_g_method_return(context,lib3270_in_tn3270e(pw3270_dbus_get_session_handle(object)));
  364 + }
  365 +
  366 + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context)
  367 + {
  368 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  369 + dbus_g_method_return(context,lib3270_wait_for_ready(pw3270_dbus_get_session_handle(object),timeout));
  370 + }
  371 +
  372 + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context)
  373 + {
  374 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  375 + dbus_g_method_return(context,lib3270_set_cursor_position(pw3270_dbus_get_session_handle(object),row,col));
  376 + }
  377 +
  378 + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context)
  379 + {
  380 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  381 + dbus_g_method_return(context,lib3270_set_cursor_address(pw3270_dbus_get_session_handle(object),addr));
  382 + }
  383 +
  384 + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context)
  385 + {
  386 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  387 + dbus_g_method_return(context,lib3270_get_cursor_address(pw3270_dbus_get_session_handle(object)));
  388 + }
  389 +
  390 + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context)
  391 + {
  392 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  393 + dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object)));
  394 + }
  395 +
  396 + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context)
  397 + {
  398 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  399 + dbus_g_method_return(context,lib3270_get_height(pw3270_dbus_get_session_handle(object)));
  400 + }
  401 +
  402 + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context)
  403 + {
  404 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  405 + dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object)));
  406 + }
  407 +
  408 + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context)
  409 + {
  410 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  411 + dbus_g_method_return(context,lib3270_set_toggle(pw3270_dbus_get_session_handle(object),id,value));
  412 + }
  413 +
  414 +void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, char lf, DBusGMethodInvocation *context)
  415 +{
  416 + gchar * text;
  417 + H3270 * hSession = pw3270_dbus_get_session_handle(object);
  418 +
  419 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  420 + if(pw3270_dbus_check_valid_state(object,context))
  421 + return;
  422 +
  423 + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL);
  424 +
  425 + dbus_g_method_return(context,lib3270_cmp_text_at(hSession,row,col,text,lf));
  426 +
  427 + g_free(text);
  428 +}
  429 +
  430 +void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context)
  431 +{
  432 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  433 + if(pw3270_dbus_check_valid_state(object,context))
  434 + return;
  435 + dbus_g_method_return(context,lib3270_pfkey(pw3270_dbus_get_session_handle(object),key));
  436 +}
  437 +
  438 +void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context)
  439 +{
  440 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  441 + if(pw3270_dbus_check_valid_state(object,context))
  442 + return;
  443 + dbus_g_method_return(context,lib3270_pakey(pw3270_dbus_get_session_handle(object),key));
  444 +}
  445 +
  446 + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context)
  447 + {
  448 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  449 + dbus_g_method_return(context,lib3270_get_field_start(pw3270_dbus_get_session_handle(object),baddr));
  450 + }
  451 +
  452 + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context)
  453 + {
  454 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  455 + dbus_g_method_return(context,lib3270_get_field_len(pw3270_dbus_get_session_handle(object),baddr));
  456 + }
  457 +
  458 + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context)
  459 + {
  460 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  461 + dbus_g_method_return(context,lib3270_get_next_unprotected(pw3270_dbus_get_session_handle(object),baddr));
  462 + }
  463 +
  464 + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context)
  465 + {
  466 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  467 + dbus_g_method_return(context,lib3270_get_is_protected(pw3270_dbus_get_session_handle(object),baddr));
  468 + }
  469 +
  470 + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context)
  471 + {
  472 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  473 + dbus_g_method_return(context,lib3270_get_is_protected_at(pw3270_dbus_get_session_handle(object),row,col));
  474 + }
  475 +
  476 + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context)
  477 + {
  478 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  479 + dbus_g_method_return(context,lib3270_action(pw3270_dbus_get_session_handle(object),text));
  480 + }
  481 +
  482 + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context)
  483 + {
  484 + gchar *text;
  485 +
  486 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  487 +
  488 + if(pw3270_dbus_check_valid_state(object,context))
  489 + return;
  490 +
  491 + text = gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD));
  492 +
  493 + trace("Clipboard:\n%s\n",text);
  494 +
  495 + if(!text)
  496 + {
  497 + GError *error = pw3270_dbus_get_error_from_errno(ENOENT);
  498 + dbus_g_method_return_error(context,error);
  499 + g_error_free(error);
  500 + }
  501 + else
  502 + {
  503 + dbus_g_method_return(context,text);
  504 + g_free(text);
  505 + }
  506 +}
  507 +
  508 +void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context)
  509 +{
  510 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  511 + gtk_clipboard_set_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD),(gchar *) text, -1);
  512 + dbus_g_method_return(context,0);
  513 +}
  514 +
  515 +void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context)
  516 +{
  517 + GtkWidget *widget = pw3270_get_terminal_widget(NULL);
  518 +
  519 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  520 +
  521 + if(!widget)
  522 + {
  523 + GError *error = pw3270_dbus_get_error_from_errno(EINVAL);
  524 + dbus_g_method_return_error(context,error);
  525 + g_error_free(error);
  526 + return;
  527 + }
  528 +
  529 + dbus_g_method_return(context,v3270_set_script(widget,mode == 0 ? 0 : 'S'));
  530 +}
  531 +
  532 +void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context)
  533 +{
  534 + lib3270_popup_dialog(pw3270_dbus_get_session_handle(object), (LIB3270_NOTIFY) id , title, msg, "%s", text);
  535 + dbus_g_method_return(context,0);
  536 +}
  537 +
  538 +void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context)
  539 +{
  540 + dbus_g_method_return(context,lib3270_get_host_charset(pw3270_dbus_get_session_handle(object)));
  541 +}
  542 +
  543 +void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context)
  544 +{
  545 + // Allways return UTF-8 to avoid double conversion
  546 + dbus_g_method_return(context,"UTF-8");
  547 +}
  548 +
  549 +void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context)
  550 +{
  551 + dbus_g_method_return(context,lib3270_set_host_charset(pw3270_dbus_get_session_handle(object),charset));
  552 +}
  553 +
  554 +void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context)
  555 +{
  556 + trace("%s object=%p context=%p",__FUNCTION__,object,context);
  557 + dbus_g_method_return(context,lib3270_eraseeof(pw3270_dbus_get_session_handle(object)));
  558 +}
  559 +
  560 +void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context)
  561 +{
  562 + dbus_g_method_return(context,lib3270_print_all(pw3270_dbus_get_session_handle(object)));
  563 +}
  564 +
  565 +void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context)
  566 +{
  567 + lib3270_set_unlock_delay(pw3270_dbus_get_session_handle(object),(unsigned short) value);
  568 + dbus_g_method_return(context,0);
  569 +}
  570 +
  571 +
  572 +void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context)
  573 +{
  574 + int sz = strlen(from);
  575 +
  576 + if(sz > 0)
  577 + {
  578 + unsigned char buffer[sz+1];
  579 + memcpy(buffer,from,sz);
  580 + dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz));
  581 + return;
  582 + }
  583 +
  584 + dbus_g_method_return(context,"");
  585 +
  586 +}
  587 +
  588 +void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context)
  589 +{
  590 + int sz = strlen(from);
  591 +
  592 + if(sz > 0)
  593 + {
  594 + unsigned char buffer[sz+1];
  595 + memcpy(buffer,from,sz);
  596 + dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz));
  597 + return;
  598 + }
  599 +
  600 + dbus_g_method_return(context,"");
  601 +
  602 +}
  603 +
  604 +void pw3270_dbus_filetransfer(PW3270Dbus *object, const gchar *local, const gchar *remote, int flags, int lrecl, int blksize, int primspace, int secspace, int dft, DBusGMethodInvocation *context)
  605 +{
  606 + /*
  607 + dbus_g_method_return(context,
  608 + v3270_transfer_file(
  609 + v3270_get_default_widget(),
  610 + (LIB3270_FT_OPTION) flags,
  611 + local,
  612 + remote,
  613 + lrecl,
  614 + blksize,
  615 + primspace,
  616 + secspace,
  617 + dft
  618 + ));
  619 + */
  620 + return;
  621 +}
  622 +
... ...
src/dbus3270/iocallback.c 0 → 100644
  1 +++ a/src/dbus3270/iocallback.c
... ... @@ -0,0 +1,361 @@
  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 iocallback.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + */
  31 +
  32 +#if defined(_WIN32) /*[*/
  33 + #include <windows.h>
  34 +#elif defined(__APPLE__)
  35 + #include <poll.h>
  36 + #include <string.h>
  37 +#else
  38 + #include <poll.h>
  39 + #include <string.h>
  40 +#endif /*]*/
  41 +
  42 +#include <stdio.h>
  43 +#include <glib.h>
  44 +#include "daemon.h"
  45 +
  46 +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm);
  47 +static void static_RemoveSource(void *id);
  48 +
  49 +static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session));
  50 +static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session));
  51 +
  52 +static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session));
  53 +static void static_RemoveTimeOut(void * timer);
  54 +static int static_Sleep(H3270 *hSession, int seconds);
  55 +static int static_RunPendingEvents(H3270 *hSession, int wait);
  56 +
  57 +static gboolean IO_prepare(GSource *source, gint *timeout);
  58 +static gboolean IO_check(GSource *source);
  59 +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
  60 +static void IO_finalize(GSource *source); /* Can be NULL */
  61 +static gboolean IO_closure(gpointer data);
  62 +
  63 +/*---[ Structs ]-------------------------------------------------------------------------------------------*/
  64 +
  65 + typedef struct _IO_Source
  66 + {
  67 + GSource gsrc;
  68 + GPollFD poll;
  69 +#if defined(_WIN32)
  70 + HANDLE source;
  71 +#else
  72 + int source;
  73 +#endif // _WIN32
  74 + void (*fn)(H3270 *session);
  75 + H3270 *session;
  76 + } IO_Source;
  77 +
  78 + typedef struct _timer
  79 + {
  80 + unsigned char remove;
  81 + void (*fn)(H3270 *session);
  82 + H3270 *session;
  83 + } TIMER;
  84 +
  85 + static GSourceFuncs IOSources =
  86 + {
  87 + IO_prepare,
  88 + IO_check,
  89 + IO_dispatch,
  90 + IO_finalize,
  91 + IO_closure,
  92 + NULL
  93 + };
  94 +
  95 +/*---[ Implement ]-----------------------------------------------------------------------------------------*/
  96 +
  97 +#ifdef _WIN32
  98 +static void * AddSource(HANDLE source, H3270 *session, gushort events, void (*fn)(H3270 *session))
  99 +#else
  100 +static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session))
  101 +#endif // _WIN32
  102 +{
  103 + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source));
  104 +
  105 + src->source = source;
  106 + src->fn = fn;
  107 + src->poll.fd = (int) source;
  108 + src->poll.events = events;
  109 + src->session = session;
  110 +
  111 + g_source_attach((GSource *) src,NULL);
  112 + g_source_add_poll((GSource *) src,&src->poll);
  113 +
  114 + return src;
  115 +}
  116 +
  117 +#ifdef _WIN32
  118 +static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session))
  119 +#else
  120 +static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session))
  121 +#endif // _WIN32
  122 +{
  123 + return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn);
  124 +}
  125 +
  126 +static void static_RemoveSource(void *id)
  127 +{
  128 + if(id)
  129 + g_source_destroy((GSource *) id);
  130 +}
  131 +
  132 +#if defined(_WIN32)
  133 +static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session))
  134 +{
  135 + return 0;
  136 +}
  137 +#else
  138 +static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session))
  139 +{
  140 + return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn);
  141 +}
  142 +#endif // _WIN32
  143 +
  144 +static gboolean do_timer(TIMER *t)
  145 +{
  146 + if(!t->remove)
  147 + t->fn(t->session);
  148 + return FALSE;
  149 +}
  150 +
  151 +static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*proc)(H3270 *session))
  152 +{
  153 + TIMER *t = g_malloc0(sizeof(TIMER));
  154 +
  155 + t->fn = proc;
  156 + t->session = session;
  157 +
  158 + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free);
  159 +
  160 + return t;
  161 +}
  162 +
  163 +static void static_RemoveTimeOut(void * timer)
  164 +{
  165 + ((TIMER *) timer)->remove++;
  166 +}
  167 +
  168 +static gboolean IO_prepare(GSource *source, gint *timeout)
  169 +{
  170 + /*
  171 + * Called before all the file descriptors are polled.
  172 + * If the source can determine that it is ready here
  173 + * (without waiting for the results of the poll() call)
  174 + * it should return TRUE.
  175 + *
  176 + * It can also return a timeout_ value which should be the maximum
  177 + * timeout (in milliseconds) which should be passed to the poll() call.
  178 + * The actual timeout used will be -1 if all sources returned -1,
  179 + * or it will be the minimum of all the timeout_ values
  180 + * returned which were >= 0.
  181 + *
  182 + */
  183 + return 0;
  184 +}
  185 +
  186 +static gboolean IO_check(GSource *source)
  187 +{
  188 + /*
  189 + * Called after all the file descriptors are polled.
  190 + * The source should return TRUE if it is ready to be dispatched.
  191 + * Note that some time may have passed since the previous prepare
  192 + * function was called, so the source should be checked again here.
  193 + *
  194 + */
  195 +#if defined(_WIN32) /*[*/
  196 +
  197 + if(WaitForSingleObject(((IO_Source *) source)->source,0) == WAIT_OBJECT_0)
  198 + return TRUE;
  199 +
  200 +#else /*][*/
  201 +
  202 + struct pollfd fds;
  203 +
  204 + memset(&fds,0,sizeof(fds));
  205 +
  206 + fds.fd = ((IO_Source *) source)->poll.fd;
  207 + fds.events = ((IO_Source *) source)->poll.events;
  208 +
  209 + if(poll(&fds,1,0) > 0)
  210 + return TRUE;
  211 +
  212 +#endif /*]*/
  213 +
  214 + return FALSE;
  215 +}
  216 +
  217 +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
  218 +{
  219 + /*
  220 + * Called to dispatch the event source,
  221 + * after it has returned TRUE in either its prepare or its check function.
  222 + * The dispatch function is passed in a callback function and data.
  223 + * The callback function may be NULL if the source was never connected
  224 + * to a callback using g_source_set_callback(). The dispatch function
  225 + * should call the callback function with user_data and whatever additional
  226 + * parameters are needed for this type of event source.
  227 + */
  228 + ((IO_Source *) source)->fn(((IO_Source *) source)->session);
  229 + return TRUE;
  230 +}
  231 +
  232 +static void IO_finalize(GSource *source)
  233 +{
  234 +
  235 +}
  236 +
  237 +static gboolean IO_closure(gpointer data)
  238 +{
  239 + return 0;
  240 +}
  241 +
  242 +struct bgParameter
  243 +{
  244 + gboolean running;
  245 + gboolean timer;
  246 + H3270 *session;
  247 + int rc;
  248 + int(*callback)(H3270 *session, void *);
  249 + void *parm;
  250 +
  251 +};
  252 +
  253 +gpointer BgCall(struct bgParameter *p)
  254 +{
  255 +// trace("%s starts",__FUNCTION__);
  256 + p->rc = p->callback(p->session, p->parm);
  257 + p->running = FALSE;
  258 +// trace("%s ends",__FUNCTION__);
  259 + return 0;
  260 +}
  261 +
  262 +static gboolean wait_for_thread(struct bgParameter *p)
  263 +{
  264 + if(!p->running)
  265 + {
  266 + p->timer = 0;
  267 + return FALSE;
  268 + }
  269 + return TRUE;
  270 +}
  271 +
  272 +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm)
  273 +{
  274 + struct bgParameter p = { TRUE, TRUE, session, -1, callback, parm };
  275 + GThread * thread;
  276 +
  277 +// trace("Starting auxiliary thread for callback %p",callback);
  278 +
  279 + p.running = TRUE;
  280 + p.timer = TRUE;
  281 +
  282 + thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL);
  283 +
  284 + if(!thread)
  285 + {
  286 + g_error("Can't start background thread");
  287 + return -1;
  288 + }
  289 +
  290 + g_timeout_add(50,(GSourceFunc) wait_for_thread,(gpointer) &p);
  291 +
  292 + while(p.timer)
  293 + g_main_context_iteration(g_main_loop_get_context(main_loop),TRUE);
  294 +
  295 + return p.rc;
  296 +}
  297 +
  298 +static int static_Sleep(H3270 *hSession, int seconds)
  299 +{
  300 + time_t end = time(0) + seconds;
  301 +
  302 + while(time(0) < end)
  303 + g_main_iteration(TRUE);
  304 +
  305 + return 0;
  306 +}
  307 +
  308 +static int static_RunPendingEvents(H3270 *hSession, int wait)
  309 +{
  310 + GMainContext *context = g_main_loop_get_context(main_loop);
  311 + int rc = 0;
  312 + while(g_main_context_pending(context))
  313 + {
  314 + rc = 1;
  315 + g_main_context_iteration(context,FALSE);
  316 + }
  317 +
  318 + if(wait)
  319 + g_main_context_iteration(context,TRUE);
  320 +
  321 + return rc;
  322 +}
  323 +
  324 +static void beep(H3270 *session)
  325 +{
  326 +}
  327 +
  328 +void pw3270_dbus_register_io_handlers(void)
  329 +{
  330 + static const struct lib3270_callbacks hdl =
  331 + {
  332 + sizeof(struct lib3270_callbacks),
  333 +
  334 + static_AddTimeOut,
  335 + static_RemoveTimeOut,
  336 +
  337 + static_AddInput,
  338 + static_RemoveSource,
  339 +
  340 + static_AddExcept,
  341 +
  342 +#ifdef G_THREADS_ENABLED
  343 + static_CallAndWait,
  344 +#else
  345 + NULL,
  346 +#endif
  347 +
  348 + static_Sleep,
  349 + static_RunPendingEvents,
  350 + beep
  351 +
  352 + };
  353 +
  354 + #error Need rewrite
  355 +
  356 + if(lib3270_register_handlers(&hdl))
  357 + {
  358 + g_error("%s","Can't set lib3270 I/O handlers");
  359 + }
  360 +
  361 +}
... ...
src/dbus3270/main.c 0 → 100644
  1 +++ a/src/dbus3270/main.c
... ... @@ -0,0 +1,172 @@
  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/fbuihuu/samples-dbus/blob/master/dbus-server.c
  26 + *
  27 + * Contatos:
  28 + *
  29 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  30 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  31 + *
  32 + */
  33 +
  34 +#include <glib.h>
  35 +#include <dbus/dbus.h>
  36 +#include <dbus/dbus-glib-lowlevel.h>
  37 +#include <dbus/dbus-glib.h>
  38 +
  39 +#include <pw3270.h>
  40 +#include <pw3270/plugin.h>
  41 +
  42 +#include "service.h"
  43 +#include "dbus-glue.h"
  44 +
  45 +#include <gtk/gtk.h>
  46 +
  47 +/*---[ Globals ]---------------------------------------------------------------------------------*/
  48 +
  49 + static DBusGConnection * connection = NULL;
  50 + static DBusGProxy * proxy = NULL;
  51 + static gchar * service_name = NULL;
  52 +
  53 +
  54 +/*---[ Implement ]-------------------------------------------------------------------------------*/
  55 +
  56 + LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal)
  57 + {
  58 +
  59 + GError * error = NULL;
  60 + guint result;
  61 + char session_id = 0;
  62 + char id = 'a';
  63 +
  64 + connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error);
  65 + if(error)
  66 + {
  67 + GtkWidget *dialog = gtk_message_dialog_new(
  68 + GTK_WINDOW(window),
  69 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  70 + GTK_MESSAGE_ERROR,
  71 + GTK_BUTTONS_OK,
  72 + _( "Can't connect to DBUS server" ));
  73 +
  74 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
  75 +
  76 + g_message("Error \"%s\" getting session dbus",error->message);
  77 +
  78 + g_error_free(error);
  79 +
  80 + gtk_dialog_run(GTK_DIALOG(dialog));
  81 + gtk_widget_destroy(dialog);
  82 +
  83 + return -1;
  84 + }
  85 +
  86 + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);
  87 +
  88 + for(id='a'; id < 'z' && !error && !service_name; id++)
  89 + {
  90 + gboolean has_owner = FALSE;
  91 +
  92 + service_name = g_strdup_printf("br.com.bb.%s.%c",pw3270_get_session_name(window),(int) id);
  93 +
  94 + org_freedesktop_DBus_name_has_owner(proxy, service_name, &has_owner, NULL);
  95 +
  96 + if(has_owner)
  97 + {
  98 + trace("Service \"%s\" has owner",service_name)
  99 + g_free(service_name);
  100 + service_name = NULL;
  101 + }
  102 + else
  103 + {
  104 + session_id = id;
  105 + g_message("DBUS service name is %s",service_name);
  106 + org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);
  107 + }
  108 + }
  109 +
  110 + if(error)
  111 + {
  112 + GtkWidget *dialog = gtk_message_dialog_new(
  113 + GTK_WINDOW(window),
  114 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  115 + GTK_MESSAGE_ERROR,
  116 + GTK_BUTTONS_OK,
  117 + _( "Can't get DBUS object name" ));
  118 +
  119 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
  120 +
  121 + g_message("Error \"%s\" requesting DBUS name",error->message);
  122 +
  123 + g_error_free(error);
  124 +
  125 + gtk_dialog_run(GTK_DIALOG(dialog));
  126 + gtk_widget_destroy(dialog);
  127 +
  128 + return -1;
  129 + }
  130 +
  131 + if(session_id)
  132 + {
  133 + gchar * path = g_strdup_printf("/br/com/bb/%s",pw3270_get_session_name(window));
  134 + gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),g_ascii_toupper(session_id));
  135 + pw3270_set_session_name(window,session);
  136 + g_free(session);
  137 +
  138 + g_message("DBUS service path is %s",path);
  139 +
  140 + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,path);
  141 +
  142 + g_free(path);
  143 + }
  144 +
  145 + return 0;
  146 + }
  147 +
  148 + LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window, GtkWidget *terminal)
  149 + {
  150 + if(service_name)
  151 + {
  152 + // org_freedesktop_DBus_release_name
  153 +
  154 + g_free(service_name);
  155 + service_name = NULL;
  156 + }
  157 + return 0;
  158 + }
  159 +
  160 + void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context)
  161 + {
  162 + gtk_main_quit();
  163 + dbus_g_method_return(context,0);
  164 + }
  165 +
  166 + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object)
  167 + {
  168 + return lib3270_get_default_session_handle();
  169 + }
  170 +
  171 +
  172 +
... ...
src/dbus3270/misc.c 0 → 100644
  1 +++ a/src/dbus3270/misc.c
... ... @@ -0,0 +1,47 @@
  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 misc.c 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + * Referencias:
  31 + *
  32 + * https://live.gnome.org/DBusGlibBindings
  33 + *
  34 + */
  35 +
  36 +#include "globals.h"
  37 +
  38 +/*---[ Implement ]-------------------------------------------------------------------------------*/
  39 +
  40 +gpointer pw3270_dbus_register_object(DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path)
  41 +{
  42 + GObject *object = g_object_new (object_type, NULL);
  43 + dbus_g_object_type_install_info (object_type, info);
  44 + dbus_g_connection_register_g_object (connection, path, object);
  45 + return object;
  46 +}
  47 +
... ...
src/dbus3270/pw3270dbus.cbp 0 → 100644
  1 +++ a/src/dbus3270/pw3270dbus.cbp
... ... @@ -0,0 +1,71 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2 +<CodeBlocks_project_file>
  3 + <FileVersion major="1" minor="6" />
  4 + <Project>
  5 + <Option title="pw3270dbus" />
  6 + <Option makefile_is_custom="1" />
  7 + <Option pch_mode="2" />
  8 + <Option compiler="gcc" />
  9 + <Build>
  10 + <Target title="Debug">
  11 + <Option output=".bin/Debug/pw3270dbus" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
  12 + <Option object_output=".obj/Debug/" />
  13 + <Option type="3" />
  14 + <Option compiler="gcc" />
  15 + <Compiler>
  16 + <Add option="-g" />
  17 + </Compiler>
  18 + </Target>
  19 + <Target title="Release">
  20 + <Option output=".bin/Release/pw3270dbus" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
  21 + <Option object_output=".obj/Release/" />
  22 + <Option type="3" />
  23 + <Option compiler="gcc" />
  24 + <Compiler>
  25 + <Add option="-O2" />
  26 + </Compiler>
  27 + <Linker>
  28 + <Add option="-s" />
  29 + </Linker>
  30 + </Target>
  31 + <Target title="debug-service">
  32 + <Option output=".bin/Debug/pw3270d" prefix_auto="1" extension_auto="1" />
  33 + <Option object_output=".obj/Debug/" />
  34 + <Option type="1" />
  35 + <Option compiler="gcc" />
  36 + <Compiler>
  37 + <Add option="-g" />
  38 + </Compiler>
  39 + </Target>
  40 + </Build>
  41 + <Compiler>
  42 + <Add option="-Wall" />
  43 + </Compiler>
  44 + <Unit filename="Makefile.in" />
  45 + <Unit filename="daemon.c">
  46 + <Option compilerVar="CC" />
  47 + </Unit>
  48 + <Unit filename="daemon.h" />
  49 + <Unit filename="dbus-glue.h" />
  50 + <Unit filename="globals.h" />
  51 + <Unit filename="gobject.c">
  52 + <Option compilerVar="CC" />
  53 + </Unit>
  54 + <Unit filename="iocallback.c">
  55 + <Option compilerVar="CC" />
  56 + </Unit>
  57 + <Unit filename="main.c">
  58 + <Option compilerVar="CC" />
  59 + </Unit>
  60 + <Unit filename="misc.c">
  61 + <Option compilerVar="CC" />
  62 + </Unit>
  63 + <Unit filename="pw3270dbus.xml" />
  64 + <Unit filename="service.h" />
  65 + <Unit filename="test.sh" />
  66 + <Extensions>
  67 + <code_completion />
  68 + <debugger />
  69 + </Extensions>
  70 + </Project>
  71 +</CodeBlocks_project_file>
... ...
src/dbus3270/pw3270dbus.xml 0 → 100644
  1 +++ a/src/dbus3270/pw3270dbus.xml
... ... @@ -0,0 +1,251 @@
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<node name="/br/com/bb/pw3270">
  3 + <interface name="br.com.bb.pw3270">
  4 + <method name="getRevision">
  5 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  6 + <arg type="s" name="revision" direction="out" />
  7 + </method>
  8 + <method name="quit">
  9 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  10 + <arg type="i" name="result" direction="out" />
  11 + </method>
  12 + <method name="connect">
  13 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  14 + <arg type="s" name="uri" direction="in" />
  15 + <arg type="i" name="result" direction="out" />
  16 + </method>
  17 + <method name="setURL">
  18 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  19 + <arg type="s" name="uri" direction="in" />
  20 + <arg type="i" name="result" direction="out" />
  21 + </method>
  22 + <method name="getURL">
  23 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  24 + <arg type="s" name="uri" direction="out" />
  25 + </method>
  26 + <method name="disconnect">
  27 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  28 + <arg type="i" name="result" direction="out" />
  29 + </method>
  30 + <method name="getMessageID">
  31 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  32 + <arg type="i" name="status" direction="out" />
  33 + </method>
  34 + <method name="getConnectionState">
  35 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  36 + <arg type="i" name="status" direction="out" />
  37 + </method>
  38 + <method name="getSecureState">
  39 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  40 + <arg type="i" name="status" direction="out" />
  41 + </method>
  42 + <method name="getScreenContents">
  43 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  44 + <arg type="s" name="contents" direction="out" />
  45 + </method>
  46 + <method name="enter">
  47 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  48 + <arg type="i" name="result" direction="out" />
  49 + </method>
  50 + <method name="pfKey">
  51 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  52 + <arg type="i" name="key" direction="in" />
  53 + <arg type="i" name="result" direction="out" />
  54 + </method>
  55 + <method name="paKey">
  56 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  57 + <arg type="i" name="key" direction="in" />
  58 + <arg type="i" name="result" direction="out" />
  59 + </method>
  60 + <method name="input">
  61 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  62 + <arg type="s" name="text" direction="in" />
  63 + </method>
  64 + <method name="setTextAt">
  65 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  66 + <arg type="i" name="row" direction="in" />
  67 + <arg type="i" name="col" direction="in" />
  68 + <arg type="s" name="text" direction="in" />
  69 + <arg type="i" name="result" direction="out" />
  70 + </method>
  71 + <method name="getTextAt">
  72 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  73 + <arg type="i" name="row" direction="in" />
  74 + <arg type="i" name="col" direction="in" />
  75 + <arg type="i" name="len" direction="in" />
  76 + <arg type="y" name="lf" direction="in" />
  77 + <arg type="s" name="text" direction="out" />
  78 + </method>
  79 + <method name="getText">
  80 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  81 + <arg type="i" name="addr" direction="in" />
  82 + <arg type="i" name="len" direction="in" />
  83 + <arg type="y" name="lf" direction="in" />
  84 + <arg type="s" name="text" direction="out" />
  85 + </method>
  86 + <method name="setClipboard">
  87 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  88 + <arg type="s" name="text" direction="in" />
  89 + <arg type="i" name="result" direction="out" />
  90 + </method>
  91 + <method name="getClipboard">
  92 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  93 + <arg type="s" name="text" direction="out" />
  94 + </method>
  95 + <method name="isConnected">
  96 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  97 + <arg type="i" name="result" direction="out" />
  98 + </method>
  99 + <method name="isReady">
  100 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  101 + <arg type="i" name="result" direction="out" />
  102 + </method>
  103 + <method name="inTN3270E">
  104 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  105 + <arg type="i" name="result" direction="out" />
  106 + </method>
  107 + <method name="waitForReady">
  108 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  109 + <arg type="i" name="timeout" direction="in" />
  110 + <arg type="i" name="result" direction="out" />
  111 + </method>
  112 + <method name="setCursorAt">
  113 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  114 + <arg type="i" name="row" direction="in" />
  115 + <arg type="i" name="col" direction="in" />
  116 + <arg type="i" name="result" direction="out" />
  117 + </method>
  118 + <method name="setCursorAddress">
  119 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  120 + <arg type="i" name="addr" direction="in" />
  121 + <arg type="i" name="result" direction="out" />
  122 + </method>
  123 + <method name="getCursorAddress">
  124 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  125 + <arg type="i" name="addr" direction="out" />
  126 + </method>
  127 + <method name="getScreenWidth">
  128 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  129 + <arg type="i" name="width" direction="out" />
  130 + </method>
  131 + <method name="getScreenHeight">
  132 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  133 + <arg type="i" name="height" direction="out" />
  134 + </method>
  135 + <method name="getScreenLength">
  136 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  137 + <arg type="i" name="len" direction="out" />
  138 + </method>
  139 + <method name="getNextUnprotected">
  140 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  141 + <arg type="i" name="addr" direction="in" />
  142 + <arg type="i" name="result" direction="out" />
  143 + </method>
  144 + <method name="getIsProtected">
  145 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  146 + <arg type="i" name="addr" direction="in" />
  147 + <arg type="i" name="result" direction="out" />
  148 + </method>
  149 + <method name="getIsProtectedAt">
  150 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  151 + <arg type="i" name="row" direction="in" />
  152 + <arg type="i" name="col" direction="in" />
  153 + <arg type="i" name="result" direction="out" />
  154 + </method>
  155 + <method name="setToggle">
  156 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  157 + <arg type="i" name="id" direction="in" />
  158 + <arg type="i" name="value" direction="in" />
  159 + <arg type="i" name="result" direction="out" />
  160 + </method>
  161 + <method name="cmpTextAt">
  162 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  163 + <arg type="i" name="row" direction="in" />
  164 + <arg type="i" name="col" direction="in" />
  165 + <arg type="s" name="text" direction="in" />
  166 + <arg type="y" name="lf" direction="in" />
  167 + <arg type="i" name="result" direction="out" />
  168 + </method>
  169 + <method name="getFieldStart">
  170 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  171 + <arg type="i" name="addr" direction="in" />
  172 + <arg type="i" name="result" direction="out" />
  173 + </method>
  174 + <method name="getFieldLength">
  175 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  176 + <arg type="i" name="addr" direction="in" />
  177 + <arg type="i" name="result" direction="out" />
  178 + </method>
  179 + <method name="setScript">
  180 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  181 + <arg type="s" name="id" direction="in" />
  182 + <arg type="i" name="status" direction="in" />
  183 + <arg type="i" name="result" direction="out" />
  184 + </method>
  185 + <method name="showPopup">
  186 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  187 + <arg type="i" name="id" direction="in" />
  188 + <arg type="s" name="title" direction="in" />
  189 + <arg type="s" name="msg" direction="in" />
  190 + <arg type="s" name="text" direction="in" />
  191 + </method>
  192 + <method name="getHostCharset">
  193 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  194 + <arg type="s" name="charset" direction="out" />
  195 + </method>
  196 + <method name="getDisplayCharset">
  197 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  198 + <arg type="s" name="charset" direction="out" />
  199 + </method>
  200 + <method name="setHostCharset">
  201 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  202 + <arg type="s" name="charset" direction="in" />
  203 + <arg type="i" name="result" direction="out" />
  204 + </method>
  205 + <method name="eraseEof">
  206 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  207 + <arg type="i" name="result" direction="out" />
  208 + </method>
  209 + <method name="print">
  210 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  211 + <arg type="i" name="result" direction="out" />
  212 + </method>
  213 + <method name="ebc2asc">
  214 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  215 + <arg type="s" name="from" direction="in" />
  216 + <arg type="s" name="to" direction="out" />
  217 + </method>
  218 + <method name="asc2ebc">
  219 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  220 + <arg type="s" name="from" direction="in" />
  221 + <arg type="s" name="to" direction="out" />
  222 + </method>
  223 +
  224 + <method name="action">
  225 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  226 + <arg type="s" name="name" direction="in" />
  227 + <arg type="i" name="result" direction="out" />
  228 + </method>
  229 +
  230 + <method name="filetransfer">
  231 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  232 + <arg type="s" name="local" direction="in" />
  233 + <arg type="s" name="remote" direction="in" />
  234 + <arg type="i" name="flags" direction="in" />
  235 + <arg type="i" name="lrecl" direction="in" />
  236 + <arg type="i" name="blksize" direction="in" />
  237 + <arg type="i" name="primspace" direction="in" />
  238 + <arg type="i" name="secspace" direction="in" />
  239 + <arg type="i" name="dft" direction="in" />
  240 + <arg type="i" name="result" direction="out" />
  241 + </method>
  242 +
  243 + <method name="setUnlockDelay">
  244 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  245 + <arg type="i" name="value" direction="in" />
  246 + <arg type="i" name="result" direction="out" />
  247 + </method>
  248 +
  249 + </interface>
  250 +
  251 +</node>
... ...
src/dbus3270/service.h 0 → 100644
  1 +++ a/src/dbus3270/service.h
... ... @@ -0,0 +1,138 @@
  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 service.h 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 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + */
  31 +
  32 +#ifndef _PW3270_DBUS_SERVICE_H
  33 +
  34 + #define _PW3270_DBUS_SERVICE_H 1
  35 +
  36 + #define ENABLE_NLS
  37 + #define GETTEXT_PACKAGE PACKAGE_NAME
  38 +
  39 + #include "globals.h"
  40 +
  41 + #define PW3270_TYPE_DBUS (pw3270_dbus_get_type ())
  42 + #define PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PW3270_TYPE_DBUS, PW3270Dbus))
  43 + #define PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DBUS, PW3270DbusClass))
  44 + #define IS_PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PW3270_TYPE_DBUS))
  45 + #define IS_PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DBUS))
  46 + #define PW3270_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DBUS, PW3270DbusClass))
  47 +
  48 + G_BEGIN_DECLS
  49 +
  50 + typedef struct _PW3270Dbus PW3270Dbus;
  51 + typedef struct _PW3270DbusClass PW3270DbusClass;
  52 +
  53 + struct _PW3270Dbus
  54 + {
  55 + GObject parent;
  56 + };
  57 +
  58 + struct _PW3270DbusClass
  59 + {
  60 + GObjectClass parent;
  61 + };
  62 +
  63 + PW3270Dbus * pw3270_dbus_new (void);
  64 + GType pw3270_dbus_get_type (void);
  65 +
  66 + void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context);
  67 + void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context);
  68 + void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context);
  69 + void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context);
  70 + void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context);
  71 + void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context);
  72 +
  73 + void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context);
  74 + void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context);
  75 + void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context);
  76 +
  77 + void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context);
  78 + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object);
  79 + GError * pw3270_dbus_get_error_from_errno(int code);
  80 +
  81 + void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context);
  82 + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context);
  83 + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context);
  84 +
  85 + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context);
  86 + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context);
  87 + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context);
  88 +
  89 + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context);
  90 + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context);
  91 + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context);
  92 +
  93 + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context);
  94 +
  95 + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context);
  96 +
  97 + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  98 + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  99 + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  100 +
  101 + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  102 + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context);
  103 +
  104 + void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context);
  105 +
  106 + void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context);
  107 +
  108 + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context);
  109 +
  110 + // Actions
  111 + void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context);
  112 + void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context);
  113 + void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context);
  114 + void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *text, DBusGMethodInvocation *context);
  115 + void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context);
  116 + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context);
  117 + void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *text, char lf, DBusGMethodInvocation *context);
  118 + void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context);
  119 +
  120 + void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context);
  121 + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context);
  122 +
  123 + void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context);
  124 + void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context);
  125 + void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context);
  126 + void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context);
  127 + void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context);
  128 +
  129 + void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context);
  130 + void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context);
  131 +
  132 + void pw3270_dbus_filetransfer(PW3270Dbus *object, const gchar *local, const gchar *remote, int flags, int lrecl, int blksize, int primspace, int secspace, int dft, DBusGMethodInvocation *context);
  133 +
  134 + void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context);
  135 +
  136 + G_END_DECLS
  137 +
  138 +#endif // _PW3270_DBUS_SERVICE_H
... ...
src/dbus3270/test.sh 0 → 100755
  1 +++ a/src/dbus3270/test.sh
... ... @@ -0,0 +1,126 @@
  1 +#!/bin/bash
  2 +
  3 +SESSION=a
  4 +DEST=br.com.bb.pw3270
  5 +BPATH=/br/com/bb/pw3270
  6 +
  7 +run_command()
  8 +{
  9 +
  10 + case $1 in
  11 +
  12 + revision)
  13 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getRevision
  14 + ;;
  15 +
  16 + message)
  17 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getMessageID
  18 + ;;
  19 +
  20 + ssl)
  21 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getSecureState
  22 + ;;
  23 +
  24 + connect)
  25 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.connect string:$2 int32:10
  26 + ;;
  27 +
  28 + disconnect)
  29 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.disconnect
  30 + ;;
  31 +
  32 + url)
  33 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getURL
  34 + ;;
  35 +
  36 + quit)
  37 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.quit
  38 + ;;
  39 +
  40 + get)
  41 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getScreenContents
  42 + ;;
  43 +
  44 + gettext)
  45 +# addr,len,lf
  46 +# dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getText int32:1 int32:-1 byte:0
  47 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getText int32:1 int32:-1 byte:10
  48 + ;;
  49 +
  50 + protect)
  51 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getIsProtectedAt int32:$2 int32:$3
  52 + ;;
  53 +
  54 + set)
  55 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setTextAt int32:$2 int32:$3 string:$4
  56 + ;;
  57 +
  58 + action)
  59 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.action string:$2
  60 + ;;
  61 +
  62 + enter)
  63 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.enter
  64 + ;;
  65 +
  66 + isconnected)
  67 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.isConnected
  68 + ;;
  69 +
  70 + hostcharset)
  71 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getHostCharset
  72 + ;;
  73 +
  74 + displaycharset)
  75 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.getDisplayCharset
  76 + ;;
  77 +
  78 + unlockdelay)
  79 + dbus-send --session --print-reply --dest=$DEST.$SESSION $BPATH $DEST.setUnlockDelay int32:$2
  80 + ;;
  81 +
  82 + *)
  83 + echo "Comando $1 desconhecido"
  84 + ;;
  85 +
  86 + esac
  87 +}
  88 +
  89 +
  90 +
  91 +until [ -z "$1" ]
  92 +do
  93 + if [ ${1:0:2} = '--' ]; then
  94 + tmp=${1:2}
  95 + parameter=${tmp%%=*}
  96 + parameter=$(echo $parameter | tr "[:lower:]" "[:upper:]")
  97 + value=${tmp##*=}
  98 +
  99 + case "$parameter" in
  100 + SESSION)
  101 + SESSION=$value
  102 + ;;
  103 + HELP)
  104 + echo "$0 options"
  105 + echo ""
  106 + echo "Options:"
  107 + echo ""
  108 + echo " --session pw3270's session manager"
  109 + echo ""
  110 + exit 0
  111 + ;;
  112 +
  113 + *)
  114 + eval $parameter=$value
  115 + ;;
  116 +
  117 + esac
  118 +
  119 + else
  120 + run_command $@
  121 + exit 0
  122 + fi
  123 +
  124 + shift
  125 +done
  126 +
... ...
src/hllapi/Makefile.in 0 → 100644
  1 +++ a/src/hllapi/Makefile.in
... ... @@ -0,0 +1,315 @@
  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., 59 Temple
  19 +# Place, Suite 330, Boston, MA, 02111-1307, USA
  20 +#
  21 +# Contatos:
  22 +#
  23 +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  24 +# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça)
  25 +#
  26 +
  27 +MODULE_NAME=hllapi
  28 +LIBNAME=lib$(MODULE_NAME)@DLLEXT@
  29 +
  30 +PLUGIN_SOURCES=pluginmain.c
  31 +API_SOURCES=calls.c hllapi.c
  32 +
  33 +#---[ Configuration values ]-------------------------------------------------------------
  34 +
  35 +PACKAGE_NAME=@PACKAGE_NAME@
  36 +PACKAGE_VERSION=@PACKAGE_VERSION@
  37 +PACKAGE_TARNAME=@PACKAGE_TARNAME@
  38 +
  39 +prefix=@prefix@
  40 +exec_prefix=@exec_prefix@
  41 +bindir=@bindir@
  42 +sbindir=@sbindir@
  43 +libdir=@libdir@
  44 +
  45 +BASEDIR=@BASEDIR@
  46 +SRCDIR=$(BASEDIR)/.src/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)/src/plugins/$(MODULE_NAME)
  47 +POTDIR=$(BASEDIR)/.pot/plugins/$(MODULE_NAME)
  48 +
  49 +OBJDIR=$(BASEDIR)/.obj/plugins/$(MODULE_NAME)
  50 +OBJDBG=$(OBJDIR)/Debug
  51 +OBJRLS=$(OBJDIR)/Release
  52 +
  53 +BINDIR=$(BASEDIR)/.bin
  54 +BINDBG=$(BINDIR)/Debug
  55 +BINRLS=$(BINDIR)/Release
  56 +
  57 +MKDIR=@MKDIR_P@
  58 +CC=@CC@
  59 +CXX=@CXX@
  60 +LD=@CXX@
  61 +AR=@AR@
  62 +XGETTEXT=@XGETTEXT@
  63 +MSGCAT=@MSGCAT@
  64 +INSTALL=@INSTALL@
  65 +INSTALL_DATA=@INSTALL_DATA@
  66 +INSTALL_PROGRAM=@INSTALL_PROGRAM@
  67 +LN_S=@LN_S@
  68 +
  69 +CFLAGS=\
  70 + @CFLAGS@ \
  71 + @LIBV3270_CFLAGS@ \
  72 + @GTK_CFLAGS@ \
  73 + -I$(BASEDIR)/src/include
  74 +
  75 +LIBS=@LIBS@
  76 +
  77 +API_LIBS=\
  78 + $(LIBS) \
  79 + -lpw3270cpp \
  80 + @LIBICONV@
  81 +
  82 +PLUGIN_LIBS=\
  83 + $(LIBS) \
  84 + @GTK_LIBS@ \
  85 + @GLIB_LIBS@ \
  86 + @LIB3270_LIBS@ \
  87 + @LIBV3270_LIBS@ \
  88 + @PW3270_LIBS@
  89 +
  90 +LDFLAGS=\
  91 + @LDFLAGS@
  92 +
  93 +#---[ Rules ]----------------------------------------------------------------------------
  94 +
  95 +DEPENDS=*.h Makefile
  96 +
  97 +$(OBJDBG)/%.o: \
  98 + %.c \
  99 + $(DEPENDS)
  100 +
  101 + @echo $< ...
  102 + @$(MKDIR) `dirname $@`
  103 + @$(CC) $(CFLAGS) \
  104 + @DBG_CFLAGS@ \
  105 + -DBUILD_DATE=`date +"0x%Y%m%d"`\
  106 + -o $@ -c $<
  107 +
  108 +$(OBJDBG)/%.o: \
  109 + %.cc \
  110 + $(DEPENDS)
  111 +
  112 + @echo $< ...
  113 + @$(MKDIR) `dirname $@`
  114 + @$(CXX) $(CFLAGS) \
  115 + @DBG_CFLAGS@ \
  116 + -DBUILD_DATE=`date +"0x%Y%m%d"`\
  117 + -o $@ -c $<
  118 +
  119 +$(OBJRLS)/%.o: \
  120 + %.c \
  121 + $(DEPENDS)
  122 +
  123 + @echo $< ...
  124 + @$(MKDIR) `dirname $@`
  125 + @$(CC) $(CFLAGS) \
  126 + @RLS_CFLAGS@ \
  127 + -DBUILD_DATE=`date +"0x%Y%m%d"` \
  128 + -o $@ -c $<
  129 +
  130 +$(OBJRLS)/%.o: \
  131 + %.cc \
  132 + $(DEPENDS)
  133 +
  134 + @echo $< ...
  135 + @$(MKDIR) `dirname $@`
  136 + @$(CXX) $(CFLAGS) \
  137 + @RLS_CFLAGS@ \
  138 + -DBUILD_DATE=`date +"0x%Y%m%d"` \
  139 + -o $@ -c $<
  140 +
  141 +$(POTDIR)/%.pot: %.c
  142 +
  143 + @echo $(notdir $@) ...
  144 + @$(MKDIR) `dirname $@`
  145 + @$(XGETTEXT) \
  146 + --default-domain=$(PACKAGE) \
  147 + --language=C \
  148 + --keyword=_ \
  149 + --keyword=N_ \
  150 + --keyword=MSG_:2 \
  151 + --output=$@ \
  152 + $<
  153 +
  154 + @touch $@
  155 +
  156 +#---[ Release Targets ]------------------------------------------------------------------
  157 +
  158 +Release: \
  159 + $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@
  160 +
  161 +install: \
  162 + $(BINRLS)/$(LIBNAME) \
  163 + $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@
  164 +
  165 + @echo $@ ...
  166 + @$(MKDIR) $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins
  167 + @$(INSTALL_PROGRAM) $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins/$(MODULE_NAME)@DLLEXT@
  168 +
  169 + @$(MKDIR) $(DESTDIR)$(libdir)
  170 + @$(INSTALL_PROGRAM) $(BINRLS)/$(LIBNAME) $(DESTDIR)$(libdir)
  171 +
  172 +$(DESTDIR)$(libdir)/$(PACKAGE_TARNAME)-plugins/$(MODULE_NAME)@DLLEXT@: \
  173 + $(BINRLS)/$(LIBNAME) \
  174 + $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@
  175 +
  176 + @echo $@ ...
  177 + @$(MKDIR) `dirname $@`
  178 + @$(INSTALL_PROGRAM) $(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@ $@
  179 +
  180 + @$(MKDIR) $(DESTDIR)$(libdir)
  181 + @$(INSTALL_PROGRAM) $(BINRLS)/$(LIBNAME) $(DESTDIR)$(libdir)
  182 +
  183 +$(BINRLS)/$(LIBNAME): \
  184 + $(BINRLS)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@
  185 +
  186 + @echo $(basename $@) ...
  187 + @$(MKDIR) `dirname $@`
  188 + @$(LN_S) -f $(LIBNAME).@PACKAGE_MAJOR_VERSION@ $@
  189 +
  190 +$(BINRLS)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@: \
  191 + $(BINRLS)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@
  192 +
  193 + @echo $(basename $@) ...
  194 + @$(MKDIR) `dirname $@`
  195 + @$(LN_S) -f $(LIBNAME).@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ $@
  196 +
  197 +$(BINRLS)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@: \
  198 + $(foreach SRC, $(basename $(API_SOURCES)), $(OBJRLS)/$(SRC).o)
  199 +
  200 + @echo $@ ...
  201 + @$(MKDIR) `dirname $@`
  202 + @$(LD) \
  203 + $(LDFLAGS) \
  204 + @DLL_LDFLAGS@ \
  205 + -Wl,-soname,`basename $@` \
  206 + -L$(BASEDIR)/.bin/Release \
  207 + @STATIC_LDFLAGS@ \
  208 + -o $@ $^ \
  209 + $(API_LIBS)
  210 +
  211 +$(BINRLS)/plugins/$(MODULE_NAME)@DLLEXT@: \
  212 + $(BINRLS)/$(LIBNAME) \
  213 + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o)
  214 +
  215 + @echo $@ ...
  216 + @$(MKDIR) `dirname $@`
  217 + @$(LD) \
  218 + $(LDFLAGS) \
  219 + @DLL_LDFLAGS@ \
  220 + -Wl,-soname,$(MODULE_NAME)d \
  221 + -L$(BASEDIR)/.bin/Release \
  222 + -o $@ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) \
  223 + $(PLUGIN_LIBS)
  224 +
  225 +pot: \
  226 + $(BASEDIR)/.pot/plugins/$(MODULE_NAME).pot
  227 +
  228 +$(BASEDIR)/.pot/plugins/$(MODULE_NAME).pot: \
  229 + $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(SRC).pot)
  230 +
  231 + @rm -f $@
  232 + @mkdir -p `dirname $@`
  233 + @$(MSGCAT) --sort-output $^ > $@
  234 +
  235 +$(SRCDIR): \
  236 + clean
  237 +
  238 + @$(MKDIR) $@
  239 + @$(INSTALL_DATA) *.c *.cc *.h *.in *.cbp $@
  240 +
  241 +
  242 +#---[ Debug Targets ]--------------------------------------------------------------------
  243 +
  244 +Debug: \
  245 + $(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@
  246 +
  247 +test: \
  248 + $(BINDBG)/$(LIBNAME) \
  249 + $(OBJDBG)/testprogram.o
  250 +
  251 + $(LD) -Wl,--rpath,$(BINDBG) -o $(BINDBG)/$(MODULE_NAME)@EXEEXT@ $(OBJDBG)/testprogram.o -L$(BINDBG) $(LIBS) -l$(MODULE_NAME)
  252 +
  253 +$(BINDBG)/$(LIBNAME): \
  254 + $(BINDBG)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@
  255 +
  256 + @echo $(basename $@) ...
  257 + @$(MKDIR) `dirname $@`
  258 + @$(LN_S) -f $(LIBNAME).@PACKAGE_MAJOR_VERSION@ $@
  259 +
  260 +$(BINDBG)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@: \
  261 + $(BINDBG)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@
  262 +
  263 + @echo $(basename $@) ...
  264 + @$(MKDIR) `dirname $@`
  265 + @$(LN_S) -f $(LIBNAME).@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ $@
  266 +
  267 +$(BINDBG)/$(LIBNAME).@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@: \
  268 + $(foreach SRC, $(basename $(API_SOURCES)), $(OBJDBG)/$(SRC).o)
  269 +
  270 + @echo $@ ...
  271 + @$(MKDIR) `dirname $@`
  272 + @$(LD) \
  273 + -shared \
  274 + -Wl,-soname,`basename $@` \
  275 + $(LDFLAGS) \
  276 + -L$(BASEDIR)/.bin/Debug \
  277 + -o $@ $^ \
  278 + $(API_LIBS)
  279 +
  280 +$(BINDBG)/plugins/$(MODULE_NAME)@DLLEXT@: \
  281 + $(BINDBG)/$(LIBNAME) \
  282 + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o)
  283 +
  284 + @echo $@ ...
  285 + @$(MKDIR) `dirname $@`
  286 + @$(LD) \
  287 + -shared \
  288 + -Wl,-soname,$(MODULE_NAME)d,--rpath,$(BASEDIR)/.bin/Debug \
  289 + $(LDFLAGS) \
  290 + -L$(BASEDIR)/.bin/Debug \
  291 + -o $@ $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \
  292 + $(PLUGIN_LIBS)
  293 +
  294 +
  295 +#---[ Clean Targets]---------------------------------------------------------------------
  296 +
  297 +cleanDebug:
  298 +
  299 + @rm -fr $(BINDBG)/$(MODULE_NAME)@DLLEXT@ \
  300 + $(OBJDBG) \
  301 + dbus-glue.h
  302 +
  303 +cleanRelease:
  304 +
  305 + @rm -fr $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \
  306 + $(OBJRLS) \
  307 + dbus-glue.h
  308 +
  309 + @rm -fr $(POTDIR)
  310 +
  311 +clean: \
  312 + cleanDebug \
  313 + cleanRelease
  314 +
  315 +
... ...
src/hllapi/calls.cc 0 → 100644
  1 +++ a/src/hllapi/calls.cc
... ... @@ -0,0 +1,821 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como calls.cc 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 <exception>
  31 + #include <cstdlib>
  32 + #include <cstring>
  33 +
  34 + #include <pw3270cpp.h>
  35 + #include <pw3270/hllapi.h>
  36 + #include "client.h"
  37 +
  38 + using namespace std;
  39 + using namespace PW3270_NAMESPACE;
  40 +
  41 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  42 +
  43 + static session * hSession = NULL;
  44 + static time_t hllapi_timeout = 120;
  45 +
  46 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  47 +
  48 + HLLAPI_API_CALL hllapi_init(LPSTR mode)
  49 + {
  50 + trace("%s(%s)",__FUNCTION__,mode);
  51 +
  52 + try
  53 + {
  54 + if(hSession)
  55 + delete hSession;
  56 + hSession = session::create(mode);
  57 +
  58 + session::get_default()->set_display_charset();
  59 +
  60 + trace("hSession=%p",hSession);
  61 + }
  62 + catch(std::exception &e)
  63 + {
  64 + trace("Error \"%s\"",e.what());
  65 + return HLLAPI_STATUS_SYSTEM_ERROR;
  66 + }
  67 +
  68 + return hSession ? HLLAPI_STATUS_SUCCESS : HLLAPI_STATUS_UNAVAILABLE;
  69 + }
  70 +
  71 + HLLAPI_API_CALL hllapi_deinit(void)
  72 + {
  73 + trace("%s()",__FUNCTION__);
  74 +
  75 + try
  76 + {
  77 + if(hSession)
  78 + {
  79 + delete hSession;
  80 + hSession = NULL;
  81 + }
  82 + }
  83 + catch(std::exception &e)
  84 + {
  85 + return HLLAPI_STATUS_SYSTEM_ERROR;
  86 + }
  87 +
  88 + return HLLAPI_STATUS_SUCCESS;
  89 + }
  90 +
  91 + HLLAPI_API_CALL hllapi_get_revision(void)
  92 + {
  93 + try
  94 + {
  95 + return atoi(session::get_default()->get_revision().c_str());
  96 + }
  97 + catch(std::exception &e)
  98 + {
  99 + return -1;
  100 + }
  101 + return (DWORD) -1;
  102 + }
  103 +
  104 + HLLAPI_API_CALL hllapi_connect(LPSTR uri, WORD wait)
  105 + {
  106 + try
  107 + {
  108 + session::get_default()->connect(uri,hllapi_timeout);
  109 + }
  110 + catch(std::exception &e)
  111 + {
  112 + return HLLAPI_STATUS_SYSTEM_ERROR;
  113 + }
  114 +
  115 + return hllapi_get_state();
  116 + }
  117 +
  118 + HLLAPI_API_CALL hllapi_is_connected(void)
  119 + {
  120 + if(!session::has_default())
  121 + {
  122 + return 0;
  123 + }
  124 +
  125 + return session::get_default()->is_connected();
  126 + }
  127 +
  128 + HLLAPI_API_CALL hllapi_get_state(void)
  129 + {
  130 + switch(hllapi_get_message_id())
  131 + {
  132 + case LIB3270_MESSAGE_NONE: // 0 - No message
  133 + return HLLAPI_STATUS_SUCCESS; // keyboard was unlocked and ready for input.
  134 +
  135 + case LIB3270_MESSAGE_DISCONNECTED: // 4 - Disconnected from host
  136 + return HLLAPI_STATUS_DISCONNECTED; // Your application program was not connected to a valid session.
  137 +
  138 + case LIB3270_MESSAGE_MINUS:
  139 + case LIB3270_MESSAGE_PROTECTED:
  140 + case LIB3270_MESSAGE_NUMERIC:
  141 + case LIB3270_MESSAGE_OVERFLOW:
  142 + case LIB3270_MESSAGE_INHIBIT:
  143 + case LIB3270_MESSAGE_KYBDLOCK:
  144 + return HLLAPI_STATUS_KEYBOARD_LOCKED; // keyboard is locked.
  145 +
  146 + case LIB3270_MESSAGE_SYSWAIT:
  147 + case LIB3270_MESSAGE_TWAIT:
  148 + case LIB3270_MESSAGE_AWAITING_FIRST:
  149 + case LIB3270_MESSAGE_X:
  150 + case LIB3270_MESSAGE_RESOLVING:
  151 + case LIB3270_MESSAGE_CONNECTING:
  152 + return HLLAPI_STATUS_WAITING; // time-out while still busy (in XCLOCK or XSYSTEM in X) for the 3270 terminal emulation.
  153 + }
  154 +
  155 + return HLLAPI_STATUS_SYSTEM_ERROR;
  156 + }
  157 +
  158 + HLLAPI_API_CALL hllapi_disconnect(void)
  159 + {
  160 + session::get_default()->disconnect();
  161 + return HLLAPI_STATUS_SUCCESS;
  162 + }
  163 +
  164 + HLLAPI_API_CALL hllapi_wait_for_ready(WORD seconds)
  165 + {
  166 + if(!hllapi_is_connected())
  167 + return HLLAPI_STATUS_DISCONNECTED;
  168 +
  169 + session::get_default()->wait_for_ready(seconds);
  170 +
  171 + return hllapi_get_state();
  172 + }
  173 +
  174 + HLLAPI_API_CALL hllapi_wait(WORD seconds)
  175 + {
  176 + if(!hllapi_is_connected())
  177 + return HLLAPI_STATUS_DISCONNECTED;
  178 +
  179 + session::get_default()->wait(seconds);
  180 +
  181 + return hllapi_get_state();
  182 + }
  183 +
  184 + HLLAPI_API_CALL hllapi_get_message_id(void)
  185 + {
  186 + if(!hllapi_is_connected())
  187 + return HLLAPI_STATUS_DISCONNECTED;
  188 +
  189 + return session::get_default()->get_program_message();
  190 + }
  191 +
  192 + HLLAPI_API_CALL hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer)
  193 + {
  194 + if(!hllapi_is_connected())
  195 + return HLLAPI_STATUS_DISCONNECTED;
  196 +
  197 + if(!(buffer && *buffer))
  198 + return HLLAPI_STATUS_SYSTEM_ERROR;
  199 +
  200 + try
  201 + {
  202 + size_t sz = strlen(buffer);
  203 + string str = session::get_default()->get_string_at(row,col,sz);
  204 + strncpy(buffer,str.c_str(),sz);
  205 + }
  206 + catch(std::exception &e)
  207 + {
  208 + return HLLAPI_STATUS_SYSTEM_ERROR;
  209 + }
  210 +
  211 + return HLLAPI_STATUS_SUCCESS;
  212 + }
  213 +
  214 + HLLAPI_API_CALL hllapi_enter(void)
  215 + {
  216 + if(!hllapi_is_connected())
  217 + return HLLAPI_STATUS_DISCONNECTED;
  218 +
  219 + return session::get_default()->enter();
  220 + }
  221 +
  222 + HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text)
  223 + {
  224 + if(!hllapi_is_connected())
  225 + return HLLAPI_STATUS_DISCONNECTED;
  226 +
  227 + try
  228 + {
  229 + session::get_default()->set_string_at(row,col,text);
  230 + }
  231 + catch(std::exception &e)
  232 + {
  233 + return HLLAPI_STATUS_SYSTEM_ERROR;
  234 + }
  235 +
  236 + return HLLAPI_STATUS_SUCCESS;
  237 + }
  238 +
  239 + HLLAPI_API_CALL hllapi_cmp_text_at(WORD row, WORD col, LPSTR text)
  240 + {
  241 +
  242 + if(!hllapi_is_connected())
  243 + return HLLAPI_STATUS_DISCONNECTED;
  244 +
  245 + int rc = HLLAPI_STATUS_SYSTEM_ERROR;
  246 +
  247 + try
  248 + {
  249 + rc = session::get_default()->cmp_string_at(row,col,text);
  250 + }
  251 + catch(std::exception &e)
  252 + {
  253 + return HLLAPI_STATUS_SYSTEM_ERROR;
  254 + }
  255 +
  256 + return rc;
  257 + }
  258 +
  259 + HLLAPI_API_CALL hllapi_find_text(LPSTR text)
  260 + {
  261 + if(!hllapi_is_connected())
  262 + return HLLAPI_STATUS_DISCONNECTED;
  263 +
  264 + return (int) session::get_default()->find_string((const char *) text, false);
  265 + }
  266 +
  267 + HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms)
  268 + {
  269 + session::get_default()->set_unlock_delay(ms);
  270 + return 0;
  271 + }
  272 +
  273 + HLLAPI_API_CALL hllapi_set_charset(LPSTR text)
  274 + {
  275 + try
  276 + {
  277 +
  278 + session::get_default()->set_display_charset(NULL, (const char *) text);
  279 +
  280 + }
  281 + catch(std::exception &e)
  282 + {
  283 + return HLLAPI_STATUS_SYSTEM_ERROR;
  284 + }
  285 +
  286 + return 0;
  287 + }
  288 +
  289 + HLLAPI_API_CALL hllapi_pfkey(WORD key)
  290 + {
  291 + if(!hllapi_is_connected())
  292 + return HLLAPI_STATUS_DISCONNECTED;
  293 +
  294 + return session::get_default()->pfkey(key);
  295 + }
  296 +
  297 + HLLAPI_API_CALL hllapi_pakey(WORD key)
  298 + {
  299 + if(!hllapi_is_connected())
  300 + return HLLAPI_STATUS_DISCONNECTED;
  301 +
  302 + return session::get_default()->pakey(key);
  303 + }
  304 +
  305 + HLLAPI_API_CALL hllapi_get_datadir(LPSTR datadir)
  306 + {
  307 + #ifdef _WIN32
  308 + HKEY hKey = 0;
  309 + unsigned long datalen = strlen(datadir);
  310 +
  311 + *datadir = 0;
  312 +
  313 + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
  314 + {
  315 + unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
  316 + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS)
  317 + *datadir = 0;
  318 + RegCloseKey(hKey);
  319 + }
  320 +#endif // _WIN32
  321 +
  322 + return *datadir;
  323 + }
  324 +
  325 + HLLAPI_API_CALL hllapi_setcursor(WORD pos)
  326 + {
  327 + if(!hllapi_is_connected())
  328 + return HLLAPI_STATUS_DISCONNECTED;
  329 +
  330 + session::get_default()->set_cursor_addr(pos-1);
  331 +
  332 + return HLLAPI_STATUS_SUCCESS;
  333 +
  334 + }
  335 +
  336 + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos)
  337 + {
  338 + if(!hllapi_is_connected())
  339 + return HLLAPI_STATUS_DISCONNECTED;
  340 +
  341 + session::get_default()->set_cursor_addr(pos-1);
  342 +
  343 + return HLLAPI_STATUS_SUCCESS;
  344 +
  345 + }
  346 +
  347 + HLLAPI_API_CALL hllapi_get_cursor_address()
  348 + {
  349 + return session::get_default()->get_cursor_addr()+1;
  350 + }
  351 +
  352 + HLLAPI_API_CALL hllapi_getcursor()
  353 + {
  354 + return session::get_default()->get_cursor_addr()+1;
  355 + }
  356 +
  357 + HLLAPI_API_CALL hllapi_get_screen(WORD offset, LPSTR buffer, WORD len)
  358 + {
  359 + if(!hllapi_is_connected())
  360 + return HLLAPI_STATUS_DISCONNECTED;
  361 +
  362 + int rc = HLLAPI_STATUS_SYSTEM_ERROR;
  363 +
  364 + if(offset < 1)
  365 + {
  366 + return HLLAPI_STATUS_BAD_PARAMETER;
  367 + }
  368 +
  369 + offset--;
  370 +
  371 + if(!session::has_default())
  372 + {
  373 + return HLLAPI_STATUS_DISCONNECTED;
  374 + }
  375 +
  376 + if(!(buffer && *buffer)) {
  377 + return HLLAPI_STATUS_BAD_PARAMETER;
  378 + }
  379 +
  380 + try
  381 + {
  382 + size_t szBuffer;
  383 +
  384 + if(len > 0)
  385 + {
  386 + szBuffer = (size_t) len;
  387 + }
  388 + else
  389 + {
  390 + return HLLAPI_STATUS_BAD_PARAMETER;
  391 + }
  392 +
  393 + memset(buffer,' ',szBuffer);
  394 +
  395 + string str = session::get_default()->get_string(offset,szBuffer,false);
  396 + strncpy(buffer,str.c_str(),szBuffer);
  397 + rc = HLLAPI_STATUS_SUCCESS;
  398 + }
  399 + catch(std::exception &e)
  400 + {
  401 + rc = HLLAPI_STATUS_SYSTEM_ERROR;
  402 + }
  403 +
  404 + return rc;
  405 + }
  406 +
  407 + HLLAPI_API_CALL hllapi_emulate_input(const LPSTR buffer, WORD len, WORD pasting)
  408 + {
  409 + if(!hllapi_is_connected())
  410 + return HLLAPI_STATUS_DISCONNECTED;
  411 +
  412 + try
  413 + {
  414 + session::get_default()->input_string(buffer);
  415 + }
  416 + catch(std::exception &e)
  417 + {
  418 + return HLLAPI_STATUS_SYSTEM_ERROR;
  419 + }
  420 +
  421 + return HLLAPI_STATUS_SUCCESS;
  422 + }
  423 +
  424 + HLLAPI_API_CALL hllapi_erase(void)
  425 + {
  426 + try
  427 + {
  428 + session::get_default()->erase();
  429 + }
  430 + catch(std::exception &e)
  431 + {
  432 + return HLLAPI_STATUS_SYSTEM_ERROR;
  433 + }
  434 + return HLLAPI_STATUS_SUCCESS;
  435 + }
  436 +
  437 + HLLAPI_API_CALL hllapi_erase_eof(void)
  438 + {
  439 + if(!hllapi_is_connected())
  440 + return HLLAPI_STATUS_DISCONNECTED;
  441 +
  442 + try
  443 + {
  444 + session::get_default()->erase_eof();
  445 + }
  446 + catch(std::exception &e)
  447 + {
  448 + return HLLAPI_STATUS_SYSTEM_ERROR;
  449 + }
  450 + return HLLAPI_STATUS_SUCCESS;
  451 + }
  452 +
  453 + HLLAPI_API_CALL hllapi_erase_eol(void)
  454 + {
  455 + if(!hllapi_is_connected())
  456 + return HLLAPI_STATUS_DISCONNECTED;
  457 +
  458 + try
  459 + {
  460 + session::get_default()->erase_eol();
  461 + }
  462 + catch(std::exception &e)
  463 + {
  464 + return HLLAPI_STATUS_SYSTEM_ERROR;
  465 + }
  466 + return HLLAPI_STATUS_SUCCESS;
  467 + }
  468 +
  469 + HLLAPI_API_CALL hllapi_erase_input(void)
  470 + {
  471 + if(!hllapi_is_connected())
  472 + return HLLAPI_STATUS_DISCONNECTED;
  473 +
  474 + try
  475 + {
  476 + session::get_default()->erase_input();
  477 + }
  478 + catch(std::exception &e)
  479 + {
  480 + return HLLAPI_STATUS_SYSTEM_ERROR;
  481 + }
  482 + return HLLAPI_STATUS_SUCCESS;
  483 + }
  484 +
  485 + HLLAPI_API_CALL hllapi_action(LPSTR buffer) {
  486 + try
  487 + {
  488 + session::get_default()->action((const char *) buffer);
  489 + }
  490 + catch(std::exception &e)
  491 + {
  492 + return HLLAPI_STATUS_SYSTEM_ERROR;
  493 + }
  494 + return HLLAPI_STATUS_SUCCESS;
  495 + }
  496 +
  497 + HLLAPI_API_CALL hllapi_print(void)
  498 + {
  499 + return session::get_default()->print();
  500 + }
  501 +
  502 + char * hllapi_get_string(int offset, size_t len)
  503 + {
  504 + try
  505 + {
  506 + string str = session::get_default()->get_string(offset-1,len);
  507 + char * ret = strdup(str.c_str());
  508 + return ret;
  509 + }
  510 + catch(std::exception &e)
  511 + {
  512 + }
  513 +
  514 + return NULL;
  515 + }
  516 +
  517 + void hllapi_free(void *p)
  518 + {
  519 + free(p);
  520 + }
  521 +
  522 + HLLAPI_API_CALL hllapi_reset(void)
  523 + {
  524 + return HLLAPI_STATUS_SUCCESS;
  525 + }
  526 +
  527 + HLLAPI_API_CALL hllapi_input_string(LPSTR input, WORD length)
  528 + {
  529 + static const char control_char = '@';
  530 +
  531 + size_t szText;
  532 + char * text;
  533 + int rc = 0;
  534 +
  535 + if(!hllapi_is_connected()) {
  536 + return HLLAPI_STATUS_DISCONNECTED;
  537 + }
  538 +
  539 + if(!input)
  540 + {
  541 + return HLLAPI_STATUS_BAD_PARAMETER;
  542 + }
  543 +
  544 + if(length > 0 )
  545 + szText = length;
  546 + else
  547 + szText = strlen(input);
  548 +
  549 + text = (char *) malloc(szText+2);
  550 + memcpy(text,input,szText);
  551 + text[szText] = 0;
  552 +
  553 + trace("input[%s]",text);
  554 +
  555 + if(strchr(text,control_char))
  556 + {
  557 + // Convert control char
  558 + char * buffer = text;
  559 + char * ptr;
  560 +
  561 + for(ptr = strchr(text,control_char);ptr;ptr = strchr(buffer,control_char))
  562 + {
  563 + *(ptr++) = 0;
  564 +
  565 + trace("input[%s]",buffer);
  566 + hllapi_emulate_input(buffer,-1,0);
  567 +
  568 + switch(*(ptr++))
  569 + {
  570 + case 'P': // Print
  571 + rc = hllapi_print();
  572 + break;
  573 +
  574 + case 'E': // Enter
  575 + hllapi_enter();
  576 + break;
  577 +
  578 + case 'F': // Erase EOF
  579 + hllapi_erase_eof();
  580 + break;
  581 +
  582 + case '1': // PF1
  583 + hllapi_pfkey(1);
  584 + break;
  585 +
  586 + case '2': // PF2
  587 + hllapi_pfkey(2);
  588 + break;
  589 +
  590 + case '3': // PF3
  591 + hllapi_pfkey(3);
  592 + break;
  593 +
  594 + case '4': // PF4
  595 + hllapi_pfkey(4);
  596 + break;
  597 +
  598 + case '5': // PF5
  599 + hllapi_pfkey(5);
  600 + break;
  601 +
  602 + case '6': // PF6
  603 + hllapi_pfkey(6);
  604 + break;
  605 +
  606 + case '7': // PF7
  607 + hllapi_pfkey(7);
  608 + break;
  609 +
  610 + case '8': // PF8
  611 + hllapi_pfkey(8);
  612 + break;
  613 +
  614 + case '9': // PF9
  615 + hllapi_pfkey(9);
  616 + break;
  617 +
  618 + case 'a': // PF10
  619 + hllapi_pfkey(10);
  620 + break;
  621 +
  622 + case 'b': // PF11
  623 + hllapi_pfkey(11);
  624 + break;
  625 +
  626 + case 'c': // PF12
  627 + hllapi_pfkey(12);
  628 + break;
  629 +
  630 + case 'd': // PF13
  631 + hllapi_pfkey(13);
  632 + break;
  633 +
  634 + case 'e': // PF14
  635 + hllapi_pfkey(14);
  636 + break;
  637 +
  638 + case 'f': // PF15
  639 + hllapi_pfkey(15);
  640 + break;
  641 +
  642 + case 'g': // PF16
  643 + hllapi_pfkey(16);
  644 + break;
  645 +
  646 + case 'h': // PF17
  647 + hllapi_pfkey(17);
  648 + break;
  649 +
  650 + case 'i': // PF18
  651 + hllapi_pfkey(18);
  652 + break;
  653 +
  654 + case 'j': // PF19
  655 + hllapi_pfkey(19);
  656 + break;
  657 +
  658 + case 'k': // PF20
  659 + hllapi_pfkey(20);
  660 + break;
  661 +
  662 + case 'l': // PF21
  663 + hllapi_pfkey(21);
  664 + break;
  665 +
  666 + case 'm': // PF22
  667 + hllapi_pfkey(22);
  668 + break;
  669 +
  670 + case 'n': // PF23
  671 + hllapi_pfkey(23);
  672 + break;
  673 +
  674 + case 'o': // PF24
  675 + hllapi_pfkey(24);
  676 + break;
  677 +
  678 + case '@': // Send '@' character
  679 + hllapi_emulate_input((LPSTR) "@",-1,0);
  680 + break;
  681 +
  682 + case 'x': // PA1
  683 + hllapi_pakey(1);
  684 + break;
  685 +
  686 + case 'y': // PA2
  687 + hllapi_pakey(2);
  688 + break;
  689 +
  690 + case 'z': // PA3
  691 + hllapi_pakey(3);
  692 + break;
  693 +
  694 + case 'B': // PC_LEFTTAB = "@B"
  695 + break;
  696 +
  697 + case 'T': // PC_RIGHTTAB = "@T"
  698 + break;
  699 +
  700 + case 'N': // PC_NEWLINE = "@N"
  701 + break;
  702 +
  703 + case 'C': // PC_CLEAR = "@C"
  704 + hllapi_erase_input();
  705 + break;
  706 +
  707 + case 'D': // PC_DELETE = "@D"
  708 + break;
  709 +
  710 + case 'H': // PC_HELP = "@H"
  711 + break;
  712 +
  713 + case 'I': // PC_INSERT = "@I"
  714 + break;
  715 +
  716 + case 'L': // PC_CURSORLEFT = "@L"
  717 + break;
  718 +
  719 + case 'R': // PC_RESET = "@R"
  720 + hllapi_reset();
  721 + break;
  722 +
  723 + case 'U': // PC_CURSORUP = "@U"
  724 + break;
  725 +
  726 + case 'V': // PC_CURSORDOWN = "@V"
  727 + break;
  728 +
  729 + case 'Z': // PC_CURSORRIGHT = "@Z"
  730 + break;
  731 +
  732 + case '0': // PC_HOME = "@0"
  733 + break;
  734 +
  735 + case 'p': // PC_PLUSKEY = "@p"
  736 + break;
  737 +
  738 + case 'q': // PC_END = "@q"
  739 + break;
  740 +
  741 + case 's': // PC_SCRLK = "@s"
  742 + break;
  743 +
  744 + case 't': // PC_NUMLOCK = "@t"
  745 + break;
  746 +
  747 + case 'u': // PC_PAGEUP = "@u"
  748 + break;
  749 +
  750 + case 'v': // PC_PAGEDOWN = "@v"
  751 + break;
  752 +
  753 + case '/': // PC_OVERRUNOFQUEUE = "@/" ' Queue overflow, used in Get Key only
  754 + break;
  755 +
  756 + case '$': // PC_ALTCURSOR = "@$" ' Presentation Manager only, unused in VB environment
  757 + break;
  758 +
  759 + case '<': // PC_BACKSPACE = "@<"
  760 + break;
  761 +
  762 +
  763 +/*
  764 +
  765 +Global Const PC_TEST = "@A@C"
  766 +Global Const PC_WORDDELETE = "@A@D"
  767 +Global Const PC_FIELDEXIT = "@A@E"
  768 +Global Const PC_ERASEINPUT = "@A@F"
  769 +Global Const PC_SYSTEMREQUEST = "@A@H"
  770 +Global Const PC_INSERTTOGGLE = "@A@I"
  771 +Global Const PC_CURSORSELECT = "@A@J"
  772 +Global Const PC_CURSLEFTFAST = "@A@L"
  773 +Global Const PC_GETCURSOR = "@A@N"
  774 +Global Const PC_LOCATECURSOR = "@A@O"
  775 +Global Const PC_ATTENTION = "@A@Q"
  776 +Global Const PC_DEVICECANCEL = "@A@R"
  777 +Global Const PC_PRINTPS = "@A@T"
  778 +Global Const PC_CURSUPFAST = "@A@U"
  779 +Global Const PC_CURSDOWNFAST = "@A@V"
  780 +Global Const PC_HEX = "@A@X"
  781 +Global Const PC_FUNCTIONKEY = "@A@Y"
  782 +Global Const PC_CURSRIGHTFAST = "@A@Z"
  783 +
  784 +Global Const PC_REVERSEVIDEO = "@A@9"
  785 +Global Const PC_UNDERSCORE = "@A@b"
  786 +Global Const PC_BLINK = "@A@c"
  787 +Global Const PC_RED = "@A@d"
  788 +Global Const PC_PINK = "@A@e"
  789 +Global Const PC_GREEN = "@A@f"
  790 +Global Const PC_YELLOW = "@A@g"
  791 +Global Const PC_BLUE = "@A@h"
  792 +Global Const PC_TURQOISE = "@A@i"
  793 +Global Const PC_WHITE = "@A@j"
  794 +Global Const PC_RSTHOSTCOLORS = "@A@l"
  795 +Global Const PC_PRINTPC = "@A@t"
  796 +
  797 +Global Const PC_FIELDMINUS = "@A@-"
  798 +Global Const PC_FIELDPLUS = "@A@+"
  799 +
  800 +*/
  801 +
  802 + }
  803 +
  804 + buffer = ptr;
  805 +
  806 + }
  807 +
  808 + if(*buffer)
  809 + hllapi_emulate_input(buffer,-1,0);
  810 +
  811 + }
  812 + else
  813 + {
  814 + hllapi_emulate_input(text,szText,0);
  815 + }
  816 +
  817 + free(text);
  818 +
  819 + return rc;
  820 + }
  821 +
... ...
src/hllapi/client.h 0 → 100644
  1 +++ a/src/hllapi/client.h
... ... @@ -0,0 +1,56 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como private.h 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 <pw3270/hllapi.h>
  31 +
  32 + #ifndef ETIMEDOUT
  33 + #define ETIMEDOUT 1238
  34 + #endif // ETIMEDOUT
  35 +
  36 + #define PIPE_BUFFER_LENGTH 8192
  37 +
  38 + #define set_active(x) /* x */
  39 +
  40 + #if defined(DEBUG) && defined(_WIN32)
  41 + #undef trace
  42 + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } }
  43 + #endif // DEBUG
  44 +
  45 + #ifdef __cplusplus
  46 + extern "C" {
  47 + #endif
  48 +
  49 + char * hllapi_get_string(int offset, size_t len);
  50 + void hllapi_free(void *p);
  51 +
  52 + #ifdef __cplusplus
  53 + } /* end of extern "C" */
  54 + #endif
  55 +
  56 +
... ...
src/hllapi/environ.bat 0 → 100644
  1 +++ a/src/hllapi/environ.bat
... ... @@ -0,0 +1,6 @@
  1 +@echo off
  2 +
  3 +set VC=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
  4 +set WINSDK=C:\Program Files (x86)\Windows Kits\8.1
  5 +set PATH=%PATH%;"%VC%\bin";"%WINSDK%\bin\x86\"
  6 +
... ...
src/hllapi/hllapi.c 0 → 100644
  1 +++ a/src/hllapi/hllapi.c
... ... @@ -0,0 +1,466 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como hllapi.c 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 <lib3270.h>
  31 + #include <malloc.h>
  32 + #include <string.h>
  33 + #include <errno.h>
  34 + #include <pw3270/hllapi.h>
  35 + #include <stdio.h>
  36 + #include <time.h>
  37 + #include <lib3270/log.h>
  38 + #include "client.h"
  39 +
  40 + /*--[ Prototipes ]-----------------------------------------------------------------------------------*/
  41 +
  42 + static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc);
  43 + static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc);
  44 + static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc);
  45 + static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc);
  46 + static int copy_str_to_ps(char *buffer, unsigned short *length, unsigned short *rc);
  47 + static int search_ps(char *buffer, unsigned short *length, unsigned short *rc);
  48 + static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc);
  49 + static int wait_system(char *buffer, unsigned short *length, unsigned short *rc);
  50 + static int reset_system(char *buffer, unsigned short *length, unsigned short *rc);
  51 + static int pause_system(char *buffer, unsigned short *length, unsigned short *rc);
  52 + static int set_session_parameters(char *buffer, unsigned short *length, unsigned short *rc);
  53 +
  54 + static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc);
  55 + static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc);
  56 + static int input_string(char *buffer, unsigned short *length, unsigned short *rc);
  57 +
  58 + static int invalid_request(char *buffer, unsigned short *length, unsigned short *rc);
  59 +
  60 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  61 +
  62 + static const struct _hllapi_call
  63 + {
  64 + unsigned long func;
  65 + int (*exec)(char *buffer, unsigned short *length, unsigned short *rc);
  66 + } hllapi_call[] =
  67 + {
  68 + { HLLAPI_CMD_CONNECTPS, connect_ps },
  69 + { HLLAPI_CMD_DISCONNECTPS, disconnect_ps },
  70 + { HLLAPI_CMD_GETREVISION, get_library_revision },
  71 + { HLLAPI_CMD_QUERYCURSOR, get_cursor_position },
  72 + { HLLAPI_CMD_SETCURSOR, set_cursor_position },
  73 + { HLLAPI_CMD_COPYPSTOSTR, copy_ps_to_str },
  74 + { HLLAPI_CMD_INPUTSTRING, input_string },
  75 + { HLLAPI_CMD_WAIT, wait_system },
  76 + { HLLAPI_CMD_COPYPS, copy_ps },
  77 + { HLLAPI_CMD_SEARCHPS, search_ps },
  78 + { HLLAPI_CMD_COPYSTRTOPS, copy_str_to_ps },
  79 + { HLLAPI_CMD_SENDFILE, invalid_request },
  80 + { HLLAPI_CMD_RECEIVEFILE, invalid_request },
  81 + { HLLAPI_RESET_SYSTEM, reset_system },
  82 + { HLLAPI_CMD_PAUSE, pause_system },
  83 + { HLLAPI_SET_SESSION_PARAMETERS, set_session_parameters }
  84 +
  85 + };
  86 +
  87 + static enum _pause_mode
  88 + {
  89 + PAUSE_MODE_IPAUSE, ///< @brief Interruptible pause. After the Start Host Notification (23) function is executed, a host event satisfies a pause.
  90 + PAUSE_MODE_FPAUSE ///< @brief A full-duration pause lasts for however long you specified in the Pause (18) function.
  91 + } pause_mode = PAUSE_MODE_IPAUSE;
  92 +
  93 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  94 +
  95 +HLLAPI_API_CALL hllapi(const LPWORD func, LPSTR buffer, LPWORD length, LPWORD rc)
  96 +{
  97 + unsigned int f;
  98 +
  99 + trace("%s(%d)",__FUNCTION__,*func);
  100 +
  101 + for(f=0;f< (sizeof (hllapi_call) / sizeof ((hllapi_call)[0]));f++)
  102 + {
  103 + if(hllapi_call[f].func == *func)
  104 + {
  105 + int status = hllapi_call[f].exec(buffer,length,rc);
  106 + trace("hllapi(%d) exits with rc=%d",*func,status);
  107 + return status;
  108 + }
  109 + }
  110 +
  111 + trace("hllapi(%d) failed",*func);
  112 +
  113 + *rc = HLLAPI_STATUS_UNSUPPORTED;
  114 + return *rc;
  115 +
  116 +}
  117 +
  118 +static int invalid_request(char *buffer, unsigned short *length, unsigned short *rc)
  119 +{
  120 + *rc = HLLAPI_STATUS_BAD_PARAMETER;
  121 + return *rc;
  122 +}
  123 +
  124 +static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc)
  125 +{
  126 + char *tempbuffer = NULL;
  127 +
  128 + trace("%s: len=%d buflen=%d",__FUNCTION__,*length,(int) strlen(buffer));
  129 +
  130 + if(strlen(buffer) > *length)
  131 + buffer[*length] = 0;
  132 +
  133 + if(!strrchr(buffer,':'))
  134 + {
  135 + int sz = strlen(buffer);
  136 +
  137 + tempbuffer = (char *) malloc(sz+2);
  138 + strcpy(tempbuffer,buffer);
  139 + tempbuffer[sz-1] = ':';
  140 + tempbuffer[sz] = buffer[sz-1];
  141 + tempbuffer[sz+1] = 0;
  142 + buffer = tempbuffer;
  143 + }
  144 +
  145 + *rc = hllapi_init(buffer);
  146 +
  147 + if(tempbuffer)
  148 + free(tempbuffer);
  149 +
  150 + return 0;
  151 +}
  152 +
  153 +static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc)
  154 +{
  155 + *rc = hllapi_deinit();
  156 + return 0;
  157 +}
  158 +
  159 +static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc)
  160 +{
  161 + *rc = hllapi_get_revision();
  162 + return 0;
  163 +}
  164 +
  165 +static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc)
  166 +{
  167 + int pos = hllapi_getcursor();
  168 +
  169 + trace("%s(%d)",__FUNCTION__,pos);
  170 +
  171 + if(pos < 0)
  172 + return -1;
  173 +
  174 + *rc = pos;
  175 + return 0;
  176 +}
  177 +
  178 +static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc)
  179 +{
  180 + trace("%s(%d)",__FUNCTION__,*rc);
  181 + *rc = hllapi_setcursor(*rc);
  182 + return 0;
  183 +}
  184 +
  185 +static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc)
  186 +{
  187 +
  188 + // Length Length of the target data string.
  189 + // PS Position Position within the host presentation space of the first byte in your target data string.
  190 + *rc = hllapi_get_screen(*rc,buffer,*length);
  191 +
  192 + return 0;
  193 +}
  194 +
  195 +static int input_string(char *buffer, unsigned short *length, unsigned short *rc)
  196 +{
  197 + *rc = hllapi_input_string(buffer,*length);
  198 + return 0;
  199 +}
  200 +
  201 +static int search_ps(char *buffer, unsigned short *length, unsigned short *ps)
  202 +{
  203 + /*
  204 + * Data String Target string for search.
  205 + * Length Length of the target data string. Overridden in EOT mode.
  206 + * PS Position Position within the host presentation space where the search is to begin (SRCHFRWD option) or to end
  207 + * (SRCHBKWD option). Overridden in SRCHALL (default) mode.
  208 + *
  209 + * Return in *ps:
  210 + *
  211 + * = 0 The string was not found.
  212 + * > 0 The string was found at the indicated host presentation space position.
  213 + *
  214 + * Return code:
  215 + *
  216 + * 0 The Search Presentation Space function was successful.
  217 + * 1 Your program is not connected to a host session.
  218 + * 2 An error was made in specifying parameters.
  219 + * 7 The host presentation space position is not valid.
  220 + * 9 A system error was encountered.
  221 + * 24 The search string was not found.
  222 + *
  223 + */
  224 + size_t szBuffer = strlen(buffer);
  225 + char * text;
  226 + int rc = HLLAPI_STATUS_SYSTEM_ERROR;
  227 +
  228 + if(!hllapi_is_connected())
  229 + return HLLAPI_STATUS_DISCONNECTED;
  230 +
  231 + if(*length < szBuffer)
  232 + szBuffer = *length;
  233 +
  234 +
  235 + text = hllapi_get_string(*ps,szBuffer);
  236 + if(!text)
  237 + return HLLAPI_STATUS_SYSTEM_ERROR;
  238 +
  239 + if(strncmp(text,buffer,szBuffer))
  240 + {
  241 + // String not found
  242 + *ps = 0;
  243 + rc = HLLAPI_STATUS_NOT_FOUND;
  244 + }
  245 + else
  246 + {
  247 + // String found
  248 + *ps = 1;
  249 + rc = HLLAPI_STATUS_SUCCESS;
  250 + }
  251 +
  252 + hllapi_free(text);
  253 +
  254 + return rc;
  255 +}
  256 +
  257 +static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc)
  258 +{
  259 + /*
  260 + * Data String Preallocated target string the size of your host presentation space. This can vary depending on how your host presentation space is configured. When the Set Session Parameters (9) function with the EAB option is issued, the length of the data string must be at least twice the length of the presentation space.
  261 + * DBCS Only: When the EAD option is specified, the length of the data string must be at least three times the length of the presentation space. When both the EAB and EAD options are specified, the length of the data string must be at least four times the length of the presentation space.
  262 + *
  263 + * Length NA (the length of the host presentation space is implied).
  264 + * PS Position NA.
  265 + *
  266 + * Return values:
  267 + *
  268 + * 0 The host presentation space contents were copied to the application program. The target presentation space was active, and the keyboard was unlocked.
  269 + * 1 Your program is not connected to a host session.
  270 + * 4 The host presentation space contents were copied. The connected host presentation space was waiting for host response.
  271 + * 5 The host presentation space was copied. The keyboard was locked.
  272 + * 9 A system error was encountered.
  273 + *
  274 + */
  275 + size_t szBuffer = strlen(buffer);
  276 + char * text;
  277 +
  278 + if(!hllapi_is_connected())
  279 + return HLLAPI_STATUS_DISCONNECTED;
  280 +
  281 + text = hllapi_get_string(1, szBuffer);
  282 +
  283 + if(!text)
  284 + return HLLAPI_STATUS_SYSTEM_ERROR;
  285 +
  286 + memcpy(buffer,text,szBuffer);
  287 +
  288 + hllapi_free(text);
  289 +
  290 + return hllapi_get_state();
  291 +}
  292 +
  293 +static int wait_system(char *buffer, unsigned short *length, unsigned short *rc)
  294 +{
  295 + /*
  296 + * Checks the status of the host-connected presentation space. If the session is
  297 + * waiting for a host response (indicated by XCLOCK (X []) or XSYSTEM), the Wait
  298 + * function causes HLLAPI to wait up to 1 minute to see if the condition clears.
  299 + *
  300 + */
  301 +
  302 + /*
  303 + * Return Code Definition
  304 + *
  305 + * HLLAPI_STATUS_SUCCESS 0 The keyboard is unlocked and ready for input.
  306 + * HLLAPI_STATUS_DISCONNECTED 1 Your application program is not connected to a valid session.
  307 + * HLLAPI_STATUS_TIMEOUT 4 Timeout while still in XCLOCK (X []) or XSYSTEM.
  308 + * HLLAPI_STATUS_KEYBOARD_LOCKED 5 The keyboard is locked.
  309 + * HLLAPI_STATUS_SYSTEM_ERROR 9 A system error was encountered.
  310 + *
  311 + */
  312 +
  313 + /*
  314 + time_t end = time(0) + 60;
  315 +
  316 + while(time(0) < end)
  317 + {
  318 + int state = hllapi_get_state();
  319 +
  320 + if(state != HLLAPI_STATUS_WAITING)
  321 + return state;
  322 +
  323 + hllapi_wait(1);
  324 +
  325 + }
  326 +
  327 + return HLLAPI_STATUS_TIMEOUT;
  328 + */
  329 +
  330 + int state = hllapi_wait_for_ready(60);
  331 + return (state == HLLAPI_STATUS_WAITING ? HLLAPI_STATUS_TIMEOUT : state);
  332 +
  333 +}
  334 +
  335 +static int copy_str_to_ps(char *text, unsigned short *length, unsigned short *ps)
  336 +{
  337 + /*
  338 + * Call Parameters
  339 + *
  340 + * Data String of ASCII data to be copied into the host presentation space.
  341 + * Length Length, in number of bytes, of the source data string. Overridden if in EOT mode.
  342 + * PS Position in the host presentation space to begin the copy, a value between 1 and the configured size of your host presentation space.
  343 + *
  344 + * Return Parameters
  345 + *
  346 + * HLLAPI_STATUS_SUCCESS 0 The Copy String to Presentation Space function was successful.
  347 + * HLLAPI_STATUS_DISCONNECTED 1 Your program is not connected to a host session.
  348 + * HLLAPI_STATUS_BAD_PARAMETER 2 Parameter error or zero length for copy.
  349 + * HLLAPI_STATUS_KEYBOARD_LOCKED 5 The target presentation space is protected or inhibited, or incorrect data was sent to the target presentation space (such as a field attribute byte).
  350 + * 6 The copy was completed, but the data was truncated.
  351 + * 7 The host presentation space position is not valid.
  352 + * HLLAPI_STATUS_SYSTEM_ERROR 9 A system error was encountered.
  353 + *
  354 + */
  355 + size_t szText = strlen(text);
  356 +
  357 + if(*length < szText)
  358 + szText = *length;
  359 +
  360 + if(!szText)
  361 + return HLLAPI_STATUS_BAD_PARAMETER;
  362 +
  363 + switch(hllapi_get_message_id())
  364 + {
  365 + case LIB3270_MESSAGE_NONE:
  366 + break;
  367 +
  368 + case LIB3270_MESSAGE_DISCONNECTED:
  369 + return HLLAPI_STATUS_DISCONNECTED;
  370 +
  371 + case LIB3270_MESSAGE_MINUS:
  372 + case LIB3270_MESSAGE_PROTECTED:
  373 + case LIB3270_MESSAGE_NUMERIC:
  374 + case LIB3270_MESSAGE_OVERFLOW:
  375 + case LIB3270_MESSAGE_INHIBIT:
  376 + case LIB3270_MESSAGE_KYBDLOCK:
  377 + return HLLAPI_STATUS_KEYBOARD_LOCKED;
  378 +
  379 + default:
  380 + return HLLAPI_STATUS_SYSTEM_ERROR;
  381 + }
  382 +
  383 + return hllapi_emulate_input(text,szText,0);
  384 +}
  385 +
  386 +static int reset_system(char *buffer, unsigned short *length, unsigned short *rc)
  387 +{
  388 + return hllapi_reset();
  389 +}
  390 +
  391 +
  392 +static int pause_system(char *buffer, unsigned short *length, unsigned short *rc)
  393 +{
  394 + if(!*length)
  395 + {
  396 + // If you use the IPAUSE option and the pause value is zero, then the function
  397 + // waits up to 2400 half-second intervals, unless interrupted sooner. If you use the
  398 + // FPAUSE option and the pause value is zero, then the function returns
  399 + // immediately.
  400 +
  401 + if(pause_mode == PAUSE_MODE_FPAUSE)
  402 + {
  403 + return HLLAPI_STATUS_SUCCESS;
  404 + }
  405 + return hllapi_wait_for_ready(1200);
  406 + }
  407 +
  408 + if(pause_mode == PAUSE_MODE_FPAUSE)
  409 + {
  410 + // Pause fixo - Aguarda pelo tempo informado, independente de eventos.
  411 + return hllapi_wait( (*length) / 2);
  412 + }
  413 +
  414 + // Pause "flexivel", aguarda mudança no conteúdo da tela!!!
  415 +
  416 + // #warning Mudar comportamento na lib!
  417 +
  418 + return hllapi_wait_for_ready((*length) / 2);
  419 +}
  420 +
  421 +static int set_session_parameters(char *buffer, unsigned short *length, unsigned short *rc)
  422 +{
  423 + if(!(*length && buffer && *buffer))
  424 + {
  425 + return HLLAPI_STATUS_BAD_PARAMETER;
  426 + }
  427 +
  428 + *rc = hllapi_set_session_parameter(buffer, *length, *rc);
  429 +
  430 + return 0;
  431 +}
  432 +
  433 +HLLAPI_API_CALL hllapi_set_session_parameter(LPSTR param, WORD len, WORD value)
  434 +{
  435 + if(!param)
  436 + {
  437 + return HLLAPI_STATUS_BAD_PARAMETER;
  438 + }
  439 +
  440 + if(!len)
  441 + {
  442 + len = strlen(param);
  443 + }
  444 +
  445 + if(!strncasecmp(param,"IPAUSE",len))
  446 + {
  447 + // IPAUSE
  448 + pause_mode = PAUSE_MODE_IPAUSE;
  449 + }
  450 + else if(!strncasecmp(param,"FPAUSE",len))
  451 + {
  452 + // FPAUSE
  453 + pause_mode = PAUSE_MODE_FPAUSE;
  454 + }
  455 + else if(!strncasecmp(param,"UNLOCKDELAY",len))
  456 + {
  457 + // UNLOCKDELAY
  458 + hllapi_set_unlock_delay(value);
  459 + }
  460 + else
  461 + {
  462 + return HLLAPI_STATUS_BAD_PARAMETER;
  463 + }
  464 +
  465 + return HLLAPI_STATUS_SUCCESS;
  466 +}
... ...
src/hllapi/hllapi.cbp 0 → 100644
  1 +++ a/src/hllapi/hllapi.cbp
... ... @@ -0,0 +1,89 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2 +<CodeBlocks_project_file>
  3 + <FileVersion major="1" minor="6" />
  4 + <Project>
  5 + <Option title="pw3270 HLLAPI" />
  6 + <Option makefile_is_custom="1" />
  7 + <Option pch_mode="2" />
  8 + <Option compiler="gcc" />
  9 + <Build>
  10 + <Target title="Debug">
  11 + <Option output=".bin/Debug/pw3270 HLLAPI" prefix_auto="1" extension_auto="1" />
  12 + <Option object_output=".obj/Debug/" />
  13 + <Option type="1" />
  14 + <Option compiler="gcc" />
  15 + <Compiler>
  16 + <Add option="-g" />
  17 + </Compiler>
  18 + <MakeCommands>
  19 + <Build command="$make LIB3270_MODE=Debug -f $makefile $target" />
  20 + <CompileFile command="$make -f $makefile $file" />
  21 + <Clean command="$make -f $makefile clean$target" />
  22 + <DistClean command="$make -f $makefile distclean$target" />
  23 + <AskRebuildNeeded command="$make -q -f $makefile $target" />
  24 + <SilentBuild command="$make LIB3270_MODE=Debug -f $makefile $target &gt; $(CMD_NULL)" />
  25 + </MakeCommands>
  26 + </Target>
  27 + <Target title="Release">
  28 + <Option output=".bin/Release/pw3270 HLLAPI" prefix_auto="1" extension_auto="1" />
  29 + <Option object_output=".obj/Release/" />
  30 + <Option type="1" />
  31 + <Option compiler="gcc" />
  32 + <Compiler>
  33 + <Add option="-O2" />
  34 + </Compiler>
  35 + <Linker>
  36 + <Add option="-s" />
  37 + </Linker>
  38 + </Target>
  39 + <Target title="test">
  40 + <Option output=".bin/Debug/test" prefix_auto="1" extension_auto="1" />
  41 + <Option object_output=".obj/Debug/" />
  42 + <Option type="1" />
  43 + <Option compiler="gcc" />
  44 + <Compiler>
  45 + <Add option="-g" />
  46 + </Compiler>
  47 + <Environment>
  48 + <Variable name="LIB3270_CFLAGS" value='&quot;-I../../../src/include&quot;' />
  49 + <Variable name="LIB3270_LIBS" value='&quot;-L../../../.bin/Debug -l3270&quot;' />
  50 + <Variable name="PW3270_LIBS" value='&quot;-L../../../.bin/Debug -lpw3270 -l3270&quot;' />
  51 + </Environment>
  52 + <MakeCommands>
  53 + <Build command="$make LIB3270_MODE=Debug -f $makefile $target" />
  54 + <CompileFile command="$make -f $makefile $file" />
  55 + <Clean command="$make -f $makefile clean$target" />
  56 + <DistClean command="$make -f $makefile distclean$target" />
  57 + <AskRebuildNeeded command="$make -q -f $makefile $target" />
  58 + <SilentBuild command="$make LIB3270_MODE=Debug -f $makefile $target &gt; $(CMD_NULL)" />
  59 + </MakeCommands>
  60 + </Target>
  61 + </Build>
  62 + <Compiler>
  63 + <Add option="-Wall" />
  64 + </Compiler>
  65 + <Unit filename="../../include/lib3270.h" />
  66 + <Unit filename="../../include/pw3270/hllapi.h" />
  67 + <Unit filename="../../include/pw3270cpp.h" />
  68 + <Unit filename="Makefile.in" />
  69 + <Unit filename="calls.cc" />
  70 + <Unit filename="client.h" />
  71 + <Unit filename="hllapi.c">
  72 + <Option compilerVar="CC" />
  73 + </Unit>
  74 + <Unit filename="pluginmain.c">
  75 + <Option compilerVar="CC" />
  76 + </Unit>
  77 + <Unit filename="remotectl.h" />
  78 + <Unit filename="server.h" />
  79 + <Unit filename="testprogram.c">
  80 + <Option compilerVar="CC" />
  81 + </Unit>
  82 + <Extensions>
  83 + <code_completion />
  84 + <envvars />
  85 + <debugger />
  86 + <lib_finder disable_auto="1" />
  87 + </Extensions>
  88 + </Project>
  89 +</CodeBlocks_project_file>
... ...
src/hllapi/idlcomp.bat 0 → 100644
  1 +++ a/src/hllapi/idlcomp.bat
... ... @@ -0,0 +1,3 @@
  1 +@echo off
  2 +
  3 +midl.exe /I "%WINSDK%\Include\um" /I "%WINSDK%\Include\shared" /cpp_cmd "cl.exe" pw3270.idl
... ...
src/hllapi/maketest.sh 0 → 100755
  1 +++ a/src/hllapi/maketest.sh
... ... @@ -0,0 +1 @@
  1 +make LIB3270_MODE=Debug test
... ...
src/hllapi/pluginmain.c 0 → 100644
  1 +++ a/src/hllapi/pluginmain.c
... ... @@ -0,0 +1,673 @@
  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. 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 pluginmain.c 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 + * Agradecimento:
  29 + *
  30 + * Hélio Passos
  31 + *
  32 + */
  33 +
  34 + #include "server.h"
  35 +
  36 +#ifdef _WIN32
  37 + #include <windows.h>
  38 +#else
  39 + #error HLLAPI is designed for windows.
  40 +#endif // _WIN32
  41 +
  42 + #include <pw3270/plugin.h>
  43 + #include <v3270.h>
  44 + #include <pw3270/ipcpackets.h>
  45 + #include <lib3270/actions.h>
  46 + #include <lib3270/charset.h>
  47 +
  48 +/*--[ Defines ]--------------------------------------------------------------------------------------*/
  49 +
  50 + #pragma pack(1)
  51 +
  52 + enum PIPE_STATE
  53 + {
  54 + PIPE_STATE_WAITING,
  55 + PIPE_STATE_READ,
  56 + PIPE_STATE_PENDING_READ,
  57 + PIPE_STATE_UNDEFINED
  58 + };
  59 +
  60 + typedef struct _pipe_source
  61 + {
  62 + GSource gsrc;
  63 + HANDLE hPipe;
  64 +
  65 + enum PIPE_STATE state;
  66 +
  67 + OVERLAPPED overlap;
  68 + unsigned char buffer[PIPE_BUFFER_LENGTH+1];
  69 + } pipe_source;
  70 +
  71 + #pragma pack()
  72 +
  73 +
  74 +/*--[ Globals ]--------------------------------------------------------------------------------------*/
  75 +
  76 +// static const gchar control_char = '@';
  77 +
  78 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  79 +
  80 + static void IO_accept(pipe_source *source)
  81 + {
  82 + set_active(FALSE);
  83 +
  84 + if(ConnectNamedPipe(source->hPipe,&source->overlap))
  85 + {
  86 + popup_lasterror("%s",_( "Error in ConnectNamedPipe" ));
  87 + return;
  88 + }
  89 +
  90 + switch(GetLastError())
  91 + {
  92 + // The overlapped connection in progress.
  93 + case ERROR_IO_PENDING:
  94 + // trace("%s: ERROR_IO_PENDING",__FUNCTION__);
  95 + source->state = PIPE_STATE_WAITING;
  96 + break;
  97 +
  98 + // Client is already connected, so signal an event.
  99 + case ERROR_PIPE_CONNECTED:
  100 + trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__);
  101 + set_active(TRUE);
  102 + if(SetEvent(source->overlap.hEvent))
  103 + break;
  104 +
  105 + // If an error occurs during the connect operation...
  106 + default:
  107 + popup_lasterror("%s", _( "ConnectNamedPipe failed" ));
  108 + }
  109 +
  110 + }
  111 +
  112 + static gboolean IO_prepare(GSource *source, gint *timeout)
  113 + {
  114 + /*
  115 + * Called before all the file descriptors are polled.
  116 + * If the source can determine that it is ready here
  117 + * (without waiting for the results of the poll() call)
  118 + * it should return TRUE.
  119 + *
  120 + * It can also return a timeout_ value which should be the maximum
  121 + * timeout (in milliseconds) which should be passed to the poll() call.
  122 + * The actual timeout used will be -1 if all sources returned -1,
  123 + * or it will be the minimum of all the timeout_ values
  124 + * returned which were >= 0.
  125 + *
  126 + */
  127 + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0)
  128 + return TRUE;
  129 +
  130 + *timeout = 10;
  131 + return FALSE;
  132 + }
  133 +
  134 + static gboolean IO_check(GSource *source)
  135 + {
  136 + /*
  137 + * Called after all the file descriptors are polled.
  138 + * The source should return TRUE if it is ready to be dispatched.
  139 + * Note that some time may have passed since the previous prepare
  140 + * function was called, so the source should be checked again here.
  141 + *
  142 + */
  143 + if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0)
  144 + return TRUE;
  145 +
  146 + return FALSE;
  147 + }
  148 +
  149 + static void send_text(pipe_source *source, char *text)
  150 + {
  151 + struct hllapi_packet_text *pkt;
  152 + DWORD szBlock;
  153 + int f;
  154 +
  155 + if(text)
  156 + {
  157 + szBlock = sizeof(struct hllapi_packet_text)+strlen(text);
  158 + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock);
  159 + pkt->packet_id = 0;
  160 + strcpy(pkt->text,text);
  161 + lib3270_free(text);
  162 + }
  163 + else
  164 + {
  165 + szBlock = sizeof(struct hllapi_packet_text);
  166 + pkt = (struct hllapi_packet_text *) g_malloc0(szBlock);
  167 + pkt->packet_id = errno ? errno : -1;
  168 + }
  169 +
  170 + trace("szBlock=%d text=\"%s\"",szBlock, ( (struct hllapi_packet_text *) pkt)->text);
  171 + for(f=0;f< (int) szBlock;f++)
  172 + {
  173 + trace("rsp(%d)= %d \"%s\"",f,* (((char *) pkt)+f),((char *) pkt)+f);
  174 + }
  175 +
  176 + WriteFile(source->hPipe,pkt,szBlock,&szBlock,NULL);
  177 +
  178 + g_free(pkt);
  179 + }
  180 +
  181 + static void send_result(pipe_source *source, int rc)
  182 + {
  183 + struct hllapi_packet_result pkt = { rc };
  184 + DWORD wrote = sizeof(pkt);
  185 + WriteFile(source->hPipe,&pkt,wrote,&wrote,NULL);
  186 + }
  187 +
  188 + static int do_file_transfer(struct hllapi_packet_file_transfer * source)
  189 + {
  190 + /*
  191 + const gchar * local = (const char *) source->text;
  192 + const gchar * remote = (const char *) (local+strlen(local)+1);
  193 +
  194 + return v3270_transfer_file( v3270_get_default_widget(),
  195 + (LIB3270_FT_OPTION) source->options,
  196 + local,
  197 + remote,
  198 + source->lrecl,
  199 + source->blksize,
  200 + source->primspace,
  201 + source->secspace,
  202 + source->dft );
  203 + */
  204 + return EINVAL;
  205 + }
  206 +
  207 + static void get_host(pipe_source *source) {
  208 + send_text(source,strdup(lib3270_get_url(lib3270_get_default_session_handle())));
  209 + }
  210 +
  211 + static void process_input(pipe_source *source, DWORD cbRead)
  212 + {
  213 + const struct hllapi_packet_query * query = ((struct hllapi_packet_query *) source->buffer);
  214 +
  215 + trace("%s id=%d",__FUNCTION__,query->packet_id);
  216 +
  217 + switch(query->packet_id)
  218 + {
  219 + case HLLAPI_PACKET_CONNECT:
  220 + send_result(source,lib3270_reconnect( lib3270_get_default_session_handle(),
  221 + ((struct hllapi_packet_connect *) source->buffer)->wait));
  222 + break;
  223 +
  224 + case HLLAPI_PACKET_CONNECT_URL:
  225 + send_result(source,lib3270_connect_url(lib3270_get_default_session_handle(),(const char *) (query+1),0));
  226 + break;
  227 +
  228 + case HLLAPI_PACKET_SET_HOST:
  229 + send_result(source,lib3270_set_url(lib3270_get_default_session_handle(),
  230 + ((struct hllapi_packet_text *) source->buffer)->text));
  231 + break;
  232 +
  233 + case HLLAPI_PACKET_GET_HOST:
  234 + get_host(source);
  235 + break;
  236 +
  237 + case HLLAPI_PACKET_DISCONNECT:
  238 + send_result(source,lib3270_disconnect(lib3270_get_default_session_handle()));
  239 + break;
  240 +
  241 + case HLLAPI_PACKET_IS_CONNECTED:
  242 + send_result(source,lib3270_in_tn3270e(lib3270_get_default_session_handle()));
  243 + break;
  244 +
  245 + case HLLAPI_PACKET_IS_READY:
  246 + send_result(source,lib3270_is_ready(lib3270_get_default_session_handle()));
  247 + break;
  248 +
  249 + case HLLAPI_PACKET_ENTER:
  250 + send_result(source,lib3270_enter(lib3270_get_default_session_handle()));
  251 + break;
  252 +
  253 + case HLLAPI_PACKET_PRINT:
  254 + send_result(source,lib3270_print_all(lib3270_get_default_session_handle()));
  255 + break;
  256 +
  257 + case HLLAPI_PACKET_ERASE:
  258 + send_result(source,lib3270_erase(lib3270_get_default_session_handle()));
  259 + break;
  260 +
  261 + case HLLAPI_PACKET_ERASE_EOF:
  262 + send_result(source,lib3270_eraseeof(lib3270_get_default_session_handle()));
  263 + break;
  264 +
  265 + case HLLAPI_PACKET_ERASE_EOL:
  266 + send_result(source,lib3270_eraseeol(lib3270_get_default_session_handle()));
  267 + break;
  268 +
  269 + case HLLAPI_PACKET_ERASE_INPUT:
  270 + send_result(source,lib3270_eraseinput(lib3270_get_default_session_handle()));
  271 + break;
  272 +
  273 + case HLLAPI_PACKET_PFKEY:
  274 + send_result(source,lib3270_pfkey( lib3270_get_default_session_handle(),
  275 + ((struct hllapi_packet_keycode *) source->buffer)->keycode));
  276 + break;
  277 +
  278 + case HLLAPI_PACKET_PAKEY:
  279 + send_result(source,lib3270_pakey( lib3270_get_default_session_handle(),
  280 + ((struct hllapi_packet_keycode *) source->buffer)->keycode));
  281 + break;
  282 +
  283 + case HLLAPI_PACKET_SET_CURSOR_POSITION:
  284 + send_result(source,lib3270_set_cursor_position( lib3270_get_default_session_handle(),
  285 + ((struct hllapi_packet_cursor *) source->buffer)->row,
  286 + ((struct hllapi_packet_cursor *) source->buffer)->col));
  287 + break;
  288 +
  289 + case HLLAPI_PACKET_SET_TEXT_AT:
  290 + send_result(source,lib3270_set_text_at( lib3270_get_default_session_handle(),
  291 + ((struct hllapi_packet_text_at *) source->buffer)->row,
  292 + ((struct hllapi_packet_text_at *) source->buffer)->col,
  293 + (unsigned char *) ((struct hllapi_packet_text_at *) source->buffer)->text));
  294 + break;
  295 +
  296 + case HLLAPI_PACKET_GET_TEXT_AT:
  297 + send_text(source,lib3270_get_string_at( lib3270_get_default_session_handle(),
  298 + ((struct hllapi_packet_at *) source->buffer)->row,
  299 + ((struct hllapi_packet_at *) source->buffer)->col,
  300 + ((struct hllapi_packet_at *) source->buffer)->len,
  301 + ((struct hllapi_packet_at *) source->buffer)->lf));
  302 + break;
  303 +
  304 + case HLLAPI_PACKET_GET_TEXT_AT_OFFSET:
  305 + send_text(source,lib3270_get_string_at_address( lib3270_get_default_session_handle(),
  306 + ((struct hllapi_packet_query_offset *) source->buffer)->addr,
  307 + ((struct hllapi_packet_query_offset *) source->buffer)->len,
  308 + ((struct hllapi_packet_query_offset *) source->buffer)->lf));
  309 + break;
  310 +
  311 + case HLLAPI_PACKET_CMP_TEXT_AT:
  312 + send_result(source,lib3270_cmp_text_at( lib3270_get_default_session_handle(),
  313 + ((struct hllapi_packet_text_at *) source->buffer)->row,
  314 + ((struct hllapi_packet_text_at *) source->buffer)->col,
  315 + ((struct hllapi_packet_text_at *) source->buffer)->text,
  316 + ((struct hllapi_packet_text_at *) source->buffer)->lf));
  317 + break;
  318 +
  319 + case HLLAPI_PACKET_INPUT_STRING:
  320 + send_result(source,lib3270_input_string(lib3270_get_default_session_handle(),
  321 + (unsigned char *) ((struct hllapi_packet_text *) source->buffer)->text));
  322 + break;
  323 +
  324 + case HLLAPI_PACKET_EMULATE_INPUT:
  325 + send_result(source,lib3270_emulate_input(lib3270_get_default_session_handle(),
  326 + (const char *) ((struct hllapi_packet_emulate_input *) source->buffer)->text,
  327 + (int) ((struct hllapi_packet_emulate_input *) source->buffer)->len,
  328 + (int) ((struct hllapi_packet_emulate_input *) source->buffer)->pasting));
  329 + break;
  330 +
  331 + case HLLAPI_PACKET_SET_CURSOR:
  332 + send_result(source,lib3270_set_cursor_address(lib3270_get_default_session_handle(),
  333 + ((struct hllapi_packet_addr *) source->buffer)->addr));
  334 + break;
  335 +
  336 + case HLLAPI_PACKET_GET_CURSOR:
  337 + send_result(source,lib3270_get_cursor_address(lib3270_get_default_session_handle()));
  338 + break;
  339 +
  340 + case HLLAPI_PACKET_GET_WIDTH:
  341 + send_result(source,lib3270_get_width(lib3270_get_default_session_handle()));
  342 + break;
  343 +
  344 + case HLLAPI_PACKET_GET_HEIGHT:
  345 + send_result(source,lib3270_get_height(lib3270_get_default_session_handle()));
  346 + break;
  347 +
  348 + case HLLAPI_PACKET_GET_LENGTH:
  349 + send_result(source,lib3270_get_length(lib3270_get_default_session_handle()));
  350 + break;
  351 +
  352 + case HLLAPI_PACKET_GET_PROGRAM_MESSAGE:
  353 + send_result(source,lib3270_get_program_message(lib3270_get_default_session_handle()));
  354 + break;
  355 +
  356 + case HLLAPI_PACKET_GET_SSL_STATE:
  357 + send_result(source,lib3270_get_secure(lib3270_get_default_session_handle()));
  358 + break;
  359 +
  360 + case HLLAPI_PACKET_SET_UNLOCK_DELAY:
  361 + lib3270_set_unlock_delay(lib3270_get_default_session_handle(),(unsigned short) ((struct hllapi_packet_set_int *) source->buffer)->value);
  362 + send_result(source,0);
  363 + break;
  364 +
  365 + case HLLAPI_PACKET_SET_TOGGLE:
  366 + send_result(source,lib3270_set_toggle(lib3270_get_default_session_handle(),
  367 + (LIB3270_TOGGLE) ((struct hllapi_packet_set *) source->buffer)->id,
  368 + ((struct hllapi_packet_set *) source->buffer)->value));
  369 + break;
  370 +
  371 + case HLLAPI_PACKET_FIELD_START:
  372 + send_result(source,lib3270_get_field_start(lib3270_get_default_session_handle(),
  373 + ((struct hllapi_packet_addr *) source->buffer)->addr));
  374 + break;
  375 +
  376 +
  377 + case HLLAPI_PACKET_FIELD_LEN:
  378 + send_result(source,lib3270_get_field_len(lib3270_get_default_session_handle(),
  379 + ((struct hllapi_packet_addr *) source->buffer)->addr));
  380 + break;
  381 +
  382 + case HLLAPI_PACKET_NEXT_UNPROTECTED:
  383 + send_result(source,lib3270_get_next_unprotected(lib3270_get_default_session_handle(),
  384 + ((struct hllapi_packet_addr *) source->buffer)->addr));
  385 + break;
  386 +
  387 + case HLLAPI_PACKET_IS_PROTECTED:
  388 + send_result(source,lib3270_get_is_protected(lib3270_get_default_session_handle(),
  389 + ((struct hllapi_packet_addr *) source->buffer)->addr));
  390 + break;
  391 +
  392 + case HLLAPI_PACKET_IS_PROTECTED_AT:
  393 + send_result(source,lib3270_get_is_protected_at( lib3270_get_default_session_handle(),
  394 + ((struct hllapi_packet_query_at *) source->buffer)->row,
  395 + ((struct hllapi_packet_query_at *) source->buffer)->col));
  396 + break;
  397 +
  398 + case HLLAPI_PACKET_QUIT:
  399 + gtk_main_quit();
  400 + send_result(source,0);
  401 + break;
  402 +
  403 + case HLLAPI_PACKET_SET_HOST_CHARSET:
  404 + send_result(source,lib3270_set_host_charset( lib3270_get_default_session_handle(),
  405 + (const char *) ((struct hllapi_packet_set_text *) source->buffer)->text));
  406 + break;
  407 +
  408 + case HLLAPI_PACKET_ASC2EBC:
  409 + send_text(source,(char *) lib3270_asc2ebc(
  410 + lib3270_get_default_session_handle(),
  411 + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1
  412 + ));
  413 + break;
  414 +
  415 + case HLLAPI_PACKET_EBC2ASC:
  416 + send_text(source,(char *) lib3270_ebc2asc(
  417 + lib3270_get_default_session_handle(),
  418 + (unsigned char *) ((struct hllapi_packet_set_text *) source->buffer)->text,-1
  419 + ));
  420 + break;
  421 +
  422 + case HLLAPI_PACKET_FILE_TRANSFER:
  423 + send_result(source,do_file_transfer((struct hllapi_packet_file_transfer *) source));
  424 + break;
  425 +
  426 + case HLLAPI_PACKET_GET_HOST_CHARSET:
  427 + trace("%s","HLLAPI_PACKET_GET_HOST_CHARSET");
  428 + send_text(source,(char *) lib3270_get_host_charset(lib3270_get_default_session_handle()));
  429 + break;
  430 +
  431 + case HLLAPI_PACKET_ACTION:
  432 + send_result(source,lib3270_action(lib3270_get_default_session_handle(),
  433 + (const char *) ((struct hllapi_packet_text *) source->buffer)->text));
  434 + break;
  435 +
  436 +
  437 + default:
  438 + send_result(source, EINVAL);
  439 + g_message("Invalid remote request (id=%d)",source->buffer[0]);
  440 + }
  441 +
  442 + }
  443 +
  444 + static void read_input_pipe(pipe_source *source)
  445 + {
  446 + DWORD cbRead = 0;
  447 +
  448 + if(ReadFile(source->hPipe,source->buffer,PIPE_BUFFER_LENGTH,&cbRead,&source->overlap) && cbRead > 0)
  449 + process_input(source,cbRead);
  450 +
  451 + // The read operation is still pending.
  452 + switch(GetLastError())
  453 + {
  454 + case 0:
  455 + break;
  456 +
  457 + case ERROR_IO_PENDING:
  458 + // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__);
  459 + source->state = PIPE_STATE_PENDING_READ;
  460 + break;
  461 +
  462 + case ERROR_PIPE_LISTENING:
  463 + // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__);
  464 + source->state = PIPE_STATE_READ;
  465 + break;
  466 +
  467 + case ERROR_BROKEN_PIPE:
  468 + trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__);
  469 +
  470 + if(!DisconnectNamedPipe(source->hPipe))
  471 + {
  472 + set_active(FALSE);
  473 + popup_lasterror("%s",_( "Error in DisconnectNamedPipe" ));
  474 + }
  475 + else
  476 + {
  477 + IO_accept(source);
  478 + }
  479 + break;
  480 +
  481 + case ERROR_PIPE_NOT_CONNECTED:
  482 + trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__);
  483 + set_active(FALSE);
  484 + break;
  485 +
  486 + default:
  487 + if(source->hPipe != INVALID_HANDLE_VALUE)
  488 + popup_lasterror("%s",_( "Error receiving message from pipe" ) );
  489 + }
  490 +
  491 + }
  492 +
  493 + static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer data)
  494 + {
  495 + /*
  496 + * Called to dispatch the event source,
  497 + * after it has returned TRUE in either its prepare or its check function.
  498 + * The dispatch function is passed in a callback function and data.
  499 + * The callback function may be NULL if the source was never connected
  500 + * to a callback using g_source_set_callback(). The dispatch function
  501 + * should call the callback function with user_data and whatever additional
  502 + * parameters are needed for this type of event source.
  503 + */
  504 + BOOL fSuccess;
  505 + DWORD cbRead = 0;
  506 +// DWORD dwErr = 0;
  507 +
  508 + fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE );
  509 +
  510 + // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead);
  511 +
  512 + switch(((pipe_source *) source)->state)
  513 + {
  514 + case PIPE_STATE_WAITING:
  515 + if(fSuccess)
  516 + {
  517 + trace("Pipe connected (cbRet=%d)",(int) cbRead);
  518 + set_active(TRUE);
  519 + ((pipe_source *) source)->state = PIPE_STATE_READ;
  520 + }
  521 + else
  522 + {
  523 + popup_lasterror("%s", _( "Pipe connection failed" ));
  524 + }
  525 + break;
  526 +
  527 + case PIPE_STATE_READ:
  528 + // trace("Reading pipe (cbRead=%d)",(int) cbRead);
  529 + read_input_pipe( (pipe_source *) source);
  530 + break;
  531 +
  532 + case PIPE_STATE_PENDING_READ:
  533 + if(fSuccess && cbRead > 0)
  534 + process_input((pipe_source *) source,cbRead);
  535 + ((pipe_source *) source)->state = PIPE_STATE_READ;
  536 + break;
  537 +
  538 + case PIPE_STATE_UNDEFINED:
  539 + break;
  540 +
  541 +//#ifdef DEBUG
  542 +// default:
  543 +// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state);
  544 +//#endif
  545 + }
  546 +
  547 + return TRUE;
  548 + }
  549 +
  550 + static void IO_finalize(GSource *source)
  551 + {
  552 +// trace("%s: source=%p",__FUNCTION__,source);
  553 +
  554 + if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE)
  555 + {
  556 + CloseHandle(((pipe_source *) source)->hPipe);
  557 + ((pipe_source *) source)->hPipe = INVALID_HANDLE_VALUE;
  558 + }
  559 +
  560 + }
  561 +
  562 + static gboolean IO_closure(gpointer data)
  563 + {
  564 +// trace("%s: data=%p",__FUNCTION__,data);
  565 + return 0;
  566 + }
  567 +
  568 + void popup_lasterror(const gchar *fmt, ...)
  569 + {
  570 + char buffer[4096];
  571 + va_list arg_ptr;
  572 + int sz;
  573 + DWORD errcode = GetLastError();
  574 + char *ptr;
  575 + LPVOID lpMsgBuf = 0;
  576 +
  577 + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
  578 +
  579 + for(ptr= (char *) lpMsgBuf;*ptr && *ptr != '\n';ptr++);
  580 + *ptr = 0;
  581 +
  582 + va_start(arg_ptr, fmt);
  583 + vsnprintf(buffer,4095,fmt,arg_ptr);
  584 + va_end(arg_ptr);
  585 +
  586 + sz = strlen(buffer);
  587 + snprintf(buffer+sz,4096-sz,": %s\n(rc=%d)",lpMsgBuf,(int) errcode);
  588 +
  589 + printf("%s\n",buffer);
  590 +
  591 +#ifdef DEBUG
  592 + fprintf(stderr,"%s\n",buffer);
  593 + fflush(stderr);
  594 +#endif
  595 +
  596 + LocalFree(lpMsgBuf);
  597 + }
  598 +
  599 + LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal)
  600 + {
  601 + char id;
  602 +
  603 + for(id='A';id < 'Z';id++)
  604 + {
  605 + gchar * pipename = g_strdup_printf("\\\\.\\pipe\\%s_%c",pw3270_get_session_name(window),id);
  606 + gchar * ptr;
  607 + HANDLE hPipe;
  608 +
  609 + for(ptr=pipename;*ptr;ptr++)
  610 + *ptr = g_ascii_tolower(*ptr);
  611 +
  612 + hPipe = CreateNamedPipe( TEXT(pipename), // pipe name
  613 + PIPE_ACCESS_DUPLEX | // read/write access
  614 + FILE_FLAG_OVERLAPPED, // overlapped mode
  615 + PIPE_TYPE_MESSAGE | // pipe type
  616 + PIPE_READMODE_MESSAGE | // pipe mode
  617 + PIPE_WAIT, // blocking mode
  618 + 1, // number of instances
  619 + PIPE_BUFFER_LENGTH, // output buffer size
  620 + PIPE_BUFFER_LENGTH, // input buffer size
  621 + NMPWAIT_USE_DEFAULT_WAIT, // client time-out
  622 + NULL); // default security attributes
  623 +
  624 + trace("%s = %p",pipename,hPipe);
  625 + g_free(pipename);
  626 +
  627 + if(hPipe != INVALID_HANDLE_VALUE)
  628 + {
  629 + static GSourceFuncs pipe_source_funcs =
  630 + {
  631 + IO_prepare,
  632 + IO_check,
  633 + IO_dispatch,
  634 + IO_finalize,
  635 + IO_closure,
  636 + NULL
  637 + };
  638 + pipe_source * source;
  639 + gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),id);
  640 +
  641 + pw3270_set_session_name(window,session);
  642 + g_free(session);
  643 +
  644 + source = (pipe_source *) g_source_new(&pipe_source_funcs,sizeof(pipe_source));
  645 +
  646 + source->hPipe = hPipe;
  647 + source->state = PIPE_STATE_WAITING;
  648 + source->overlap.hEvent = CreateEvent( NULL,TRUE,TRUE,NULL);
  649 +
  650 + g_source_attach((GSource *) source,NULL);
  651 + IO_accept(source);
  652 +
  653 + return 0;
  654 + }
  655 +
  656 + }
  657 +
  658 + popup_lasterror( "%s", _( "Can´t create remote control pipe" ));
  659 +
  660 + return -1;
  661 + }
  662 +
  663 + LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window, GtkWidget *terminal)
  664 + {
  665 +
  666 + return 0;
  667 + }
  668 +
  669 + G_GNUC_INTERNAL void set_active(gboolean on)
  670 + {
  671 + trace("%s(%s)",__FUNCTION__,on ? "Active" : "Inactive");
  672 + // v3270_set_script(v3270_get_default_widget(),'H');
  673 + }
... ...
src/hllapi/pw3270.idl 0 → 100644
  1 +++ a/src/hllapi/pw3270.idl
... ... @@ -0,0 +1,53 @@
  1 +// This is the type library for libhllapi.dll
  2 +
  3 +//
  4 +// References:
  5 +//
  6 +// http://support.microsoft.com/kb/189133
  7 +// http://msdn.microsoft.com/en-us/library/windows/desktop/aa367300(v=vs.85).aspx
  8 +//
  9 +[
  10 + // Use GUIDGEN.EXE to create the UUID that uniquely identifies
  11 + // this library on the user's system. NOTE: This must be done!!
  12 + uuid(4CC73F7D-5C10-4313-8FFD-F01999A44656),
  13 +
  14 + // This helpstring defines how the library will appear in the
  15 + // References dialog of VB.
  16 + helpstring("PW3270 HLLAPI typelib"),
  17 +
  18 + // Assume standard English locale.
  19 + lcid(0x0409),
  20 +
  21 + // Assign a version number to keep track of changes.
  22 + version(5.0)
  23 +]
  24 +
  25 +library HLLAPI
  26 +{
  27 +
  28 + // Now define the module that will "declare" your C functions.
  29 + [
  30 + helpstring("HLLAPI calls for pw3270"),
  31 +
  32 + version(5.0),
  33 +
  34 + // Give the name of your DLL here.
  35 + dllname("libhllapi.dll")
  36 + ]
  37 +
  38 + module hllApiFunctions
  39 + {
  40 + [
  41 + helpstring("Initialize pw3270´s instance."),
  42 + entry("hllapi_init")
  43 + ]
  44 + // The [in], [out], and [in, out] keywords tell the Automation
  45 + // client which direction parameters need to be passed. Some
  46 + // calls can be optimized if a function only needs a parameter
  47 + // to be passed one-way.
  48 + DWORD __stdcall hllapi_init( [in] LPSTR mode);
  49 +
  50 +
  51 + } // End of Module
  52 +
  53 +}; // End of Library
... ...
src/hllapi/remotectl.h 0 → 100644
  1 +++ a/src/hllapi/remotectl.h
... ... @@ -0,0 +1,84 @@
  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. 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 remotectl.h 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 + * Agradecimento:
  29 + *
  30 + * Hélio Passos
  31 + *
  32 + */
  33 +
  34 + #define ENABLE_NLS
  35 + #define GETTEXT_PACKAGE PACKAGE_NAME
  36 +
  37 + #include <libintl.h>
  38 + #include <glib/gi18n.h>
  39 + #include <gtk/gtk.h>
  40 +
  41 + #include <lib3270.h>
  42 + #include <lib3270/log.h>
  43 + #include <pw3270/hllapi.h>
  44 +
  45 + typedef struct _remotequery
  46 + {
  47 +#ifdef _WIN32
  48 + HANDLE hPipe; /**< Pipe handle (for response) */
  49 +#endif // _WIN32
  50 +
  51 + H3270 * hSession; /**< 3270 Session */
  52 + int cmd; /**< Command */
  53 + int rc; /**< Response status */
  54 +
  55 + int pos;
  56 + unsigned short length; /**< Query string length */
  57 + const gchar * text; /**< Query string */
  58 +
  59 + } QUERY;
  60 +
  61 + G_GNUC_INTERNAL void enqueue_request(QUERY *qry);
  62 + G_GNUC_INTERNAL void request_complete(QUERY *qry, int rc, const gchar *text);
  63 +
  64 + G_GNUC_INTERNAL void request_status(QUERY *qry, int rc);
  65 + G_GNUC_INTERNAL void request_value(QUERY *qry, int rc, unsigned int value);
  66 + G_GNUC_INTERNAL void request_buffer(QUERY *qry, int rc, size_t sz, const gpointer buffer);
  67 +
  68 +// int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc);
  69 +
  70 +
  71 +#ifdef _WIN32
  72 +
  73 + #define PIPE_BUFFER_LENGTH 8192
  74 +
  75 + void init_source_pipe(HANDLE hPipe);
  76 + void popup_lasterror(const gchar *fmt, ...);
  77 +
  78 +#endif // _WIN32
  79 +
  80 +
  81 +
  82 +
  83 +
  84 +
... ...
src/hllapi/server.h 0 → 100644
  1 +++ a/src/hllapi/server.h
... ... @@ -0,0 +1,53 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como server.h 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 <config.h>
  31 + #define ENABLE_NLS
  32 + #define GETTEXT_PACKAGE PACKAGE_NAME
  33 +
  34 + #include <libintl.h>
  35 + #include <glib/gi18n.h>
  36 + #include <gtk/gtk.h>
  37 +
  38 + #include <lib3270.h>
  39 + #include <lib3270/log.h>
  40 + #include <pw3270.h>
  41 + #include <pw3270/hllapi.h>
  42 +
  43 +#ifdef _WIN32
  44 + #include <windows.h>
  45 +
  46 + #define PIPE_BUFFER_LENGTH HLLAPI_MAXLENGTH+30
  47 +
  48 + G_GNUC_INTERNAL void popup_lasterror(const gchar *fmt, ...);
  49 + G_GNUC_INTERNAL void set_active(gboolean on);
  50 +
  51 +#endif // _WIN32
  52 +
  53 +
... ...
src/hllapi/testprogram.c 0 → 100644
  1 +++ a/src/hllapi/testprogram.c
... ... @@ -0,0 +1,169 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como testprogram.c 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 <stdio.h>
  31 + #include <string.h>
  32 + #include <time.h>
  33 + #include <pw3270/hllapi.h>
  34 +
  35 + #if defined(DEBUG) && defined(_WIN32)
  36 + #undef trace
  37 + #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } }
  38 + #endif // DEBUG
  39 +
  40 + #define MAX_DATA_SIZE 8000 //< Maximum data size for this application.
  41 +
  42 + static CHAR hllapi_data[MAX_DATA_SIZE];
  43 +
  44 +/*---[ Implement ]--------------------------------------------------------------------------------*/
  45 +
  46 + static void connect_ps(const char *session)
  47 + {
  48 + WORD len;
  49 + WORD fn = HLLAPI_CMD_CONNECTPS;
  50 + WORD rc = 0;
  51 +
  52 + strncpy(hllapi_data,session,MAX_DATA_SIZE);
  53 +
  54 + len = strlen(session);
  55 + hllapi(&fn,hllapi_data,&len,&rc);
  56 +
  57 + /*
  58 + if(rc)
  59 + {
  60 + trace("HLLAPI_CMD_CONNECTPS(%s) exits with rc=%d", session, (int) rc);
  61 + }
  62 + */
  63 +
  64 + }
  65 +
  66 + int main(int numpar, char *param[])
  67 + {
  68 + const char *session = "pw3270:A";
  69 +
  70 + connect_ps(session);
  71 +
  72 + /*
  73 +
  74 + printf("init(%s)=%d\n",session,(int) hllapi_init((LPSTR) session));
  75 + printf("revision=%d\n",(int) hllapi_get_revision());
  76 + printf("connect=%d\n",(int) hllapi_connect((char *) "fandezhi.efglobe.com:23",1));
  77 + printf("wait_for_ready=%d\n",(int) hllapi_wait_for_ready(10));
  78 + printf("connected=%s\n",(int) hllapi_is_connected() ? "Yes" : "No");
  79 +
  80 +// printf("disconnect=%d\n",(int) hllapi_disconnect());
  81 +
  82 +
  83 + printf("deinit=%d\n",(int) hllapi_deinit());
  84 +
  85 + DWORD revision;
  86 + int rc;
  87 +
  88 + rc = hllapi_init("");
  89 + if(rc)
  90 + {
  91 + printf("Init exits with rc=%d\n",rc);
  92 + return rc;
  93 + }
  94 +
  95 + if(!hllapi_get_revision(&revision))
  96 + printf("Library revision is %d\n",(int) revision);
  97 +
  98 +
  99 + printf("Deinit exits with rc=%d\n",rc);
  100 + rc = hllapi_deinit();
  101 +*/
  102 + return 0;
  103 + }
  104 +
  105 +/*
  106 + int main(int numpar, char *param[])
  107 + {
  108 + char buffer[BUFFER_LENGTH];
  109 + unsigned short rc;
  110 + unsigned short len;
  111 + unsigned long fn;
  112 +
  113 + static const struct _cmd
  114 + {
  115 + const char * name;
  116 + unsigned short fn;
  117 + const char * arg;
  118 + } cmd[] =
  119 + {
  120 + { "GetRevision", HLLAPI_CMD_GETREVISION, " " },
  121 + { "ConnectPS", HLLAPI_CMD_CONNECTPS, "pw3270A" },
  122 + { "InputString", HLLAPI_CMD_INPUTSTRING, "test" },
  123 +
  124 + };
  125 +
  126 + int f;
  127 +
  128 +
  129 + for(f=0;f< (sizeof(cmd)/sizeof(struct _cmd)); f++)
  130 + {
  131 + len = strlen(cmd[f].arg);
  132 + memcpy(buffer,cmd[f].arg,len);
  133 + hllapi((LPWORD) &cmd[f].fn,buffer,&len,&rc);
  134 + printf("%s exits with rc=%d\n[%s]\n",cmd[f].name,rc,buffer);
  135 + }
  136 +
  137 + len = 80;
  138 + rc = 1040;
  139 + fn = HLLAPI_CMD_COPYPSTOSTR;
  140 + hllapi((LPWORD) &fn,buffer,&len,&rc);
  141 + printf("%s exits with rc=%d\n%s\n","HLLAPI_CMD_COPYPSTOSTR",rc,buffer);
  142 +
  143 + // Performance
  144 + len = strlen(cmd[0].arg);
  145 + memcpy(buffer,cmd[0].arg,len);
  146 + if(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0)
  147 + {
  148 + time_t end = time(0) + 5;
  149 + int qtd = 0;
  150 + do
  151 + {
  152 + qtd++;
  153 + } while(hllapi((LPWORD) &cmd[0].fn,buffer,&len,&rc) == 0 && rc == 0 && time(0)<end);
  154 + printf("%d interacoes em 5 segundos (rc=%d)\n",qtd,rc);
  155 +
  156 + }
  157 +
  158 + // Disconnect
  159 + len = 10;
  160 + rc = 1;
  161 + fn = HLLAPI_CMD_DISCONNECTPS;
  162 + *buffer = 0;
  163 + hllapi((LPWORD) &fn,buffer,&len,&rc);
  164 + printf("%s exits with rc=%d\n[%s]\n","HLLAPI_CMD_DISCONNECTPS",rc,buffer);
  165 +
  166 +
  167 + return 0;
  168 + }
  169 +*/
... ...