Commit 59419215f1be4bd094cf70b09a1602652e83045f

Authored by Perry Werneck
1 parent 40091dae
Exists in master

Importando fontes iniciais.

.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +*.bak
  2 +*.depend
  3 +*.layout
  4 +*.[0-9]
  5 +
... ...
pw3270d.cbp 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2 +<CodeBlocks_project_file>
  3 + <FileVersion major="1" minor="6" />
  4 + <Project>
  5 + <Option title="Gateway pw3270" />
  6 + <Option pch_mode="2" />
  7 + <Option compiler="gcc" />
  8 + <Build>
  9 + <Target title="Debug">
  10 + <Option output=".bin/Debug/pw3270d" prefix_auto="1" extension_auto="1" />
  11 + <Option object_output=".obj/Debug/" />
  12 + <Option type="1" />
  13 + <Option compiler="gcc" />
  14 + <Compiler>
  15 + <Add option="-g" />
  16 + <Add option="-DDEBUG=1" />
  17 + </Compiler>
  18 + </Target>
  19 + <Target title="Release">
  20 + <Option output=".bin/Release/pw3270d" prefix_auto="1" extension_auto="1" />
  21 + <Option object_output=".obj/Release/" />
  22 + <Option type="1" />
  23 + <Option compiler="gcc" />
  24 + <Compiler>
  25 + <Add option="-O2" />
  26 + <Add option="-DNDEBUG=1" />
  27 + </Compiler>
  28 + <Linker>
  29 + <Add option="-s" />
  30 + </Linker>
  31 + </Target>
  32 + </Build>
  33 + <Compiler>
  34 + <Add option="-Wall" />
  35 + <Add option="`pkg-config --cflags dbus-glib-1 glib-2.0 dbus-1 lib3270`" />
  36 + </Compiler>
  37 + <Linker>
  38 + <Add option="`pkg-config --libs dbus-glib-1 glib-2.0 dbus-1 lib3270`" />
  39 + </Linker>
  40 + <ExtraCommands>
  41 + <Add before="dbus-binding-tool --mode=glib-server --output=src/dbus-glue.h --prefix=pw3270_dbus src/pw3270service.xml" />
  42 + </ExtraCommands>
  43 + <Unit filename="src/gobject.c">
  44 + <Option compilerVar="CC" />
  45 + </Unit>
  46 + <Unit filename="src/iocallback.c">
  47 + <Option compilerVar="CC" />
  48 + </Unit>
  49 + <Unit filename="src/main.c">
  50 + <Option compilerVar="CC" />
  51 + </Unit>
  52 + <Unit filename="src/private.h" />
  53 + <Unit filename="src/pw3270service.xml" />
  54 + <Unit filename="src/service.h" />
  55 + <Unit filename="src/session.c">
  56 + <Option compilerVar="CC" />
  57 + </Unit>
  58 + <Unit filename="src/tn3270glue.c">
  59 + <Option compilerVar="CC" />
  60 + </Unit>
  61 + <Extensions>
  62 + <code_completion />
  63 + <envvars />
  64 + <debugger />
  65 + </Extensions>
  66 + </Project>
  67 +</CodeBlocks_project_file>
