Commit 0d821011bcce1bc9f1c95bcaaed0957d525916b0

Authored by Perry Werneck
1 parent 6d747872
Exists in master and in 1 other branch develop

Refactoring IPC to use multiple source files.

client/Makefile.in
@@ -33,6 +33,7 @@ MAIN_SOURCES= \ @@ -33,6 +33,7 @@ MAIN_SOURCES= \
33 $(wildcard src/core/*.cc) \ 33 $(wildcard src/core/*.cc) \
34 $(wildcard src/core/@OSNAME@/*.cc) \ 34 $(wildcard src/core/@OSNAME@/*.cc) \
35 $(wildcard src/core/@OSNAME@/*.rc) \ 35 $(wildcard src/core/@OSNAME@/*.rc) \
  36 + $(wildcard src/session/*.cc) \
36 $(wildcard src/session/local/*.cc) \ 37 $(wildcard src/session/local/*.cc) \
37 $(wildcard src/session/remote/*.cc) 38 $(wildcard src/session/remote/*.cc)
38 39
@@ -55,6 +56,7 @@ XGETTEXT=@XGETTEXT@ @@ -55,6 +56,7 @@ XGETTEXT=@XGETTEXT@
55 MSGCAT=@MSGCAT@ 56 MSGCAT=@MSGCAT@
56 WINDRES=@WINDRES@ 57 WINDRES=@WINDRES@
57 AR=@AR@ 58 AR=@AR@
  59 +VALGRIND=@VALGRIND@
58 60
59 #---[ Paths ]---------------------------------------------------------------------------- 61 #---[ Paths ]----------------------------------------------------------------------------
60 62
@@ -310,8 +312,18 @@ $(BINDBG)/lib$(MODULE_NAME)@LIBEXT@: \ @@ -310,8 +312,18 @@ $(BINDBG)/lib$(MODULE_NAME)@LIBEXT@: \
310 run: \ 312 run: \
311 $(BINDBG)/$(MODULE_NAME)-client@EXEEXT@ 313 $(BINDBG)/$(MODULE_NAME)-client@EXEEXT@
312 314
  315 +ifeq ($(VALGRIND),no)
  316 +
  317 + @LD_LIBRARY_PATH=$(BINDBG) \
  318 + $(BINDBG)/$(MODULE_NAME)-client@EXEEXT@
  319 +
  320 +else
  321 + @touch valgrind.suppression
  322 +
313 @LD_LIBRARY_PATH=$(BINDBG) \ 323 @LD_LIBRARY_PATH=$(BINDBG) \
  324 + $(VALGRIND) --leak-check=full --track-origins=yes --gen-suppressions=all --suppressions=valgrind.suppression \
314 $(BINDBG)/$(MODULE_NAME)-client@EXEEXT@ 325 $(BINDBG)/$(MODULE_NAME)-client@EXEEXT@
  326 +endif
315 327
316 #---[ Clean Targets ]-------------------------------------------------------------------- 328 #---[ Clean Targets ]--------------------------------------------------------------------
317 329
client/lib3270++.cbp
@@ -53,8 +53,15 @@ @@ -53,8 +53,15 @@
53 <Unit filename="src/core/windows/resources.rc.in" /> 53 <Unit filename="src/core/windows/resources.rc.in" />
54 <Unit filename="src/core/windows/session.cc" /> 54 <Unit filename="src/core/windows/session.cc" />
55 <Unit filename="src/include/ipc-client-internals.h" /> 55 <Unit filename="src/include/ipc-client-internals.h" />
  56 + <Unit filename="src/session/get.cc" />
  57 + <Unit filename="src/session/local/actions.cc" />
56 <Unit filename="src/session/local/events.cc" /> 58 <Unit filename="src/session/local/events.cc" />
57 - <Unit filename="src/session/local/session.cc" /> 59 + <Unit filename="src/session/local/get.cc" />
  60 + <Unit filename="src/session/local/init.cc" />
  61 + <Unit filename="src/session/local/private.h" />
  62 + <Unit filename="src/session/local/properties.cc" />
  63 + <Unit filename="src/session/local/set.cc" />
  64 + <Unit filename="src/session/local/tools.cc" />
58 <Unit filename="src/session/remote/session.cc" /> 65 <Unit filename="src/session/remote/session.cc" />
59 <Unit filename="src/testprogram/testprogram.cc" /> 66 <Unit filename="src/testprogram/testprogram.cc" />
60 <Extensions> 67 <Extensions>
client/src/core/abstract.cc
@@ -51,8 +51,6 @@ @@ -51,8 +51,6 @@
51 this->converter.host = (iconv_t) (-1); 51 this->converter.host = (iconv_t) (-1);
52 #endif 52 #endif
53 53
54 - this->baddr = 0;  
55 -  
56 } 54 }
57 55
58 Abstract::Session::~Session() { 56 Abstract::Session::~Session() {
@@ -72,6 +70,17 @@ @@ -72,6 +70,17 @@
72 /// @brief Setup charsets 70 /// @brief Setup charsets
73 void Abstract::Session::setCharSet(const char *remote, const char *local) { 71 void Abstract::Session::setCharSet(const char *remote, const char *local) {
74 72
  73 + if(!local) {
  74 +
  75 + // TODO: Detect the current value (maybee something like g_charset)
  76 +#ifdef _WIN32
  77 + local = "CP1252";
  78 +#else
  79 + local = "UTF-8";
  80 +#endif // _WIN32
  81 +
  82 + }
  83 +
75 #ifdef HAVE_ICONV 84 #ifdef HAVE_ICONV
76 85
77 if(this->converter.local != (iconv_t) (-1)) 86 if(this->converter.local != (iconv_t) (-1))
@@ -101,24 +110,19 @@ @@ -101,24 +110,19 @@
101 } 110 }
102 111
103 /// @brief Converte charset. 112 /// @brief Converte charset.
104 - std::string Abstract::Session::convertCharset(iconv_t &converter, const char *str, int length) { 113 + std::string Abstract::Session::convertCharset(iconv_t &converter, const std::string &str) {
105 114
106 std::string rc; 115 std::string rc;
107 116
108 #ifdef HAVE_ICONV 117 #ifdef HAVE_ICONV
109 - size_t in;  
110 -  
111 - if(length < 0)  
112 - in = (size_t) strlen(str);  
113 - else  
114 - in = (size_t) length; 118 + size_t in = str.size();
115 119
116 if(in && converter != (iconv_t)(-1)) { 120 if(in && converter != (iconv_t)(-1)) {
117 121
118 size_t out = (in << 1); 122 size_t out = (in << 1);
119 char * ptr; 123 char * ptr;
120 char * outBuffer = (char *) malloc(out); 124 char * outBuffer = (char *) malloc(out);
121 - ICONV_CONST char * inBuffer = (ICONV_CONST char *) str; 125 + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str.c_str();
122 126
123 memset(ptr=outBuffer,0,out); 127 memset(ptr=outBuffer,0,out);
124 128
@@ -141,13 +145,13 @@ @@ -141,13 +145,13 @@
141 } 145 }
142 146
143 /// @brief Converte string recebida do host para o charset atual. 147 /// @brief Converte string recebida do host para o charset atual.
144 - std::string Abstract::Session::convertFromHost(const char *str, int length) const {  
145 - return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str,length); 148 + std::string Abstract::Session::convertFromHost(const std::string &str) const {
  149 + return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str);
146 } 150 }
147 151
148 /// @brief Converte string do charset atual para o charset do host. 152 /// @brief Converte string do charset atual para o charset do host.
149 - std::string Abstract::Session::convertToHost(const char *str, int length) const {  
150 - return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,str,length); 153 + std::string Abstract::Session::convertToHost(const std::string &str) const {
  154 + return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,str);
151 } 155 }
152 156
153 157
client/src/core/constants.cc
@@ -36,11 +36,20 @@ @@ -36,11 +36,20 @@
36 * 36 *
37 */ 37 */
38 38
39 - #include <ipc-client-internals.h>  
40 39
  40 + #include <ipc-client-internals.h>
  41 + #include <lib3270.h>
41 42
42 /*---[ Implement ]----------------------------------------------------------------------------------*/ 43 /*---[ Implement ]----------------------------------------------------------------------------------*/
43 44
  45 +TN3270_PUBLIC const char * getVersion() {
  46 + return PACKAGE_VERSION;
  47 +}
  48 +
  49 +TN3270_PUBLIC const char * getRevision() {
  50 + return LIB3270_STRINGIZE_VALUE_OF(PACKAGE_RELEASE);
  51 +}
  52 +
44 TN3270_PUBLIC const char * toCharString(const TN3270::Action action) { 53 TN3270_PUBLIC const char * toCharString(const TN3270::Action action) {
45 54
46 static const char * actions[] = { 55 static const char * actions[] = {
client/src/core/host.cc
@@ -49,6 +49,7 @@ @@ -49,6 +49,7 @@
49 49
50 namespace TN3270 { 50 namespace TN3270 {
51 51
  52 + /*
52 Host::Host(const char *id, const char *url, time_t timeout) { 53 Host::Host(const char *id, const char *url, time_t timeout) {
53 54
54 debug("Creating host id=\"", id); 55 debug("Creating host id=\"", id);
@@ -464,7 +465,7 @@ @@ -464,7 +465,7 @@
464 return *this; 465 return *this;
465 466
466 } 467 }
467 - 468 + */
468 469
469 470
470 } 471 }
client/src/core/linux/request.cc
@@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
44 44
45 namespace TN3270 { 45 namespace TN3270 {
46 46
  47 + /*
47 IPC::Request::Request(const Session &session) { 48 IPC::Request::Request(const Session &session) {
48 this->conn = session.conn; 49 this->conn = session.conn;
49 this->msg.in = nullptr; 50 this->msg.in = nullptr;
@@ -67,16 +68,6 @@ @@ -67,16 +68,6 @@
67 68
68 IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) { 69 IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) {
69 70
70 -/*  
71 - dbus-send \  
72 - --session \  
73 - --dest=br.com.bb.pw3270.a\  
74 - --print-reply \  
75 - "/br/com/bb/tn3270/session" \  
76 - "org.freedesktop.DBus.Properties.Get" \  
77 - string:br.com.bb.tn3270.session \  
78 - string:${1}  
79 -*/  
80 this->msg.out = dbus_message_new_method_call( 71 this->msg.out = dbus_message_new_method_call(
81 session.name.c_str(), // Destination 72 session.name.c_str(), // Destination
82 session.path.c_str(), // Path 73 session.path.c_str(), // Path
@@ -262,6 +253,8 @@ @@ -262,6 +253,8 @@
262 253
263 } 254 }
264 255
  256 + */
  257 +
265 } 258 }
266 259
267 260
client/src/core/linux/session.cc
@@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
58 58
59 namespace TN3270 { 59 namespace TN3270 {
60 60
  61 + /*
61 IPC::Session::Session(const char *id) : Abstract::Session() { 62 IPC::Session::Session(const char *id) : Abstract::Session() {
62 63
63 // Create D-Bus session. 64 // Create D-Bus session.
@@ -92,6 +93,7 @@ @@ -92,6 +93,7 @@
92 IPC::Session::~Session() { 93 IPC::Session::~Session() {
93 94
94 } 95 }
  96 + */
95 97
96 } 98 }
97 99
client/src/core/session.cc
@@ -43,37 +43,33 @@ @@ -43,37 +43,33 @@
43 43
44 namespace TN3270 { 44 namespace TN3270 {
45 45
46 - /// @brief Create a tn3270 session.  
47 - Session * Session::create(const char *id) {  
48 -  
49 - debug("Creating session with ID \"",id,"\""); 46 + Session * Session::getInstance(const char *id) {
50 47
51 if(!(id && *id)) { 48 if(!(id && *id)) {
52 - return new Local::Session(); 49 + return Local::getSessionInstance();
53 } 50 }
54 51
55 - return new IPC::Session(id); 52 + // return new IPC::Session(id);
56 53
  54 + return nullptr;
57 } 55 }
58 56
59 57
60 Session::Session() { 58 Session::Session() {
61 -  
62 } 59 }
63 60
64 Session::~Session() { 61 Session::~Session() {
65 -  
66 - }  
67 -  
68 - void Session::insert(Event::Type type, std::function <void(const Event &event)> listener) {  
69 } 62 }
70 63
71 /// @brief Fire event. 64 /// @brief Fire event.
72 void Session::fire(const Event &event) { 65 void Session::fire(const Event &event) {
  66 + }
73 67
74 - 68 + /*
  69 + void Session::insert(Event::Type type, std::function <void(const Event &event)> listener) {
75 } 70 }
76 71
  72 +
77 Session & Session::push(const PFKey key) { 73 Session & Session::push(const PFKey key) {
78 return pfkey( ((unsigned short) key) + 1); 74 return pfkey( ((unsigned short) key) + 1);
79 } 75 }
@@ -93,7 +89,7 @@ @@ -93,7 +89,7 @@
93 void Session::setCharSet(const char *charset) { 89 void Session::setCharSet(const char *charset) {
94 } 90 }
95 91
96 - 92 + */
97 93
98 } 94 }
99 95
client/src/include/ipc-client-internals.h
@@ -36,9 +36,9 @@ @@ -36,9 +36,9 @@
36 * 36 *
37 */ 37 */
38 38
39 -#ifndef PRIVATE_H_INCLUDED 39 +#ifndef IPC_CLIENT_INTERNALS_INCLUDED
40 40
41 - #define PRIVATE_H_INCLUDED 41 + #define IPC_CLIENT_INTERNALS_INCLUDED
42 42
43 #include <config.h> 43 #include <config.h>
44 44
@@ -70,12 +70,6 @@ @@ -70,12 +70,6 @@
70 #include <iconv.h> 70 #include <iconv.h>
71 #endif // HAVE_ICONV 71 #endif // HAVE_ICONV
72 72
73 -#ifdef WIN32  
74 - #define SYSTEM_CHARSET "CP1252"  
75 -#else  
76 - #define SYSTEM_CHARSET "UTF-8"  
77 -#endif // WIN32  
78 -  
79 #ifdef DEBUG 73 #ifdef DEBUG
80 74
81 inline void console(std::ostream &out) { 75 inline void console(std::ostream &out) {
@@ -121,24 +115,38 @@ @@ -121,24 +115,38 @@
121 #endif 115 #endif
122 116
123 /// @brief Converte charset. 117 /// @brief Converte charset.
124 - static std::string convertCharset(iconv_t &converter, const char *str, int length); 118 + static std::string convertCharset(iconv_t &converter, const std::string &str);
125 119
126 protected: 120 protected:
127 121
128 - /// @brief Current in/out position.  
129 - int baddr;  
130 -  
131 Session(); 122 Session();
132 virtual ~Session(); 123 virtual ~Session();
133 124
134 /// @brief Setup charsets 125 /// @brief Setup charsets
135 - void setCharSet(const char *remote, const char *local = SYSTEM_CHARSET); 126 + void setCharSet(const char *remote, const char *local);
136 127
137 /// @brief Converte string recebida do host para o charset atual. 128 /// @brief Converte string recebida do host para o charset atual.
138 - std::string convertFromHost(const char *str, int length = -1) const; 129 + std::string convertFromHost(const std::string &str) const;
139 130
140 /// @brief Converte string do charset atual para o charset do host. 131 /// @brief Converte string do charset atual para o charset do host.
141 - std::string convertToHost(const char *str, int length = -1) const; 132 + std::string convertToHost(const std::string &str) const;
  133 +
  134 + // Get strings from lib3270 without charset conversion.
  135 + virtual std::string get() const = 0;
  136 + virtual std::string get(int baddr, size_t len, char lf) const = 0;
  137 + virtual std::string get(int row, int col, size_t sz, char lf) const = 0;
  138 +
  139 + // Set strings to lib3270 without charset conversion.
  140 + virtual void set(const std::string &str) = 0;
  141 + virtual void set(int baddr, const std::string &str) = 0;
  142 + virtual void set(int row, int col, const std::string &str) = 0;
  143 +
  144 + public:
  145 +
  146 + // Contents
  147 + std::string toString(int baddr = 0, size_t len = -1, char lf = '\n') const override;
  148 + std::string toString(int row, int col, size_t sz, char lf = '\n') const override;
  149 +
142 150
143 }; 151 };
144 152
@@ -147,6 +155,15 @@ @@ -147,6 +155,15 @@
147 /// @brief lib3270 direct access objects (no IPC); 155 /// @brief lib3270 direct access objects (no IPC);
148 namespace Local { 156 namespace Local {
149 157
  158 + TN3270_PRIVATE Session * getSessionInstance();
  159 +
  160 + }
  161 +
  162 + /*
  163 +
  164 + /// @brief lib3270 direct access objects (no IPC);
  165 + namespace Local {
  166 +
150 class TN3270_PRIVATE Session : public TN3270::Abstract::Session { 167 class TN3270_PRIVATE Session : public TN3270::Abstract::Session {
151 private: 168 private:
152 169
@@ -429,7 +446,8 @@ @@ -429,7 +446,8 @@
429 }; 446 };
430 447
431 } 448 }
  449 + */
432 450
433 } 451 }
434 452
435 -#endif // PRIVATE_H_INCLUDED 453 +#endif // IPC_CLIENT_INTERNALS_INCLUDED
client/src/session/get.cc 0 → 100644
@@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
  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 <ipc-client-internals.h>
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + namespace TN3270 {
  44 +
  45 + std::string Abstract::Session::toString(int baddr, size_t len, char lf) const {
  46 + return convertFromHost(get(baddr,len,lf));
  47 + }
  48 +
  49 + std::string Abstract::Session::toString(int row, int col, size_t sz, char lf) const {
  50 + return convertFromHost(get(row,col,sz,lf));
  51 + }
  52 +
  53 + }
  54 +
  55 +
client/src/session/local/actions.cc 0 → 100644
@@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
  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 "private.h"
  40 + #include <lib3270/actions.h>
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + void Local::Session::connect(const char *url, bool wait) {
  47 +
  48 + std::lock_guard<std::mutex> lock(sync);
  49 + chkResponse(lib3270_connect_url(hSession,url,(wait ? 1 : 0)));
  50 + }
  51 +
  52 + void Local::Session::disconnect() {
  53 +
  54 + std::lock_guard<std::mutex> lock(sync);
  55 + chkResponse(lib3270_disconnect(hSession));
  56 + }
  57 +
  58 + void Local::Session::wait(unsigned short seconds) const {
  59 +
  60 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  61 + chkResponse(lib3270_wait(this->hSession, seconds));
  62 +
  63 + }
  64 +
  65 + void Local::Session::waitForReady(time_t timeout) const {
  66 +
  67 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  68 + chkResponse(lib3270_wait_for_ready(this->hSession, timeout));
  69 +
  70 + }
  71 +
  72 + void Local::Session::waitForChange(unsigned short seconds) const {
  73 +
  74 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  75 + chkResponse(lib3270_wait_for_update(this->hSession, seconds));
  76 +
  77 + }
  78 +
  79 + void Local::Session::pfkey(unsigned short value) {
  80 +
  81 + std::lock_guard<std::mutex> lock(sync);
  82 + chkResponse(lib3270_pfkey(hSession,value));
  83 +
  84 + }
  85 +
  86 + void Local::Session::pakey(unsigned short value) {
  87 +
  88 + std::lock_guard<std::mutex> lock(sync);
  89 + chkResponse(lib3270_pakey(hSession,value));
  90 +
  91 + }
  92 +
  93 + }
  94 +
  95 +
client/src/session/local/events.cc
@@ -36,11 +36,7 @@ @@ -36,11 +36,7 @@
36 * 36 *
37 */ 37 */
38 38
39 - #include <config.h>  
40 - #include <cstdio>  
41 - #include <ipc-client-internals.h>  
42 - #include <cstring>  
43 - #include <malloc.h> 39 + #include "private.h"
44 40
45 extern "C" { 41 extern "C" {
46 #include <lib3270/actions.h> 42 #include <lib3270/actions.h>
@@ -179,7 +175,6 @@ @@ -179,7 +175,6 @@
179 175
180 } 176 }
181 177
182 -  
183 } 178 }
184 179
185 180
client/src/session/local/get.cc 0 → 100644
@@ -0,0 +1,109 @@ @@ -0,0 +1,109 @@
  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 "private.h"
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + namespace TN3270 {
  44 +
  45 + std::string Local::Session::get() const {
  46 +
  47 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  48 +
  49 + lib3270_autoptr(char) text = lib3270_get_string_at_address(hSession, 0, -1, '\n');
  50 +
  51 + if(!text) {
  52 + throw std::runtime_error( _("Can't get screen contents") );
  53 + }
  54 +
  55 + return std::string(text);
  56 + }
  57 +
  58 + std::string Local::Session::get(int baddr, size_t len, char lf) const {
  59 +
  60 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  61 +
  62 + lib3270_autoptr(char) text = lib3270_get_string_at_address(hSession, baddr, len, lf);
  63 +
  64 + if(!text) {
  65 + throw std::runtime_error( _("Can't get screen contents") );
  66 + }
  67 +
  68 + return std::string(text);
  69 + }
  70 +
  71 + std::string Local::Session::get(int row, int col, size_t sz, char lf) const {
  72 +
  73 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  74 +
  75 + lib3270_autoptr(char) text = lib3270_get_string_at(hSession, row, col, sz, lf);
  76 +
  77 + if(!text) {
  78 + throw std::runtime_error( _("Can't get screen contents") );
  79 + }
  80 +
  81 + return std::string(text);
  82 +
  83 + }
  84 +
  85 + ProgramMessage Local::Session::getProgramMessage() const {
  86 +
  87 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  88 + return (ProgramMessage) lib3270_get_program_message(this->hSession);
  89 +
  90 + }
  91 +
  92 + ConnectionState Local::Session::getConnectionState() const {
  93 +
  94 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  95 + return (ConnectionState) lib3270_get_connection_state(this->hSession);
  96 +
  97 + }
  98 +
  99 + SSLState Local::Session::getSSLState() const {
  100 +
  101 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  102 + return (TN3270::SSLState) lib3270_get_ssl_state(hSession);
  103 +
  104 + }
  105 +
  106 +
  107 + }
  108 +
  109 +
client/src/session/local/init.cc 0 → 100644
@@ -0,0 +1,270 @@ @@ -0,0 +1,270 @@
  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 src/session/local/init.cc
  32 + *
  33 + * @brief Implement lib3270 direct access layout (NO IPC).
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 + extern "C" {
  42 + #include <lib3270/session.h>
  43 + }
  44 +
  45 +
  46 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  47 +
  48 + namespace TN3270 {
  49 +
  50 + Session * Local::getSessionInstance() {
  51 + return new Local::Session();
  52 + }
  53 +
  54 + #ifdef _WIN32
  55 +
  56 + string getUserName() {
  57 +
  58 + char username[UNLEN + 1];
  59 + DWORD szName = sizeof(username);
  60 +
  61 + memset(username,0,UNLEN + 1);
  62 +
  63 + if(!GetUserName(username, &szName)) {
  64 + return "?";
  65 + }
  66 +
  67 + return string(username);
  68 +
  69 + }
  70 +
  71 + static void writeLog(HANDLE hEventLog, const char *msg, int rc = (int) GetLastError()) {
  72 +
  73 +
  74 + debug(msg," rc=",rc);
  75 +
  76 + if(hEventLog) {
  77 +
  78 + string username = getUserName();
  79 + char lasterror[1024];
  80 + snprintf(lasterror,sizeof(lasterror),"The error code was %d",rc);
  81 +
  82 + const char *outMsg[] = {
  83 + username.c_str(),
  84 + msg,
  85 + lasterror
  86 + };
  87 +
  88 + ReportEvent(
  89 + hEventLog,
  90 + EVENTLOG_ERROR_TYPE,
  91 + 1,
  92 + 0,
  93 + NULL,
  94 + (sizeof(outMsg) / sizeof(outMsg[0])),
  95 + 0,
  96 + outMsg,
  97 + NULL
  98 + );
  99 +
  100 + }
  101 +
  102 + }
  103 +
  104 + static string getInstallLocation(HANDLE hEventLog) {
  105 +
  106 + LSTATUS rc;
  107 + HKEY hKey = 0;
  108 +
  109 + static const char * keys[] = {
  110 +#ifdef LIB3270_NAME
  111 + "Software\\" LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME),
  112 + "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME),
  113 +#endif
  114 + "Software\\pw3270",
  115 + "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270"
  116 + };
  117 +
  118 + size_t ix;
  119 +
  120 + string installLocation;
  121 +
  122 + for(ix = 0; installLocation.empty() && ix < (sizeof(keys)/sizeof(keys[0])); ix++) {
  123 +
  124 + debug(ix,"=",keys[ix]);
  125 +
  126 + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,keys[ix],0,KEY_QUERY_VALUE,&hKey);
  127 + if(rc == ERROR_SUCCESS) {
  128 +
  129 + unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
  130 + char datadir[4096];
  131 + unsigned long datalen = sizeof(datadir);
  132 +
  133 + memset(datadir,0,datalen);
  134 +
  135 + rc = RegQueryValueExA(hKey,"InstallLocation",NULL,&datatype,(LPBYTE) datadir,&datalen);
  136 + if(rc == ERROR_SUCCESS) {
  137 +
  138 + debug("Found: ",datadir);
  139 +
  140 + installLocation.assign(datadir);
  141 + string username = getUserName();
  142 +
  143 + const char *outMsg[] = {
  144 + username.c_str(),
  145 + "Found LIB3270 installation",
  146 + keys[ix],
  147 + installLocation.c_str()
  148 + };
  149 +
  150 + ReportEvent(
  151 + hEventLog,
  152 + EVENTLOG_INFORMATION_TYPE,
  153 + 1,
  154 + 0,
  155 + NULL,
  156 + (sizeof(outMsg) / sizeof(outMsg[0])),
  157 + 0,
  158 + outMsg,
  159 + NULL
  160 + );
  161 +
  162 + }
  163 +
  164 + RegCloseKey(hKey);
  165 +
  166 + }
  167 +
  168 + }
  169 +
  170 + return installLocation;
  171 + }
  172 +
  173 + #endif // _WIN32
  174 +
  175 + Local::Session::Session() : Abstract::Session() {
  176 +
  177 + std::lock_guard<std::mutex> lock(sync);
  178 +
  179 +#ifdef _WIN32
  180 + {
  181 + static bool initialized = false;
  182 +
  183 + if(!initialized) {
  184 +
  185 +#ifdef LIB3270_NAME
  186 + HANDLE hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME));
  187 +#else
  188 + HANDLE hEventLog = RegisterEventSource(NULL, PACKAGE_NAME);
  189 +#endif // LIB3270_NAME
  190 +
  191 + string installLocation = getInstallLocation(hEventLog);
  192 +
  193 + if(installLocation.empty()) {
  194 +
  195 + writeLog(hEventLog, "Can't identify lib3270 installation path");
  196 +
  197 + } else {
  198 +
  199 + // TODO: Understand why SetDefaultDllDirectories & AddDllDirectory causes failure in DNS resolution.
  200 +
  201 +
  202 + SetCurrentDirectory(installLocation.c_str());
  203 +
  204 +/*
  205 + wchar_t *path = (wchar_t *) malloc(sizeof(datadir)*sizeof(wchar_t));
  206 + mbstowcs(path, datadir, 4095);
  207 +
  208 + if(!SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS)) {
  209 + writeLog(hEventLog,"SetDefaultDllDirectories has failed");
  210 + }
  211 +#ifdef DEBUG
  212 + else {
  213 + debug("SetDefaultDllDirectories has suceeded");
  214 + }
  215 +#endif
  216 +
  217 + if(!AddDllDirectory(path)) {
  218 + string msg = "Can't add ";
  219 + msg += datadir;
  220 + msg += " to directory path";
  221 + writeLog(hEventLog,msg.c_str());
  222 + }
  223 +#ifdef DEBUG
  224 + else {
  225 + debug("AddDllDirectory has suceeded");
  226 + }
  227 +#endif
  228 + free(path);
  229 +
  230 +*/
  231 + }
  232 +
  233 + initialized = true;
  234 + DeregisterEventSource(hEventLog);
  235 +
  236 + }
  237 +
  238 + }
  239 +#endif // _WIN32
  240 +
  241 + this->hSession = lib3270_session_new("");
  242 +
  243 + lib3270_set_user_data(this->hSession,(void *) this);
  244 + setCharSet();
  245 + lib3270_set_popup_handler(this->hSession, popupHandler);
  246 +
  247 + // Setup callbacks
  248 + struct lib3270_session_callbacks *cbk;
  249 +
  250 + cbk = lib3270_get_session_callbacks(this->hSession,sizeof(struct lib3270_session_callbacks));
  251 + if(!cbk) {
  252 + throw runtime_error( _("Invalid callback table, possible version mismatch in lib3270") );
  253 + }
  254 +
  255 + cbk->update_connect = connectHandler;
  256 +
  257 + }
  258 +
  259 + Local::Session::~Session() {
  260 +
  261 + std::lock_guard<std::mutex> lock(sync);
  262 +
  263 + lib3270_session_free(this->hSession);
  264 + this->hSession = nullptr;
  265 +
  266 + }
  267 +
  268 + }
  269 +
  270 +
