Commit 445fb1d5114ae43cb9a5601feb0e2749cae71e1e

Authored by Perry Werneck
1 parent 25a7945f
Exists in master

Refactoring .NET native module.

src/include/native.h 0 → 100644
@@ -0,0 +1,165 @@ @@ -0,0 +1,165 @@
  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 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + * Referências:
  29 + *
  30 + * http://www.mono-project.com/docs/advanced/pinvoke/
  31 + * http://tirania.org/blog/archive/2011/Dec-19.html
  32 + *
  33 + */
  34 +
  35 +/**
  36 + * @file private.h
  37 + *
  38 + * @brief Internal definitions for the .NET Native module.
  39 + *
  40 + * @author Perry Werneck <perry.werneck@gmail.com>
  41 + *
  42 + */
  43 +
  44 +#ifndef PRIVATE_H_INCLUDED
  45 +
  46 + #define PRIVATE_H_INCLUDED
  47 +
  48 + #include <config.h>
  49 +
  50 + #if defined(_WIN32)
  51 +
  52 + #include <windows.h>
  53 +
  54 + #define DLL_PRIVATE extern
  55 + #define DLL_PUBLIC extern __declspec (dllexport) __attribute__((cdecl))
  56 +
  57 + #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
  58 +
  59 + #define DLL_PRIVATE __hidden extern
  60 + #define DLL_PUBLIC extern
  61 +
  62 + #else
  63 +
  64 + #define DLL_PRIVATE __attribute__((visibility("hidden"))) extern
  65 + #define DLL_PUBLIC __attribute__((visibility("default"))) extern
  66 +
  67 + #endif
  68 +
  69 + #include <cstdio>
  70 + #include <string>
  71 +
  72 + #ifdef DEBUG
  73 + #define debug( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n" , __FILE__, (int) __LINE__, __VA_ARGS__ ); fflush(stderr);
  74 + #else
  75 + #define debug( fmt, ... ) /* */
  76 + #endif // DEBUG
  77 +
  78 + /*
  79 + #ifdef ENABLE_TRACE_TO_FILE
  80 + DLL_PRIVATE void write_trace(const char *fmt, ...);
  81 + #define trace( ... ) write_trace(__VA_ARGS__)
  82 + #else
  83 + #define trace( ... )
  84 + #endif // ENABLE_TRACE_TO_FILE
  85 + */
  86 +
  87 + #include <lib3270/ipc.h>
  88 + #include <cerrno>
  89 + #include <cstring>
  90 + #include <functional>
  91 +
  92 + using std::string;
  93 + using std::exception;
  94 +
  95 + DLL_PRIVATE string tn3270_lasterror;
  96 + DLL_PRIVATE int call(TN3270::Host *ses, std::function<int(TN3270::Host &ses)> worker) noexcept;
  97 + DLL_PRIVATE int call(TN3270::Host *ses, char* str, int length, std::function<string(TN3270::Host &ses, int length)> worker);
  98 +
  99 + DLL_PRIVATE int tn3270_set_error(TN3270::Host *ses, const char *msg) noexcept;
  100 + DLL_PRIVATE int tn3270_set_error(TN3270::Host *ses, const std::exception &e) noexcept;
  101 +
  102 + extern "C" {
  103 +
  104 + DLL_PUBLIC TN3270::Host * tn3270_create_session(const char *name);
  105 +
  106 + DLL_PUBLIC int tn3270_destroy_session(TN3270::Host *ses);
  107 +
  108 + DLL_PUBLIC int tn3270_get_version(TN3270::Host *ses, char* str, int strlen);
  109 + DLL_PUBLIC int tn3270_get_revision(TN3270::Host *ses, char* str, int strlen);
  110 +
  111 + DLL_PUBLIC int tn3270_connect(TN3270::Host *ses, const char *host, time_t wait);
  112 + DLL_PUBLIC int tn3270_disconnect(TN3270::Host *ses);
  113 + DLL_PUBLIC int tn3270_is_connected(TN3270::Host *ses);
  114 + DLL_PUBLIC int tn3270_is_ready(TN3270::Host *ses);
  115 +
  116 + DLL_PUBLIC int tn3270_set_url(TN3270::Host *ses, const char *url);
  117 + DLL_PUBLIC int tn3270_get_url(TN3270::Host *ses, char* str, int strlen);
  118 +
  119 + DLL_PUBLIC int tn3270_get_luname(TN3270::Host *ses, char * str, int strlen);
  120 +
  121 + DLL_PUBLIC int tn3270_get_error_message(TN3270::Host *ses, char* str, int strlen);
  122 +
  123 + DLL_PUBLIC int tn3270_set_cursor_position(TN3270::Host *ses, int row, int col);
  124 + DLL_PUBLIC int tn3270_set_cursor_addr(TN3270::Host *ses, int addr);
  125 + DLL_PUBLIC int tn3270_get_cursor_addr(TN3270::Host *ses);
  126 +
  127 + DLL_PUBLIC int tn3270_action(TN3270::Host *ses, const char *name);
  128 +
  129 + DLL_PUBLIC int tn3270_erase(TN3270::Host *ses);
  130 + DLL_PUBLIC int tn3270_erase_eof(TN3270::Host *ses);
  131 + DLL_PUBLIC int tn3270_erase_eol(TN3270::Host *ses);
  132 + DLL_PUBLIC int tn3270_erase_input(TN3270::Host *ses);
  133 +
  134 + DLL_PUBLIC int tn3270_wait_for_ready(TN3270::Host *ses, int seconds);
  135 + DLL_PUBLIC int tn3270_wait(TN3270::Host *ses, int seconds);
  136 +
  137 + DLL_PUBLIC int tn3270_get_cstate(TN3270::Host *ses);
  138 + DLL_PUBLIC int tn3270_get_program_message(TN3270::Host *ses);
  139 + DLL_PUBLIC int tn3270_get_secure(TN3270::Host *ses);
  140 +
  141 + DLL_PUBLIC int tn3270_get_contents(TN3270::Host *ses, char* str, int strlen);
  142 + DLL_PUBLIC int tn3270_get_string(TN3270::Host *ses, int addr, char* str, int strlen);
  143 + DLL_PUBLIC int tn3270_get_string_at(TN3270::Host *ses, int row, int col, char* str, int strlen);
  144 +
  145 + DLL_PUBLIC int tn3270_set_string_at(TN3270::Host *ses, int row, int col, const char* str);
  146 +
  147 + DLL_PUBLIC int tn3270_wait_for_string_at(TN3270::Host *ses, int row, int col, const char *key, int timeout);
  148 + DLL_PUBLIC int tn3270_cmp_string_at(TN3270::Host *ses, int row, int col, const char* str);
  149 +
  150 + DLL_PUBLIC int tn3270_set_unlock_delay(TN3270::Host *ses, int ms);
  151 +
  152 + DLL_PUBLIC int tn3270_enter(TN3270::Host *ses);
  153 + DLL_PUBLIC int tn3270_pfkey(TN3270::Host *ses, int key);
  154 + DLL_PUBLIC int tn3270_pakey(TN3270::Host *ses, int key);
  155 +
  156 + DLL_PUBLIC int tn3270_get_width(TN3270::Host *ses);
  157 + DLL_PUBLIC int tn3270_get_height(TN3270::Host *ses);
  158 + DLL_PUBLIC int tn3270_get_length(TN3270::Host *ses);
  159 +
  160 + DLL_PUBLIC int tn3270_set_charset(TN3270::Host *ses, const char* str);
  161 +
  162 + }
  163 +
  164 +
  165 +#endif // PRIVATE_H_INCLUDED