... ...
src/gobject.c 0 → 100644
... ... @@ -0,0 +1,282 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como gobject.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + * Referencias:
  28 + *
  29 + * https://live.gnome.org/DBusGlibBindings
  30 + *
  31 + */
  32 +
  33 +#include <glib.h>
  34 +#include <dbus/dbus.h>
  35 +#include <dbus/dbus-glib-lowlevel.h>
  36 +#include <dbus/dbus-glib.h>
  37 +
  38 +#include <lib3270.h>
  39 +#include <lib3270/actions.h>
  40 +
  41 +#include "service.h"
  42 +
  43 +/*---[ Globals ]---------------------------------------------------------------------------------*/
  44 +
  45 +
  46 +/*---[ Implement ]-------------------------------------------------------------------------------*/
  47 +
  48 +G_DEFINE_TYPE(PW3270Dbus, pw3270_dbus, G_TYPE_OBJECT)
  49 +
  50 +static void pw3270_dbus_finalize(GObject *object) {
  51 + G_OBJECT_CLASS(pw3270_dbus_parent_class)->finalize (object);
  52 +}
  53 +
  54 +static void pw3270_dbus_class_init(PW3270DbusClass *klass) {
  55 + GObjectClass *object_class;
  56 + object_class = G_OBJECT_CLASS (klass);
  57 + object_class->finalize = pw3270_dbus_finalize;
  58 +}
  59 +
  60 +static void pw3270_dbus_init(PW3270Dbus *object) {
  61 +
  62 +}
  63 +
  64 +PW3270Dbus * pw3270_dbus_new(void) {
  65 + g_message("Creating D-Bus proxy");
  66 + return g_object_new(PW3270_TYPE_DBUS, NULL);
  67 +}
  68 +
  69 +static void pw3270_dbus_return_error(DBusGMethodInvocation *context, int err) {
  70 + GError *error = g_error_new(ERROR_DOMAIN,err,"%s",g_strerror(err));
  71 + dbus_g_method_return_error(context,error);
  72 + g_error_free(error);
  73 +}
  74 +
  75 +void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context) {
  76 + dbus_g_method_return(context,lib3270_get_revision());
  77 +}
  78 +
  79 +void pw3270_dbus_get_version(PW3270Dbus *object, DBusGMethodInvocation *context) {
  80 + dbus_g_method_return(context,lib3270_get_version());
  81 +}
  82 +
  83 +void pw3270_dbus_create_session(PW3270Dbus *object, DBusGMethodInvocation *context) {
  84 +
  85 + struct session * ses = session_new();
  86 + gchar * key = g_strdup_printf("%p-%u",ses,ses->id);
  87 +
  88 + dbus_g_method_return(context,key);
  89 +
  90 + g_free(key);
  91 +}
  92 +
  93 +void pw3270_dbus_destroy_session(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  94 +
  95 + struct session * ses = session_find(id);
  96 +
  97 + if(!ses) {
  98 + dbus_g_method_return(context,ENOENT);
  99 + return;
  100 + }
  101 +
  102 + session_destroy(ses);
  103 +
  104 + dbus_g_method_return(context,0);
  105 +}
  106 +
  107 +void pw3270_dbus_connect(PW3270Dbus *object, const gchar *id, const gchar *uri, DBusGMethodInvocation *context) {
  108 +
  109 + struct session * ses = session_find(id);
  110 +
  111 + if(!ses) {
  112 + pw3270_dbus_return_error(context,ENOENT);
  113 + return;
  114 + }
  115 +
  116 + if(uri && *uri) {
  117 + lib3270_set_url(ses->host,uri);
  118 + }
  119 +
  120 + dbus_g_method_return(context,lib3270_connect(ses->host,0));
  121 +
  122 +}
  123 +
  124 +void pw3270_dbus_disconnect(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  125 +
  126 + struct session * ses = session_find(id);
  127 +
  128 + if(!ses) {
  129 + pw3270_dbus_return_error(context,ENOENT);
  130 + return;
  131 + }
  132 +
  133 + dbus_g_method_return(context,lib3270_disconnect(ses->host));
  134 +}
  135 +
  136 +void pw3270_dbus_enter(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  137 +
  138 + struct session * ses = session_find(id);
  139 +
  140 + if(!ses) {
  141 + pw3270_dbus_return_error(context,ENOENT);
  142 + return;
  143 + }
  144 +
  145 + dbus_g_method_return(context,lib3270_enter(ses->host));
  146 +}
  147 +
  148 +void pw3270_dbus_pf_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context) {
  149 +
  150 + struct session * ses = session_find(id);
  151 +
  152 + if(!ses) {
  153 + pw3270_dbus_return_error(context,ENOENT);
  154 + return;
  155 + }
  156 +
  157 + dbus_g_method_return(context,lib3270_pfkey(ses->host,key));
  158 +}
  159 +
  160 +void pw3270_dbus_pa_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context) {
  161 +
  162 + struct session * ses = session_find(id);
  163 +
  164 + if(!ses) {
  165 + pw3270_dbus_return_error(context,ENOENT);
  166 + return;
  167 + }
  168 +
  169 + dbus_g_method_return(context,lib3270_pakey(ses->host,key));
  170 +}
  171 +
  172 +void pw3270_dbus_set_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) {
  173 +
  174 + gchar * text;
  175 + struct session * ses = session_find(id);
  176 +
  177 + if(!ses) {
  178 + pw3270_dbus_return_error(context,ENOENT);
  179 + return;
  180 + }
  181 +
  182 + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(ses->host),"UTF-8","?",NULL,NULL,NULL);
  183 +
  184 + dbus_g_method_return(context,lib3270_set_string_at(ses->host,row,col,(const unsigned char *) text));
  185 +
  186 + g_free(text);
  187 +}
  188 +
  189 +void pw3270_dbus_get_text_at(PW3270Dbus *object, const gchar *id, int row, int col, int len, DBusGMethodInvocation *context) {
  190 +
  191 + gchar *text;
  192 + struct session * ses = session_find(id);
  193 +
  194 + if(!ses) {
  195 + pw3270_dbus_return_error(context,ENOENT);
  196 + return;
  197 + }
  198 +
  199 + text = lib3270_get_text_at(ses->host, row, col, len);
  200 + if(!text) {
  201 +
  202 + pw3270_dbus_return_error(context,errno);
  203 +
  204 + } else {
  205 +
  206 + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(ses->host),"?",NULL,NULL,NULL);
  207 + lib3270_free(text);
  208 + dbus_g_method_return(context,utftext);
  209 + g_free(utftext);
  210 +
  211 + }
  212 +
  213 +}
  214 +
  215 +void pw3270_dbus_is_ready(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  216 +
  217 + struct session * ses = session_find(id);
  218 +
  219 + if(!ses) {
  220 + pw3270_dbus_return_error(context,ENOENT);
  221 + return;
  222 + }
  223 +
  224 + dbus_g_method_return(context,lib3270_is_ready(ses->host));
  225 +}
  226 +
  227 +void pw3270_dbus_chk_id(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  228 +
  229 + struct session * ses = session_find(id);
  230 +
  231 + if(!ses) {
  232 + dbus_g_method_return(context,ENOENT);
  233 + return;
  234 + }
  235 +
  236 + dbus_g_method_return(context,0);
  237 +
  238 +}
  239 +
  240 +void pw3270_dbus_cmp_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) {
  241 +
  242 + gchar * text;
  243 + struct session * ses = session_find(id);
  244 +
  245 + if(!ses) {
  246 + pw3270_dbus_return_error(context,ENOENT);
  247 + return;
  248 + }
  249 +
  250 + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(ses->host),"UTF-8","?",NULL,NULL,NULL);
  251 +
  252 + dbus_g_method_return(context,lib3270_cmp_text_at(ses->host,row,col,text));
  253 +
  254 + g_free(text);
  255 +
  256 +}
  257 +
  258 +void pw3270_dbus_is_connected(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  259 +
  260 + struct session * ses = session_find(id);
  261 +
  262 + if(!ses) {
  263 + pw3270_dbus_return_error(context,ENOENT);
  264 + return;
  265 + }
  266 +
  267 + dbus_g_method_return(context,lib3270_is_connected(ses->host));
  268 +
  269 +}
  270 +
  271 +void pw3270_dbus_get_connection_state(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) {
  272 +
  273 + struct session * ses = session_find(id);
  274 +
  275 + if(!ses) {
  276 + pw3270_dbus_return_error(context,ENOENT);
  277 + return;
  278 + }
  279 +
  280 + dbus_g_method_return(context,lib3270_get_connection_state(ses->host));
  281 +
  282 +}