client/src/session/local/private.h 0 → 100644
@@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
  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 private.h
  32 + *
  33 + * @brief Private definitions for local session.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 +#ifndef PRIVATE_H_INCLUDED
  40 +
  41 + #define PRIVATE_H_INCLUDED
  42 +
  43 + #include <config.h>
  44 + #include <ipc-client-internals.h>
  45 + #include <string>
  46 + #include <lib3270.h>
  47 + #include <stdexcept>
  48 +
  49 + using std::string;
  50 + using std::runtime_error;
  51 +
  52 + namespace TN3270 {
  53 +
  54 + namespace Local {
  55 +
  56 + class TN3270_PRIVATE Session : public TN3270::Abstract::Session {
  57 + private:
  58 +
  59 + /// @brief Handle of the related instance of lib3270
  60 + H3270 * hSession;
  61 +
  62 + /// @brief Mutex to serialize access to lib3270
  63 + std::mutex sync;
  64 +
  65 + /// @brief Popup Handler.
  66 + static void popupHandler(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg);
  67 +
  68 + /// @brief Connect Handler.
  69 + static void connectHandler(H3270 *session, unsigned char connected);
  70 +
  71 + /// @brief Wait for network events
  72 + void wait(time_t timeout = 5);
  73 +
  74 + /// @brief Check lib3270 return codes, launch exception when failed.
  75 + static void chkResponse(int rc);
  76 +
  77 + protected:
  78 +
  79 + // Get strings from lib3270 without charset conversion.
  80 + std::string get() const override;
  81 + std::string get(int baddr, size_t len, char lf) const override;
  82 + std::string get(int row, int col, size_t sz, char lf) const override;
  83 +
  84 + // Set strings to lib3270 without charset conversion.
  85 + void set(const std::string &str) override;
  86 + void set(int baddr, const std::string &str) override;
  87 + void set(int row, int col, const std::string &str) override;
  88 +
  89 + public:
  90 +
  91 + Session();
  92 + virtual ~Session();
  93 +
  94 + // Actions
  95 + void connect(const char *url, bool wait) override;
  96 + void disconnect() override;
  97 + void pfkey(unsigned short value) override;
  98 + void pakey(unsigned short value) override;
  99 +
  100 + void wait(unsigned short seconds) const override;
  101 + void waitForReady(time_t timeout) const override;
  102 + void waitForChange(unsigned short seconds) const override;
  103 +
  104 + // States
  105 + ProgramMessage getProgramMessage() const override;
  106 + ConnectionState getConnectionState() const override;
  107 + SSLState getSSLState() const override;
  108 +
  109 + // Properties.
  110 + std::string getVersion() const override;
  111 + std::string getRevision() const override;
  112 + std::string getLUName() const override;
  113 + std::string getHostURL() const override;
  114 + unsigned short getScreenWidth() const override;
  115 + unsigned short getScreenHeight() const override;
  116 + unsigned short getScreenLength() const override;
  117 + void setUnlockDelay(unsigned short delay) override;
  118 + void setCharSet(const char *charset = NULL) override;
  119 + void setCursor(unsigned short addr) override;
  120 + void setCursor(unsigned short row, unsigned short col) override;
  121 + unsigned short getCursorAddress() override;
  122 +
  123 +
  124 + };
  125 +
  126 + }
  127 +
  128 + }
  129 +
  130 +#endif // PRIVATE_H_INCLUDED