src/native/Makefile.in
@@ -27,15 +27,15 @@ @@ -27,15 +27,15 @@
27 #---[ Library configuration ]------------------------------------------------------------ 27 #---[ Library configuration ]------------------------------------------------------------
28 28
29 LIBNAME=lib3270-mono 29 LIBNAME=lib3270-mono
30 -SONAME=@SONAME@ 30 +SONAME=@NATIVE_SONAME@
31 31
32 SOURCES= \ 32 SOURCES= \
33 - $(wildcard *.cc) \ 33 + $(wildcard core/*.cc) \
34 $(wildcard @OSNAME@/*.rc) \ 34 $(wildcard @OSNAME@/*.rc) \
35 $(wildcard @OSNAME@/*.cc) 35 $(wildcard @OSNAME@/*.cc)
36 36
37 TEST_SOURCES= \ 37 TEST_SOURCES= \
38 - $(wildcard src/testprogram/*.cc) 38 + $(wildcard testprogram/*.cc)
39 39
40 #---[ Tools ]---------------------------------------------------------------------------- 40 #---[ Tools ]----------------------------------------------------------------------------
41 41
@@ -83,7 +83,6 @@ BINRLS=$(BINDIR)/Release @@ -83,7 +83,6 @@ BINRLS=$(BINDIR)/Release
83 83
84 DEPENDS= \ 84 DEPENDS= \
85 Makefile \ 85 Makefile \
86 - *.h \  
87 $(BASEDIR)/src/include/*.h 86 $(BASEDIR)/src/include/*.h
88 87
89 88
src/native/actions.cc
@@ -1,131 +0,0 @@ @@ -1,131 +0,0 @@
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 actions.cc e possui - linhas de código.  
22 - *  
23 - * Contatos:  
24 - *  
25 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
26 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - */  
29 -  
30 - /**  
31 - * @file actions.cc  
32 - *  
33 - * @brief Actions wrapper.  
34 - *  
35 - * @author Perry Werneck <perry.werneck@gmail.com>  
36 - *  
37 - */  
38 -  
39 - #include "private.h"  
40 -  
41 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
42 -  
43 -static int do_action(TN3270::Session *ses, TN3270::Action action) {  
44 -  
45 - if(ses) {  
46 -  
47 - try {  
48 -  
49 - ses->push(action);  
50 - return 0;  
51 -  
52 - } catch(const exception &e) {  
53 -  
54 - tn3270_lasterror = e.what();  
55 - return -1;  
56 -  
57 - }  
58 -  
59 - }  
60 -  
61 - return -1;  
62 -  
63 -}  
64 -  
65 -int tn3270_enter(TN3270::Session *ses) {  
66 - return do_action(ses,TN3270::ENTER);  
67 -}  
68 -  
69 -int tn3270_pfkey(TN3270::Session *ses, int key) {  
70 -  
71 - try {  
72 -  
73 - ses->pfkey(key);  
74 - return 0;  
75 -  
76 - } catch(const exception &e) {  
77 -  
78 - tn3270_lasterror = e.what();  
79 -  
80 - }  
81 - return -1;  
82 -  
83 -}  
84 -  
85 -int tn3270_pakey(TN3270::Session *ses, int key) {  
86 -  
87 - try {  
88 -  
89 - ses->pakey(key);  
90 - return 0;  
91 -  
92 - } catch(const exception &e) {  
93 -  
94 - tn3270_lasterror = e.what();  
95 -  
96 - }  
97 - return -1;  
98 -}  
99 -  
100 -int tn3270_action(TN3270::Session *ses, const char *name) {  
101 -  
102 - try {  
103 -  
104 - ses->action(name);  
105 - return 0;  
106 -  
107 - } catch(const exception &e) {  
108 -  
109 - tn3270_lasterror = e.what();  
110 -  
111 - }  
112 - return -1;  
113 -  
114 -}  
115 -  
116 -int tn3270_erase(TN3270::Session *ses) {  
117 - return do_action(ses,TN3270::ERASE);  
118 -}  
119 -  
120 -int tn3270_erase_eof(TN3270::Session *ses) {  
121 - return do_action(ses,TN3270::ERASE_EOF);  
122 -}  
123 -  
124 -int tn3270_erase_eol(TN3270::Session *ses) {  
125 - return do_action(ses,TN3270::ERASE_EOL);  
126 -}  
127 -  
128 -int tn3270_erase_input(TN3270::Session *ses) {  
129 - return do_action(ses,TN3270::ERASE_INPUT);  
130 -}  
131 -  
src/native/core/actions.cc 0 → 100644
@@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
  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 actions.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + /**
  31 + * @file actions.cc
  32 + *
  33 + * @brief Actions wrapper.
  34 + *
  35 + * @author Perry Werneck <perry.werneck@gmail.com>
  36 + *
  37 + */
  38 +
  39 + #include <native.h>
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + static int action(TN3270::Host *ses, std::function<void(TN3270::Host &ses)> worker) noexcept {
  44 +
  45 + try {
  46 +
  47 + if(!ses->isConnected()) {
  48 + tn3270_lasterror = "Not connected";
  49 + }
  50 +
  51 + worker(*ses);
  52 + return 0;
  53 +
  54 + } catch(const std::system_error &e) {
  55 +
  56 + tn3270_set_error(ses,e);
  57 +
  58 + } catch(const std::exception &e) {
  59 +
  60 + tn3270_set_error(ses,e);
  61 +
  62 + } catch(...) {
  63 +
  64 + tn3270_set_error(ses,"Unexpected error");
  65 +
  66 + }
  67 +
  68 + return -1;
  69 +
  70 + }
  71 +
  72 +
  73 +static int action(TN3270::Host *ses, TN3270::Action id) noexcept {
  74 +
  75 + return action(ses, [id](TN3270::Host &ses) {
  76 + ses.push(id);
  77 + });
  78 +
  79 +}
  80 +
  81 +int tn3270_pfkey(TN3270::Host *ses, int key) {
  82 +
  83 + return action(ses, [key](TN3270::Host &ses) {
  84 + ses.pfkey(key);
  85 + });
  86 +
  87 +}
  88 +
  89 +int tn3270_pakey(TN3270::Host *ses, int key) {
  90 +
  91 + return action(ses, [key](TN3270::Host &ses) {
  92 + ses.pakey(key);
  93 + });
  94 +
  95 +}
  96 +
  97 +int tn3270_action(TN3270::Host *ses, const char *name) {
  98 +
  99 + return action(ses, [name](TN3270::Host &ses) {
  100 + ses.action(name);
  101 + });
  102 +
  103 +}
  104 +
  105 +int tn3270_enter(TN3270::Host *ses) {
  106 + return action(ses,TN3270::ENTER);
  107 +}
  108 +
  109 +int tn3270_erase(TN3270::Host *ses) {
  110 + return action(ses,TN3270::ERASE);
  111 +}
  112 +
  113 +int tn3270_erase_eof(TN3270::Host *ses) {
  114 + return action(ses,TN3270::ERASE_EOF);
  115 +}
  116 +
  117 +int tn3270_erase_eol(TN3270::Host *ses) {
  118 + return action(ses,TN3270::ERASE_EOL);
  119 +}
  120 +
  121 +int tn3270_erase_input(TN3270::Host *ses) {
  122 + return action(ses,TN3270::ERASE_INPUT);
  123 +}
  124 +
src/native/core/get.cc 0 → 100644
@@ -0,0 +1,166 @@ @@ -0,0 +1,166 @@
  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 get.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <native.h>
  31 +
  32 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  33 +
  34 + /**
  35 + * @brief Obtém a versão da biblioteca.
  36 + *
  37 + */
  38 +DLL_PUBLIC int tn3270_get_version(TN3270::Host *ses, char * str, int strlen) {
  39 +
  40 + if(!(str && strlen))
  41 + return -1;
  42 +
  43 + return call(ses,[str,strlen](TN3270::Host &ses){
  44 +
  45 + strncpy(str,ses.getVersion().c_str(),strlen);
  46 + return 0;
  47 +
  48 + });
  49 +
  50 + }
  51 +
  52 + /**
  53 + * @brief Obtém a revisão da biblioteca.
  54 + *
  55 + */
  56 + int tn3270_get_revision(TN3270::Host *ses, char* str, int strlen) {
  57 +
  58 + if(!(str && strlen))
  59 + return -1;
  60 +
  61 + return call(ses,[str,strlen](TN3270::Host &ses){
  62 +
  63 + strncpy(str,ses.getRevision().c_str(),strlen);
  64 + return 0;
  65 +
  66 + });
  67 +
  68 + }
  69 +
  70 + int tn3270_get_cstate(TN3270::Host *ses) {
  71 +
  72 + return call(ses,[](TN3270::Host &ses){
  73 +
  74 + return (int) ses.getConnectionState();
  75 +
  76 + });
  77 +
  78 + }
  79 +
  80 + int tn3270_get_program_message(TN3270::Host *ses) {
  81 +
  82 + return call(ses,[](TN3270::Host &ses){
  83 +
  84 + return (int) ses.getProgramMessage();
  85 +
  86 + });
  87 +
  88 + }
  89 +
  90 + int tn3270_get_secure(TN3270::Host *ses) {
  91 +
  92 +
  93 + return call(ses,[](TN3270::Host &ses){
  94 +
  95 + return (int) ses.getSSLState();
  96 +
  97 + });
  98 +
  99 + }
  100 +
  101 + int tn3270_get_width(TN3270::Host *ses) {
  102 +
  103 + return call(ses,[](TN3270::Host &ses){
  104 +
  105 + return (int) ses.getScreenWidth();
  106 +
  107 + });
  108 +
  109 + }
  110 +
  111 + int tn3270_get_height(TN3270::Host *ses) {
  112 +
  113 + return call(ses,[](TN3270::Host &ses){
  114 +
  115 + return (int) ses.getScreenHeight();
  116 +
  117 + });
  118 +
  119 + }
  120 +
  121 + int tn3270_get_length(TN3270::Host *ses) {
  122 +
  123 + return call(ses,[](TN3270::Host &ses){
  124 +
  125 + return (int) ses.getScreenLength();
  126 +
  127 + });
  128 +
  129 + }
  130 +
  131 + int tn3270_get_cursor_addr(TN3270::Host *ses) {
  132 +
  133 + return call(ses,[](TN3270::Host &ses){
  134 +
  135 + return (int) ses.getCursorAddress();
  136 +
  137 + });
  138 +
  139 + }
  140 +
  141 + int tn3270_get_url(TN3270::Host *ses, char* str, int length) {
  142 +
  143 + return call(ses, str, length, [](TN3270::Host &ses, int length) {
  144 +
  145 + return ses.getHostURL();
  146 +
  147 + });
  148 +
  149 + }
  150 +
  151 + DLL_PUBLIC int tn3270_get_luname(TN3270::Host *ses, char * str, int length) {
  152 +
  153 + return call(ses, str, length, [](TN3270::Host &ses, int length) {
  154 +
  155 + return ses.getLUName();
  156 +
  157 + });
  158 +
  159 + }
  160 +
  161 + int tn3270_get_error_message(TN3270::Host *ses, char* str, int length) {
  162 +
  163 + strncpy(str,tn3270_lasterror.c_str(),length);
  164 + return 0;
  165 +
  166 + }
src/native/core/init.cc 0 → 100644
@@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
  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 init.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <native.h>
  31 +
  32 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  33 +
  34 + std::string tn3270_lasterror = "";
  35 +
  36 +/**
  37 + * @brief Cria uma sessão tn3270.
  38 + *
  39 + * @param name Nome da janela ou "" para criar uma sessão oculta.
  40 + *
  41 + * @return Identificador da sessão criada.
  42 + *
  43 + */
  44 + TN3270::Host * tn3270_create_session(const char *name) {
  45 +
  46 + try {
  47 +
  48 + return new TN3270::Host(name);
  49 +
  50 + } catch(const exception &e) {
  51 +
  52 + tn3270_lasterror = e.what();
  53 +
  54 + } catch(...) {
  55 +
  56 + tn3270_lasterror = "Unexpected error";
  57 +
  58 + }
  59 +
  60 + return nullptr;
  61 + }
  62 +
  63 + /**
  64 + * @brief Destrói uma sessão.
  65 + *
  66 + */
  67 + int tn3270_destroy_session(TN3270::Host *ses) {
  68 +
  69 + try {
  70 +
  71 + delete ses;
  72 + return 0;
  73 +
  74 + } catch(const exception &e) {
  75 +
  76 + tn3270_lasterror = e.what();
  77 +
  78 + } catch(...) {
  79 +
  80 + tn3270_lasterror = "Unexpected error";
  81 +
  82 + }
  83 +
  84 + return -1;
  85 + }
  86 +
src/native/core/network.cc 0 → 100644
@@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
  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 network.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <native.h>
  31 +
  32 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  33 +
  34 +int tn3270_connect(TN3270::Host *ses, const char *url, time_t timeout) {
  35 +
  36 + return call(ses,[url,timeout](TN3270::Host &ses){
  37 +
  38 + ses.connect(url);
  39 +
  40 + if(timeout) {
  41 + ses.waitForReady(timeout);
  42 + }
  43 +
  44 + return 0;
  45 +
  46 + });
  47 +
  48 +}
  49 +
  50 +int tn3270_disconnect(TN3270::Host *ses) {
  51 +
  52 + return call(ses,[](TN3270::Host &ses){
  53 +
  54 + ses.disconnect();
  55 + return 0;
  56 +
  57 + });
  58 +
  59 +}
  60 +
  61 +int tn3270_is_connected(TN3270::Host *ses) {
  62 +
  63 + return call(ses,[](TN3270::Host &ses){
  64 +
  65 + return (ses.isConnected() ? 1 : 0);
  66 +
  67 + });
  68 +
  69 +}
  70 +
  71 +int tn3270_is_ready(TN3270::Host *ses) {
  72 +
  73 + return call(ses,[](TN3270::Host &ses){
  74 +
  75 + return (int) (ses.isReady() ? 1 : 0);
  76 +
  77 + });
  78 +
  79 +}
  80 +
  81 +int tn3270_wait_for_ready(TN3270::Host *ses, int seconds) {
  82 +
  83 + return call(ses,[seconds](TN3270::Host &ses){
  84 +
  85 + ses.waitForReady(seconds);
  86 + return 0;
  87 +
  88 + });
  89 +
  90 +}
  91 +
  92 +int tn3270_wait(TN3270::Host *ses, int seconds) {
  93 +
  94 + return call(ses,[seconds](TN3270::Host &ses){
  95 +
  96 + ses.wait(seconds);
  97 + return 0;
  98 +
  99 + });
  100 +
  101 +}
  102 +
src/native/core/screen.cc 0 → 100644
@@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
  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 screen.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <native.h>
  31 +
  32 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  33 +
  34 +int tn3270_get_contents(TN3270::Host *ses, char* str, int length) {
  35 +
  36 + return call(ses,str,length,[](TN3270::Host &ses, int length){
  37 +
  38 + return ses.toString(0,length);
  39 +
  40 + });
  41 +
  42 +}
  43 +
  44 +int tn3270_get_string(TN3270::Host *ses, int addr, char* str, int length) {
  45 +
  46 + return call(ses,str,length,[addr](TN3270::Host &ses, int length){
  47 +
  48 + return ses.toString(addr,length);
  49 +
  50 + });
  51 +
  52 +
  53 +}
  54 +
  55 +int tn3270_get_string_at(TN3270::Host *ses, int row, int col, char* str, int length) {
  56 +
  57 + return call(ses,str,length,[row,col](TN3270::Host &ses, int length){
  58 +
  59 + return ses.toString((unsigned int) row, (unsigned int) col, length);
  60 +
  61 + });
  62 +
  63 +}
  64 +
  65 +int tn3270_set_string_at(TN3270::Host *ses, int row, int col, const char* str) {
  66 +
  67 + return call(ses,[row,col,str](TN3270::Host &ses){
  68 +
  69 + ses.push((unsigned int) row, (unsigned int) col, str);
  70 + return 0;
  71 +
  72 + });
  73 +
  74 +
  75 +}
  76 +
  77 +int tn3270_wait_for_string_at(TN3270::Host *ses, int row, int col, const char *key, int timeout) {
  78 +
  79 + return call(ses,[row,col,key,timeout](TN3270::Host &ses){
  80 +
  81 + ses.wait((unsigned int) row, (unsigned int) col, key, timeout);
  82 + return 0;
  83 +
  84 + });
  85 +
  86 +}
  87 +
  88 +int tn3270_cmp_string_at(TN3270::Host *ses, int row, int col, const char* str) {
  89 +
  90 + return call(ses,[row,col,str](TN3270::Host &ses){
  91 +
  92 + return ses.compare((unsigned int) row, (unsigned int) col, str);
  93 +
  94 + });
  95 +
  96 +}
src/native/core/set.cc 0 → 100644
@@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
  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 set.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <native.h>
  31 +
  32 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  33 +
  34 +int tn3270_set_unlock_delay(TN3270::Host *ses, int ms) {
  35 +
  36 + return call(ses,[ms](TN3270::Host &ses) {
  37 +
  38 + ses.setUnlockDelay(ms);
  39 + return 0;
  40 +
  41 + });
  42 +
  43 +}
  44 +
  45 +int tn3270_set_cursor_position(TN3270::Host *ses, int row, int col) {
  46 +
  47 + return call(ses,[row,col](TN3270::Host &ses) {
  48 +
  49 + ses.setCursor((unsigned short) row, (unsigned short) row);
  50 + return 0;
  51 +
  52 + });
  53 +
  54 +
  55 +}
  56 +
  57 +int tn3270_set_cursor_addr(TN3270::Host *ses, int addr) {
  58 +
  59 + return call(ses,[addr](TN3270::Host &ses) {
  60 +
  61 + ses.setCursor(addr);
  62 + return 0;
  63 +
  64 + });
  65 +
  66 +}
  67 +
  68 +int tn3270_set_charset(TN3270::Host *ses, const char* str) {
  69 +
  70 + return call(ses,[str](TN3270::Host &ses) {
  71 +
  72 + ses.setCharSet(str);
  73 + return 0;
  74 +
  75 + });
  76 +
  77 +}
  78 +
  79 +int tn3270_set_url(TN3270::Host *ses, const char *url) {
  80 +
  81 + return call(ses,[url](TN3270::Host &ses) {
  82 +
  83 + ses.setHostURL(url);
  84 + return 0;
  85 +
  86 + });
  87 +}
  88 +
src/native/core/tools.cc 0 → 100644
@@ -0,0 +1,121 @@ @@ -0,0 +1,121 @@
  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 actions.cc e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + /**
  31 + * @file
  32 + *
  33 + * @brief
  34 + *
  35 + * @author
  36 + *
  37 + */
  38 +
  39 + #include <native.h>
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 +int call(TN3270::Host *ses, std::function<int(TN3270::Host &ses)> worker) noexcept {
  44 +
  45 + if(!ses) {
  46 +
  47 + return tn3270_set_error(ses, "Invalid session handle");
  48 +
  49 + }
  50 +
  51 + try {
  52 +
  53 + return worker(*ses);
  54 +
  55 + } catch(const exception &e) {
  56 +
  57 + tn3270_set_error(ses, e);
  58 +
  59 + } catch(...) {
  60 +
  61 + tn3270_set_error(ses, "Unexpected error");
  62 +
  63 + }
  64 +
  65 + return -1;
  66 +
  67 +}
  68 +
  69 +int call(TN3270::Host *ses, char* str, int length, std::function<string(TN3270::Host &ses, int length)> worker) {
  70 +
  71 + if(!(str && length)) {
  72 +
  73 + return tn3270_set_error(ses, "The output buffer is invalid");
  74 +
  75 + }
  76 +
  77 + if(!ses) {
  78 +
  79 + return tn3270_set_error(ses, "Invalid session handle");
  80 +
  81 + }
  82 +
  83 + try {
  84 +
  85 + std::string contents = worker(*ses, length);
  86 +
  87 + memset(str,0,length);
  88 + strncpy(str,contents.c_str(),length);
  89 + if(contents.size() < ((size_t) length)) {
  90 + str[contents.size()] = 0;
  91 + return contents.size();
  92 + }
  93 +
  94 + return length;
  95 +
  96 + } catch(const exception &e) {
  97 +
  98 + tn3270_set_error(ses, e);
  99 +
  100 + } catch(...) {
  101 +
  102 + tn3270_set_error(ses, "Unexpected error");
  103 +
  104 + }
  105 +
  106 + return -1;
  107 +
  108 +
  109 +}
  110 +
  111 +int tn3270_set_error(TN3270::Host *ses, const char *str) noexcept {
  112 + tn3270_lasterror = str;
  113 + return -1;
  114 +}
  115 +
  116 +int tn3270_set_error(TN3270::Host *ses, const std::exception &e) noexcept {
  117 + tn3270_lasterror = e.what();
  118 + return -1;
  119 +}
  120 +
  121 +
src/native/get.cc
@@ -1,220 +0,0 @@ @@ -1,220 +0,0 @@
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 get.cc e possui - linhas de código.  
22 - *  
23 - * Contatos:  
24 - *  
25 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
26 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - */  
29 -  
30 - #include "private.h"  
31 -  
32 -  
33 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
34 -  
35 - /**  
36 - * @brief Obtém a versão da biblioteca.  
37 - *  
38 - */  
39 - int tn3270_get_version(TN3270::Session *ses, char * str, int strlen) {  
40 -  
41 - if(!ses) {  
42 - return -1;  
43 - }  
44 -  
45 - try {  
46 -  
47 - strncpy(str,ses->getVersion().c_str(),strlen);  
48 -  
49 - } catch(const exception &e) {  
50 -  
51 - tn3270_lasterror = e.what();  
52 - return -1;  
53 -  
54 - }  
55 - return 0;  
56 - }  
57 -  
58 - /**  
59 - * @brief Obtém a revisão da biblioteca.  
60 - *  
61 - */  
62 - int tn3270_get_revision(TN3270::Session *ses, char* str, int strlen) {  
63 -  
64 - if(!ses) {  
65 - return -1;  
66 - }  
67 -  
68 - try {  
69 -  
70 - strncpy(str,ses->getRevision().c_str(),strlen);  
71 -  
72 - } catch(const exception &e) {  
73 -  
74 - tn3270_lasterror = e.what();  
75 - return -1;  
76 -  
77 - }  
78 - return 0;  
79 - }  
80 -  
81 - int tn3270_get_cstate(TN3270::Session *ses) {  
82 -  
83 - if(!ses) {  
84 - return -1;  
85 - }  
86 -  
87 - try {  
88 -  
89 - return (int) ses->getConnectionState();  
90 -  
91 - } catch(const exception &e) {  
92 -  
93 - tn3270_lasterror = e.what();  
94 -  
95 - }  
96 - return -1;  
97 -  
98 - }  
99 -  
100 - int tn3270_get_program_message(TN3270::Session *ses) {  
101 -  
102 - if(!ses) {  
103 - return -1;  
104 - }  
105 -  
106 - try {  
107 -  
108 - return (int) ses->getProgramMessage();  
109 -  
110 - } catch(const exception &e) {  
111 - tn3270_lasterror = e.what();  
112 - }  
113 - return -1;  
114 -  
115 - }  
116 -  
117 - int tn3270_get_secure(TN3270::Session *ses) {  
118 -  
119 - if(!ses) {  
120 - return -1;  
121 - }  
122 -  
123 - try {  
124 -  
125 - return (int) ses->getSSLState();  
126 -  
127 - } catch(const exception &e) {  
128 -  
129 - tn3270_lasterror = e.what();  
130 -  
131 - }  
132 -  
133 - return -1;  
134 -  
135 - }  
136 -  
137 - int tn3270_get_width(TN3270::Session *ses) {  
138 -  
139 - if(!ses) {  
140 - return 0;  
141 - }  
142 -  
143 - try {  
144 - return (int) ses->getScreenWidth();  
145 - } catch(const exception &e) {  
146 - tn3270_lasterror = e.what();  
147 - }  
148 - return -1;  
149 -  
150 - }  
151 -  
152 - int tn3270_get_height(TN3270::Session *ses) {  
153 -  
154 - if(!ses) {  
155 - return 0;  
156 - }  
157 -  
158 - try {  
159 - return (int) ses->getScreenHeight();  
160 - } catch(const exception &e) {  
161 - tn3270_lasterror = e.what();  
162 - }  
163 - return -1;  
164 -  
165 - }  
166 -  
167 - int tn3270_get_length(TN3270::Session *ses) {  
168 -  
169 - if(!ses) {  
170 - return 0;  
171 - }  
172 -  
173 - try {  
174 - return (int) ses->getScreenLength();  
175 - } catch(const exception &e) {  
176 - tn3270_lasterror = e.what();  
177 - }  
178 - return -1;  
179 -  
180 - }  
181 -  
182 - int tn3270_get_cursor_addr(TN3270::Session *ses) {  
183 -  
184 - if(ses) {  
185 -  
186 - try {  
187 - return (int) ses->getCursorAddress();  
188 - } catch(const exception &e) {  
189 - tn3270_lasterror = e.what();  
190 - }  
191 -  
192 - }  
193 - return -1;  
194 -  
195 - }  
196 -  
197 - int tn3270_get_url(TN3270::Session *ses, char* str, int strlen) {  
198 -  
199 - if(ses) {  
200 -  
201 - try {  
202 -  
203 - strncpy(str,ses->getHostURL().c_str(),strlen);  
204 - return 0;  
205 -  
206 - } catch(const exception &e) {  
207 - tn3270_lasterror = e.what();  
208 - }  
209 -  
210 - }  
211 - return -1;  
212 -  
213 - }  
214 -  
215 - int tn3270_get_error_message(TN3270::Session *ses, char* str, int strlen) {  
216 -  
217 - strncpy(str,tn3270_lasterror.c_str(),strlen);  
218 - return 0;  
219 -  
220 - }  
src/native/init.cc
@@ -1,76 +0,0 @@ @@ -1,76 +0,0 @@
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 init.cc e possui - linhas de código.  
22 - *  
23 - * Contatos:  
24 - *  
25 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
26 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - */  
29 -  
30 - #include "private.h"  
31 -  
32 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
33 -  
34 - std::string tn3270_lasterror = "";  
35 -  
36 -/**  
37 - * @brief Cria uma sessão tn3270.  
38 - *  
39 - * @param name Nome da janela ou "" para criar uma sessão oculta.  
40 - *  
41 - * @return Identificador da sessão criada.  
42 - *  
43 - */  
44 - TN3270::Session * tn3270_create_session(const char *name) {  
45 -  
46 - try {  
47 -  
48 - return TN3270::Session::create(name);  
49 -  
50 - } catch(const exception &e) {  
51 -  
52 - tn3270_lasterror = e.what();  
53 - }  
54 -  
55 - return nullptr;  
56 - }  
57 -  
58 - /**  
59 - * @brief Destrói uma sessão.  
60 - *  
61 - */  
62 - int tn3270_destroy_session(TN3270::Session *ses) {  
63 -  
64 - try {  
65 -  
66 - delete ses;  
67 -  
68 - } catch(const exception &e) {  
69 -  
70 - tn3270_lasterror = e.what();  
71 - return -1;  
72 -  
73 - }  
74 - return 0;  
75 - }  
76 -  
src/native/native.cbp
@@ -32,13 +32,15 @@ @@ -32,13 +32,15 @@
32 <Compiler> 32 <Compiler>
33 <Add option="-Wall" /> 33 <Add option="-Wall" />
34 </Compiler> 34 </Compiler>
35 - <Unit filename="actions.cc" />  
36 - <Unit filename="get.cc" />  
37 - <Unit filename="init.cc" />  
38 - <Unit filename="network.cc" />  
39 - <Unit filename="private.h" />  
40 - <Unit filename="screen.cc" />  
41 - <Unit filename="set.cc" /> 35 + <Unit filename="../include/native.h" />
  36 + <Unit filename="core/actions.cc" />
  37 + <Unit filename="core/get.cc" />
  38 + <Unit filename="core/init.cc" />
  39 + <Unit filename="core/network.cc" />
  40 + <Unit filename="core/screen.cc" />
  41 + <Unit filename="core/set.cc" />
  42 + <Unit filename="core/tools.cc" />
  43 + <Unit filename="testprogram/testprogram.cc" />
42 <Unit filename="windows/resources.rc.in" /> 44 <Unit filename="windows/resources.rc.in" />
43 <Extensions> 45 <Extensions>
44 <code_completion /> 46 <code_completion />
src/native/network.cc
@@ -1,147 +0,0 @@ @@ -1,147 +0,0 @@
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 network.cc e possui - linhas de código.  
22 - *  
23 - * Contatos:  
24 - *  
25 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
26 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - */  
29 -  
30 - #include "private.h"  
31 -  
32 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
33 -  
34 -int tn3270_connect(TN3270::Session *ses, const char *url, time_t timeout) {  
35 -  
36 - if(ses) {  
37 -  
38 - try {  
39 -  
40 - ses->connect(url);  
41 -  
42 - if(timeout) {  
43 - ses->waitForReady(timeout);  
44 - }  
45 -  
46 - return 0;  
47 -  
48 - } catch(const exception &e) {  
49 -  
50 - tn3270_lasterror = e.what();  
51 -  
52 - }  
53 -  
54 - }  
55 -  
56 - return -1;  
57 -}  
58 -  
59 -int tn3270_disconnect(TN3270::Session *ses) {  
60 -  
61 - if(ses) {  
62 -  
63 - try {  
64 -  
65 - ses->disconnect();  
66 - return 0;  
67 -  
68 - } catch(const exception &e) {  
69 - tn3270_lasterror = e.what();  
70 - }  
71 -  
72 - }  
73 -  
74 - return -1;  
75 -}  
76 -  
77 -int tn3270_is_connected(TN3270::Session *ses) {  
78 -  
79 - if(ses) {  
80 -  
81 - try {  
82 -  
83 - return (int) (ses->getConnectionState() == TN3270::CONNECTED_TN3270E ? 1 : 0);  
84 -  
85 - } catch(const exception &e) {  
86 - tn3270_lasterror = e.what();  
87 - }  
88 -  
89 - }  
90 -  
91 - return -1;  
92 -}  
93 -  
94 -int tn3270_is_ready(TN3270::Session *ses) {  
95 -  
96 - if(ses) {  
97 -  
98 - try {  
99 -  
100 - return (int) (ses->getProgramMessage() == TN3270::MESSAGE_NONE ? 1 : 0);  
101 -  
102 - } catch(const exception &e) {  
103 -  
104 - tn3270_lasterror = e.what();  
105 -  
106 - }  
107 -  
108 - }  
109 -  
110 - return -1;  
111 -}  
112 -  
113 -int tn3270_wait_for_ready(TN3270::Session *ses, int seconds) {  
114 -  
115 - if(ses) {  
116 -  
117 - try {  
118 -  
119 - ses->waitForReady(seconds);  
120 - return 0;  
121 -  
122 - } catch(const exception &e) {  
123 - tn3270_lasterror = e.what();  
124 - }  
125 -  
126 - }  
127 - return -1;  
128 -  
129 -}  
130 -  
131 -int tn3270_wait(TN3270::Session *ses, int seconds) {  
132 -  
133 - if(ses) {  
134 -  
135 - try {  
136 -  
137 - ses->wait(seconds);  
138 - return 0;  
139 -  
140 - } catch(const exception &e) {  
141 - tn3270_lasterror = e.what();  
142 - }  
143 -  
144 - }  
145 - return -1;  
146 -}  
147 -  
src/native/private.h
@@ -1,158 +0,0 @@ @@ -1,158 +0,0 @@
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 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - * Referências:  
29 - *  
30 - * http://www.mono-project.com/docs/advanced/pinvoke/  
31 - * http://tirania.org/blog/archive/2011/Dec-19.html  
32 - *  
33 - */  
34 -  
35 -/**  
36 - * @file private.h  
37 - *  
38 - * @brief Internal definitions for the .NET Native module.  
39 - *  
40 - * @author Perry Werneck <perry.werneck@gmail.com>  
41 - *  
42 - */  
43 -  
44 -#ifndef PRIVATE_H_INCLUDED  
45 -  
46 - #define PRIVATE_H_INCLUDED  
47 -  
48 - #include <config.h>  
49 -  
50 - #if defined(_WIN32)  
51 -  
52 - #include <windows.h>  
53 -  
54 - #define DLL_PRIVATE extern  
55 - #define DLL_PUBLIC extern __declspec (dllexport) __attribute__((cdecl))  
56 -  
57 - #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)  
58 -  
59 - #define DLL_PRIVATE __hidden extern  
60 - #define DLL_PUBLIC extern  
61 -  
62 - #else  
63 -  
64 - #define DLL_PRIVATE __attribute__((visibility("hidden"))) extern  
65 - #define DLL_PUBLIC __attribute__((visibility("default"))) extern  
66 -  
67 - #endif  
68 -  
69 - #include <cstdio>  
70 - #include <string>  
71 -  
72 - #ifdef DEBUG  
73 - #define debug( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n" , __FILE__, (int) __LINE__, __VA_ARGS__ ); fflush(stderr);  
74 - #else  
75 - #define debug( fmt, ... ) /* */  
76 - #endif // DEBUG  
77 -  
78 - /*  
79 - #ifdef ENABLE_TRACE_TO_FILE  
80 - DLL_PRIVATE void write_trace(const char *fmt, ...);  
81 - #define trace( ... ) write_trace(__VA_ARGS__)  
82 - #else  
83 - #define trace( ... )  
84 - #endif // ENABLE_TRACE_TO_FILE  
85 - */  
86 -  
87 - #include <lib3270/ipc.h>  
88 - #include <cerrno>  
89 - #include <cstring>  
90 -  
91 - using std::string;  
92 - using std::exception;  
93 -  
94 - DLL_PRIVATE string tn3270_lasterror;  
95 -  
96 - extern "C" {  
97 -  
98 - DLL_PUBLIC TN3270::Session * tn3270_create_session(const char *name);  
99 -  
100 - DLL_PUBLIC int tn3270_destroy_session(TN3270::Session *ses);  
101 -  
102 - DLL_PUBLIC int tn3270_get_version(TN3270::Session *ses, char* str, int strlen);  
103 - DLL_PUBLIC int tn3270_get_revision(TN3270::Session *ses, char* str, int strlen);  
104 -  
105 - DLL_PUBLIC int tn3270_connect(TN3270::Session *ses, const char *host, time_t wait);  
106 - DLL_PUBLIC int tn3270_disconnect(TN3270::Session *ses);  
107 - DLL_PUBLIC int tn3270_is_connected(TN3270::Session *ses);  
108 - DLL_PUBLIC int tn3270_is_ready(TN3270::Session *ses);  
109 -  
110 - DLL_PUBLIC int tn3270_set_url(TN3270::Session *ses, const char *url);  
111 - DLL_PUBLIC int tn3270_get_url(TN3270::Session *ses, char* str, int strlen);  
112 -  
113 - DLL_PUBLIC int tn3270_set_error_message(TN3270::Session *ses, const char *url);  
114 - DLL_PUBLIC int tn3270_get_error_message(TN3270::Session *ses, char* str, int strlen);  
115 -  
116 - DLL_PUBLIC int tn3270_set_cursor_addr(TN3270::Session *ses, int addr);  
117 - DLL_PUBLIC int tn3270_get_cursor_addr(TN3270::Session *ses);  
118 -  
119 - DLL_PUBLIC int tn3270_action(TN3270::Session *ses, const char *name);  
120 -  
121 - DLL_PUBLIC int tn3270_erase(TN3270::Session *ses);  
122 - DLL_PUBLIC int tn3270_erase_eof(TN3270::Session *ses);  
123 - DLL_PUBLIC int tn3270_erase_eol(TN3270::Session *ses);  
124 - DLL_PUBLIC int tn3270_erase_input(TN3270::Session *ses);  
125 -  
126 - DLL_PUBLIC int tn3270_wait_for_ready(TN3270::Session *ses, int seconds);  
127 - DLL_PUBLIC int tn3270_wait(TN3270::Session *ses, int seconds);  
128 -  
129 - DLL_PUBLIC int tn3270_get_cstate(TN3270::Session *ses);  
130 - DLL_PUBLIC int tn3270_get_program_message(TN3270::Session *ses);  
131 - DLL_PUBLIC int tn3270_get_secure(TN3270::Session *ses);  
132 -  
133 - DLL_PUBLIC int tn3270_get_contents(TN3270::Session *ses, char* str, int strlen);  
134 - DLL_PUBLIC int tn3270_get_string(TN3270::Session *ses, int addr, char* str, int strlen);  
135 - DLL_PUBLIC int tn3270_get_string_at(TN3270::Session *ses, int row, int col, char* str, int strlen);  
136 -  
137 - DLL_PUBLIC int tn3270_set_string_at(TN3270::Session *ses, int row, int col, const char* str);  
138 -  
139 - DLL_PUBLIC int tn3270_wait_for_string_at(TN3270::Session *ses, int row, int col, const char *key, int timeout);  
140 - DLL_PUBLIC int tn3270_cmp_string_at(TN3270::Session *ses, int row, int col, const char* str);  
141 -  
142 - DLL_PUBLIC int tn3270_set_unlock_delay(TN3270::Session *ses, int ms);  
143 - DLL_PUBLIC int tn3270_set_cursor_position(TN3270::Session *ses, int row, int col);  
144 -  
145 - DLL_PUBLIC int tn3270_enter(TN3270::Session *ses);  
146 - DLL_PUBLIC int tn3270_pfkey(TN3270::Session *ses, int key);  
147 - DLL_PUBLIC int tn3270_pakey(TN3270::Session *ses, int key);  
148 -  
149 - DLL_PUBLIC int tn3270_get_width(TN3270::Session *ses);  
150 - DLL_PUBLIC int tn3270_get_height(TN3270::Session *ses);  
151 - DLL_PUBLIC int tn3270_get_length(TN3270::Session *ses);  
152 -  
153 - DLL_PUBLIC int tn3270_set_charset(TN3270::Session *ses, const char* str);  
154 -  
155 - }  
156 -  
157 -  
158 -#endif // PRIVATE_H_INCLUDED  
src/native/screen.cc
@@ -1,145 +0,0 @@ @@ -1,145 +0,0 @@
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 screen.cc e possui - linhas de código.  
22 - *  
23 - * Contatos:  
24 - *  
25 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
26 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - */  
29 -  
30 - #include "private.h"  
31 -  
32 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
33 -  
34 -int tn3270_get_contents(TN3270::Session *ses, char* str, int sz) {  
35 -  
36 - if(!ses) {  
37 - return -1;  
38 - }  
39 -  
40 - try {  
41 -  
42 - std::string contents = ses->toString(0,sz);  
43 -  
44 - memset(str,0,sz);  
45 - strncpy(str,contents.c_str(),sz);  
46 - if(contents.size() < ((size_t) sz)) {  
47 - str[contents.size()] = 0;  
48 - return contents.size();  
49 - }  
50 -  
51 - } catch(const exception &e) {  
52 - tn3270_lasterror = e.what();  
53 - return -1;  
54 - }  
55 -  
56 - return sz;  
57 -  
58 -}  
59 -  
60 -int tn3270_get_string(TN3270::Session *ses, int addr, char* str, int strlen) {  
61 -  
62 - if(!ses) {  
63 - return -1;  
64 - }  
65 -  
66 - try {  
67 - memset(str,0,strlen);  
68 - strncpy(str,ses->toString(addr,(size_t) strlen).c_str(),strlen);  
69 - } catch(const exception &e) {  
70 - tn3270_lasterror = e.what();  
71 - return -1;  
72 - }  
73 -  
74 - return 0;  
75 -}  
76 -  
77 -int tn3270_get_string_at(TN3270::Session *ses, int row, int col, char* str, int length) {  
78 -  
79 - if(!ses) {  
80 - return -1;  
81 - }  
82 -  
83 - try {  
84 -  
85 - memset(str,0,length);  
86 - strncpy(str,ses->toString(row,col,(size_t) length).c_str(),length);  
87 -  
88 - } catch(const exception &e) {  
89 - tn3270_lasterror = e.what();  
90 - return -1;  
91 - }  
92 - return (int) strlen(str);  
93 -}  
94 -  
95 -int tn3270_set_string_at(TN3270::Session *ses, int row, int col, const char* str) {  
96 -  
97 - if(!ses) {  
98 - return -1;  
99 - }  
100 -  
101 - try {  
102 -  
103 - ses->push(row,col,str);  
104 -  
105 - } catch(const exception &e) {  
106 - tn3270_lasterror = e.what();  
107 - return -1;  
108 - }  
109 - return 0;  
110 -}  
111 -  
112 -int tn3270_wait_for_string_at(TN3270::Session *ses, int row, int col, const char *key, int timeout) {  
113 -  
114 - if(ses) {  
115 -  
116 - try {  
117 -  
118 - return ses->wait(row,col,key,timeout);  
119 -  
120 - } catch(const exception &e) {  
121 -  
122 - tn3270_lasterror = e.what();  
123 -  
124 - }  
125 -  
126 - }  
127 -  
128 - return -1;  
129 -  
130 -}  
131 -  
132 -int tn3270_cmp_string_at(TN3270::Session *ses, int row, int col, const char* str) {  
133 -  
134 - if(ses) {  
135 -  
136 - try {  
137 - return ses->compare(row,col,str,strlen(str));  
138 - } catch(const exception &e) {  
139 - tn3270_lasterror = e.what();  
140 - }  
141 -  
142 - }  
143 -  
144 - return -1;  
145 -}  
src/native/set.cc
@@ -1,98 +0,0 @@ @@ -1,98 +0,0 @@
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 set.cc e possui - linhas de código.  
22 - *  
23 - * Contatos:  
24 - *  
25 - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)  
26 - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)  
27 - *  
28 - */  
29 -  
30 - #include "private.h"  
31 -  
32 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
33 -  
34 -int tn3270_set_unlock_delay(TN3270::Session *ses, int ms) {  
35 - try {  
36 - ses->setUnlockDelay((unsigned short) ms);  
37 - } catch(const exception &e) {  
38 - tn3270_lasterror = e.what();  
39 - return -1;  
40 - }  
41 - return 0;  
42 -}  
43 -  
44 -int tn3270_set_cursor_position(TN3270::Session *ses, int row, int col) {  
45 - try {  
46 - ses->setCursor((unsigned short) row, (unsigned short) col);  
47 - } catch(const exception &e) {  
48 - tn3270_lasterror = e.what();  
49 - return -1;  
50 - }  
51 - return 0;  
52 -}  
53 -  
54 -int tn3270_set_cursor_addr(TN3270::Session *ses, int addr) {  
55 - try {  
56 - ses->setCursor((unsigned short) addr);  
57 - } catch(const exception &e) {  
58 - tn3270_lasterror = e.what();  
59 - return -1;  
60 - }  
61 - return 0;  
62 -}  
63 -  
64 -int tn3270_set_charset(TN3270::Session *ses, const char* str) {  
65 -  
66 - try {  
67 -  
68 - ses->setCharSet(str);  
69 -  
70 - } catch(const exception &e) {  
71 -  
72 - tn3270_lasterror = e.what();  
73 - return -1;  
74 -  
75 - }  
76 -  
77 - return 0;  
78 -  
79 -}  
80 -  
81 -int tn3270_set_url(TN3270::Session *ses, const char *url) {  
82 -  
83 - try {  
84 -  
85 - ses->setHostURL(url);  
86 -  
87 - } catch(const exception &e) {  
88 - tn3270_lasterror = e.what();  
89 - return -1;  
90 - }  
91 -  
92 - return 0;  
93 -}  
94 -  
95 -int tn3270_set_error_message(TN3270::Session *ses, const char *str) {  
96 - tn3270_lasterror = str;  
97 - return 0;  
98 -}  
src/native/testprogram/testprogram.cc 0 → 100644
@@ -0,0 +1,167 @@ @@ -0,0 +1,167 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 +/**
  31 + * @file
  32 + *
  33 + * @brief
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include <getopt.h>
  40 + #include <cstdlib>
  41 + #include <native.h>
  42 +
  43 + using namespace std;
  44 +
  45 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  46 +
  47 +
  48 +/*
  49 + // test host object
  50 + static void testHost(const char *session) {
  51 +
  52 + TN3270::Host host{session,nullptr,10};
  53 +
  54 + try {
  55 +
  56 + cout
  57 + << "Version: " << host.getVersion()
  58 + << "\tRevision: " << host.getRevision()
  59 + << std::endl;
  60 +
  61 + host.connect(nullptr);
  62 +
  63 + cout
  64 + << "Wait for unlock returns " << host.getKeyboardLockState() << std::endl
  65 + << "Connection state is " << toCharString(host.getConnectionState()) << std::endl
  66 + << "Program message is " << toCharString(host.getProgramMessage()) << std::endl
  67 + << "Luname is " << host.getLUName() << std::endl
  68 + << std::endl;
  69 +
  70 + if(host) {
  71 + cout << host << endl;
  72 + }
  73 +
  74 + host.setCursor(10,10);
  75 +
  76 + host.wait(10);
  77 +
  78 + // host.input("test@0another line");
  79 +
  80 + host.push(TN3270::ENTER);
  81 +
  82 + cout << endl << "[" << host.toString((unsigned int) 1, (unsigned int) 3,7) << "]" << endl;
  83 + cout << endl << "[" << host.toString((int) 15, (int) 10) << "]" << endl;
  84 +
  85 + host.pfkey(3);
  86 +
  87 + host.wait(10);
  88 +
  89 + host.disconnect();
  90 +
  91 + } catch(const std::exception &e) {
  92 +
  93 + cerr << std::endl << e.what() << std::endl << std::endl;
  94 +
  95 + }
  96 +
  97 + }
  98 + */
  99 +
  100 + int main(int argc, char **argv) {
  101 +
  102 + const char * session = ""; // "pw3270:a";
  103 + char buffer[4096];
  104 +
  105 + #pragma GCC diagnostic push
  106 + #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
  107 + static struct option options[] = {
  108 + { "session", required_argument, 0, 's' },
  109 + { 0, 0, 0, 0}
  110 +
  111 + };
  112 + #pragma GCC diagnostic pop
  113 +
  114 + int long_index =0;
  115 + int opt;
  116 + while((opt = getopt_long(argc, argv, "s:", options, &long_index )) != -1) {
  117 +
  118 + switch(opt) {
  119 + case 's':
  120 + session = optarg;
  121 + break;
  122 +
  123 + }
  124 +
  125 + }
  126 +
  127 + cout << "Session: " << session << endl;
  128 +
  129 + TN3270::Host * host = tn3270_create_session(session);
  130 +
  131 + tn3270_get_version(host,buffer,sizeof(buffer));
  132 + cout << "Version: " << buffer << endl;
  133 +
  134 + tn3270_get_revision(host,buffer,sizeof(buffer));
  135 + cout << "Revision: " << buffer << endl;
  136 +
  137 + tn3270_connect(host,nullptr,10);
  138 +
  139 + cout << "Connection state is " << tn3270_get_cstate(host) << std::endl
  140 + << "Program message is " << tn3270_get_program_message(host) << std::endl;
  141 +
  142 + tn3270_get_contents(host,buffer,sizeof(buffer));
  143 + cout << buffer << endl;
  144 +
  145 + tn3270_set_cursor_position(host,10,10);
  146 + tn3270_wait(host,10);
  147 +
  148 + tn3270_enter(host);
  149 + tn3270_wait_for_ready(host,10);
  150 +
  151 + tn3270_get_contents(host,buffer,sizeof(buffer));
  152 + cout << buffer << endl;
  153 +
  154 + tn3270_pfkey(host,3);
  155 + tn3270_wait_for_ready(host,10);
  156 +
  157 + tn3270_get_contents(host,buffer,sizeof(buffer));
  158 + cout << buffer << endl;
  159 +
  160 + tn3270_disconnect(host);
  161 +
  162 + tn3270_destroy_session(host);
  163 +
  164 + return 0;
  165 + }
  166 +
  167 +
src/native/valgrind.suppression 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +{
  2 + libcrypt_FIPS_selftest
  3 + Memcheck:Cond
  4 + ...
  5 + fun:FIPS_selftest
  6 +}
  7 +
  8 +{
  9 + libcrypt_FIPS_mode_set
  10 + Memcheck:Cond
  11 + ...
  12 + fun:FIPS_mode_set
  13 +}
  14 +