... ...
src/iocallback.c 0 → 100644
... ... @@ -0,0 +1,277 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como iocallback.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 +#include "private.h"
  30 +#include <lib3270.h>
  31 +#include <poll.h>
  32 +#include <string.h>
  33 +
  34 +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata);
  35 +static void static_RemoveSource(H3270 *session, void *id);
  36 +
  37 +static void * static_AddTimeOut(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session));
  38 +static void static_RemoveTimeOut(H3270 *session, void * timer);
  39 +static int static_Sleep(H3270 *hSession, int seconds);
  40 +static int static_RunPendingEvents(H3270 *hSession, int wait);
  41 +
  42 +static gboolean IO_prepare(GSource *source, gint *timeout);
  43 +static gboolean IO_check(GSource *source);
  44 +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
  45 +static void IO_finalize(GSource *source); /* Can be NULL */
  46 +static gboolean IO_closure(gpointer data);
  47 +
  48 +/*---[ Structs ]-------------------------------------------------------------------------------------------*/
  49 +
  50 + typedef struct _IO_Source {
  51 + GSource gsrc;
  52 + GPollFD poll;
  53 + int fd;
  54 + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *);
  55 + H3270 *session;
  56 + void *userdata;
  57 + } IO_Source;
  58 +
  59 + typedef struct _timer {
  60 + unsigned char remove;
  61 + void * userdata;
  62 + void (*call)(H3270 *session);
  63 + H3270 * session;
  64 + } TIMER;
  65 +
  66 + static GSourceFuncs IOSources = {
  67 + IO_prepare,
  68 + IO_check,
  69 + IO_dispatch,
  70 + IO_finalize,
  71 + IO_closure,
  72 + NULL
  73 + };
  74 +
  75 +/*---[ Implement ]-----------------------------------------------------------------------------------------*/
  76 +
  77 +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) {
  78 +
  79 + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source));
  80 +
  81 + src->fd = fd;
  82 + src->call = call;
  83 + src->userdata = userdata;
  84 + src->session = session;
  85 +
  86 + src->poll.fd = (int) fd;
  87 + src->poll.events = G_IO_HUP|G_IO_ERR;
  88 +
  89 + if(flag & LIB3270_IO_FLAG_READ)
  90 + src->poll.events |= G_IO_IN;
  91 +
  92 + if(flag & LIB3270_IO_FLAG_WRITE)
  93 + src->poll.events |= G_IO_OUT;
  94 +
  95 + g_source_attach((GSource *) src,NULL);
  96 + g_source_add_poll((GSource *) src,&src->poll);
  97 +
  98 + return src;
  99 +}
  100 +
  101 +static void static_RemoveSource(H3270 *session, void *id) {
  102 + if(id)
  103 + g_source_destroy((GSource *) id);
  104 +}
  105 +
  106 +static gboolean do_timer(TIMER *t) {
  107 + if(!t->remove)
  108 + t->call(t->session);
  109 + return FALSE;
  110 +}
  111 +
  112 +static void * static_AddTimeOut(H3270 *session, unsigned long interval, void (*call)(H3270 *session)) {
  113 + TIMER *t = g_malloc0(sizeof(TIMER));
  114 +
  115 + t->call = call;
  116 + t->session = session;
  117 +
  118 + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free);
  119 +
  120 + return t;
  121 +}
  122 +
  123 +static void static_RemoveTimeOut(H3270 *session, void * timer) {
  124 + ((TIMER *) timer)->remove++;
  125 +}
  126 +
  127 +static gboolean IO_prepare(GSource *source, gint *timeout) {
  128 + /*
  129 + * Called before all the file descriptors are polled.
  130 + * If the source can determine that it is ready here
  131 + * (without waiting for the results of the poll() call)
  132 + * it should return TRUE.
  133 + *
  134 + * It can also return a timeout_ value which should be the maximum
  135 + * timeout (in milliseconds) which should be passed to the poll() call.
  136 + * The actual timeout used will be -1 if all sources returned -1,
  137 + * or it will be the minimum of all the timeout_ values
  138 + * returned which were >= 0.
  139 + *
  140 + */
  141 + return 0;
  142 +}
  143 +
  144 +static gboolean IO_check(GSource *source) {
  145 + /*
  146 + * Called after all the file descriptors are polled.
  147 + * The source should return TRUE if it is ready to be dispatched.
  148 + * Note that some time may have passed since the previous prepare
  149 + * function was called, so the source should be checked again here.
  150 + *
  151 + */
  152 +#ifdef _WIN32
  153 +
  154 + fd_set rfds, wfds;
  155 + struct timeval tm;
  156 +
  157 + memset(&tm,0,sizeof(tm));
  158 +
  159 + FD_ZERO(&rfds);
  160 + FD_ZERO(&wfds);
  161 +// FD_ZERO(&xfds);
  162 +
  163 + if(((IO_Source *) source)->poll.events & G_IO_IN) {
  164 + FD_SET(((IO_Source *) source)->poll.fd, &rfds);
  165 + }
  166 +
  167 + if(((IO_Source *) source)->poll.events & G_IO_OUT) {
  168 + FD_SET(((IO_Source *) source)->poll.fd, &wfds);
  169 + }
  170 +
  171 + if(select(((IO_Source *) source)->poll.fd+1, &rfds, &wfds, NULL, &tm) > 0)
  172 + return TRUE;
  173 +
  174 +#else
  175 +
  176 + struct pollfd fds;
  177 +
  178 + memset(&fds,0,sizeof(fds));
  179 +
  180 + fds.fd = ((IO_Source *) source)->poll.fd;
  181 + fds.events = ((IO_Source *) source)->poll.events;
  182 +
  183 + if(poll(&fds,1,0) > 0)
  184 + return TRUE;
  185 +
  186 +#endif // _WIN32
  187 +
  188 + return FALSE;
  189 +}
  190 +
  191 +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
  192 + /*
  193 + * Called to dispatch the event source,
  194 + * after it has returned TRUE in either its prepare or its check function.
  195 + * The dispatch function is passed in a callback function and data.
  196 + * The callback function may be NULL if the source was never connected
  197 + * to a callback using g_source_set_callback(). The dispatch function
  198 + * should call the callback function with user_data and whatever additional
  199 + * parameters are needed for this type of event source.
  200 + */
  201 + IO_Source *obj = (IO_Source *) source;
  202 +
  203 + obj->call(obj->session,obj->fd,0,obj->userdata);
  204 +
  205 + return TRUE;
  206 +}
  207 +
  208 +static void IO_finalize(GSource *source) {
  209 +
  210 +}
  211 +
  212 +static gboolean IO_closure(gpointer data) {
  213 + return 0;
  214 +}
  215 +
  216 +struct bgParameter {
  217 + gboolean running;
  218 + H3270 *session;
  219 + int rc;
  220 + int(*callback)(H3270 *session, void *);
  221 + void *parm;
  222 +
  223 +};
  224 +
  225 +gpointer BgCall(struct bgParameter *p) {
  226 +// trace("%s starts",__FUNCTION__);
  227 + p->rc = p->callback(p->session, p->parm);
  228 + p->running = FALSE;
  229 +// trace("%s ends",__FUNCTION__);
  230 + return 0;
  231 +}
  232 +
  233 +static int static_Sleep(H3270 *hSession, int seconds) {
  234 + time_t end = time(0) + seconds;
  235 +
  236 + while(time(0) < end) {
  237 + g_main_context_iteration(NULL, TRUE);
  238 + }
  239 +
  240 + return 0;
  241 +}
  242 +
  243 +static int static_RunPendingEvents(H3270 *hSession, int wait) {
  244 +
  245 + int rc = 0;
  246 + while(g_main_context_iteration(NULL, wait ? TRUE : FALSE)) {
  247 + rc = 1;
  248 + }
  249 +
  250 + return rc;
  251 +}
  252 +
  253 +static void beep(H3270 *session) {
  254 +}
  255 +
  256 +void register_3270_io_handlers(void) {
  257 + static const struct lib3270_callbacks hdl = {
  258 +
  259 + sizeof(struct lib3270_callbacks),
  260 +
  261 + static_AddTimeOut,
  262 + static_RemoveTimeOut,
  263 +
  264 + static_AddSource,
  265 + static_RemoveSource,
  266 +
  267 + static_Sleep,
  268 + static_RunPendingEvents,
  269 + beep
  270 +
  271 + };
  272 +
  273 + if(lib3270_register_handlers(&hdl)) {
  274 + g_error("%s","Can't set lib3270 I/O handlers");
  275 + }
  276 +
  277 +}