client/src/session/local/properties.cc 0 → 100644
@@ -0,0 +1,87 @@ @@ -0,0 +1,87 @@
  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 "private.h"
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + namespace TN3270 {
  44 +
  45 + void Local::Session::setCharSet(const char *charset) {
  46 + Abstract::Session::setCharSet(lib3270_get_display_charset(this->hSession),charset);
  47 + }
  48 +
  49 + unsigned short Local::Session::getScreenWidth() const {
  50 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  51 + return (unsigned short) lib3270_get_width(hSession);
  52 + }
  53 +
  54 + unsigned short Local::Session::getScreenHeight() const {
  55 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  56 + return (unsigned short) lib3270_get_height(hSession);
  57 + }
  58 +
  59 + unsigned short Local::Session::getScreenLength() const {
  60 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  61 + return (unsigned short) lib3270_get_length(hSession);
  62 + }
  63 +
  64 + void Local::Session::setUnlockDelay(unsigned short delay) {
  65 + std::lock_guard<std::mutex> lock(sync);
  66 + chkResponse(lib3270_set_unlock_delay(hSession,delay));
  67 + }
  68 +
  69 + void Local::Session::setCursor(unsigned short addr) {
  70 + std::lock_guard<std::mutex> lock(sync);
  71 + chkResponse(lib3270_set_cursor_address(hSession,addr));
  72 + }
  73 +
  74 + void Local::Session::setCursor(unsigned short row, unsigned short col) {
  75 + std::lock_guard<std::mutex> lock(sync);
  76 + chkResponse(lib3270_set_cursor_position(hSession,row,col));
  77 + }
  78 +
  79 + unsigned short Local::Session::getCursorAddress() {
  80 + std::lock_guard<std::mutex> lock(sync);
  81 + return lib3270_get_cursor_address(hSession);
  82 + }
  83 +
  84 +
  85 + }
  86 +
  87 +
