From 488118752d64776145d1dc0150147a4a8b34edce Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 20 Feb 2019 15:29:06 -0300 Subject: [PATCH] Reorganizing linux sources. --- .gitignore | 10 ++++++++++ Makefile.in | 315 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ autogen.sh | 29 +++++++++++++++++++++++++++++ configure.ac | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/dbus3270/daemon.c | 122 -------------------------------------------------------------------------------------------------------------------------- src/dbus3270/daemon.h | 46 ---------------------------------------------- src/dbus3270/globals.h | 59 ----------------------------------------------------------- src/dbus3270/gobject.c | 622 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/dbus3270/iocallback.c | 361 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/dbus3270/main.c | 172 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/dbus3270/misc.c | 47 ----------------------------------------------- src/dbus3270/service.h | 138 ------------------------------------------------------------------------------------------------------------------------------------------ src/include/config.h.in | 41 +++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/daemon.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/daemon.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/globals.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/gobject.c | 622 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/iocallback.c | 361 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/main.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/misc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/linux/service.h | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin/windows/resources.rc.in | 29 +++++++++++++++++++++++++++++ 22 files changed, 2241 insertions(+), 1567 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile.in create mode 100755 autogen.sh create mode 100644 configure.ac delete mode 100644 src/dbus3270/daemon.c delete mode 100644 src/dbus3270/daemon.h delete mode 100644 src/dbus3270/globals.h delete mode 100644 src/dbus3270/gobject.c delete mode 100644 src/dbus3270/iocallback.c delete mode 100644 src/dbus3270/main.c delete mode 100644 src/dbus3270/misc.c delete mode 100644 src/dbus3270/service.h create mode 100644 src/include/config.h.in create mode 100644 src/plugin/linux/daemon.c create mode 100644 src/plugin/linux/daemon.h create mode 100644 src/plugin/linux/globals.h create mode 100644 src/plugin/linux/gobject.c create mode 100644 src/plugin/linux/iocallback.c create mode 100644 src/plugin/linux/main.c create mode 100644 src/plugin/linux/misc.c create mode 100644 src/plugin/linux/service.h create mode 100644 src/plugin/windows/resources.rc.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..946f055 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +aclocal.m4 +autom4te.cache +*.log +*.status +configure +Makefile +scripts +config.h +stamp-h1 + diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..eb0fe93 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,315 @@ +# +# "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 +# (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a +# aplicativos mainframe. Registro no INPI sob o nome G3270. +# +# Copyright (C) <2008> +# +# Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob +# os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela +# Free Software Foundation. +# +# Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER +# GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO +# A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para +# obter mais detalhes. +# +# Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este +# programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple +# Place, Suite 330, Boston, MA, 02111-1307, USA +# +# Contatos: +# +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) +# erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) +# + +#---[ Library configuration ]------------------------------------------------------------ + +MODULE_NAME=ipc3270c +PACKAGE_NAME=@PACKAGE_NAME@ + +PLUGIN_SOURCES= \ + $(wildcard src/plugin/*.c) \ + $(wildcard src/plugin/@OSNAME@/*.rc) + +TEST_SOURCES= \ + $(wildcard src/testprogram/*.c) + +#---[ Tools ]---------------------------------------------------------------------------- + +CC=@CC@ +LD=@CC@ +LN_S=@LN_S@ +MKDIR=@MKDIR_P@ +INSTALL=@INSTALL@ +INSTALL_DATA=@INSTALL_DATA@ +INSTALL_PROGRAM=@INSTALL_PROGRAM@ +XGETTEXT=@XGETTEXT@ +MSGCAT=@MSGCAT@ +WINDRES=@WINDRES@ +AR=@AR@ + +#---[ Paths ]---------------------------------------------------------------------------- + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +sbindir=@sbindir@ +libdir=@libdir@ +includedir=@includedir@ +datarootdir=@datarootdir@ +localedir=@localedir@ +docdir=@docdir@ +sysconfdir=@sysconfdir@ + +BASEDIR=@BASEDIR@ + +POTDIR=$(BASEDIR)/.pot + +OBJDIR=$(BASEDIR)/.obj/$(MODULE_NAME) +OBJDBG=$(OBJDIR)/Debug +OBJRLS=$(OBJDIR)/Release + +BINDIR=$(BASEDIR)/.bin +BINDBG=$(BINDIR)/Debug +BINRLS=$(BINDIR)/Release + +#---[ Rules ]---------------------------------------------------------------------------- + +DEPENDS= \ + Makefile \ + src/include/*.h \ + src/include/lib3270/*.h + +CFLAGS= \ + @CFLAGS@ \ + -g \ + -Isrc/include \ + -DBUILD_DATE=`date +%Y%m%d` \ + @LIB3270_CFLAGS@ \ + @V3270_CFLAGS@ \ + @GTK_CFLAGS@ \ + @GLIB_CFLAGS@ + +GTK_LIBS=@GTK_LIBS@ +V3270_LIBS=@V3270_LIBS@ +GLIB_LIBS=@GLIB_LIBS@ + +LIBS= \ + @LIBS@ \ + @LIBICONV@ \ + @INTL_LIBS@ \ + @LIB3270_LIBS@ + +#---[ Debug Rules ]---------------------------------------------------------------------- + +$(OBJDBG)/%.o: \ + %.c \ + $(DEPENDS) + + @echo $< ... + @$(MKDIR) $(@D) + + @$(CC) \ + $(CFLAGS) \ + -Wall -Wextra -fstack-check \ + -DDEBUG=1 \ + -o $@ -c $< + +$(OBJDBG)/%.o: \ + %.rc + + @echo $< ... + @$(MKDIR) $(@D) + @$(WINDRES) $< -O coff -o $@ + +#---[ Release Rules ]-------------------------------------------------------------------- + +$(OBJRLS)/%.o: \ + %.c \ + $(DEPENDS) + + @echo $< ... + @$(MKDIR) $(@D) + @$(CC) \ + $(CFLAGS) \ + -DNDEBUG=1 \ + -o $@ -c $< + +$(OBJRLS)/%.o: \ + %.rc + + @echo $< ... + @$(MKDIR) $(@D) + @$(WINDRES) $< -O coff -o $@ + +#---[ Misc Rules ]----------------------------------------------------------------------- + +$(POTDIR)/$(MODULE_NAME)/%.pot: \ + %.c + + @echo $(notdir $@) ... + @$(MKDIR) $(@D) + @$(XGETTEXT) \ + --language=C \ + --keyword=_ \ + --keyword=N_ \ + --keyword=MSG_:2 \ + --output=$@ \ + $< + @touch $@ + +$(POTDIR)/$(MODULE_NAME)/%.pot: \ + %.rc + + @echo $< ... + @$(MKDIR) $(@D) + @touch $@ + + +#---[ Release Targets ]------------------------------------------------------------------ + +all: \ + $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \ + $(POTDIR)/$(MODULE_NAME).pot + +Release: \ + $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \ + $(BINRLS)/$(PACKAGE_NAME)d@EXEEXT@ + +$(BINRLS)/$(MODULE_NAME)@DLLEXT@: \ + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) \ + $(BINRLS)/lib$(MODULE_NAME).a + + @$(MKDIR) $(@D) + @echo $< ... + @$(LD) \ + -shared -Wl,-soname,$(@F) \ + -o $@ \ + $(LDFLAGS) \ + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJRLS)/$(SRC).o) \ + -L$(BINRLS) -l$(MODULE_NAME) \ + $(V3270_LIBS) \ + $(LIBS) \ + $(GTK_LIBS) + +$(BINRLS)/lib$(MODULE_NAME).a: \ + $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJRLS)/$(SRC).o) + + @$(MKDIR) $(@D) + @echo $< ... + + @$(AR) rcs $@ $^ + + +#---[ Install Targets ]------------------------------------------------------------------ + +install: \ + install-plugin + +install-plugin: \ + $(BINRLS)/$(MODULE_NAME)@DLLEXT@ + + @$(MKDIR) $(DESTDIR)$(libdir)/pw3270-plugins + + @$(INSTALL_PROGRAM) \ + $(BINRLS)/$(MODULE_NAME)@DLLEXT@ \ + $(DESTDIR)$(libdir)/pw3270-plugins + +#---[ Misc Targets ]--------------------------------------------------------------------- + +$(POTDIR)/$(MODULE_NAME).pot: \ + $(foreach SRC, $(basename $(SOURCES)), $(POTDIR)/$(MODULE_NAME)/$(SRC).pot) + + @rm -f $@ + @mkdir -p `dirname $@` + @$(MSGCAT) --sort-output $^ > $@ + +locale: \ + $(POTDIR)/$(MODULE_NAME).pot + + +#---[ Debug Targets ]-------------------------------------------------------------------- + +Debug: \ + $(BINDBG)/$(MODULE_NAME)@DLLEXT@ + +$(BINDBG)/lib$(MODULE_NAME).a: \ + $(foreach SRC, $(basename $(CORE_SOURCES)), $(OBJDBG)/$(SRC).o) + + @$(MKDIR) $(@D) + @echo $< ... + + @$(AR) rcs $@ $^ + + +$(BINDBG)/$(MODULE_NAME)@EXEEXT@: \ + $(foreach SRC, $(basename $(TEST_SOURCES)), $(OBJDBG)/$(SRC).o) + + @$(MKDIR) $(@D) + @echo $< ... + @$(LD) \ + -o $@ \ + $^ \ + -L$(BINDBG) \ + -Wl,-rpath,$(BINDBG) \ + $(LDFLAGS) \ + $(LIBS) \ + $(V3270_LIBS) \ + $(GTK_LIBS) \ + $(GLIB_LIBS) + +$(BINDBG)/$(PACKAGE_NAME)d@EXEEXT@: \ + $(foreach SRC, $(basename $(SERVICE_SOURCES)), $(OBJDBG)/$(SRC).o) \ + $(BINDBG)/lib$(MODULE_NAME).a + + @$(MKDIR) $(@D) + @echo $< ... + @$(LD) \ + -o $@ \ + $(foreach SRC, $(basename $(SERVICE_SOURCES)), $(OBJDBG)/$(SRC).o) \ + -L$(BINDBG) \ + -Wl,-rpath,$(BINDBG) \ + $(LDFLAGS) \ + $(LIBS) \ + -l$(MODULE_NAME) \ + $(GLIB_LIBS) + +$(BINDBG)/$(MODULE_NAME)@DLLEXT@: \ + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ + $(BINDBG)/lib$(MODULE_NAME).a + + @$(MKDIR) $(@D) + @echo $< ... + @$(LD) \ + -shared -Wl,-soname,$(@F) \ + -o $@ \ + $(LDFLAGS) \ + $(foreach SRC, $(basename $(PLUGIN_SOURCES)), $(OBJDBG)/$(SRC).o) \ + -L$(BINDBG) -l$(MODULE_NAME) \ + $(V3270_LIBS) \ + $(LIBS) \ + $(GTK_LIBS) + + +#---[ Clean Targets ]-------------------------------------------------------------------- + +clean: \ + cleanDebug \ + cleanRelease + + @rm -fr $(BASEDIR)/.tmp/$(MODULE_NAME) + @rm -fr $(POTDIR)/$(MODULE_NAME) + +cleanDebug: + + @rm -fr $(OBJDBG) + @rm -fr $(BINDBG) + @rm -fr $(OBJDIR)/marshal + +clean: \ + cleanDebug \ + cleanRelease + + diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..dc2863e --- /dev/null +++ b/autogen.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +test -n "$srcdir" || srcdir=`dirname "$0"` +test -n "$srcdir" || srcdir=. + +olddir=`pwd` +cd "$srcdir" + +aclocal +if test $? != 0 ; then + echo "aclocal failed." + exit -1 +fi + +autoconf +if test $? != 0 ; then + echo "autoconf failed." + exit -1 +fi + +mkdir -p scripts +automake --add-missing 2> /dev/null | true + +cd "$olddir" +test -n "$NOCONFIGURE" || "$srcdir/configure" "$@" + + + + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..4798f94 --- /dev/null +++ b/configure.ac @@ -0,0 +1,250 @@ +dnl +dnl Software pw3270, desenvolvido com base nos códigos fontes do C3270 e X3270 +dnl (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a +dnl aplicativos mainframe. Registro no INPI sob o nome G3270. +dnl +dnl Copyright (C) <2008> +dnl +dnl Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob +dnl os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela +dnl Free Software Foundation. +dnl +dnl Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER +dnl GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO +dnl A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para +dnl obter mais detalhes. +dnl +dnl Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este +dnl programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple +dnl Place, Suite 330, Boston, MA, 02111-1307, USA +dnl +dnl Contatos: +dnl +dnl perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) +dnl erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) +dnl + +dnl Process this file with autoconf to produce a configure script. + +dnl The minimum version of autoconf required. +AC_PREREQ(2.61) + +dnl Initialise automake with the package name, version and +dnl bug-reporting address. +AC_INIT([pw3270], [5.2], [perry.werneck@gmail.com]) + +dnl Place auxilliary scripts here. +AC_CONFIG_AUX_DIR([scripts]) + +dnl Compute the canonical host-system type +AC_CANONICAL_HOST + +dnl Put macro definitions here (though they aren't used). +AC_CONFIG_HEADER([src/include/config.h]) + +dnl Initialise automake stuff. +AM_INIT_AUTOMAKE + +dnl Check for iconv +AM_ICONV + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_SED +AC_PROG_LN_S + +AC_LANG([C]) + +dnl --------------------------------------------------------------------------- +dnl Initialize defaults +dnl --------------------------------------------------------------------------- + +DBG_CFLAGS="-g -fstack-check -DDEBUG=1" +RLS_CFLAGS="-DNDEBUG=1" +PLUGINS="" +APP_RESOURCES="" +APP_LDFLAGS="" +DLL_LDFLAGS="-shared" +STATIC_LDFLAGS="" + +dnl --------------------------------------------------------------------------- +dnl Check for OS specifics +dnl --------------------------------------------------------------------------- + +DLLPREFIX="lib" + +case "$host" in + *-mingw32|*-pc-msys) + app_cv_osname="windows" + CFLAGS="$CFLAGS -pthread -D_WIN32_WINNT=0x0600" + LIBS="$LIBS -lws2_32 -lwtsapi32 -lcomdlg32" + LDFLAGS="$LDFLAGS -pthread" + DLLEXT=".dll" + DLLPREFIX="" + + app_win32_revision=$(date +%y.%m.%d.%H) + AC_SUBST(WIN32_VERSION,$app_win32_revision) + AC_CONFIG_FILES(src/plugin/windows/resources.rc) + ;; + + *) + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" + app_cv_datadir="/usr/share" + app_cv_confdir="/etc" + app_cv_osname="linux" + LOGDIR="/var/log" + DLLEXT=".so" + +esac + +AC_SUBST(DATADIR,$app_cv_datadir) +AC_SUBST(CONFDIR,$app_cv_confdir) +AC_SUBST(OSNAME,$app_cv_osname) +AC_SUBST(LIBS) +AC_SUBST(LOGDIR) +AC_SUBST(DLLEXT) +AC_SUBST(DLLPREFIX) + +dnl --------------------------------------------------------------------------- +dnl Check for other programs +dnl --------------------------------------------------------------------------- + +AC_PATH_TOOL([AR], [ar], [ar]) +AC_PATH_TOOL([WINDRES], [windres], [no]) + +PKG_CHECK_EXISTS + +dnl --------------------------------------------------------------------------- +dnl Version info +dnl --------------------------------------------------------------------------- + +AC_SUBST(PACKAGE_DESCRIPTION,"PW3270 IPC Compatible Module") + +app_vrs_major=$(echo $VERSION | cut -d. -f1) +app_vrs_minor=$(echo $VERSION | cut -d. -f2) + +AC_DEFINE_UNQUOTED(PACKAGE_MAJOR_VERSION, $app_vrs_major) +AC_DEFINE_UNQUOTED(PACKAGE_MINOR_VERSION, $app_vrs_minor) + +AC_SUBST(PACKAGE_MAJOR_VERSION,$app_vrs_major) +AC_SUBST(PACKAGE_MINOR_VERSION,$app_vrs_minor) + +AC_ARG_WITH([release], [AS_HELP_STRING([--with-release], [Set release])], [ app_cv_release="$withval" ],[ app_cv_release="`date +%y`.`date +%m`.`date +%d`" ]) + +app_rls_major=$(echo $app_cv_release.0.0 | cut -d. -f1) +app_rls_minor=$(echo $app_cv_release.0.0 | cut -d. -f2) + +AC_DEFINE_UNQUOTED(PACKAGE_RELEASE, $app_cv_release) +AC_DEFINE_UNQUOTED(PACKAGE_MAJOR_RELEASE, $app_rls_major) +AC_DEFINE_UNQUOTED(PACKAGE_MINOR_RELEASE, $app_rls_minor) + +AC_SUBST(PACKAGE_RELEASE,$app_cv_release) +AC_SUBST(PACKAGE_MAJOR_RELEASE,$app_rls_major) +AC_SUBST(PACKAGE_MINOR_RELEASE,$app_rls_minor) + +dnl --------------------------------------------------------------------------- +dnl Check for libintl +dnl --------------------------------------------------------------------------- + +INTL_LIBS="" + +AC_PATH_TOOL([XGETTEXT], [xgettext], [no]) +AC_PATH_TOOL([MSGCAT], [msgcat], [no]) +AC_PATH_TOOL([MSGINIT], [msginit], [no]) +AC_PATH_TOOL([MSGMERGE], [msgmerge], [no]) +AC_PATH_TOOL([MSGFMT], [msgfmt], [no]) + +AC_SUBST(INTL_LIBS) + +dnl --------------------------------------------------------------------------- +dnl Check for LIB3270 +dnl --------------------------------------------------------------------------- + +PKG_CHECK_MODULES( [LIB3270], [lib3270], AC_DEFINE(HAVE_LIB3270), AC_MSG_ERROR([LIB3270 not present.])) + +AC_SUBST(LIB3270_LIBS) +AC_SUBST(LIB3270_CFLAGS) + +dnl --------------------------------------------------------------------------- +dnl Check for LIBV3270 +dnl --------------------------------------------------------------------------- + +PKG_CHECK_MODULES( [V3270], [libv3270], AC_DEFINE(HAVE_V3270), AC_MSG_ERROR([V3270 not present.])) + +AC_SUBST(V3270_LIBS) +AC_SUBST(V3270_CFLAGS) + +dnl --------------------------------------------------------------------------- +dnl Check for GTK +dnl --------------------------------------------------------------------------- + +PKG_CHECK_MODULES( [GTK], [gtk+-3.0], AC_DEFINE(HAVE_GTK), AC_MSG_ERROR([GTK not present.])) + +AC_SUBST(GTK_LIBS) +AC_SUBST(GTK_CFLAGS) + +dnl --------------------------------------------------------------------------- +dnl Check for GLIB +dnl --------------------------------------------------------------------------- + +PKG_CHECK_MODULES( [GLIB], [glib-2.0 gobject-2.0 gmodule-2.0 gio-2.0], AC_DEFINE(HAVE_GLIB), AC_MSG_ERROR([GLIB not present.] )) +AC_SUBST(GLIB_LIBS) +AC_SUBST(GLIB_CFLAGS) + +dnl --------------------------------------------------------------------------- +dnl Check for D-Bus +dnl --------------------------------------------------------------------------- + +PKG_CHECK_MODULES( [DBUS], [dbus-1], app_cv_libdbus=yes, AC_MSG_NOTICE([ No DBUS support.]) ) +AC_SUBST(DBUS_LIBS) +AC_SUBST(DBUS_CFLAGS) + +PKG_CHECK_MODULES( [GDBUS], [dbus-glib-1], app_cv_dbus=yes, AC_MSG_NOTICE([No GDBUS support.]) ) +AC_SUBST(GDBUS_LIBS) +AC_SUBST(GDBUS_CFLAGS) + +dnl --------------------------------------------------------------------------- +dnl Check for pic +dnl --------------------------------------------------------------------------- + +AC_ARG_ENABLE([pic], + [AS_HELP_STRING([--disable-pic], [disable support for PIC libraries (required to compile on 64bits)])], +[ + app_cv_pic="$enableval" +],[ + + case "$host_cpu" in + x86_64) + app_cv_pic="yes" + ;; + + aarch64) + app_cv_pic="yes" + ;; + + *) + app_cv_pic="no" + esac + +]) + +if test "$app_cv_pic" == "yes"; then + CFLAGS="$CFLAGS -fPIC" + CXXFLAGS="$CXXFLAGS -fPIC" +fi + +dnl --------------------------------------------------------------------------- +dnl Configure which files to generate. +dnl --------------------------------------------------------------------------- + +AC_CONFIG_FILES(Makefile) + +dnl --------------------------------------------------------------------------- +dnl Output the generated config.status script. +dnl --------------------------------------------------------------------------- +AC_SUBST(BASEDIR,$ac_pwd) + +AC_OUTPUT + + diff --git a/src/dbus3270/daemon.c b/src/dbus3270/daemon.c deleted file mode 100644 index a429514..0000000 --- a/src/dbus3270/daemon.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como daemon.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - -#include -#include -#include -#include - -#include "daemon.h" -#include "dbus-glue.h" - -#define PW3270_DBUS_SERVICE_PATH "/br/com/bb/pw3270" -#define PW3270_DBUS_SERVICE "br.com.bb.pw3270" - - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - static DBusGConnection * connection = NULL; - static DBusGProxy * proxy = NULL; - static H3270 * hSession = NULL; - - GMainLoop * main_loop = NULL; - - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - -static int initialize(void) -{ - GError * error = NULL; - guint result; - - connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); - if(error) - { - g_message("Error \"%s\" getting session dbus",error->message); - g_error_free(error); - return -1; - } - - proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); - - org_freedesktop_DBus_request_name(proxy, PW3270_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); - - pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,PW3270_DBUS_SERVICE_PATH); - - return 0; -} - -static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) -{ - g_logv(module,rc ? G_LOG_LEVEL_WARNING : G_LOG_LEVEL_MESSAGE, fmt, args); -} - -int main(int numpar, char *param[]) -{ - g_type_init (); - - if (!g_thread_supported ()) - g_thread_init (NULL); - - dbus_g_thread_init (); - - lib3270_set_log_handler(loghandler); - pw3270_dbus_register_io_handlers(); - - hSession = lib3270_session_new(""); - - main_loop = g_main_loop_new (NULL, FALSE); - - if(initialize()) - return -1; - - g_main_loop_run(main_loop); - - lib3270_session_free(hSession); - - return 0; -} - -void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - g_main_loop_quit(main_loop); - dbus_g_method_return(context,0); -} - -H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object) -{ - return hSession; -} - diff --git a/src/dbus3270/daemon.h b/src/dbus3270/daemon.h deleted file mode 100644 index 152a618..0000000 --- a/src/dbus3270/daemon.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como daemon.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - - #include "service.h" - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - G_GNUC_INTERNAL GMainLoop * main_loop; - - -/*---[ Prototipes ]------------------------------------------------------------------------------*/ - - G_GNUC_INTERNAL void pw3270_dbus_register_io_handlers(void); - diff --git a/src/dbus3270/globals.h b/src/dbus3270/globals.h deleted file mode 100644 index ed4ccbc..0000000 --- a/src/dbus3270/globals.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como globals.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#ifndef PW3270_DBUS_GLOBALS_H_INCLUDED - - #define PW3270_DBUS_GLOBALS_H_INCLUDED 1 - - #include - #include - - #include - #include - #include - #include - - // - // Disabling warning on unused-function defined in dbus-glib-bindings.h - // warning: 'org_freedesktop_DBus_reload_config' defined but not used [-Wunused-function] ... - // - #pragma GCC diagnostic ignored "-Wunused-function" - - #include - #include - #include - - #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS") - - G_GNUC_INTERNAL gpointer pw3270_dbus_register_object (DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path); - - -#endif // PW3270_DBUS_GLOBALS_H_INCLUDED diff --git a/src/dbus3270/gobject.c b/src/dbus3270/gobject.c deleted file mode 100644 index 1cd90a6..0000000 --- a/src/dbus3270/gobject.c +++ /dev/null @@ -1,622 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como gobject.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "service.h" - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - -G_DEFINE_TYPE(PW3270Dbus, pw3270_dbus, G_TYPE_OBJECT) - -static void pw3270_dbus_finalize(GObject *object) -{ - G_OBJECT_CLASS(pw3270_dbus_parent_class)->finalize (object); -} - - -static void pw3270_dbus_class_init(PW3270DbusClass *klass) -{ - GObjectClass *object_class; - object_class = G_OBJECT_CLASS (klass); - object_class->finalize = pw3270_dbus_finalize; -} - -static void pw3270_dbus_init(PW3270Dbus *object) -{ - -} - -PW3270Dbus * pw3270_dbus_new(void) -{ - return g_object_new(PW3270_TYPE_DBUS, NULL); -} - -void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); -#ifdef PACKAGE_REVISION - dbus_g_method_return(context,PACKAGE_REVISION); -#else - dbus_g_method_return(context,BUILD_DATE); -#endif -} - -void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) -{ - H3270 *hSession = pw3270_dbus_get_session_handle(PW3270_DBUS(object)); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(uri && *uri) - { - lib3270_set_url(hSession,uri); - g_message("Connecting to \"%s\" by remote request",lib3270_get_url(hSession)); - } - else - { - g_message("%s","Connecting by remote request"); - } - - dbus_g_method_return(context,lib3270_reconnect(hSession,0)); -} - -void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - g_message("Changing host to \"%s\" by remote request",uri); - - dbus_g_method_return(context,lib3270_set_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri) != 0); -} - -void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)))); -} - - -void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - g_message("Disconnecting by remote request"); - lib3270_disconnect(pw3270_dbus_get_session_handle(object)); - dbus_g_method_return(context,0); -} - -void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_connection_state(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_secure(pw3270_dbus_get_session_handle(object))); -} - -GError * pw3270_dbus_get_error_from_errno(int code) -{ - return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code)); -} - -int pw3270_dbus_check_valid_state(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - H3270 * hSession = pw3270_dbus_get_session_handle(object); - GError * error = NULL; - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(!lib3270_is_connected(hSession)) - { - error = pw3270_dbus_get_error_from_errno(ENOTCONN); - } - else - { - LIB3270_MESSAGE state = lib3270_get_program_message(hSession); - - switch(state) - { - case LIB3270_MESSAGE_NONE: - return 0; - - case LIB3270_MESSAGE_DISCONNECTED: - error = pw3270_dbus_get_error_from_errno(ENOTCONN); - break; - - case LIB3270_MESSAGE_MINUS: - case LIB3270_MESSAGE_PROTECTED: - case LIB3270_MESSAGE_NUMERIC: - case LIB3270_MESSAGE_OVERFLOW: - case LIB3270_MESSAGE_INHIBIT: - case LIB3270_MESSAGE_KYBDLOCK: - case LIB3270_MESSAGE_X: - error = g_error_new(ERROR_DOMAIN,-1,_( "State %04d can't accept requests" ),state); - break; - - case LIB3270_MESSAGE_SYSWAIT: - case LIB3270_MESSAGE_TWAIT: - case LIB3270_MESSAGE_CONNECTED: - case LIB3270_MESSAGE_AWAITING_FIRST: - error = pw3270_dbus_get_error_from_errno(EBUSY); - break; - - case LIB3270_MESSAGE_RESOLVING: - case LIB3270_MESSAGE_CONNECTING: - error = g_error_new(ERROR_DOMAIN,EINPROGRESS,_( "Connecting to host" )); - - case LIB3270_MESSAGE_USER: - error = g_error_new(ERROR_DOMAIN,-1,_( "Unexpected state %04d" ),state); - } - } - - if(error) - { - dbus_g_method_return_error(context,error); - g_error_free(error); - return -1; - } - - return 0; -} - -void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - char * text; - gchar * utftext; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = lib3270_get_string_at_address(hSession,0,-1,'\n'); - - utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); - - lib3270_free(text); - - dbus_g_method_return(context,utftext); - - g_free(utftext); - -} - -void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - dbus_g_method_return(context,lib3270_enter(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); - - int sz = lib3270_set_string_at(hSession,row,col,(const unsigned char *) text); - - trace("%s returns %d",__FUNCTION__,sz); - dbus_g_method_return(context,sz); - - g_free(text); -} - -void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); - - dbus_g_method_return(context,lib3270_emulate_input(hSession,(const char *) text,-1,1)); - - g_free(text); -} - - -void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = lib3270_get_string_at(hSession, row, col, len, lf); - if(!text) - { - GError *error = pw3270_dbus_get_error_from_errno(errno); - dbus_g_method_return_error(context,error); - g_error_free(error); - } - else - { - gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); - - lib3270_free(text); - - dbus_g_method_return(context,utftext); - - g_free(utftext); - } - } - - void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context) - { - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - if(len < 0) { - len = lib3270_get_length(hSession); - } - - text = lib3270_get_string_at_address(hSession,offset,len,lf); - if(!text) - { - GError *error = pw3270_dbus_get_error_from_errno(errno); - dbus_g_method_return_error(context,error); - g_error_free(error); - } - else - { - gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); - - lib3270_free(text); - - debug("\n%s\n",utftext); - - dbus_g_method_return(context,utftext); - - g_free(utftext); - } - - } - - void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p connected=%s",__FUNCTION__,object,context, lib3270_is_connected(pw3270_dbus_get_session_handle(object)) ? "Yes" : "No"); - dbus_g_method_return(context,lib3270_is_connected(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_is_ready(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_in_tn3270e(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_wait_for_ready(pw3270_dbus_get_session_handle(object),timeout)); - } - - void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_set_cursor_position(pw3270_dbus_get_session_handle(object),row,col)); - } - - void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_set_cursor_address(pw3270_dbus_get_session_handle(object),addr)); - } - - void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_cursor_address(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_height(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); - } - - void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_set_toggle(pw3270_dbus_get_session_handle(object),id,value)); - } - -void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, char lf, DBusGMethodInvocation *context) -{ - gchar * text; - H3270 * hSession = pw3270_dbus_get_session_handle(object); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); - - dbus_g_method_return(context,lib3270_cmp_text_at(hSession,row,col,text,lf)); - - g_free(text); -} - -void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - dbus_g_method_return(context,lib3270_pfkey(pw3270_dbus_get_session_handle(object),key)); -} - -void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - if(pw3270_dbus_check_valid_state(object,context)) - return; - dbus_g_method_return(context,lib3270_pakey(pw3270_dbus_get_session_handle(object),key)); -} - - void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_field_start(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_field_len(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_next_unprotected(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_is_protected(pw3270_dbus_get_session_handle(object),baddr)); - } - - void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_get_is_protected_at(pw3270_dbus_get_session_handle(object),row,col)); - } - - void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) - { - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_action(pw3270_dbus_get_session_handle(object),text)); - } - - void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context) - { - gchar *text; - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(pw3270_dbus_check_valid_state(object,context)) - return; - - text = gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD)); - - trace("Clipboard:\n%s\n",text); - - if(!text) - { - GError *error = pw3270_dbus_get_error_from_errno(ENOENT); - dbus_g_method_return_error(context,error); - g_error_free(error); - } - else - { - dbus_g_method_return(context,text); - g_free(text); - } -} - -void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - gtk_clipboard_set_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD),(gchar *) text, -1); - dbus_g_method_return(context,0); -} - -void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context) -{ - GtkWidget *widget = pw3270_get_terminal_widget(NULL); - - trace("%s object=%p context=%p",__FUNCTION__,object,context); - - if(!widget) - { - GError *error = pw3270_dbus_get_error_from_errno(EINVAL); - dbus_g_method_return_error(context,error); - g_error_free(error); - return; - } - - dbus_g_method_return(context,v3270_set_script(widget,mode == 0 ? 0 : 'S')); -} - -void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context) -{ - lib3270_popup_dialog(pw3270_dbus_get_session_handle(object), (LIB3270_NOTIFY) id , title, msg, "%s", text); - dbus_g_method_return(context,0); -} - -void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - dbus_g_method_return(context,lib3270_get_host_charset(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - // Allways return UTF-8 to avoid double conversion - dbus_g_method_return(context,"UTF-8"); -} - -void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context) -{ - dbus_g_method_return(context,lib3270_set_host_charset(pw3270_dbus_get_session_handle(object),charset)); -} - -void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - trace("%s object=%p context=%p",__FUNCTION__,object,context); - dbus_g_method_return(context,lib3270_eraseeof(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context) -{ - dbus_g_method_return(context,lib3270_print_all(pw3270_dbus_get_session_handle(object))); -} - -void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context) -{ - lib3270_set_unlock_delay(pw3270_dbus_get_session_handle(object),(unsigned short) value); - dbus_g_method_return(context,0); -} - - -void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) -{ - int sz = strlen(from); - - if(sz > 0) - { - unsigned char buffer[sz+1]; - memcpy(buffer,from,sz); - dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz)); - return; - } - - dbus_g_method_return(context,""); - -} - -void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) -{ - int sz = strlen(from); - - if(sz > 0) - { - unsigned char buffer[sz+1]; - memcpy(buffer,from,sz); - dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz)); - return; - } - - dbus_g_method_return(context,""); - -} - -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) -{ - /* - dbus_g_method_return(context, - v3270_transfer_file( - v3270_get_default_widget(), - (LIB3270_FT_OPTION) flags, - local, - remote, - lrecl, - blksize, - primspace, - secspace, - dft - )); - */ - return; -} - diff --git a/src/dbus3270/iocallback.c b/src/dbus3270/iocallback.c deleted file mode 100644 index 5292f4c..0000000 --- a/src/dbus3270/iocallback.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como iocallback.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#if defined(_WIN32) /*[*/ - #include -#elif defined(__APPLE__) - #include - #include -#else - #include - #include -#endif /*]*/ - -#include -#include -#include "daemon.h" - -static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); -static void static_RemoveSource(void *id); - -static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); -static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); - -static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); -static void static_RemoveTimeOut(void * timer); -static int static_Sleep(H3270 *hSession, int seconds); -static int static_RunPendingEvents(H3270 *hSession, int wait); - -static gboolean IO_prepare(GSource *source, gint *timeout); -static gboolean IO_check(GSource *source); -static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); -static void IO_finalize(GSource *source); /* Can be NULL */ -static gboolean IO_closure(gpointer data); - -/*---[ Structs ]-------------------------------------------------------------------------------------------*/ - - typedef struct _IO_Source - { - GSource gsrc; - GPollFD poll; -#if defined(_WIN32) - HANDLE source; -#else - int source; -#endif // _WIN32 - void (*fn)(H3270 *session); - H3270 *session; - } IO_Source; - - typedef struct _timer - { - unsigned char remove; - void (*fn)(H3270 *session); - H3270 *session; - } TIMER; - - static GSourceFuncs IOSources = - { - IO_prepare, - IO_check, - IO_dispatch, - IO_finalize, - IO_closure, - NULL - }; - -/*---[ Implement ]-----------------------------------------------------------------------------------------*/ - -#ifdef _WIN32 -static void * AddSource(HANDLE source, H3270 *session, gushort events, void (*fn)(H3270 *session)) -#else -static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session)) -#endif // _WIN32 -{ - IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); - - src->source = source; - src->fn = fn; - src->poll.fd = (int) source; - src->poll.events = events; - src->session = session; - - g_source_attach((GSource *) src,NULL); - g_source_add_poll((GSource *) src,&src->poll); - - return src; -} - -#ifdef _WIN32 -static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -#else -static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) -#endif // _WIN32 -{ - return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); -} - -static void static_RemoveSource(void *id) -{ - if(id) - g_source_destroy((GSource *) id); -} - -#if defined(_WIN32) -static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) -{ - return 0; -} -#else -static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) -{ - return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); -} -#endif // _WIN32 - -static gboolean do_timer(TIMER *t) -{ - if(!t->remove) - t->fn(t->session); - return FALSE; -} - -static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*proc)(H3270 *session)) -{ - TIMER *t = g_malloc0(sizeof(TIMER)); - - t->fn = proc; - t->session = session; - - g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free); - - return t; -} - -static void static_RemoveTimeOut(void * timer) -{ - ((TIMER *) timer)->remove++; -} - -static gboolean IO_prepare(GSource *source, gint *timeout) -{ - /* - * Called before all the file descriptors are polled. - * If the source can determine that it is ready here - * (without waiting for the results of the poll() call) - * it should return TRUE. - * - * It can also return a timeout_ value which should be the maximum - * timeout (in milliseconds) which should be passed to the poll() call. - * The actual timeout used will be -1 if all sources returned -1, - * or it will be the minimum of all the timeout_ values - * returned which were >= 0. - * - */ - return 0; -} - -static gboolean IO_check(GSource *source) -{ - /* - * Called after all the file descriptors are polled. - * The source should return TRUE if it is ready to be dispatched. - * Note that some time may have passed since the previous prepare - * function was called, so the source should be checked again here. - * - */ -#if defined(_WIN32) /*[*/ - - if(WaitForSingleObject(((IO_Source *) source)->source,0) == WAIT_OBJECT_0) - return TRUE; - -#else /*][*/ - - struct pollfd fds; - - memset(&fds,0,sizeof(fds)); - - fds.fd = ((IO_Source *) source)->poll.fd; - fds.events = ((IO_Source *) source)->poll.events; - - if(poll(&fds,1,0) > 0) - return TRUE; - -#endif /*]*/ - - return FALSE; -} - -static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) -{ - /* - * Called to dispatch the event source, - * after it has returned TRUE in either its prepare or its check function. - * The dispatch function is passed in a callback function and data. - * The callback function may be NULL if the source was never connected - * to a callback using g_source_set_callback(). The dispatch function - * should call the callback function with user_data and whatever additional - * parameters are needed for this type of event source. - */ - ((IO_Source *) source)->fn(((IO_Source *) source)->session); - return TRUE; -} - -static void IO_finalize(GSource *source) -{ - -} - -static gboolean IO_closure(gpointer data) -{ - return 0; -} - -struct bgParameter -{ - gboolean running; - gboolean timer; - H3270 *session; - int rc; - int(*callback)(H3270 *session, void *); - void *parm; - -}; - -gpointer BgCall(struct bgParameter *p) -{ -// trace("%s starts",__FUNCTION__); - p->rc = p->callback(p->session, p->parm); - p->running = FALSE; -// trace("%s ends",__FUNCTION__); - return 0; -} - -static gboolean wait_for_thread(struct bgParameter *p) -{ - if(!p->running) - { - p->timer = 0; - return FALSE; - } - return TRUE; -} - -static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm) -{ - struct bgParameter p = { TRUE, TRUE, session, -1, callback, parm }; - GThread * thread; - -// trace("Starting auxiliary thread for callback %p",callback); - - p.running = TRUE; - p.timer = TRUE; - - thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL); - - if(!thread) - { - g_error("Can't start background thread"); - return -1; - } - - g_timeout_add(50,(GSourceFunc) wait_for_thread,(gpointer) &p); - - while(p.timer) - g_main_context_iteration(g_main_loop_get_context(main_loop),TRUE); - - return p.rc; -} - -static int static_Sleep(H3270 *hSession, int seconds) -{ - time_t end = time(0) + seconds; - - while(time(0) < end) - g_main_iteration(TRUE); - - return 0; -} - -static int static_RunPendingEvents(H3270 *hSession, int wait) -{ - GMainContext *context = g_main_loop_get_context(main_loop); - int rc = 0; - while(g_main_context_pending(context)) - { - rc = 1; - g_main_context_iteration(context,FALSE); - } - - if(wait) - g_main_context_iteration(context,TRUE); - - return rc; -} - -static void beep(H3270 *session) -{ -} - -void pw3270_dbus_register_io_handlers(void) -{ - static const struct lib3270_callbacks hdl = - { - sizeof(struct lib3270_callbacks), - - static_AddTimeOut, - static_RemoveTimeOut, - - static_AddInput, - static_RemoveSource, - - static_AddExcept, - -#ifdef G_THREADS_ENABLED - static_CallAndWait, -#else - NULL, -#endif - - static_Sleep, - static_RunPendingEvents, - beep - - }; - - #error Need rewrite - - if(lib3270_register_handlers(&hdl)) - { - g_error("%s","Can't set lib3270 I/O handlers"); - } - -} diff --git a/src/dbus3270/main.c b/src/dbus3270/main.c deleted file mode 100644 index d24d358..0000000 --- a/src/dbus3270/main.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como main.c e possui - linhas de código. - * - * Referências: - * - * https://github.com/fbuihuu/samples-dbus/blob/master/dbus-server.c - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#include -#include -#include -#include - -#include -#include - -#include "service.h" -#include "dbus-glue.h" - -#include - -/*---[ Globals ]---------------------------------------------------------------------------------*/ - - static DBusGConnection * connection = NULL; - static DBusGProxy * proxy = NULL; - static gchar * service_name = NULL; - - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - - LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) - { - - GError * error = NULL; - guint result; - char session_id = 0; - char id = 'a'; - - connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); - if(error) - { - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't connect to DBUS server" )); - - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - - g_message("Error \"%s\" getting session dbus",error->message); - - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - - proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); - - for(id='a'; id < 'z' && !error && !service_name; id++) - { - gboolean has_owner = FALSE; - - service_name = g_strdup_printf("br.com.bb.%s.%c",pw3270_get_session_name(window),(int) id); - - org_freedesktop_DBus_name_has_owner(proxy, service_name, &has_owner, NULL); - - if(has_owner) - { - trace("Service \"%s\" has owner",service_name) - g_free(service_name); - service_name = NULL; - } - else - { - session_id = id; - g_message("DBUS service name is %s",service_name); - org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); - } - } - - if(error) - { - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(window), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _( "Can't get DBUS object name" )); - - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); - - g_message("Error \"%s\" requesting DBUS name",error->message); - - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - return -1; - } - - if(session_id) - { - gchar * path = g_strdup_printf("/br/com/bb/%s",pw3270_get_session_name(window)); - gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),g_ascii_toupper(session_id)); - pw3270_set_session_name(window,session); - g_free(session); - - g_message("DBUS service path is %s",path); - - pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,path); - - g_free(path); - } - - return 0; - } - - LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window, GtkWidget *terminal) - { - if(service_name) - { - // org_freedesktop_DBus_release_name - - g_free(service_name); - service_name = NULL; - } - return 0; - } - - void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context) - { - gtk_main_quit(); - dbus_g_method_return(context,0); - } - - H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object) - { - return lib3270_get_default_session_handle(); - } - - - diff --git a/src/dbus3270/misc.c b/src/dbus3270/misc.c deleted file mode 100644 index 0e73503..0000000 --- a/src/dbus3270/misc.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como misc.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * Referencias: - * - * https://live.gnome.org/DBusGlibBindings - * - */ - -#include "globals.h" - -/*---[ Implement ]-------------------------------------------------------------------------------*/ - -gpointer pw3270_dbus_register_object(DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path) -{ - GObject *object = g_object_new (object_type, NULL); - dbus_g_object_type_install_info (object_type, info); - dbus_g_connection_register_g_object (connection, path, object); - return object; -} - diff --git a/src/dbus3270/service.h b/src/dbus3270/service.h deleted file mode 100644 index aba8322..0000000 --- a/src/dbus3270/service.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como service.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#ifndef _PW3270_DBUS_SERVICE_H - - #define _PW3270_DBUS_SERVICE_H 1 - - #define ENABLE_NLS - #define GETTEXT_PACKAGE PACKAGE_NAME - - #include "globals.h" - - #define PW3270_TYPE_DBUS (pw3270_dbus_get_type ()) - #define PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PW3270_TYPE_DBUS, PW3270Dbus)) - #define PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DBUS, PW3270DbusClass)) - #define IS_PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PW3270_TYPE_DBUS)) - #define IS_PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DBUS)) - #define PW3270_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DBUS, PW3270DbusClass)) - - G_BEGIN_DECLS - - typedef struct _PW3270Dbus PW3270Dbus; - typedef struct _PW3270DbusClass PW3270DbusClass; - - struct _PW3270Dbus - { - GObject parent; - }; - - struct _PW3270DbusClass - { - GObjectClass parent; - }; - - PW3270Dbus * pw3270_dbus_new (void); - GType pw3270_dbus_get_type (void); - - void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); - void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); - void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); - H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); - GError * pw3270_dbus_get_error_from_errno(int code); - - void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); - void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context); - void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context); - - void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context); - - void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - - void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); - void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); - - void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context); - - void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context); - - void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); - - // Actions - void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); - void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); - void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *text, DBusGMethodInvocation *context); - void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context); - void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context); - void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *text, char lf, DBusGMethodInvocation *context); - void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context); - - void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); - void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context); - void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context); - void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context); - - void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); - void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); - - 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); - - void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context); - - G_END_DECLS - -#endif // _PW3270_DBUS_SERVICE_H diff --git a/src/include/config.h.in b/src/include/config.h.in new file mode 100644 index 0000000..ca153ed --- /dev/null +++ b/src/include/config.h.in @@ -0,0 +1,41 @@ +/* + * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como config.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas de Mendonça) + * + */ + +#ifndef LIBV3270_CONFIG_INCLUDED + + #define LIBV3270_CONFIG_INCLUDED 1 + + #undef PACKAGE_NAME + #undef PACKAGE_VERSION + #undef PACKAGE_RELEASE + + #undef HAVE_GNOME + #undef HAVE_GTKMAC + +#endif /* LIBV3270_CONFIG_INCLUDED */ diff --git a/src/plugin/linux/daemon.c b/src/plugin/linux/daemon.c new file mode 100644 index 0000000..a429514 --- /dev/null +++ b/src/plugin/linux/daemon.c @@ -0,0 +1,122 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como daemon.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + +#include +#include +#include +#include + +#include "daemon.h" +#include "dbus-glue.h" + +#define PW3270_DBUS_SERVICE_PATH "/br/com/bb/pw3270" +#define PW3270_DBUS_SERVICE "br.com.bb.pw3270" + + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + static DBusGConnection * connection = NULL; + static DBusGProxy * proxy = NULL; + static H3270 * hSession = NULL; + + GMainLoop * main_loop = NULL; + + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + +static int initialize(void) +{ + GError * error = NULL; + guint result; + + connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); + if(error) + { + g_message("Error \"%s\" getting session dbus",error->message); + g_error_free(error); + return -1; + } + + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); + + org_freedesktop_DBus_request_name(proxy, PW3270_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); + + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,PW3270_DBUS_SERVICE_PATH); + + return 0; +} + +static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) +{ + g_logv(module,rc ? G_LOG_LEVEL_WARNING : G_LOG_LEVEL_MESSAGE, fmt, args); +} + +int main(int numpar, char *param[]) +{ + g_type_init (); + + if (!g_thread_supported ()) + g_thread_init (NULL); + + dbus_g_thread_init (); + + lib3270_set_log_handler(loghandler); + pw3270_dbus_register_io_handlers(); + + hSession = lib3270_session_new(""); + + main_loop = g_main_loop_new (NULL, FALSE); + + if(initialize()) + return -1; + + g_main_loop_run(main_loop); + + lib3270_session_free(hSession); + + return 0; +} + +void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + g_main_loop_quit(main_loop); + dbus_g_method_return(context,0); +} + +H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object) +{ + return hSession; +} + diff --git a/src/plugin/linux/daemon.h b/src/plugin/linux/daemon.h new file mode 100644 index 0000000..152a618 --- /dev/null +++ b/src/plugin/linux/daemon.h @@ -0,0 +1,46 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como daemon.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + + #include "service.h" + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + G_GNUC_INTERNAL GMainLoop * main_loop; + + +/*---[ Prototipes ]------------------------------------------------------------------------------*/ + + G_GNUC_INTERNAL void pw3270_dbus_register_io_handlers(void); + diff --git a/src/plugin/linux/globals.h b/src/plugin/linux/globals.h new file mode 100644 index 0000000..ed4ccbc --- /dev/null +++ b/src/plugin/linux/globals.h @@ -0,0 +1,59 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como globals.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#ifndef PW3270_DBUS_GLOBALS_H_INCLUDED + + #define PW3270_DBUS_GLOBALS_H_INCLUDED 1 + + #include + #include + + #include + #include + #include + #include + + // + // Disabling warning on unused-function defined in dbus-glib-bindings.h + // warning: 'org_freedesktop_DBus_reload_config' defined but not used [-Wunused-function] ... + // + #pragma GCC diagnostic ignored "-Wunused-function" + + #include + #include + #include + + #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS") + + G_GNUC_INTERNAL gpointer pw3270_dbus_register_object (DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path); + + +#endif // PW3270_DBUS_GLOBALS_H_INCLUDED diff --git a/src/plugin/linux/gobject.c b/src/plugin/linux/gobject.c new file mode 100644 index 0000000..1cd90a6 --- /dev/null +++ b/src/plugin/linux/gobject.c @@ -0,0 +1,622 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como gobject.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "service.h" + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + +G_DEFINE_TYPE(PW3270Dbus, pw3270_dbus, G_TYPE_OBJECT) + +static void pw3270_dbus_finalize(GObject *object) +{ + G_OBJECT_CLASS(pw3270_dbus_parent_class)->finalize (object); +} + + +static void pw3270_dbus_class_init(PW3270DbusClass *klass) +{ + GObjectClass *object_class; + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = pw3270_dbus_finalize; +} + +static void pw3270_dbus_init(PW3270Dbus *object) +{ + +} + +PW3270Dbus * pw3270_dbus_new(void) +{ + return g_object_new(PW3270_TYPE_DBUS, NULL); +} + +void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); +#ifdef PACKAGE_REVISION + dbus_g_method_return(context,PACKAGE_REVISION); +#else + dbus_g_method_return(context,BUILD_DATE); +#endif +} + +void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) +{ + H3270 *hSession = pw3270_dbus_get_session_handle(PW3270_DBUS(object)); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(uri && *uri) + { + lib3270_set_url(hSession,uri); + g_message("Connecting to \"%s\" by remote request",lib3270_get_url(hSession)); + } + else + { + g_message("%s","Connecting by remote request"); + } + + dbus_g_method_return(context,lib3270_reconnect(hSession,0)); +} + +void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + g_message("Changing host to \"%s\" by remote request",uri); + + dbus_g_method_return(context,lib3270_set_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)),uri) != 0); +} + +void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_url(pw3270_dbus_get_session_handle(PW3270_DBUS(object)))); +} + + +void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + g_message("Disconnecting by remote request"); + lib3270_disconnect(pw3270_dbus_get_session_handle(object)); + dbus_g_method_return(context,0); +} + +void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_program_message(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_connection_state(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_secure(pw3270_dbus_get_session_handle(object))); +} + +GError * pw3270_dbus_get_error_from_errno(int code) +{ + return g_error_new(ERROR_DOMAIN,code,"%s",g_strerror(code)); +} + +int pw3270_dbus_check_valid_state(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + H3270 * hSession = pw3270_dbus_get_session_handle(object); + GError * error = NULL; + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(!lib3270_is_connected(hSession)) + { + error = pw3270_dbus_get_error_from_errno(ENOTCONN); + } + else + { + LIB3270_MESSAGE state = lib3270_get_program_message(hSession); + + switch(state) + { + case LIB3270_MESSAGE_NONE: + return 0; + + case LIB3270_MESSAGE_DISCONNECTED: + error = pw3270_dbus_get_error_from_errno(ENOTCONN); + break; + + case LIB3270_MESSAGE_MINUS: + case LIB3270_MESSAGE_PROTECTED: + case LIB3270_MESSAGE_NUMERIC: + case LIB3270_MESSAGE_OVERFLOW: + case LIB3270_MESSAGE_INHIBIT: + case LIB3270_MESSAGE_KYBDLOCK: + case LIB3270_MESSAGE_X: + error = g_error_new(ERROR_DOMAIN,-1,_( "State %04d can't accept requests" ),state); + break; + + case LIB3270_MESSAGE_SYSWAIT: + case LIB3270_MESSAGE_TWAIT: + case LIB3270_MESSAGE_CONNECTED: + case LIB3270_MESSAGE_AWAITING_FIRST: + error = pw3270_dbus_get_error_from_errno(EBUSY); + break; + + case LIB3270_MESSAGE_RESOLVING: + case LIB3270_MESSAGE_CONNECTING: + error = g_error_new(ERROR_DOMAIN,EINPROGRESS,_( "Connecting to host" )); + + case LIB3270_MESSAGE_USER: + error = g_error_new(ERROR_DOMAIN,-1,_( "Unexpected state %04d" ),state); + } + } + + if(error) + { + dbus_g_method_return_error(context,error); + g_error_free(error); + return -1; + } + + return 0; +} + +void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + char * text; + gchar * utftext; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = lib3270_get_string_at_address(hSession,0,-1,'\n'); + + utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); + + lib3270_free(text); + + dbus_g_method_return(context,utftext); + + g_free(utftext); + +} + +void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + dbus_g_method_return(context,lib3270_enter(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); + + int sz = lib3270_set_string_at(hSession,row,col,(const unsigned char *) text); + + trace("%s returns %d",__FUNCTION__,sz); + dbus_g_method_return(context,sz); + + g_free(text); +} + +void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); + + dbus_g_method_return(context,lib3270_emulate_input(hSession,(const char *) text,-1,1)); + + g_free(text); +} + + +void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = lib3270_get_string_at(hSession, row, col, len, lf); + if(!text) + { + GError *error = pw3270_dbus_get_error_from_errno(errno); + dbus_g_method_return_error(context,error); + g_error_free(error); + } + else + { + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); + + lib3270_free(text); + + dbus_g_method_return(context,utftext); + + g_free(utftext); + } + } + + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context) + { + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + if(len < 0) { + len = lib3270_get_length(hSession); + } + + text = lib3270_get_string_at_address(hSession,offset,len,lf); + if(!text) + { + GError *error = pw3270_dbus_get_error_from_errno(errno); + dbus_g_method_return_error(context,error); + g_error_free(error); + } + else + { + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(hSession),"?",NULL,NULL,NULL); + + lib3270_free(text); + + debug("\n%s\n",utftext); + + dbus_g_method_return(context,utftext); + + g_free(utftext); + } + + } + + void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p connected=%s",__FUNCTION__,object,context, lib3270_is_connected(pw3270_dbus_get_session_handle(object)) ? "Yes" : "No"); + dbus_g_method_return(context,lib3270_is_connected(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_is_ready(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_in_tn3270e(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_wait_for_ready(pw3270_dbus_get_session_handle(object),timeout)); + } + + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_set_cursor_position(pw3270_dbus_get_session_handle(object),row,col)); + } + + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_set_cursor_address(pw3270_dbus_get_session_handle(object),addr)); + } + + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_cursor_address(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_height(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_width(pw3270_dbus_get_session_handle(object))); + } + + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_set_toggle(pw3270_dbus_get_session_handle(object),id,value)); + } + +void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *utftext, char lf, DBusGMethodInvocation *context) +{ + gchar * text; + H3270 * hSession = pw3270_dbus_get_session_handle(object); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(hSession),"UTF-8","?",NULL,NULL,NULL); + + dbus_g_method_return(context,lib3270_cmp_text_at(hSession,row,col,text,lf)); + + g_free(text); +} + +void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + dbus_g_method_return(context,lib3270_pfkey(pw3270_dbus_get_session_handle(object),key)); +} + +void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + if(pw3270_dbus_check_valid_state(object,context)) + return; + dbus_g_method_return(context,lib3270_pakey(pw3270_dbus_get_session_handle(object),key)); +} + + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_field_start(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_field_len(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_next_unprotected(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_is_protected(pw3270_dbus_get_session_handle(object),baddr)); + } + + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_get_is_protected_at(pw3270_dbus_get_session_handle(object),row,col)); + } + + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) + { + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_action(pw3270_dbus_get_session_handle(object),text)); + } + + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context) + { + gchar *text; + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(pw3270_dbus_check_valid_state(object,context)) + return; + + text = gtk_clipboard_wait_for_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD)); + + trace("Clipboard:\n%s\n",text); + + if(!text) + { + GError *error = pw3270_dbus_get_error_from_errno(ENOENT); + dbus_g_method_return_error(context,error); + g_error_free(error); + } + else + { + dbus_g_method_return(context,text); + g_free(text); + } +} + +void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + gtk_clipboard_set_text(gtk_widget_get_clipboard(pw3270_get_toplevel(),GDK_SELECTION_CLIPBOARD),(gchar *) text, -1); + dbus_g_method_return(context,0); +} + +void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context) +{ + GtkWidget *widget = pw3270_get_terminal_widget(NULL); + + trace("%s object=%p context=%p",__FUNCTION__,object,context); + + if(!widget) + { + GError *error = pw3270_dbus_get_error_from_errno(EINVAL); + dbus_g_method_return_error(context,error); + g_error_free(error); + return; + } + + dbus_g_method_return(context,v3270_set_script(widget,mode == 0 ? 0 : 'S')); +} + +void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context) +{ + lib3270_popup_dialog(pw3270_dbus_get_session_handle(object), (LIB3270_NOTIFY) id , title, msg, "%s", text); + dbus_g_method_return(context,0); +} + +void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + dbus_g_method_return(context,lib3270_get_host_charset(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + // Allways return UTF-8 to avoid double conversion + dbus_g_method_return(context,"UTF-8"); +} + +void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context) +{ + dbus_g_method_return(context,lib3270_set_host_charset(pw3270_dbus_get_session_handle(object),charset)); +} + +void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + trace("%s object=%p context=%p",__FUNCTION__,object,context); + dbus_g_method_return(context,lib3270_eraseeof(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context) +{ + dbus_g_method_return(context,lib3270_print_all(pw3270_dbus_get_session_handle(object))); +} + +void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context) +{ + lib3270_set_unlock_delay(pw3270_dbus_get_session_handle(object),(unsigned short) value); + dbus_g_method_return(context,0); +} + + +void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) +{ + int sz = strlen(from); + + if(sz > 0) + { + unsigned char buffer[sz+1]; + memcpy(buffer,from,sz); + dbus_g_method_return(context,lib3270_ebc2asc(pw3270_dbus_get_session_handle(object),buffer,sz)); + return; + } + + dbus_g_method_return(context,""); + +} + +void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context) +{ + int sz = strlen(from); + + if(sz > 0) + { + unsigned char buffer[sz+1]; + memcpy(buffer,from,sz); + dbus_g_method_return(context,lib3270_asc2ebc(pw3270_dbus_get_session_handle(object),buffer,sz)); + return; + } + + dbus_g_method_return(context,""); + +} + +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) +{ + /* + dbus_g_method_return(context, + v3270_transfer_file( + v3270_get_default_widget(), + (LIB3270_FT_OPTION) flags, + local, + remote, + lrecl, + blksize, + primspace, + secspace, + dft + )); + */ + return; +} + diff --git a/src/plugin/linux/iocallback.c b/src/plugin/linux/iocallback.c new file mode 100644 index 0000000..5292f4c --- /dev/null +++ b/src/plugin/linux/iocallback.c @@ -0,0 +1,361 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como iocallback.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#if defined(_WIN32) /*[*/ + #include +#elif defined(__APPLE__) + #include + #include +#else + #include + #include +#endif /*]*/ + +#include +#include +#include "daemon.h" + +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); +static void static_RemoveSource(void *id); + +static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); +static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); + +static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); +static void static_RemoveTimeOut(void * timer); +static int static_Sleep(H3270 *hSession, int seconds); +static int static_RunPendingEvents(H3270 *hSession, int wait); + +static gboolean IO_prepare(GSource *source, gint *timeout); +static gboolean IO_check(GSource *source); +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); +static void IO_finalize(GSource *source); /* Can be NULL */ +static gboolean IO_closure(gpointer data); + +/*---[ Structs ]-------------------------------------------------------------------------------------------*/ + + typedef struct _IO_Source + { + GSource gsrc; + GPollFD poll; +#if defined(_WIN32) + HANDLE source; +#else + int source; +#endif // _WIN32 + void (*fn)(H3270 *session); + H3270 *session; + } IO_Source; + + typedef struct _timer + { + unsigned char remove; + void (*fn)(H3270 *session); + H3270 *session; + } TIMER; + + static GSourceFuncs IOSources = + { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL + }; + +/*---[ Implement ]-----------------------------------------------------------------------------------------*/ + +#ifdef _WIN32 +static void * AddSource(HANDLE source, H3270 *session, gushort events, void (*fn)(H3270 *session)) +#else +static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session)) +#endif // _WIN32 +{ + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); + + src->source = source; + src->fn = fn; + src->poll.fd = (int) source; + src->poll.events = events; + src->session = session; + + g_source_attach((GSource *) src,NULL); + g_source_add_poll((GSource *) src,&src->poll); + + return src; +} + +#ifdef _WIN32 +static void * static_AddInput(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) +#else +static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)) +#endif // _WIN32 +{ + return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); +} + +static void static_RemoveSource(void *id) +{ + if(id) + g_source_destroy((GSource *) id); +} + +#if defined(_WIN32) +static void * static_AddExcept(HANDLE source, H3270 *session, void (*fn)(H3270 *session)) +{ + return 0; +} +#else +static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) +{ + return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); +} +#endif // _WIN32 + +static gboolean do_timer(TIMER *t) +{ + if(!t->remove) + t->fn(t->session); + return FALSE; +} + +static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*proc)(H3270 *session)) +{ + TIMER *t = g_malloc0(sizeof(TIMER)); + + t->fn = proc; + t->session = session; + + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free); + + return t; +} + +static void static_RemoveTimeOut(void * timer) +{ + ((TIMER *) timer)->remove++; +} + +static gboolean IO_prepare(GSource *source, gint *timeout) +{ + /* + * Called before all the file descriptors are polled. + * If the source can determine that it is ready here + * (without waiting for the results of the poll() call) + * it should return TRUE. + * + * It can also return a timeout_ value which should be the maximum + * timeout (in milliseconds) which should be passed to the poll() call. + * The actual timeout used will be -1 if all sources returned -1, + * or it will be the minimum of all the timeout_ values + * returned which were >= 0. + * + */ + return 0; +} + +static gboolean IO_check(GSource *source) +{ + /* + * Called after all the file descriptors are polled. + * The source should return TRUE if it is ready to be dispatched. + * Note that some time may have passed since the previous prepare + * function was called, so the source should be checked again here. + * + */ +#if defined(_WIN32) /*[*/ + + if(WaitForSingleObject(((IO_Source *) source)->source,0) == WAIT_OBJECT_0) + return TRUE; + +#else /*][*/ + + struct pollfd fds; + + memset(&fds,0,sizeof(fds)); + + fds.fd = ((IO_Source *) source)->poll.fd; + fds.events = ((IO_Source *) source)->poll.events; + + if(poll(&fds,1,0) > 0) + return TRUE; + +#endif /*]*/ + + return FALSE; +} + +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) +{ + /* + * Called to dispatch the event source, + * after it has returned TRUE in either its prepare or its check function. + * The dispatch function is passed in a callback function and data. + * The callback function may be NULL if the source was never connected + * to a callback using g_source_set_callback(). The dispatch function + * should call the callback function with user_data and whatever additional + * parameters are needed for this type of event source. + */ + ((IO_Source *) source)->fn(((IO_Source *) source)->session); + return TRUE; +} + +static void IO_finalize(GSource *source) +{ + +} + +static gboolean IO_closure(gpointer data) +{ + return 0; +} + +struct bgParameter +{ + gboolean running; + gboolean timer; + H3270 *session; + int rc; + int(*callback)(H3270 *session, void *); + void *parm; + +}; + +gpointer BgCall(struct bgParameter *p) +{ +// trace("%s starts",__FUNCTION__); + p->rc = p->callback(p->session, p->parm); + p->running = FALSE; +// trace("%s ends",__FUNCTION__); + return 0; +} + +static gboolean wait_for_thread(struct bgParameter *p) +{ + if(!p->running) + { + p->timer = 0; + return FALSE; + } + return TRUE; +} + +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm) +{ + struct bgParameter p = { TRUE, TRUE, session, -1, callback, parm }; + GThread * thread; + +// trace("Starting auxiliary thread for callback %p",callback); + + p.running = TRUE; + p.timer = TRUE; + + thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL); + + if(!thread) + { + g_error("Can't start background thread"); + return -1; + } + + g_timeout_add(50,(GSourceFunc) wait_for_thread,(gpointer) &p); + + while(p.timer) + g_main_context_iteration(g_main_loop_get_context(main_loop),TRUE); + + return p.rc; +} + +static int static_Sleep(H3270 *hSession, int seconds) +{ + time_t end = time(0) + seconds; + + while(time(0) < end) + g_main_iteration(TRUE); + + return 0; +} + +static int static_RunPendingEvents(H3270 *hSession, int wait) +{ + GMainContext *context = g_main_loop_get_context(main_loop); + int rc = 0; + while(g_main_context_pending(context)) + { + rc = 1; + g_main_context_iteration(context,FALSE); + } + + if(wait) + g_main_context_iteration(context,TRUE); + + return rc; +} + +static void beep(H3270 *session) +{ +} + +void pw3270_dbus_register_io_handlers(void) +{ + static const struct lib3270_callbacks hdl = + { + sizeof(struct lib3270_callbacks), + + static_AddTimeOut, + static_RemoveTimeOut, + + static_AddInput, + static_RemoveSource, + + static_AddExcept, + +#ifdef G_THREADS_ENABLED + static_CallAndWait, +#else + NULL, +#endif + + static_Sleep, + static_RunPendingEvents, + beep + + }; + + #error Need rewrite + + if(lib3270_register_handlers(&hdl)) + { + g_error("%s","Can't set lib3270 I/O handlers"); + } + +} diff --git a/src/plugin/linux/main.c b/src/plugin/linux/main.c new file mode 100644 index 0000000..d24d358 --- /dev/null +++ b/src/plugin/linux/main.c @@ -0,0 +1,172 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como main.c e possui - linhas de código. + * + * Referências: + * + * https://github.com/fbuihuu/samples-dbus/blob/master/dbus-server.c + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#include +#include +#include +#include + +#include +#include + +#include "service.h" +#include "dbus-glue.h" + +#include + +/*---[ Globals ]---------------------------------------------------------------------------------*/ + + static DBusGConnection * connection = NULL; + static DBusGProxy * proxy = NULL; + static gchar * service_name = NULL; + + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + + LIB3270_EXPORT int pw3270_plugin_start(GtkWidget *window, GtkWidget *terminal) + { + + GError * error = NULL; + guint result; + char session_id = 0; + char id = 'a'; + + connection = dbus_g_bus_get_private(DBUS_BUS_SESSION, g_main_context_default(), &error); + if(error) + { + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't connect to DBUS server" )); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); + + g_message("Error \"%s\" getting session dbus",error->message); + + g_error_free(error); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS); + + for(id='a'; id < 'z' && !error && !service_name; id++) + { + gboolean has_owner = FALSE; + + service_name = g_strdup_printf("br.com.bb.%s.%c",pw3270_get_session_name(window),(int) id); + + org_freedesktop_DBus_name_has_owner(proxy, service_name, &has_owner, NULL); + + if(has_owner) + { + trace("Service \"%s\" has owner",service_name) + g_free(service_name); + service_name = NULL; + } + else + { + session_id = id; + g_message("DBUS service name is %s",service_name); + org_freedesktop_DBus_request_name(proxy, service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); + } + } + + if(error) + { + GtkWidget *dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _( "Can't get DBUS object name" )); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); + + g_message("Error \"%s\" requesting DBUS name",error->message); + + g_error_free(error); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + return -1; + } + + if(session_id) + { + gchar * path = g_strdup_printf("/br/com/bb/%s",pw3270_get_session_name(window)); + gchar * session = g_strdup_printf("%s:%c",pw3270_get_session_name(window),g_ascii_toupper(session_id)); + pw3270_set_session_name(window,session); + g_free(session); + + g_message("DBUS service path is %s",path); + + pw3270_dbus_register_object(connection,proxy,PW3270_TYPE_DBUS,&dbus_glib_pw3270_dbus_object_info,path); + + g_free(path); + } + + return 0; + } + + LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window, GtkWidget *terminal) + { + if(service_name) + { + // org_freedesktop_DBus_release_name + + g_free(service_name); + service_name = NULL; + } + return 0; + } + + void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context) + { + gtk_main_quit(); + dbus_g_method_return(context,0); + } + + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object) + { + return lib3270_get_default_session_handle(); + } + + + diff --git a/src/plugin/linux/misc.c b/src/plugin/linux/misc.c new file mode 100644 index 0000000..0e73503 --- /dev/null +++ b/src/plugin/linux/misc.c @@ -0,0 +1,47 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como misc.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + +#include "globals.h" + +/*---[ Implement ]-------------------------------------------------------------------------------*/ + +gpointer pw3270_dbus_register_object(DBusGConnection *connection,DBusGProxy *proxy,GType object_type,const DBusGObjectInfo *info,const gchar *path) +{ + GObject *object = g_object_new (object_type, NULL); + dbus_g_object_type_install_info (object_type, info); + dbus_g_connection_register_g_object (connection, path, object); + return object; +} + diff --git a/src/plugin/linux/service.h b/src/plugin/linux/service.h new file mode 100644 index 0000000..aba8322 --- /dev/null +++ b/src/plugin/linux/service.h @@ -0,0 +1,138 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como service.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#ifndef _PW3270_DBUS_SERVICE_H + + #define _PW3270_DBUS_SERVICE_H 1 + + #define ENABLE_NLS + #define GETTEXT_PACKAGE PACKAGE_NAME + + #include "globals.h" + + #define PW3270_TYPE_DBUS (pw3270_dbus_get_type ()) + #define PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PW3270_TYPE_DBUS, PW3270Dbus)) + #define PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DBUS, PW3270DbusClass)) + #define IS_PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PW3270_TYPE_DBUS)) + #define IS_PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DBUS)) + #define PW3270_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DBUS, PW3270DbusClass)) + + G_BEGIN_DECLS + + typedef struct _PW3270Dbus PW3270Dbus; + typedef struct _PW3270DbusClass PW3270DbusClass; + + struct _PW3270Dbus + { + GObject parent; + }; + + struct _PW3270DbusClass + { + GObjectClass parent; + }; + + PW3270Dbus * pw3270_dbus_new (void); + GType pw3270_dbus_get_type (void); + + void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); + void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context); + void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context); + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object); + GError * pw3270_dbus_get_error_from_errno(int code); + + void pw3270_dbus_is_connected(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context); + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context); + + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context); + + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context); + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context); + + void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context); + + void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context); + + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); + + // Actions + void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); + void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context); + void pw3270_dbus_set_text_at(PW3270Dbus *object, int row, int col, const gchar *text, DBusGMethodInvocation *context); + void pw3270_dbus_get_text_at(PW3270Dbus *object, int row, int col, int len, char lf, DBusGMethodInvocation *context); + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, char lf, DBusGMethodInvocation *context); + void pw3270_dbus_cmp_text_at(PW3270Dbus *object, int row, int col, const gchar *text, char lf, DBusGMethodInvocation *context); + void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context); + + void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context); + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context); + void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context); + + void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); + void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context); + + 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); + + void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context); + + G_END_DECLS + +#endif // _PW3270_DBUS_SERVICE_H diff --git a/src/plugin/windows/resources.rc.in b/src/plugin/windows/resources.rc.in new file mode 100644 index 0000000..e3675ae --- /dev/null +++ b/src/plugin/windows/resources.rc.in @@ -0,0 +1,29 @@ +#include + +VS_VERSION_INFO VERSIONINFO +FILEVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0 +PRODUCTVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0 + +BEGIN + + BLOCK "StringFileInfo" + BEGIN + BLOCK "080904E4" + BEGIN + VALUE "FileDescription", "@PACKAGE_NAME@ IPC Plugin\0" + VALUE "CompanyName", "Banco do Brasil S/A.\0" + VALUE "FileVersion", "@WIN32_VERSION@\0" + VALUE "LegalCopyright", "(C) 2017 Banco do Brasil S/A. All Rights Reserved\0" + VALUE "OriginalFilename", "ipc3270@DLLEXT@\0" + VALUE "ProductName", "@PACKAGE_NAME@\0" + VALUE "ProductVersion", "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.0\0" + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x809, 0x04E4 + END + +END + -- libgit2 0.21.2