... ...
src/main.c 0 → 100644
... ... @@ -0,0 +1,170 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como main.c e possui - linhas de código.
  22 + *
  23 + * Referencias:
  24 + *
  25 + * https://live.gnome.org/DBusGlibBindings
  26 + *
  27 + * Contatos:
  28 + *
  29 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  30 + *
  31 + */
  32 +
  33 +#include <glib.h>
  34 +#include <glib-object.h>
  35 +#include <dbus/dbus.h>
  36 +#include <dbus/dbus-glib.h>
  37 +#include <dbus/dbus-glib-bindings.h>
  38 +
  39 +#include "service.h"
  40 +#include "dbus-glue.h"
  41 +
  42 +#include "private.h"
  43 +#ifdef DEBUG
  44 + #include <stdio.h>
  45 +#endif // DEBUG
  46 +
  47 +#if defined( HAVE_SYSLOG )
  48 + #include <syslog.h>
  49 +#endif // HAVE_SYSLOG
  50 +
  51 +#ifdef DEBUG
  52 + static GBusType bustype = G_BUS_TYPE_SESSION;
  53 +#else
  54 + static GBusType bustype = G_BUS_TYPE_SYSTEM;
  55 +#endif // DEBUG
  56 +
  57 +static DBusGConnection * connection = NULL;
  58 +static DBusGProxy * proxy = NULL;
  59 +
  60 +GMainLoop * main_loop = NULL;
  61 +
  62 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  63 +
  64 +#if defined( HAVE_SYSLOG )
  65 +static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
  66 +{
  67 + static const struct _logtype
  68 + {
  69 + GLogLevelFlags log_level;
  70 + int priority;
  71 + const gchar * msg;
  72 + } logtype[] =
  73 + {
  74 + { G_LOG_FLAG_RECURSION, LOG_INFO, "recursion" },
  75 + { G_LOG_FLAG_FATAL, LOG_ERR, "fatal error" },
  76 +
  77 + /* GLib log levels */
  78 + { G_LOG_LEVEL_ERROR, LOG_ERR, "error" },
  79 + { G_LOG_LEVEL_CRITICAL, LOG_ERR, "critical error" },
  80 + { G_LOG_LEVEL_WARNING, LOG_ERR, "warning" },
  81 + { G_LOG_LEVEL_MESSAGE, LOG_ERR, "message" },
  82 + { G_LOG_LEVEL_INFO, LOG_INFO, "info" },
  83 + { G_LOG_LEVEL_DEBUG, LOG_DEBUG, "debug" },
  84 + };
  85 +
  86 + int f;
  87 +
  88 + for(f=0;f<G_N_ELEMENTS(logtype);f++)
  89 + {
  90 + if(logtype[f].log_level == log_level)
  91 + {
  92 + gchar *ptr;
  93 + gchar *text = g_strdup_printf("%s: %s %s",logtype[f].msg,log_domain ? log_domain : "",message);
  94 + for(ptr = text;*ptr;ptr++)
  95 + {
  96 + if(*ptr < ' ')
  97 + *ptr = ' ';
  98 + }
  99 +
  100 + syslog(logtype[f].priority,"%s",text);
  101 + g_free(text);
  102 + return;
  103 + }
  104 + }
  105 +
  106 + #ifdef DEBUG
  107 + fprintf(stderr,"%s\n",message);
  108 + fflush(stderr);
  109 + #endif // DEBUG
  110 +
  111 + syslog(LOG_INFO,"%s %s",log_domain ? log_domain : "", message);
  112 +}
  113 +#endif // HAVE_SYSLOG
  114 +
  115 +static gboolean do_idle_check(gpointer dunno) {
  116 + session_check_for_timeout();
  117 + return TRUE;
  118 +}
  119 +
  120 +static int initialize(void) {
  121 +
  122 + GError * error = NULL;
  123 + guint result;
  124 +
  125 + connection = dbus_g_bus_get_private(bustype, g_main_context_default(), &error);
  126 +
  127 + if(error) {
  128 + g_message("Error \"%s\" getting D-Bus connection",error->message);
  129 + g_error_free(error);
  130 + return -1;
  131 + }
  132 +
  133 + proxy = dbus_g_proxy_new_for_name(connection,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);
  134 +
  135 + org_freedesktop_DBus_request_name(proxy, PW3270_SERVICE_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);
  136 + if(error) {
  137 + g_message("Error \"%s\" getting D-Bus name",error->message);
  138 + g_error_free(error);
  139 + return -1;
  140 + }
  141 +
  142 + GType object_type = PW3270_TYPE_DBUS;
  143 + GObject *object = g_object_new (object_type, NULL);
  144 + dbus_g_object_type_install_info (object_type, &dbus_glib_pw3270_dbus_object_info);
  145 + dbus_g_connection_register_g_object (connection, PW3270_SERVICE_DBUS_SERVICE_PATH, object);
  146 +
  147 + g_timeout_add_seconds (1, do_idle_check, NULL);
  148 +
  149 + return 0;
  150 +}
  151 +
  152 +
  153 +
  154 +int main(int argc, char *argv[]) {
  155 +
  156 +#if defined( HAVE_SYSLOG )
  157 + openlog(g_get_prgname(), LOG_NDELAY, LOG_USER);
  158 + g_log_set_default_handler(g_syslog,NULL);
  159 +#endif // HAVE_SYSLOG
  160 +
  161 + initialize();
  162 + init_3270();
  163 +
  164 + main_loop = g_main_loop_new(NULL, FALSE);
  165 +
  166 + g_main_loop_run(main_loop);
  167 +
  168 + return 0;
  169 +
  170 + }