client/src/session/local/session.cc
@@ -1,704 +0,0 @@ @@ -1,704 +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 - 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 src/session/local/session.cc  
32 - *  
33 - * @brief Implement lib3270 direct access layout (NO IPC).  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #ifdef _WIN32  
40 -  
41 - #include <winsock2.h>  
42 - #include <windows.h>  
43 - #include <lmcons.h>  
44 - #include <libloaderapi.h>  
45 -  
46 - #endif // _WIN32  
47 -  
48 - #include <ipc-client-internals.h>  
49 - #include <lib3270/actions.h>  
50 - #include <lib3270/properties.h>  
51 - #include <lib3270/toggle.h>  
52 - #include <iostream>  
53 - #include <cstring>  
54 -  
55 - extern "C" {  
56 - #include <lib3270/session.h>  
57 -  
58 -  
59 - }  
60 -  
61 - using std::string;  
62 -  
63 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
64 -  
65 - namespace TN3270 {  
66 -  
67 - #ifdef _WIN32  
68 -  
69 - string getUserName() {  
70 -  
71 - char username[UNLEN + 1];  
72 - DWORD szName = sizeof(username);  
73 -  
74 - memset(username,0,UNLEN + 1);  
75 -  
76 - if(!GetUserName(username, &szName)) {  
77 - return "?";  
78 - }  
79 -  
80 - return string(username);  
81 -  
82 - }  
83 -  
84 - static void writeLog(HANDLE hEventLog, const char *msg, int rc = (int) GetLastError()) {  
85 -  
86 -  
87 - debug(msg," rc=",rc);  
88 -  
89 - if(hEventLog) {  
90 -  
91 - string username = getUserName();  
92 - char lasterror[1024];  
93 - snprintf(lasterror,sizeof(lasterror),"The error code was %d",rc);  
94 -  
95 - const char *outMsg[] = {  
96 - username.c_str(),  
97 - msg,  
98 - lasterror  
99 - };  
100 -  
101 - ReportEvent(  
102 - hEventLog,  
103 - EVENTLOG_ERROR_TYPE,  
104 - 1,  
105 - 0,  
106 - NULL,  
107 - (sizeof(outMsg) / sizeof(outMsg[0])),  
108 - 0,  
109 - outMsg,  
110 - NULL  
111 - );  
112 -  
113 - }  
114 -  
115 - }  
116 -  
117 - static string getInstallLocation(HANDLE hEventLog) {  
118 -  
119 - LSTATUS rc;  
120 - HKEY hKey = 0;  
121 -  
122 - static const char * keys[] = {  
123 -#ifdef LIB3270_NAME  
124 - "Software\\" LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME),  
125 - "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME),  
126 -#endif  
127 - "Software\\pw3270",  
128 - "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270"  
129 - };  
130 -  
131 - size_t ix;  
132 -  
133 - string installLocation;  
134 -  
135 - for(ix = 0; installLocation.empty() && ix < (sizeof(keys)/sizeof(keys[0])); ix++) {  
136 -  
137 - debug(ix,"=",keys[ix]);  
138 -  
139 - rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,keys[ix],0,KEY_QUERY_VALUE,&hKey);  
140 - if(rc == ERROR_SUCCESS) {  
141 -  
142 - unsigned long datatype; // #defined in winnt.h (predefined types 0-11)  
143 - char datadir[4096];  
144 - unsigned long datalen = sizeof(datadir);  
145 -  
146 - memset(datadir,0,datalen);  
147 -  
148 - rc = RegQueryValueExA(hKey,"InstallLocation",NULL,&datatype,(LPBYTE) datadir,&datalen);  
149 - if(rc == ERROR_SUCCESS) {  
150 -  
151 - debug("Found: ",datadir);  
152 -  
153 - installLocation.assign(datadir);  
154 - string username = getUserName();  
155 -  
156 - const char *outMsg[] = {  
157 - username.c_str(),  
158 - "Found LIB3270 installation",  
159 - keys[ix],  
160 - installLocation.c_str()  
161 - };  
162 -  
163 - ReportEvent(  
164 - hEventLog,  
165 - EVENTLOG_INFORMATION_TYPE,  
166 - 1,  
167 - 0,  
168 - NULL,  
169 - (sizeof(outMsg) / sizeof(outMsg[0])),  
170 - 0,  
171 - outMsg,  
172 - NULL  
173 - );  
174 -  
175 - }  
176 -  
177 - RegCloseKey(hKey);  
178 -  
179 - }  
180 -  
181 - }  
182 -  
183 - return installLocation;  
184 - }  
185 -  
186 - #endif // _WIN32  
187 -  
188 - Local::Session::Session() : Abstract::Session() {  
189 -  
190 - std::lock_guard<std::mutex> lock(sync);  
191 -  
192 -#ifdef _WIN32  
193 - {  
194 - static bool initialized = false;  
195 -  
196 - if(!initialized) {  
197 -  
198 -#ifdef LIB3270_NAME  
199 - HANDLE hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME));  
200 -#else  
201 - HANDLE hEventLog = RegisterEventSource(NULL, PACKAGE_NAME);  
202 -#endif // LIB3270_NAME  
203 -  
204 - string installLocation = getInstallLocation(hEventLog);  
205 -  
206 - if(installLocation.empty()) {  
207 -  
208 - writeLog(hEventLog, "Can't identify lib3270 installation path");  
209 -  
210 - } else {  
211 -  
212 - // TODO: Understand why SetDefaultDllDirectories & AddDllDirectory causes failure in DNS resolution.  
213 -  
214 -  
215 - SetCurrentDirectory(installLocation.c_str());  
216 -  
217 -/*  
218 - wchar_t *path = (wchar_t *) malloc(sizeof(datadir)*sizeof(wchar_t));  
219 - mbstowcs(path, datadir, 4095);  
220 -  
221 - if(!SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS)) {  
222 - writeLog(hEventLog,"SetDefaultDllDirectories has failed");  
223 - }  
224 -#ifdef DEBUG  
225 - else {  
226 - debug("SetDefaultDllDirectories has suceeded");  
227 - }  
228 -#endif  
229 -  
230 - if(!AddDllDirectory(path)) {  
231 - string msg = "Can't add ";  
232 - msg += datadir;  
233 - msg += " to directory path";  
234 - writeLog(hEventLog,msg.c_str());  
235 - }  
236 -#ifdef DEBUG  
237 - else {  
238 - debug("AddDllDirectory has suceeded");  
239 - }  
240 -#endif  
241 - free(path);  
242 -  
243 -*/  
244 - }  
245 -  
246 - initialized = true;  
247 - DeregisterEventSource(hEventLog);  
248 -  
249 - }  
250 -  
251 - }  
252 -#endif // _WIN32  
253 -  
254 - this->hSession = lib3270_session_new("");  
255 -  
256 - lib3270_set_user_data(this->hSession,(void *) this);  
257 - setCharSet(lib3270_get_display_charset(this->hSession));  
258 -  
259 - lib3270_set_popup_handler(this->hSession, popupHandler);  
260 -  
261 - // Setup callbacks  
262 - struct lib3270_session_callbacks *cbk;  
263 -  
264 - cbk = lib3270_get_session_callbacks(this->hSession,sizeof(struct lib3270_session_callbacks));  
265 - if(!cbk) {  
266 - throw std::runtime_error( _("Invalid callback table, possible version mismatch in lib3270") );  
267 - }  
268 -  
269 - cbk->update_connect = connectHandler;  
270 -  
271 -  
272 - }  
273 -  
274 - Local::Session::~Session() {  
275 -  
276 - std::lock_guard<std::mutex> lock(sync);  
277 -  
278 - lib3270_session_free(this->hSession);  
279 - this->hSession = nullptr;  
280 - }  
281 -  
282 - void Local::Session::chkResponse(int rc) {  
283 -  
284 - if(rc == 0)  
285 - return;  
286 -  
287 -#ifdef _WIN32  
288 - if(rc == ENOTCONN)  
289 - throw std::runtime_error("Not connected");  
290 -#endif // _WIN32  
291 -  
292 - throw std::system_error(rc, std::system_category());  
293 -  
294 - }  
295 -  
296 - void Local::Session::wait(time_t timeout) {  
297 -  
298 - std::lock_guard<std::mutex> lock(sync);  
299 - chkResponse(lib3270_wait(this->hSession, timeout));  
300 -  
301 - }  
302 -  
303 - void Local::Session::connect(const char *url) {  
304 - std::lock_guard<std::mutex> lock(sync);  
305 - chkResponse(lib3270_connect_url(hSession,url,0));  
306 - }  
307 -  
308 - void Local::Session::disconnect() {  
309 - std::lock_guard<std::mutex> lock(sync);  
310 - lib3270_disconnect(hSession);  
311 - }  
312 -  
313 - // Wait for session state.  
314 - void Local::Session::waitForReady(time_t timeout) throw() {  
315 - std::lock_guard<std::mutex> lock(sync);  
316 - chkResponse(lib3270_wait_for_ready(hSession,timeout));  
317 - }  
318 -  
319 - std::string Local::Session::toString(int baddr, size_t len, char lf) const {  
320 -  
321 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
322 -  
323 - char * text = lib3270_get_string_at_address(hSession, baddr, len, lf);  
324 -  
325 - if(!text) {  
326 - throw std::runtime_error( _("Can't get screen contents") );  
327 - }  
328 -  
329 - string rc = convertFromHost(text);  
330 -  
331 - lib3270_free(text);  
332 -  
333 - return rc;  
334 -  
335 - }  
336 -  
337 - std::string Local::Session::toString(int row, int col, size_t sz, char lf) const {  
338 -  
339 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
340 -  
341 - char * text = lib3270_get_string_at(hSession, row, col, sz, lf);  
342 -  
343 - if(!text) {  
344 - throw std::runtime_error( _("Can't get screen contents") );  
345 - }  
346 -  
347 - string rc = convertFromHost(text);  
348 -  
349 - lib3270_free(text);  
350 -  
351 - return rc;  
352 - }  
353 -  
354 - void Local::Session::getProperty(const char *name, int &value) const {  
355 -  
356 - const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list();  
357 - for(size_t ix = 0; intprop[ix].name; ix++) {  
358 -  
359 - if(!strcasecmp(name,intprop[ix].name)) {  
360 -  
361 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
362 -  
363 - value = intprop[ix].get(hSession);  
364 -  
365 - if(value < 0 && errno != 0) {  
366 - throw std::system_error(errno, std::system_category());  
367 - }  
368 -  
369 -  
370 - }  
371 -  
372 - }  
373 -  
374 - throw std::system_error(ENOENT, std::system_category());  
375 -  
376 - }  
377 -  
378 - void Local::Session::getProperty(const char *name, std::string &value) const {  
379 -  
380 - const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list();  
381 -  
382 - for(size_t ix = 0; strprop[ix].name; ix++) {  
383 -  
384 - if(!strcasecmp(name,strprop[ix].name)) {  
385 -  
386 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
387 -  
388 - // Found it!  
389 - const char * str = strprop[ix].get(hSession);  
390 -  
391 - if(str) {  
392 - value.assign(str);  
393 - return;  
394 - }  
395 -  
396 - throw std::system_error(errno, std::system_category());  
397 -  
398 - }  
399 -  
400 - }  
401 -  
402 - throw std::system_error(ENOENT, std::system_category());  
403 - }  
404 -  
405 - void Local::Session::getProperty(const char *name, bool &value) const {  
406 -  
407 - LIB3270_TOGGLE toggle = lib3270_get_toggle_id(name);  
408 - if(toggle != (LIB3270_TOGGLE) -1) {  
409 -  
410 - // Is a Tn3270 toggle, get it!  
411 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
412 - value = lib3270_get_toggle(hSession,toggle);  
413 -  
414 - }  
415 -  
416 - throw std::system_error(ENOENT, std::system_category());  
417 - }  
418 -  
419 - ProgramMessage Local::Session::getProgramMessage() const {  
420 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
421 - return (ProgramMessage) lib3270_get_program_message(this->hSession);  
422 - }  
423 -  
424 - ConnectionState Local::Session::getConnectionState() const {  
425 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
426 - return (ConnectionState) lib3270_get_connection_state(this->hSession);  
427 - }  
428 -  
429 - /// @brief Set field at current position, jumps to next writable field.  
430 - TN3270::Session & Local::Session::push(const char *text) {  
431 - std::lock_guard<std::mutex> lock(sync);  
432 -  
433 - string converted = convertToHost(text);  
434 -  
435 - chkResponse(lib3270_input_string(this->hSession, (unsigned char *) converted.c_str(), converted.size()));  
436 -  
437 - return *this;  
438 - }  
439 -  
440 - TN3270::Session & Local::Session::input(const char *text, size_t length) {  
441 - std::lock_guard<std::mutex> lock(sync);  
442 -  
443 - string converted = convertToHost(text,length);  
444 -  
445 - chkResponse(lib3270_input_string(this->hSession, (unsigned char *) converted.c_str(), converted.size()));  
446 -  
447 - return *this;  
448 - }  
449 -  
450 - TN3270::Session & Local::Session::push(int baddr, const char * text, int length) {  
451 - std::lock_guard<std::mutex> lock(sync);  
452 -  
453 - string converted = convertToHost(text, length);  
454 -  
455 - if(lib3270_set_string_at_address(this->hSession,baddr,(unsigned char *) converted.c_str(),converted.length()) < 0) {  
456 - throw std::system_error(errno, std::system_category());  
457 - }  
458 -  
459 - return *this;  
460 - }  
461 -  
462 - TN3270::Session & Local::Session::push(int row, int col, const char *text, int length) {  
463 - std::lock_guard<std::mutex> lock(sync);  
464 -  
465 - string converted = convertToHost(text,length);  
466 -  
467 - if(lib3270_set_string_at(this->hSession,row,col,(unsigned char *) converted.c_str(),-1)) {  
468 - throw std::system_error(errno, std::system_category());  
469 - }  
470 -  
471 - return *this;  
472 - }  
473 -  
474 - TN3270::Session & Local::Session::push(const Action action) {  
475 -  
476 - typedef int (*ActionCallback)(H3270 *);  
477 -  
478 - static const ActionCallback actions[] = {  
479 - lib3270_enter, // ENTER  
480 - lib3270_erase, // ERASE  
481 - lib3270_eraseeof, // ERASE_EOF  
482 - lib3270_eraseeol, // ERASE_EOL  
483 - lib3270_eraseinput, // ERASE_INPUT  
484 - lib3270_kybdreset, // KYBD_RESET  
485 - lib3270_newline, // NEWLINE  
486 - lib3270_clear, // CLEAR  
487 - lib3270_select_field, // SELECT_FIELD  
488 - lib3270_select_all, // SELECT_ALL  
489 - lib3270_unselect, // UNSELECT  
490 - lib3270_reselect, // RESELECT  
491 - lib3270_delete, // DELETE  
492 - lib3270_dup, // DUP  
493 - lib3270_fieldmark, // FIELDMARK  
494 - lib3270_backspace, // BACKSPACE  
495 - lib3270_previousword, // WORD_PREVIOUS  
496 - lib3270_nextword, // WORD_NEXT  
497 - lib3270_fieldend, // FIELD_END  
498 - lib3270_firstfield, // FIELD_FIRST  
499 - lib3270_nextfield, // FIELD_NEXT  
500 - lib3270_previousfield, // FIELD_PREVIOUS  
501 - lib3270_attn, // ATTN  
502 - lib3270_break, // BREAK  
503 - lib3270_deleteword, // WORD_DELETE  
504 - lib3270_deletefield, // FIELD_DELETE  
505 - lib3270_sysreq, // SYSREQ  
506 - };  
507 -  
508 - if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) {  
509 - throw std::system_error(EINVAL, std::system_category());  
510 - }  
511 -  
512 - std::lock_guard<std::mutex> lock(sync);  
513 -  
514 - chkResponse(actions[(size_t) action](hSession));  
515 -  
516 - return *this;  
517 - }  
518 -  
519 - TN3270::Session & Local::Session::pfkey(unsigned short value) {  
520 -  
521 - std::lock_guard<std::mutex> lock(sync);  
522 -  
523 - chkResponse(lib3270_pfkey(hSession,(int) value));  
524 -  
525 - return *this;  
526 - }  
527 -  
528 - TN3270::Session & Local::Session::pakey(unsigned short value) {  
529 -  
530 - std::lock_guard<std::mutex> lock(sync);  
531 -  
532 - chkResponse(lib3270_pakey(hSession,(int) value));  
533 -  
534 - return *this;  
535 - }  
536 -  
537 -  
538 - TN3270::Session & Local::Session::pop(int baddr, std::string &text) {  
539 -  
540 - std::lock_guard<std::mutex> lock(sync);  
541 -  
542 - if(!lib3270_is_connected(hSession)) {  
543 - throw std::system_error(ENOTCONN, std::system_category());  
544 - }  
545 -  
546 - char *contents = lib3270_get_field_text_at(hSession, baddr);  
547 -  
548 - if(!contents) {  
549 - throw std::system_error(errno, std::system_category());  
550 - }  
551 -  
552 - text.assign(convertFromHost(contents).c_str());  
553 -  
554 - lib3270_free(contents);  
555 -  
556 - return *this;  
557 - }  
558 -  
559 - TN3270::Session & Local::Session::pop(int row, int col, std::string &text) {  
560 - return this->pop(lib3270_translate_to_address(hSession,row,col),text);  
561 - }  
562 -  
563 - TN3270::Session & Local::Session::pop(std::string &text) {  
564 -  
565 - std::lock_guard<std::mutex> lock(sync);  
566 -  
567 - if(!lib3270_is_connected(hSession)) {  
568 - throw std::system_error(ENOTCONN, std::system_category());  
569 - }  
570 -  
571 - int baddr = lib3270_get_cursor_address(hSession);  
572 - if(baddr < 0) {  
573 - throw std::system_error(errno, std::system_category());  
574 - }  
575 -  
576 - char *contents = lib3270_get_field_text_at(hSession, baddr);  
577 -  
578 - if(!contents) {  
579 - throw std::system_error(errno, std::system_category());  
580 - }  
581 -  
582 - text.assign(convertFromHost(contents).c_str());  
583 -  
584 - lib3270_free(contents);  
585 -  
586 - baddr = lib3270_get_next_unprotected(hSession,baddr);  
587 - if(!baddr) {  
588 - baddr = lib3270_get_next_unprotected(hSession,0);  
589 - }  
590 -  
591 - if(lib3270_set_cursor_address(hSession,baddr)) {  
592 - throw std::system_error(errno, std::system_category());  
593 - }  
594 -  
595 - return *this;  
596 - }  
597 -  
598 - /// @brief Set cursor address.  
599 - ///  
600 - /// @param addr Cursor address.  
601 - TN3270::Session & Local::Session::setCursor(unsigned short addr) {  
602 -  
603 - if(lib3270_set_cursor_address(hSession,addr) < 0) {  
604 - throw std::system_error(errno, std::system_category());  
605 - }  
606 -  
607 - return *this;  
608 - }  
609 -  
610 - /// @brief Get cursor address.  
611 - ///  
612 - /// @return  
613 - unsigned short Local::Session::getCursorAddress() {  
614 -  
615 - unsigned int position = lib3270_get_cursor_address(hSession);  
616 -  
617 - if(!position)  
618 - throw std::system_error(errno, std::system_category());  
619 -  
620 - return position;  
621 - }  
622 -  
623 -  
624 - /// @brief Set cursor position.  
625 - ///  
626 - /// @param row New cursor row.  
627 - /// @param col New cursor column.  
628 - TN3270::Session & Local::Session::setCursor(unsigned short row, unsigned short col) {  
629 -  
630 - if(lib3270_set_cursor_position(hSession,row,col)) {  
631 - throw std::system_error(errno, std::system_category());  
632 - }  
633 -  
634 - return *this;  
635 -  
636 - }  
637 -  
638 - // Get properties.  
639 - std::string Local::Session::getVersion() const {  
640 - return lib3270_get_version();  
641 - }  
642 -  
643 - std::string Local::Session::getRevision() const {  
644 - return lib3270_get_revision();  
645 - }  
646 -  
647 - std::string Local::Session::getLUName() const {  
648 - const char * luname = lib3270_get_luname(hSession);  
649 - if(luname)  
650 - return luname;  
651 - return "";  
652 - }  
653 -  
654 - /// @brief Execute action by name.  
655 - TN3270::Session & Local::Session::action(const char *action_name) {  
656 -  
657 - chkResponse(lib3270_action(hSession,action_name));  
658 -  
659 - return *this;  
660 - }  
661 -  
662 - /// @brief Wait.  
663 - TN3270::Session & Local::Session::wait(unsigned short seconds) {  
664 - chkResponse(lib3270_wait(hSession,seconds));  
665 - return *this;  
666 - }  
667 -  
668 - /// @brief Wait for update.  
669 - TN3270::Session & Local::Session::waitForChange(unsigned short seconds) {  
670 - chkResponse(lib3270_wait_for_update(hSession,seconds));  
671 - return *this;  
672 - }  
673 -  
674 - void Local::Session::setUnlockDelay(unsigned short delay) {  
675 - lib3270_set_unlock_delay(hSession,delay);  
676 - }  
677 -  
678 - std::string Local::Session::getHostURL() const {  
679 - return lib3270_get_url(hSession);  
680 - }  
681 -  
682 - void Local::Session::setHostURL(const char *url) {  
683 - lib3270_set_url(hSession,url);  
684 - }  
685 -  
686 - unsigned short Local::Session::getScreenWidth() const {  
687 - return (unsigned short) lib3270_get_width(hSession);  
688 - }  
689 -  
690 - unsigned short Local::Session::getScreenHeight() const {  
691 - return (unsigned short) lib3270_get_height(hSession);  
692 - }  
693 -  
694 - unsigned short Local::Session::getScreenLength() const {  
695 - return (unsigned short) lib3270_get_length(hSession);  
696 - }  
697 -  
698 - TN3270::SSLState Local::Session::getSSLState() const {  
699 - return (TN3270::SSLState) lib3270_get_ssl_state(hSession);  
700 - }  
701 -  
702 - }  
703 -  
704 -  
client/src/session/local/set.cc 0 → 100644
@@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
  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 "private.h"
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + namespace TN3270 {
  44 +
  45 + void Local::Session::set(const std::string &str) {
  46 +
  47 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  48 + chkResponse(lib3270_input_string(hSession,(unsigned char *) str.c_str(),str.length()));
  49 +
  50 + }
  51 +
  52 + void Local::Session::set(int baddr, const std::string &str) {
  53 +
  54 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  55 + chkResponse(lib3270_set_string_at_address(hSession,baddr,(unsigned char *) str.c_str(),str.length()));
  56 +
  57 + }
  58 +
  59 + void Local::Session::set(int row, int col, const std::string &str) {
  60 +
  61 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  62 + chkResponse(lib3270_set_string_at(hSession,row,col,(unsigned char *) str.c_str(),str.length()));
  63 +
  64 + }
  65 +
  66 + }
  67 +
  68 +
