From 59419215f1be4bd094cf70b09a1602652e83045f Mon Sep 17 00:00:00 2001 From: PerryWerneck Date: Fri, 3 Mar 2017 11:24:53 -0300 Subject: [PATCH] Importando fontes iniciais. --- .gitignore | 5 +++++ pw3270d.cbp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gobject.c | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/iocallback.c | 277 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/private.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pw3270service.xml | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/service.h | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/session.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/status.c | 30 ++++++++++++++++++++++++++++++ src/tn3270glue.c | 43 +++++++++++++++++++++++++++++++++++++++++++ testscripts/createsession.sh | 6 ++++++ testscripts/destroysession.sh | 6 ++++++ testscripts/getconnectionstate.sh | 5 +++++ testscripts/getrevision.sh | 5 +++++ testscripts/getversion.sh | 5 +++++ 16 files changed, 1326 insertions(+), 0 deletions(-) create mode 100644 .gitignore create mode 100644 pw3270d.cbp create mode 100644 src/gobject.c create mode 100644 src/iocallback.c create mode 100644 src/main.c create mode 100644 src/private.h create mode 100644 src/pw3270service.xml create mode 100644 src/service.h create mode 100644 src/session.c create mode 100644 src/status.c create mode 100644 src/tn3270glue.c create mode 100755 testscripts/createsession.sh create mode 100755 testscripts/destroysession.sh create mode 100755 testscripts/getconnectionstate.sh create mode 100755 testscripts/getrevision.sh create mode 100755 testscripts/getversion.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2860a1c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.bak +*.depend +*.layout +*.[0-9] + diff --git a/pw3270d.cbp b/pw3270d.cbp new file mode 100644 index 0000000..1a2975e --- /dev/null +++ b/pw3270d.cbp @@ -0,0 +1,67 @@ + + + + + + diff --git a/src/gobject.c b/src/gobject.c new file mode 100644 index 0000000..5c82a4d --- /dev/null +++ b/src/gobject.c @@ -0,0 +1,282 @@ +/* + * "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) + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + */ + +#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) { + g_message("Creating D-Bus proxy"); + return g_object_new(PW3270_TYPE_DBUS, NULL); +} + +static void pw3270_dbus_return_error(DBusGMethodInvocation *context, int err) { + GError *error = g_error_new(ERROR_DOMAIN,err,"%s",g_strerror(err)); + dbus_g_method_return_error(context,error); + g_error_free(error); +} + +void pw3270_dbus_get_revision(PW3270Dbus *object, DBusGMethodInvocation *context) { + dbus_g_method_return(context,lib3270_get_revision()); +} + +void pw3270_dbus_get_version(PW3270Dbus *object, DBusGMethodInvocation *context) { + dbus_g_method_return(context,lib3270_get_version()); +} + +void pw3270_dbus_create_session(PW3270Dbus *object, DBusGMethodInvocation *context) { + + struct session * ses = session_new(); + gchar * key = g_strdup_printf("%p-%u",ses,ses->id); + + dbus_g_method_return(context,key); + + g_free(key); +} + +void pw3270_dbus_destroy_session(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + dbus_g_method_return(context,ENOENT); + return; + } + + session_destroy(ses); + + dbus_g_method_return(context,0); +} + +void pw3270_dbus_connect(PW3270Dbus *object, const gchar *id, const gchar *uri, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + if(uri && *uri) { + lib3270_set_url(ses->host,uri); + } + + dbus_g_method_return(context,lib3270_connect(ses->host,0)); + +} + +void pw3270_dbus_disconnect(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_disconnect(ses->host)); +} + +void pw3270_dbus_enter(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_enter(ses->host)); +} + +void pw3270_dbus_pf_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_pfkey(ses->host,key)); +} + +void pw3270_dbus_pa_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_pakey(ses->host,key)); +} + +void pw3270_dbus_set_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) { + + gchar * text; + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(ses->host),"UTF-8","?",NULL,NULL,NULL); + + dbus_g_method_return(context,lib3270_set_string_at(ses->host,row,col,(const unsigned char *) text)); + + g_free(text); +} + +void pw3270_dbus_get_text_at(PW3270Dbus *object, const gchar *id, int row, int col, int len, DBusGMethodInvocation *context) { + + gchar *text; + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + text = lib3270_get_text_at(ses->host, row, col, len); + if(!text) { + + pw3270_dbus_return_error(context,errno); + + } else { + + gchar * utftext = g_convert_with_fallback(text,-1,"UTF-8",lib3270_get_display_charset(ses->host),"?",NULL,NULL,NULL); + lib3270_free(text); + dbus_g_method_return(context,utftext); + g_free(utftext); + + } + +} + +void pw3270_dbus_is_ready(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_is_ready(ses->host)); +} + +void pw3270_dbus_chk_id(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + dbus_g_method_return(context,ENOENT); + return; + } + + dbus_g_method_return(context,0); + +} + +void pw3270_dbus_cmp_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *utftext, DBusGMethodInvocation *context) { + + gchar * text; + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + text = g_convert_with_fallback(utftext,-1,lib3270_get_display_charset(ses->host),"UTF-8","?",NULL,NULL,NULL); + + dbus_g_method_return(context,lib3270_cmp_text_at(ses->host,row,col,text)); + + g_free(text); + +} + +void pw3270_dbus_is_connected(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_is_connected(ses->host)); + +} + +void pw3270_dbus_get_connection_state(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context) { + + struct session * ses = session_find(id); + + if(!ses) { + pw3270_dbus_return_error(context,ENOENT); + return; + } + + dbus_g_method_return(context,lib3270_get_connection_state(ses->host)); + +} diff --git a/src/iocallback.c b/src/iocallback.c new file mode 100644 index 0000000..eb45daf --- /dev/null +++ b/src/iocallback.c @@ -0,0 +1,277 @@ +/* + * "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) + * + */ + +#include "private.h" +#include +#include +#include + +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata); +static void static_RemoveSource(H3270 *session, void *id); + +static void * static_AddTimeOut(H3270 *session, unsigned long interval_ms, void (*proc)(H3270 *session)); +static void static_RemoveTimeOut(H3270 *session, 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; + int fd; + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); + H3270 *session; + void *userdata; + } IO_Source; + + typedef struct _timer { + unsigned char remove; + void * userdata; + void (*call)(H3270 *session); + H3270 * session; + } TIMER; + + static GSourceFuncs IOSources = { + IO_prepare, + IO_check, + IO_dispatch, + IO_finalize, + IO_closure, + NULL + }; + +/*---[ Implement ]-----------------------------------------------------------------------------------------*/ + +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) { + + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); + + src->fd = fd; + src->call = call; + src->userdata = userdata; + src->session = session; + + src->poll.fd = (int) fd; + src->poll.events = G_IO_HUP|G_IO_ERR; + + if(flag & LIB3270_IO_FLAG_READ) + src->poll.events |= G_IO_IN; + + if(flag & LIB3270_IO_FLAG_WRITE) + src->poll.events |= G_IO_OUT; + + g_source_attach((GSource *) src,NULL); + g_source_add_poll((GSource *) src,&src->poll); + + return src; +} + +static void static_RemoveSource(H3270 *session, void *id) { + if(id) + g_source_destroy((GSource *) id); +} + +static gboolean do_timer(TIMER *t) { + if(!t->remove) + t->call(t->session); + return FALSE; +} + +static void * static_AddTimeOut(H3270 *session, unsigned long interval, void (*call)(H3270 *session)) { + TIMER *t = g_malloc0(sizeof(TIMER)); + + t->call = call; + t->session = session; + + g_timeout_add_full(G_PRIORITY_DEFAULT, (guint) interval, (GSourceFunc) do_timer, t, g_free); + + return t; +} + +static void static_RemoveTimeOut(H3270 *session, 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. + * + */ +#ifdef _WIN32 + + fd_set rfds, wfds; + struct timeval tm; + + memset(&tm,0,sizeof(tm)); + + FD_ZERO(&rfds); + FD_ZERO(&wfds); +// FD_ZERO(&xfds); + + if(((IO_Source *) source)->poll.events & G_IO_IN) { + FD_SET(((IO_Source *) source)->poll.fd, &rfds); + } + + if(((IO_Source *) source)->poll.events & G_IO_OUT) { + FD_SET(((IO_Source *) source)->poll.fd, &wfds); + } + + if(select(((IO_Source *) source)->poll.fd+1, &rfds, &wfds, NULL, &tm) > 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 // _WIN32 + + 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 *obj = (IO_Source *) source; + + obj->call(obj->session,obj->fd,0,obj->userdata); + + return TRUE; +} + +static void IO_finalize(GSource *source) { + +} + +static gboolean IO_closure(gpointer data) { + return 0; +} + +struct bgParameter { + gboolean running; + 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 int static_Sleep(H3270 *hSession, int seconds) { + time_t end = time(0) + seconds; + + while(time(0) < end) { + g_main_context_iteration(NULL, TRUE); + } + + return 0; +} + +static int static_RunPendingEvents(H3270 *hSession, int wait) { + + int rc = 0; + while(g_main_context_iteration(NULL, wait ? TRUE : FALSE)) { + rc = 1; + } + + return rc; +} + +static void beep(H3270 *session) { +} + +void register_3270_io_handlers(void) { + static const struct lib3270_callbacks hdl = { + + sizeof(struct lib3270_callbacks), + + static_AddTimeOut, + static_RemoveTimeOut, + + static_AddSource, + static_RemoveSource, + + static_Sleep, + static_RunPendingEvents, + beep + + }; + + if(lib3270_register_handlers(&hdl)) { + g_error("%s","Can't set lib3270 I/O handlers"); + } + +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f6e7496 --- /dev/null +++ b/src/main.c @@ -0,0 +1,170 @@ +/* + * "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. + * + * Referencias: + * + * https://live.gnome.org/DBusGlibBindings + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * + */ + +#include +#include +#include +#include +#include + +#include "service.h" +#include "dbus-glue.h" + +#include "private.h" +#ifdef DEBUG + #include +#endif // DEBUG + +#if defined( HAVE_SYSLOG ) + #include +#endif // HAVE_SYSLOG + +#ifdef DEBUG + static GBusType bustype = G_BUS_TYPE_SESSION; +#else + static GBusType bustype = G_BUS_TYPE_SYSTEM; +#endif // DEBUG + +static DBusGConnection * connection = NULL; +static DBusGProxy * proxy = NULL; + +GMainLoop * main_loop = NULL; + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +#if defined( HAVE_SYSLOG ) +static void g_syslog(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data) +{ + static const struct _logtype + { + GLogLevelFlags log_level; + int priority; + const gchar * msg; + } logtype[] = + { + { G_LOG_FLAG_RECURSION, LOG_INFO, "recursion" }, + { G_LOG_FLAG_FATAL, LOG_ERR, "fatal error" }, + + /* GLib log levels */ + { G_LOG_LEVEL_ERROR, LOG_ERR, "error" }, + { G_LOG_LEVEL_CRITICAL, LOG_ERR, "critical error" }, + { G_LOG_LEVEL_WARNING, LOG_ERR, "warning" }, + { G_LOG_LEVEL_MESSAGE, LOG_ERR, "message" }, + { G_LOG_LEVEL_INFO, LOG_INFO, "info" }, + { G_LOG_LEVEL_DEBUG, LOG_DEBUG, "debug" }, + }; + + int f; + + for(f=0;fmessage); + 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_SERVICE_DBUS_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); + if(error) { + g_message("Error \"%s\" getting D-Bus name",error->message); + g_error_free(error); + return -1; + } + + GType object_type = PW3270_TYPE_DBUS; + GObject *object = g_object_new (object_type, NULL); + dbus_g_object_type_install_info (object_type, &dbus_glib_pw3270_dbus_object_info); + dbus_g_connection_register_g_object (connection, PW3270_SERVICE_DBUS_SERVICE_PATH, object); + + g_timeout_add_seconds (1, do_idle_check, NULL); + + return 0; +} + + + +int main(int argc, char *argv[]) { + +#if defined( HAVE_SYSLOG ) + openlog(g_get_prgname(), LOG_NDELAY, LOG_USER); + g_log_set_default_handler(g_syslog,NULL); +#endif // HAVE_SYSLOG + + initialize(); + init_3270(); + + main_loop = g_main_loop_new(NULL, FALSE); + + g_main_loop_run(main_loop); + + return 0; + + } diff --git a/src/private.h b/src/private.h new file mode 100644 index 0000000..162a2bf --- /dev/null +++ b/src/private.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 private.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * + */ + +#ifndef PRIVATE_H_INCLUDED + + #define PRIVATE_H_INCLUDED + + #define ERROR_DOMAIN g_quark_from_static_string("pw3270DBUS") + + // #define HAVE_SYSLOG 1 + #define PW3270_SERVICE_DBUS_SERVICE_PATH "/br/com/bb/pw3270/service" + #define PW3270_SERVICE_DBUS_SERVICE "br.com.bb.pw3270.service" + + #include + #include + #include + + struct session { + unsigned int id; ///< @brief Identificador da sessão. + time_t activity; ///< @brief Timestamp da última atividade dessa sessão. + H3270 * host; ///< @brief Sessão TN3270. + }; + + G_GNUC_INTERNAL GMainLoop * main_loop; + + G_GNUC_INTERNAL void init_3270(void); + G_GNUC_INTERNAL void register_3270_io_handlers(void); + + G_GNUC_INTERNAL struct session * session_new(); + G_GNUC_INTERNAL struct session * session_find(const gchar *key); + G_GNUC_INTERNAL void session_destroy(struct session *ses); + G_GNUC_INTERNAL void session_check_for_timeout(void); + +#endif // PRIVATE_H_INCLUDED diff --git a/src/pw3270service.xml b/src/pw3270service.xml new file mode 100644 index 0000000..144f960 --- /dev/null +++ b/src/pw3270service.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/service.h b/src/service.h new file mode 100644 index 0000000..e8da267 --- /dev/null +++ b/src/service.h @@ -0,0 +1,151 @@ +/* + * "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) + * + */ + +#ifndef _PW3270_DBUS_SERVICE_H + + #define _PW3270_DBUS_SERVICE_H 1 + + #include "private.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_get_version(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_create_session(PW3270Dbus *object, DBusGMethodInvocation *context); + void pw3270_dbus_destroy_session(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); + void pw3270_dbus_connect(PW3270Dbus *object, const gchar *id, const gchar *uri, DBusGMethodInvocation *context); + void pw3270_dbus_disconnect(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); + + void pw3270_dbus_enter(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); + void pw3270_dbus_pf_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context); + void pw3270_dbus_pa_key(PW3270Dbus *object, const gchar *id, int key, DBusGMethodInvocation *context); + + void pw3270_dbus_set_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *text, DBusGMethodInvocation *context); + void pw3270_dbus_get_text_at(PW3270Dbus *object, const gchar *id, int row, int col, int len, DBusGMethodInvocation *context); + void pw3270_dbus_cmp_text_at(PW3270Dbus *object, const gchar *id, int row, int col, const gchar *text, DBusGMethodInvocation *context); + + void pw3270_dbus_is_ready(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); + void pw3270_dbus_is_connected(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); + void pw3270_dbus_wait_for_ready(PW3270Dbus *object, const gchar *id, int timeout, DBusGMethodInvocation *context); + void pw3270_dbus_chk_id(PW3270Dbus *object, const gchar *id, DBusGMethodInvocation *context); + + void pw3270_dbus_get_connection_state(PW3270Dbus *object, const gchar *id, 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_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_get_text(PW3270Dbus *object, int offset, int len, 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/session.c b/src/session.c new file mode 100644 index 0000000..30f5d08 --- /dev/null +++ b/src/session.c @@ -0,0 +1,101 @@ +/* + * "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) + * + */ + + #include "private.h" + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +static GList * sessions = NULL; ///< @brief Lista de sessões ativas. +static time_t maxidle = 300; + +struct session * session_new() { + + static unsigned int id = 0; + + struct session * rc = g_new0(struct session,1); + + rc->id = ++id; + rc->activity = time(0); + rc->host = lib3270_session_new(""); + + sessions = g_list_append(sessions,rc); + + return rc; + +}; + +struct session * session_find(const gchar *key) { + + struct session * rc = NULL; + unsigned int id = 0; + + if(sscanf(key,"%p-%u",&rc,&id) != 2) { + g_warning("Invalid session id: %s",key); + return NULL; + } + + if(!g_list_find(sessions,rc)) { + return NULL; + } + + if(rc->id != id) { + g_warning("Unexpected session id: %s",key); + return NULL; + } + + rc->activity = time(0); + + return rc; +}; + +void session_destroy(struct session *ses) { + + lib3270_session_free(ses->host); + sessions = g_list_remove(sessions,ses); + g_free(ses); + +} + +void session_check_for_timeout(void) { + + time_t timeout = time(NULL) - maxidle; + GList * it; + + for(it = g_list_first(sessions); it != NULL; it = g_list_next(it)) { + + struct session *ses = (struct session *) it->data; + + if( ses->activity < timeout) { + g_message("Closing IDLE session %p-%u",ses,ses->id); + session_destroy(ses); + break; + } + + } + +} diff --git a/src/status.c b/src/status.c new file mode 100644 index 0000000..3840bdf --- /dev/null +++ b/src/status.c @@ -0,0 +1,30 @@ +/* + * "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 status.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * + */ + #include "private.h" + +/*---[ Implement ]----------------------------------------------------------------------------------*/ diff --git a/src/tn3270glue.c b/src/tn3270glue.c new file mode 100644 index 0000000..c465518 --- /dev/null +++ b/src/tn3270glue.c @@ -0,0 +1,43 @@ +/* + * "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 tn3270glue.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * + */ + +#include "private.h" +#include +#include + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + +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); +} + +void init_3270(void) { + lib3270_set_log_handler(loghandler); + register_3270_io_handlers(); + g_message("Bind to lib3270 %s-%s is complete",lib3270_get_version(),lib3270_get_revision()); +} diff --git a/testscripts/createsession.sh b/testscripts/createsession.sh new file mode 100755 index 0000000..b7dd912 --- /dev/null +++ b/testscripts/createsession.sh @@ -0,0 +1,6 @@ +#!/bin/bash +DEST=br.com.bb.pw3270.service +PATH=/br/com/bb/pw3270/service +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.createSession + + diff --git a/testscripts/destroysession.sh b/testscripts/destroysession.sh new file mode 100755 index 0000000..2d4b172 --- /dev/null +++ b/testscripts/destroysession.sh @@ -0,0 +1,6 @@ +#!/bin/bash +DEST=br.com.bb.pw3270.service +PATH=/br/com/bb/pw3270/service +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.destroySession string:$1 + + diff --git a/testscripts/getconnectionstate.sh b/testscripts/getconnectionstate.sh new file mode 100755 index 0000000..842c67a --- /dev/null +++ b/testscripts/getconnectionstate.sh @@ -0,0 +1,5 @@ +#!/bin/bash +DEST=br.com.bb.pw3270.service +PATH=/br/com/bb/pw3270/service +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.getConnectionState string:$1 + diff --git a/testscripts/getrevision.sh b/testscripts/getrevision.sh new file mode 100755 index 0000000..3271059 --- /dev/null +++ b/testscripts/getrevision.sh @@ -0,0 +1,5 @@ +#!/bin/bash +DEST=br.com.bb.pw3270.service +PATH=/br/com/bb/pw3270/service +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.getRevision + diff --git a/testscripts/getversion.sh b/testscripts/getversion.sh new file mode 100755 index 0000000..66b16a6 --- /dev/null +++ b/testscripts/getversion.sh @@ -0,0 +1,5 @@ +#!/bin/bash +DEST=br.com.bb.pw3270.service +PATH=/br/com/bb/pw3270/service +/bin/dbus-send --session --print-reply --dest=$DEST $PATH $DEST.getVersion + -- libgit2 0.21.2