... ...
src/private.h 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como private.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 +#ifndef PRIVATE_H_INCLUDED
  30 +
  31 + #define PRIVATE_H_INCLUDED
  32 +
  33 + #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS")
  34 +
  35 + // #define HAVE_SYSLOG 1
  36 + #define PW3270_SERVICE_DBUS_SERVICE_PATH "/br/com/bb/pw3270/service"
  37 + #define PW3270_SERVICE_DBUS_SERVICE "br.com.bb.pw3270.service"
  38 +
  39 + #include <glib.h>
  40 + #include <gio/gio.h>
  41 + #include <lib3270.h>
  42 +
  43 + struct session {
  44 + unsigned int id; ///< @brief Identificador da sessão.
  45 + time_t activity; ///< @brief Timestamp da última atividade dessa sessão.
  46 + H3270 * host; ///< @brief Sessão TN3270.
  47 + };
  48 +
  49 + G_GNUC_INTERNAL GMainLoop * main_loop;
  50 +
  51 + G_GNUC_INTERNAL void init_3270(void);
  52 + G_GNUC_INTERNAL void register_3270_io_handlers(void);
  53 +
  54 + G_GNUC_INTERNAL struct session * session_new();
  55 + G_GNUC_INTERNAL struct session * session_find(const gchar *key);
  56 + G_GNUC_INTERNAL void session_destroy(struct session *ses);
  57 + G_GNUC_INTERNAL void session_check_for_timeout(void);
  58 +
  59 +#endif // PRIVATE_H_INCLUDED