client/src/session/local/tools.cc 0 → 100644
@@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
  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 "private.h"
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + namespace TN3270 {
  44 +
  45 + void Local::Session::chkResponse(int rc) {
  46 +
  47 + if(rc == 0)
  48 + return;
  49 +
  50 +#ifdef _WIN32
  51 + if(rc == ENOTCONN)
  52 + throw std::runtime_error("Not connected");
  53 +#endif // _WIN32
  54 +
  55 + throw std::system_error(rc, std::system_category());
  56 +
  57 + }
  58 +
  59 + std::string Local::Session::getVersion() const {
  60 +
  61 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  62 + return lib3270_get_version();
  63 +
  64 + }
  65 +
  66 + std::string Local::Session::getRevision() const {
  67 +
  68 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  69 + return lib3270_get_revision();
  70 +
  71 + }
  72 +
  73 + std::string Local::Session::getLUName() const {
  74 +
  75 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  76 + return lib3270_get_luname(hSession);
  77 +
  78 + }
  79 +
  80 + std::string Local::Session::getHostURL() const {
  81 +
  82 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  83 + return lib3270_get_url(hSession);
  84 +
  85 + }
  86 +
  87 +
  88 +
  89 + }
  90 +
  91 +
client/src/session/remote/session.cc
@@ -1,504 +0,0 @@ @@ -1,504 +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 - 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 src/session/remote/session.cc  
32 - *  
33 - * @brief Implements lib3270 access using IPC calls.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include <ipc-client-internals.h>  
40 - #include <cstring>  
41 -  
42 -#ifndef _WIN32  
43 - #include <unistd.h> // sleep  
44 -#endif // _WIN32  
45 -  
46 - using std::string;  
47 -  
48 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
49 -  
50 - namespace TN3270 {  
51 -  
52 - void IPC::Session::connect(const char *url) {  
53 - Request request(*this,"connect");  
54 - request.push(url).call();  
55 - }  
56 -  
57 - void IPC::Session::disconnect() {  
58 - Request(*this,"disconnect").call();  
59 - }  
60 -  
61 - // Wait for session state.  
62 - void IPC::Session::waitForReady(time_t timeout) {  
63 -  
64 - int rc;  
65 -  
66 - time_t end = time(nullptr) + timeout;  
67 -  
68 - while(time(nullptr) < end) {  
69 -  
70 - debug("Running waitForReady request...");  
71 -  
72 - Request(*this,"waitForReady")  
73 - .push((uint32_t) 1)  
74 - .call()  
75 - .pop(rc);  
76 -  
77 - debug("Wait for ready returned ",rc);  
78 -  
79 - if(rc == 0)  
80 - return;  
81 -  
82 - }  
83 -  
84 - throw std::system_error(ETIMEDOUT, std::system_category());  
85 -  
86 - }  
87 -  
88 - std::string IPC::Session::toString(int baddr, size_t len, char lf) const {  
89 -  
90 - std::string rc;  
91 -  
92 - Request(*this,"getStringAtAddress")  
93 - .push((uint32_t) baddr)  
94 - .push((uint32_t) len)  
95 - .push((uint8_t) lf)  
96 - .call()  
97 - .pop(rc);  
98 -  
99 - return rc;  
100 - }  
101 -  
102 - std::string IPC::Session::toString(int row, int col, size_t sz, char lf) const {  
103 -  
104 - std::string rc;  
105 -  
106 - Request(*this,"getStringAt")  
107 - .push((uint32_t) row)  
108 - .push((uint32_t) col)  
109 - .push((uint32_t) sz)  
110 - .push((uint8_t) lf)  
111 - .call()  
112 - .pop(rc);  
113 -  
114 - return rc;  
115 - }  
116 -  
117 - ProgramMessage IPC::Session::getProgramMessage() const {  
118 -  
119 - int program_message;  
120 - getProperty("program_message",program_message);  
121 - return (ProgramMessage) program_message;  
122 -  
123 - }  
124 -  
125 - ConnectionState IPC::Session::getConnectionState() const {  
126 -  
127 - int cstate;  
128 - getProperty("cstate",cstate);  
129 - return (ConnectionState) cstate;  
130 -  
131 - }  
132 -  
133 - TN3270::Session & IPC::Session::input(const char *text, size_t length) {  
134 -  
135 - throw std::system_error(ENOTSUP, std::system_category());  
136 -  
137 - return *this;  
138 - }  
139 -  
140 - /// @brief Set field at current position, jumps to next writable field.  
141 - TN3270::Session & IPC::Session::push(const char *text) {  
142 -  
143 - int rc;  
144 -  
145 - Request(*this,"setString")  
146 - .push(text)  
147 - .call()  
148 - .pop(rc);  
149 -  
150 - if(rc) {  
151 - throw std::system_error((int) rc, std::system_category());  
152 - }  
153 -  
154 - return *this;  
155 -  
156 - }  
157 -  
158 - TN3270::Session & IPC::Session::push(int baddr, const char *text, int length) {  
159 -  
160 - int rc;  
161 -  
162 - if(length < 0)  
163 - length = strlen(text);  
164 -  
165 - Request(*this,"setStringAtAddress")  
166 - .push((uint32_t) baddr)  
167 - .push(text)  
168 - .push((uint32_t) length)  
169 - .call()  
170 - .pop(rc);  
171 -  
172 - if(rc) {  
173 - throw std::system_error((int) rc, std::system_category());  
174 - }  
175 -  
176 - return *this;  
177 -  
178 - }  
179 -  
180 - TN3270::Session & IPC::Session::push(int row, int col, const char *text, int length) {  
181 -  
182 - int32_t rc;  
183 -  
184 - if(length < 0)  
185 - length = strlen(text);  
186 -  
187 - Request(*this,"setStringAt")  
188 - .push((uint32_t) row)  
189 - .push((uint32_t) col)  
190 - .push(text)  
191 - .push((uint32_t) length)  
192 - .call()  
193 - .pop(rc);  
194 -  
195 - if(rc) {  
196 - throw std::system_error((int) rc, std::system_category());  
197 - }  
198 -  
199 - return *this;  
200 -  
201 - }  
202 -  
203 - TN3270::Session & IPC::Session::pfkey(unsigned short value) {  
204 -  
205 - int32_t rc;  
206 -  
207 - Request(*this,"pfkey")  
208 - .push((uint32_t) value)  
209 - .call()  
210 - .pop(rc);  
211 -  
212 - if(rc) {  
213 - throw std::system_error((int) rc, std::system_category());  
214 - }  
215 -  
216 - return *this;  
217 - }  
218 -  
219 - TN3270::Session & IPC::Session::pakey(unsigned short value) {  
220 -  
221 - int32_t rc;  
222 -  
223 - Request(*this,"pakey")  
224 - .push((uint32_t) value)  
225 - .call()  
226 - .pop(rc);  
227 -  
228 - if(rc) {  
229 - throw std::system_error((int) rc, std::system_category());  
230 - }  
231 -  
232 - return *this;  
233 -  
234 - }  
235 -  
236 - TN3270::Session & IPC::Session::push(const Action action) {  
237 - return this->action(toCharString(action));  
238 - }  
239 -  
240 - TN3270::Session & IPC::Session::pop(int baddr, std::string &text) {  
241 -  
242 - Request(*this,"getFieldAtAddress")  
243 - .push((uint32_t) baddr)  
244 - .call()  
245 - .pop(text);  
246 -  
247 - return *this;  
248 - }  
249 -  
250 - TN3270::Session & IPC::Session::pop(int row, int col, std::string &text) {  
251 -  
252 - Request(*this,"getFieldAt")  
253 - .push((uint32_t) row)  
254 - .push((uint32_t) col)  
255 - .call()  
256 - .pop(text);  
257 -  
258 - return *this;  
259 - }  
260 -  
261 - TN3270::Session & IPC::Session::pop(std::string &text) {  
262 -  
263 - Request(*this,"getFieldAtCursor")  
264 - .call()  
265 - .pop(text);  
266 -  
267 - return *this;  
268 -  
269 - }  
270 -  
271 - /// @brief Set cursor address.  
272 - ///  
273 - /// @param addr Cursor address.  
274 - TN3270::Session & IPC::Session::setCursor(unsigned short addr) {  
275 -  
276 - setProperty("setCursorAddress", (uint32_t) addr);  
277 - return *this;  
278 -  
279 - }  
280 -  
281 - unsigned short IPC::Session::getCursorAddress() {  
282 -  
283 - int32_t address;  
284 - getProperty("cursor_address",address);  
285 - return (unsigned short) address;  
286 -  
287 - }  
288 -  
289 - /// @brief Set cursor position.  
290 - ///  
291 - /// @param row New cursor row.  
292 - /// @param col New cursor column.  
293 - TN3270::Session & IPC::Session::setCursor(unsigned short row, unsigned short col) {  
294 -  
295 - int32_t rc;  
296 -  
297 - Request(*this,"setCursorPosition")  
298 - .push((uint32_t) row)  
299 - .push((uint32_t) col)  
300 - .call()  
301 - .pop(rc);  
302 -  
303 - if(rc) {  
304 - throw std::system_error((int) rc, std::system_category());  
305 - }  
306 -  
307 - return *this;  
308 -  
309 - }  
310 -  
311 - void IPC::Session::getProperty(const char *name, int &value) const {  
312 -  
313 - Request(*this,false,name)  
314 - .call()  
315 - .pop(value);  
316 -  
317 - }  
318 -  
319 - void IPC::Session::setProperty(const char *name, const int value) const {  
320 -  
321 - int32_t rc;  
322 -  
323 - Request(*this,true,name)  
324 - .push(value)  
325 - .call()  
326 - .pop(rc);  
327 -  
328 - if(rc) {  
329 - throw std::system_error((int) rc, std::system_category());  
330 - }  
331 -  
332 - }  
333 -  
334 - void IPC::Session::setProperty(const char *name, const char *value) const {  
335 -  
336 - int32_t rc;  
337 -  
338 - Request(*this,true,name)  
339 - .push(value)  
340 - .call()  
341 - .pop(rc);  
342 -  
343 - if(rc) {  
344 - throw std::system_error((int) rc, std::system_category());  
345 - }  
346 -  
347 - }  
348 -  
349 - void IPC::Session::getProperty(const char *name, std::string &value) const {  
350 -  
351 - Request(*this,false,name)  
352 - .call()  
353 - .pop(value);  
354 -  
355 - }  
356 -  
357 - void IPC::Session::getProperty(const char *name, bool &value) const {  
358 - throw std::system_error(ENOENT, std::system_category());  
359 - }  
360 -  
361 - /// @brief Get lib3270 version.  
362 - std::string IPC::Session::getVersion() const {  
363 -  
364 - string rc;  
365 - getProperty("version",rc);  
366 - return rc;  
367 -  
368 - }  
369 -  
370 - /// @brief Get lib3270 revision.  
371 - std::string IPC::Session::getRevision() const {  
372 -  
373 - string rc;  
374 - getProperty("revision",rc);  
375 - return rc;  
376 -  
377 - }  
378 -  
379 - std::string IPC::Session::getLUName() const {  
380 -  
381 - string rc;  
382 - getProperty("luname",rc);  
383 - return rc;  
384 -  
385 - }  
386 -  
387 - /// @brief Execute action by name.  
388 - TN3270::Session & IPC::Session::action(const char *action_name) {  
389 -  
390 - int32_t rc;  
391 -  
392 - Request(*this,"action")  
393 - .push(action_name)  
394 - .call()  
395 - .pop(rc);  
396 -  
397 - if(rc) {  
398 - throw std::system_error((int) rc, std::system_category());  
399 - }  
400 -  
401 - return *this;  
402 - }  
403 -  
404 - /// @brief Wait.  
405 - TN3270::Session & IPC::Session::wait(unsigned short seconds) {  
406 -  
407 - time_t end = time(nullptr) + seconds;  
408 -  
409 - while(time(nullptr) < end) {  
410 -  
411 -#ifdef _WIN32  
412 - Sleep(1000);  
413 -#else  
414 - sleep(1);  
415 -#endif // _WIN32  
416 -  
417 - if(getConnectionState() == TN3270::DISCONNECTED)  
418 - throw std::runtime_error("Disconnected");  
419 -  
420 - }  
421 -  
422 - return *this;  
423 - }  
424 -  
425 - /// @brief Wait for update.  
426 - TN3270::Session & IPC::Session::waitForChange(unsigned short seconds) {  
427 -  
428 - int rc;  
429 -  
430 - time_t end = time(nullptr) + seconds;  
431 -  
432 - while(time(nullptr) < end) {  
433 -  
434 - debug("Running waitForUpdate request...");  
435 -  
436 - Request(*this,"waitForUpdate")  
437 - .push((uint32_t) 1)  
438 - .call()  
439 - .pop(rc);  
440 -  
441 - debug("Wait for update returned ",rc);  
442 -  
443 - if(rc == 0)  
444 - return *this;  
445 -  
446 - }  
447 -  
448 - throw std::system_error(ETIMEDOUT, std::system_category());  
449 -  
450 - }  
451 -  
452 - void IPC::Session::setUnlockDelay(unsigned short delay) {  
453 -  
454 - setProperty("unlock_delay", (uint32_t) delay);  
455 -  
456 - }  
457 -  
458 - std::string IPC::Session::getHostURL() const {  
459 -  
460 - std::string value;  
461 - getProperty("url",value);  
462 - return value;  
463 -  
464 - }  
465 -  
466 - void IPC::Session::setHostURL(const char *url) {  
467 - setProperty("url",url);  
468 - }  
469 -  
470 - unsigned short IPC::Session::getScreenWidth() const {  
471 -  
472 - int value;  
473 - getProperty("width",value);  
474 - return (unsigned short) value;  
475 -  
476 - }  
477 -  
478 - unsigned short IPC::Session::getScreenHeight() const {  
479 -  
480 - int value;  
481 - getProperty("height",value);  
482 - return (unsigned short) value;  
483 -  
484 - }  
485 -  
486 - unsigned short IPC::Session::getScreenLength() const {  
487 -  
488 - int value;  
489 - getProperty("length",value);  
490 - return (unsigned short) value;  
491 -  
492 - }  
493 -  
494 - TN3270::SSLState IPC::Session::getSSLState() const {  
495 -  
496 - int value;  
497 - getProperty("sslstate",value);  
498 - return (TN3270::SSLState) value;  
499 -  
500 - }  
501 -  
502 - }  
503 -  
504 -  
client/src/testprogram/testprogram.cc
@@ -44,6 +44,44 @@ @@ -44,6 +44,44 @@
44 44
45 /*---[ Implement ]----------------------------------------------------------------------------------*/ 45 /*---[ Implement ]----------------------------------------------------------------------------------*/
46 46
  47 + // Test "Session" object
  48 + static void chkSession() {
  49 +
  50 + TN3270::Session * hSession = TN3270::Session::getInstance();
  51 +
  52 + try {
  53 +
  54 + cout
  55 + << "Version: " << hSession->getVersion()
  56 + << "\tRevision: " << hSession->getRevision()
  57 + << endl;
  58 +
  59 + hSession->connect("tn3270s://3270.df.bb:9023");
  60 + hSession->waitForReady(30);
  61 +
  62 + cout
  63 + << "Connection state is " << toCharString(hSession->getConnectionState()) << std::endl
  64 + << "Program message is " << toCharString(hSession->getProgramMessage()) << std::endl
  65 + << "Luname is " << hSession->getLUName() << std::endl
  66 + << std::endl;
  67 +
  68 + cout
  69 + << endl << endl
  70 + << hSession->toString()
  71 + << endl << endl;
  72 +
  73 + hSession->disconnect();
  74 +
  75 + } catch(const std::exception &e) {
  76 +
  77 + cerr << "Exception: " << e.what() << endl;
  78 +
  79 + }
  80 +
  81 + delete hSession;
  82 +
  83 + }
  84 +