... ...
src/pw3270service.xml 0 → 100644
... ... @@ -0,0 +1,114 @@
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +
  3 +<node name="/br/com/bb/pw3270/service">
  4 +
  5 + <interface name="br.com.bb.pw3270.service">
  6 +
  7 + <method name="getRevision">
  8 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  9 + <arg type="s" name="revision" direction="out" />
  10 + </method>
  11 +
  12 + <method name="getVersion">
  13 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  14 + <arg type="s" name="revision" direction="out" />
  15 + </method>
  16 +
  17 + <method name="createSession">
  18 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  19 + <arg type="s" name="id" direction="out" />
  20 + </method>
  21 +
  22 + <method name="destroySession">
  23 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  24 + <arg type="s" name="id" direction="in" />
  25 + <arg type="i" name="rc" direction="out" />
  26 + </method>
  27 +
  28 + <method name="connect">
  29 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  30 + <arg type="s" name="id" direction="in" />
  31 + <arg type="s" name="uri" direction="in" />
  32 + <arg type="i" name="rc" direction="out" />
  33 + </method>
  34 +
  35 + <method name="disconnect">
  36 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  37 + <arg type="s" name="id" direction="in" />
  38 + <arg type="i" name="rc" direction="out" />
  39 + </method>
  40 +
  41 + <method name="enter">
  42 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  43 + <arg type="s" name="id" direction="in" />
  44 + <arg type="i" name="result" direction="out" />
  45 + </method>
  46 +
  47 + <method name="pfKey">
  48 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  49 + <arg type="s" name="id" direction="in" />
  50 + <arg type="i" name="key" direction="in" />
  51 + <arg type="i" name="result" direction="out" />
  52 + </method>
  53 +
  54 + <method name="paKey">
  55 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  56 + <arg type="s" name="id" direction="in" />
  57 + <arg type="i" name="key" direction="in" />
  58 + <arg type="i" name="result" direction="out" />
  59 + </method>
  60 +
  61 + <method name="setTextAt">
  62 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  63 + <arg type="s" name="id" direction="in" />
  64 + <arg type="i" name="row" direction="in" />
  65 + <arg type="i" name="col" direction="in" />
  66 + <arg type="s" name="text" direction="in" />
  67 + <arg type="i" name="result" direction="out" />
  68 + </method>
  69 +
  70 + <method name="cmpTextAt">
  71 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  72 + <arg type="s" name="id" direction="in" />
  73 + <arg type="i" name="row" direction="in" />
  74 + <arg type="i" name="col" direction="in" />
  75 + <arg type="s" name="text" direction="in" />
  76 + <arg type="i" name="result" direction="out" />
  77 + </method>
  78 +
  79 + <method name="getTextAt">
  80 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  81 + <arg type="s" name="id" direction="in" />
  82 + <arg type="i" name="row" direction="in" />
  83 + <arg type="i" name="col" direction="in" />
  84 + <arg type="i" name="len" direction="in" />
  85 + <arg type="s" name="text" direction="out" />
  86 + </method>
  87 +
  88 + <method name="isReady">
  89 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  90 + <arg type="s" name="id" direction="in" />
  91 + <arg type="i" name="result" direction="out" />
  92 + </method>
  93 +
  94 + <method name="chkId">
  95 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  96 + <arg type="s" name="id" direction="in" />
  97 + <arg type="i" name="result" direction="out" />
  98 + </method>
  99 +
  100 + <method name="isConnected">
  101 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  102 + <arg type="s" name="id" direction="in" />
  103 + <arg type="i" name="result" direction="out" />
  104 + </method>
  105 +
  106 + <method name="getConnectionState">
  107 + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
  108 + <arg type="s" name="id" direction="in" />
  109 + <arg type="i" name="status" direction="out" />
  110 + </method>
  111 +
  112 + </interface>
  113 +
  114 +</node>