47 int main(int argc, char **argv) { 85 int main(int argc, char **argv) {
48 86
49 const char * session = ""; // "pw3270:a"; 87 const char * session = ""; // "pw3270:a";
@@ -70,6 +108,9 @@ @@ -70,6 +108,9 @@
70 108
71 } 109 }
72 110
  111 + chkSession();
  112 +
  113 + /*
73 cout << "Session: " << session << endl; 114 cout << "Session: " << session << endl;
74 115
75 TN3270::Host host{session}; 116 TN3270::Host host{session};
@@ -92,19 +133,17 @@ @@ -92,19 +133,17 @@
92 133
93 // host.input("test@0another line"); 134 // host.input("test@0another line");
94 135
95 - /*  
96 - host.connect();  
97 -  
98 - if(host) {  
99 - cout << host << endl;  
100 - }  
101 - */ 136 + //host.connect();
  137 + //if(host) {
  138 + // cout << host << endl;
  139 + //}
102 140
103 } catch(const std::exception &e) { 141 } catch(const std::exception &e) {
104 142
105 cerr << std::endl << e.what() << std::endl << std::endl; 143 cerr << std::endl << e.what() << std::endl << std::endl;
106 144
107 } 145 }
  146 + */
108 147
109 148
110 return 0; 149 return 0;
client/valgrind.suppression
@@ -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 +
common/src/include/lib3270/ipc.h
@@ -69,6 +69,9 @@ @@ -69,6 +69,9 @@
69 69
70 #define DEFAULT_TIMEOUT 5 70 #define DEFAULT_TIMEOUT 5
71 71
  72 + TN3270_PUBLIC const char * getVersion();
  73 + TN3270_PUBLIC const char * getRevision();
  74 +