... ...
src/service.h 0 → 100644
... ... @@ -0,0 +1,151 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como service.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 +#ifndef _PW3270_DBUS_SERVICE_H
  30 +
  31 + #define _PW3270_DBUS_SERVICE_H 1
  32 +
  33 + #include "private.h"
  34 +
  35 + #define PW3270_TYPE_DBUS (pw3270_dbus_get_type ())
  36 + #define PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PW3270_TYPE_DBUS, PW3270Dbus))
  37 + #define PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_DBUS, PW3270DbusClass))
  38 + #define IS_PW3270_DBUS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PW3270_TYPE_DBUS))
  39 + #define IS_PW3270_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_DBUS))
  40 + #define PW3270_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_DBUS, PW3270DbusClass))
  41 +
  42 + G_BEGIN_DECLS
  43 +
  44 + typedef struct _PW3270Dbus PW3270Dbus;
  45 + typedef struct _PW3270DbusClass PW3270DbusClass;
  46 +
  47 + struct _PW3270Dbus
  48 + {
  49 + GObject parent;
  50 + };
  51 +
  52 + struct _PW3270DbusClass
  53 + {
  54 + GObjectClass parent;
  55 + };
  56 +
  57 + PW3270Dbus * pw3270_dbus_new (void);
  58 + GType pw3270_dbus_get_type (void);
  59 +
  60 + void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context);
  61 + void pw3270_dbus_get_version(PW3270Dbus *object, DBusGMethodInvocation *context);
  62 + void pw3270_dbus_create_session(PW3270Dbus *object, DBusGMethodInvocation *context);
  63 + void pw3270_dbus_destroy_session(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  64 + void pw3270_dbus_connect(PW3270Dbus *object, const gchar *id, const gchar *uri, DBusGMethodInvocation *context);
  65 + void pw3270_dbus_disconnect(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  66 +
  67 + void pw3270_dbus_enter(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  68 + void pw3270_dbus_pf_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context);
  69 + void pw3270_dbus_pa_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context);
  70 +
  71 + void pw3270_dbus_set_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *text, DBusGMethodInvocation *context);
  72 + void pw3270_dbus_get_text_at(PW3270Dbus *object, const gchar *id, int row, int col, int len, DBusGMethodInvocation *context);
  73 + void pw3270_dbus_cmp_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *text, DBusGMethodInvocation *context);
  74 +
  75 + void pw3270_dbus_is_ready(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  76 + void pw3270_dbus_is_connected(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  77 + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, const gchar *id, int timeout, DBusGMethodInvocation *context);
  78 + void pw3270_dbus_chk_id(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  79 +
  80 + void pw3270_dbus_get_connection_state(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context);
  81 +
  82 +/*
  83 + void pw3270_dbus_quit(PW3270Dbus *object, DBusGMethodInvocation *context);
  84 + void pw3270_dbus_connect(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context);
  85 + void pw3270_dbus_get_ur_l(PW3270Dbus *object, DBusGMethodInvocation *context);
  86 + void pw3270_dbus_set_ur_l(PW3270Dbus *object, const gchar *uri, DBusGMethodInvocation *context);
  87 + void pw3270_dbus_disconnect(PW3270Dbus *object, DBusGMethodInvocation *context);
  88 +
  89 + void pw3270_dbus_get_message_id(PW3270Dbus *object, DBusGMethodInvocation *context);
  90 + void pw3270_dbus_get_connection_state(PW3270Dbus *object, DBusGMethodInvocation *context);
  91 + void pw3270_dbus_get_secure_state(PW3270Dbus *object, DBusGMethodInvocation *context);
  92 +
  93 + void pw3270_dbus_get_screen_contents(PW3270Dbus *object, DBusGMethodInvocation *context);
  94 + H3270 * pw3270_dbus_get_session_handle(PW3270Dbus *object);
  95 + GError * pw3270_dbus_get_error_from_errno(int code);
  96 +
  97 + void pw3270_dbus_is_ready(PW3270Dbus *object, DBusGMethodInvocation *context);
  98 + void pw3270_dbus_in_tn3270_e(PW3270Dbus *object, DBusGMethodInvocation *context);
  99 +
  100 + void pw3270_dbus_set_cursor_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context);
  101 + void pw3270_dbus_set_cursor_address(PW3270Dbus *object, int addr, DBusGMethodInvocation *context);
  102 + void pw3270_dbus_get_cursor_address(PW3270Dbus *object, DBusGMethodInvocation *context);
  103 +
  104 + void pw3270_dbus_get_screen_width(PW3270Dbus *object, DBusGMethodInvocation *context);
  105 + void pw3270_dbus_get_screen_height(PW3270Dbus *object, DBusGMethodInvocation *context);
  106 + void pw3270_dbus_get_screen_length(PW3270Dbus *object, DBusGMethodInvocation *context);
  107 +
  108 + void pw3270_dbus_set_toggle(PW3270Dbus *object, int id, int value, DBusGMethodInvocation *context);
  109 +
  110 + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, int timeout, DBusGMethodInvocation *context);
  111 +
  112 + void pw3270_dbus_get_field_start(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  113 + void pw3270_dbus_get_field_length(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  114 + void pw3270_dbus_get_next_unprotected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  115 +
  116 + void pw3270_dbus_get_is_protected(PW3270Dbus *object, int baddr, DBusGMethodInvocation *context);
  117 + void pw3270_dbus_get_is_protected_at(PW3270Dbus *object, int row, int col, DBusGMethodInvocation *context);
  118 +
  119 + void pw3270_dbus_set_script(PW3270Dbus *object, const gchar *text, int mode, DBusGMethodInvocation *context);
  120 +
  121 + void pw3270_dbus_show_popup(PW3270Dbus *object, int id, const gchar *title, const gchar *msg, const gchar *text, DBusGMethodInvocation *context);
  122 +
  123 + void pw3270_dbus_action(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context);
  124 +
  125 + // Actions
  126 + void pw3270_dbus_enter(PW3270Dbus *object, DBusGMethodInvocation *context);
  127 + void pw3270_dbus_pf_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context);
  128 + void pw3270_dbus_pa_key(PW3270Dbus *object, int key, DBusGMethodInvocation *context);
  129 + void pw3270_dbus_get_text(PW3270Dbus *object, int offset, int len, DBusGMethodInvocation *context);
  130 + void pw3270_dbus_input(PW3270Dbus *object, const gchar *utftext, DBusGMethodInvocation *context);
  131 +
  132 + void pw3270_dbus_set_clipboard(PW3270Dbus *object, const gchar *text, DBusGMethodInvocation *context);
  133 + void pw3270_dbus_get_clipboard(PW3270Dbus *object, DBusGMethodInvocation *context);
  134 +
  135 + void pw3270_dbus_get_display_charset(PW3270Dbus *object, DBusGMethodInvocation *context);
  136 + void pw3270_dbus_get_host_charset(PW3270Dbus *object, DBusGMethodInvocation *context);
  137 + void pw3270_dbus_set_host_charset(PW3270Dbus *object, const gchar *charset, DBusGMethodInvocation *context);
  138 + void pw3270_dbus_erase_eof(PW3270Dbus *object, DBusGMethodInvocation *context);
  139 + void pw3270_dbus_print(PW3270Dbus *object, DBusGMethodInvocation *context);
  140 +
  141 + void pw3270_dbus_asc2ebc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context);
  142 + void pw3270_dbus_ebc2asc(PW3270Dbus *object, const gchar *from, DBusGMethodInvocation *context);
  143 +
  144 + 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);
  145 +
  146 + void pw3270_dbus_set_unlock_delay(PW3270Dbus *object, int value, DBusGMethodInvocation *context);
  147 +*/
  148 +
  149 + G_END_DECLS
  150 +
  151 +#endif // _PW3270_DBUS_SERVICE_H
... ...
src/session.c 0 → 100644
... ... @@ -0,0 +1,101 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como gobject.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 + #include "private.h"
  30 +
  31 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  32 +
  33 +static GList * sessions = NULL; ///< @brief Lista de sessões ativas.
  34 +static time_t maxidle = 300;
  35 +
  36 +struct session * session_new() {
  37 +
  38 + static unsigned int id = 0;
  39 +
  40 + struct session * rc = g_new0(struct session,1);
  41 +
  42 + rc->id = ++id;
  43 + rc->activity = time(0);
  44 + rc->host = lib3270_session_new("");
  45 +
  46 + sessions = g_list_append(sessions,rc);
  47 +
  48 + return rc;
  49 +
  50 +};
  51 +
  52 +struct session * session_find(const gchar *key) {
  53 +
  54 + struct session * rc = NULL;
  55 + unsigned int id = 0;
  56 +
  57 + if(sscanf(key,"%p-%u",&rc,&id) != 2) {
  58 + g_warning("Invalid session id: %s",key);
  59 + return NULL;
  60 + }
  61 +
  62 + if(!g_list_find(sessions,rc)) {
  63 + return NULL;
  64 + }
  65 +
  66 + if(rc->id != id) {
  67 + g_warning("Unexpected session id: %s",key);
  68 + return NULL;
  69 + }
  70 +
  71 + rc->activity = time(0);
  72 +
  73 + return rc;
  74 +};
  75 +
  76 +void session_destroy(struct session *ses) {
  77 +
  78 + lib3270_session_free(ses->host);
  79 + sessions = g_list_remove(sessions,ses);
  80 + g_free(ses);
  81 +
  82 +}
  83 +
  84 +void session_check_for_timeout(void) {
  85 +
  86 + time_t timeout = time(NULL) - maxidle;
  87 + GList * it;
  88 +
  89 + for(it = g_list_first(sessions); it != NULL; it = g_list_next(it)) {
  90 +
  91 + struct session *ses = (struct session *) it->data;
  92 +
  93 + if( ses->activity < timeout) {
  94 + g_message("Closing IDLE session %p-%u",ses,ses->id);
  95 + session_destroy(ses);
  96 + break;
  97 + }
  98 +
  99 + }
  100 +
  101 +}
... ...
src/status.c 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como status.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 + #include "private.h"
  29 +
  30 +/*---[ Implement ]----------------------------------------------------------------------------------*/
... ...
src/tn3270glue.c 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como tn3270glue.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 +#include "private.h"
  30 +#include <lib3270.h>
  31 +#include <lib3270/log.h>
  32 +
  33 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  34 +
  35 +static void loghandler(H3270 *session, const char *module, int rc, const char *fmt, va_list args) {
  36 + g_logv(module,rc ? G_LOG_LEVEL_WARNING : G_LOG_LEVEL_MESSAGE, fmt, args);
  37 +}
  38 +
  39 +void init_3270(void) {
  40 + lib3270_set_log_handler(loghandler);
  41 + register_3270_io_handlers();
  42 + g_message("Bind to lib3270 %s-%s is complete",lib3270_get_version(),lib3270_get_revision());
  43 +}
... ...
testscripts/createsession.sh 0 → 100755
... ... @@ -0,0 +1,6 @@
  1 +#!/bin/bash
  2 +DEST=br.com.bb.pw3270.service
  3 +PATH=/br/com/bb/pw3270/service
  4 +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.createSession
  5 +
  6 +
... ...
testscripts/destroysession.sh 0 → 100755
... ... @@ -0,0 +1,6 @@
  1 +#!/bin/bash
  2 +DEST=br.com.bb.pw3270.service
  3 +PATH=/br/com/bb/pw3270/service
  4 +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.destroySession string:$1
  5 +
  6 +
... ...
testscripts/getconnectionstate.sh 0 → 100755
... ... @@ -0,0 +1,5 @@
  1 +#!/bin/bash
  2 +DEST=br.com.bb.pw3270.service
  3 +PATH=/br/com/bb/pw3270/service
  4 +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.getConnectionState string:$1
  5 +
... ...
testscripts/getrevision.sh 0 → 100755
... ... @@ -0,0 +1,5 @@
  1 +#!/bin/bash
  2 +DEST=br.com.bb.pw3270.service
  3 +PATH=/br/com/bb/pw3270/service
  4 +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.getRevision
  5 +
... ...
testscripts/getversion.sh 0 → 100755
... ... @@ -0,0 +1,5 @@
  1 +#!/bin/bash
  2 +DEST=br.com.bb.pw3270.service
  3 +PATH=/br/com/bb/pw3270/service
  4 +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.getVersion
  5 +
... ...