72 class TN3270_PUBLIC Event { 75 class TN3270_PUBLIC Event {
73 public: 76 public:
74 enum Type : uint8_t { 77 enum Type : uint8_t {
@@ -234,64 +237,74 @@ @@ -234,64 +237,74 @@
234 237
235 public: 238 public:
236 239
237 - /// @brief Create a tn3270 session.  
238 - static Session * create(const char *id = nullptr);  
239 - 240 + /// @brief Get an instance of the TN3270 session based on the supplied ID.
  241 + static Session * getInstance(const char *id = nullptr);
240 virtual ~Session(); 242 virtual ~Session();
241 243
242 - // Connect/disconnect  
243 - virtual void connect(const char *url) = 0;  
244 - virtual void disconnect() = 0; 244 + // States
  245 + virtual ProgramMessage getProgramMessage() const = 0;
  246 + virtual ConnectionState getConnectionState() const = 0;
  247 + virtual SSLState getSSLState() const = 0;
245 248
246 - // Gets 249 + // Contents
247 virtual std::string toString(int baddr = 0, size_t len = -1, char lf = '\n') const = 0; 250 virtual std::string toString(int baddr = 0, size_t len = -1, char lf = '\n') const = 0;
248 virtual std::string toString(int row, int col, size_t sz, char lf = '\n') const = 0; 251 virtual std::string toString(int row, int col, size_t sz, char lf = '\n') const = 0;
249 252
250 - inline operator std::string() const {  
251 - return toString();  
252 - }  
253 -  
254 - // Get properties.  
255 - virtual void getProperty(const char *name, int &value) const = 0;  
256 - virtual void getProperty(const char *name, std::string &value) const = 0;  
257 - virtual void getProperty(const char *name, bool &value) const = 0; 253 + // Properties.
258 254
259 virtual std::string getVersion() const = 0; 255 virtual std::string getVersion() const = 0;
260 virtual std::string getRevision() const = 0; 256 virtual std::string getRevision() const = 0;
261 virtual std::string getLUName() const = 0; 257 virtual std::string getLUName() const = 0;
262 virtual std::string getHostURL() const = 0; 258 virtual std::string getHostURL() const = 0;
263 259
  260 + virtual void setUnlockDelay(unsigned short delay = 350) = 0;
  261 +
264 virtual unsigned short getScreenWidth() const = 0; 262 virtual unsigned short getScreenWidth() const = 0;
265 virtual unsigned short getScreenHeight() const = 0; 263 virtual unsigned short getScreenHeight() const = 0;
266 virtual unsigned short getScreenLength() const = 0; 264 virtual unsigned short getScreenLength() const = 0;
267 265
268 - virtual ProgramMessage getProgramMessage() const = 0;  
269 - inline operator ProgramMessage() const {  
270 - return getProgramMessage();  
271 - } 266 + /// @brief Set cursor address.
  267 + virtual void setCursor(unsigned short addr) = 0;
272 268
273 - virtual ConnectionState getConnectionState() const = 0;  
274 - inline operator ConnectionState() const {  
275 - return getConnectionState();  
276 - } 269 + /// @brief Set cursor position.
  270 + virtual void setCursor(unsigned short row, unsigned short col) = 0;
277 271
278 - inline bool operator==(ConnectionState state) const {  
279 - return this->getConnectionState() == state;  
280 - } 272 + /// @brief Get cursor address
  273 + virtual unsigned short getCursorAddress() = 0;
281 274
282 - virtual SSLState getSSLState() const = 0; 275 + /// @brief Set local charset.
  276 + virtual void setCharSet(const char *charset = NULL) = 0;
283 277
284 - inline operator SSLState() const {  
285 - return getSSLState();  
286 - } 278 + // Actions
  279 +
  280 + // Connect/disconnect
  281 + virtual void connect(const char *url = nullptr, bool wait = true) = 0;
  282 + virtual void disconnect() = 0;
  283 +
  284 + /// @brief Wait.
  285 + virtual void wait(unsigned short seconds) const = 0;
  286 +
  287 + /// @brief Wait until session state changes to "ready".
  288 + virtual void waitForReady(time_t timeout = DEFAULT_TIMEOUT) const = 0;
  289 +
  290 + /// @brief Wait for screen changes.
  291 + virtual void waitForChange(unsigned short seconds) const = 0;
  292 +
  293 + /// @brief Send PF.
  294 + virtual void pfkey(unsigned short value) = 0;
  295 +
  296 + /// @brief Send PA.
  297 + virtual void pakey(unsigned short value) = 0;
  298 +
  299 + /*
  300 +
  301 + // Get properties.
  302 + virtual void getProperty(const char *name, int &value) const = 0;
  303 + virtual void getProperty(const char *name, std::string &value) const = 0;
  304 + virtual void getProperty(const char *name, bool &value) const = 0;
287 305
288 - inline bool operator==(SSLState state) const {  
289 - return this->getSSLState() == state;  
290 - }  
291 306
292 // Set properties. 307 // Set properties.
293 - virtual void setUnlockDelay(unsigned short delay = 350) = 0;  
294 - void setCharSet(const char *charset);  
295 virtual void setHostURL(const char *url) = 0; 308 virtual void setHostURL(const char *url) = 0;
296 309
297 // Set contents. 310 // Set contents.
@@ -305,21 +318,6 @@ @@ -305,21 +318,6 @@
305 /// @brief Input string. 318 /// @brief Input string.
306 virtual Session & input(const char *text, size_t length) = 0; 319 virtual Session & input(const char *text, size_t length) = 0;
307 320
308 - /// @brief Set cursor address.  
309 - virtual TN3270::Session & setCursor(unsigned short addr) = 0;  
310 -  
311 - /// @brief Set cursor position.  
312 - virtual TN3270::Session & setCursor(unsigned short row, unsigned short col) = 0;  
313 -  
314 - /// @brief Get cursor address  
315 - virtual unsigned short getCursorAddress() = 0;  
316 -  
317 - /// @brief Send PF.  
318 - virtual Session & pfkey(unsigned short value) = 0;  
319 -  
320 - /// @brief Send PA.  
321 - virtual Session & pakey(unsigned short value) = 0;  
322 -  
323 virtual Session & push(int baddr, const char *text, int length) = 0; 321 virtual Session & push(int baddr, const char *text, int length) = 0;
324 virtual Session & push(int row, int col, const char *text, int length) = 0; 322 virtual Session & push(int row, int col, const char *text, int length) = 0;
325 323
@@ -344,15 +342,6 @@ @@ -344,15 +342,6 @@
344 /// @brief Execute action by name. 342 /// @brief Execute action by name.
345 virtual Session & action(const char *action_name) = 0; 343 virtual Session & action(const char *action_name) = 0;
346 344
347 - /// @brief Wait.  
348 - virtual Session & wait(unsigned short seconds) = 0;  
349 -  
350 - /// @brief Wait until session state changes to "ready".  
351 - virtual void waitForReady(time_t timeout = DEFAULT_TIMEOUT) = 0;  
352 -  
353 - /// @brief Wait for screen changes.  
354 - virtual Session & waitForChange(unsigned short seconds) = 0;  
355 -  
356 /// @brief Wait for string. 345 /// @brief Wait for string.
357 /// 346 ///
358 /// @return 0 if the string was found, error code if not. 347 /// @return 0 if the string was found, error code if not.
@@ -366,9 +355,11 @@ @@ -366,9 +355,11 @@
366 int compare(size_t baddr, const char* s, size_t len) const; 355 int compare(size_t baddr, const char* s, size_t len) const;
367 int compare(int row, int col, const char* s, size_t len) const; 356 int compare(int row, int col, const char* s, size_t len) const;
368 357
  358 + */
369 }; 359 };
370 360
371 /// @brief TN3270 Host 361 /// @brief TN3270 Host
  362 + /*
372 class TN3270_PUBLIC Host : public std::basic_streambuf<char, std::char_traits<char> > { 363 class TN3270_PUBLIC Host : public std::basic_streambuf<char, std::char_traits<char> > {
373 private: 364 private:
374 365
@@ -579,6 +570,7 @@ @@ -579,6 +570,7 @@
579 570
580 571
581 }; 572 };
  573 + */
582 574
583 } 575 }
584 576
@@ -586,6 +578,7 @@ @@ -586,6 +578,7 @@
586 TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState); 578 TN3270_PUBLIC const char * toCharString(const TN3270::ConnectionState connectionState);
587 TN3270_PUBLIC const char * toCharString(const TN3270::Action action); 579 TN3270_PUBLIC const char * toCharString(const TN3270::Action action);
588 580
  581 + /*
589 template <typename T> 582 template <typename T>
590 inline TN3270_PUBLIC TN3270::Session & operator<<(TN3270::Session& session, const T value) { 583 inline TN3270_PUBLIC TN3270::Session & operator<<(TN3270::Session& session, const T value) {
591 return session.push(value); 584 return session.push(value);
@@ -605,6 +598,7 @@ @@ -605,6 +598,7 @@
605 stream << host.toString(); 598 stream << host.toString();
606 return stream; 599 return stream;
607 } 600 }
  601 + */
608 602
609 603
610 #endif 604 #endif