Commit 323902f60939cbb7e3532b3baffe8a2efdbc289b

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

Reorganizing sources.

src/client/lib3270++.cbp
@@ -47,19 +47,19 @@ @@ -47,19 +47,19 @@
47 <Unit filename="../include/lib3270/actions.h" /> 47 <Unit filename="../include/lib3270/actions.h" />
48 <Unit filename="../include/lib3270/popup.h" /> 48 <Unit filename="../include/lib3270/popup.h" />
49 <Unit filename="../include/lib3270/session.h" /> 49 <Unit filename="../include/lib3270/session.h" />
50 - <Unit filename="abstract.cc" />  
51 - <Unit filename="events.cc" />  
52 - <Unit filename="host.cc" />  
53 - <Unit filename="ipc/session.cc" />  
54 - <Unit filename="linux/request.cc" />  
55 - <Unit filename="linux/session.cc" />  
56 - <Unit filename="local/events.cc" />  
57 - <Unit filename="local/session.cc" />  
58 <Unit filename="private.h" /> 50 <Unit filename="private.h" />
59 - <Unit filename="session.cc" />  
60 - <Unit filename="testprogram/testprogram.cc" />  
61 - <Unit filename="windows/request.cc" />  
62 - <Unit filename="windows/session.cc" /> 51 + <Unit filename="src/core/abstract.cc" />
  52 + <Unit filename="src/core/events.cc" />
  53 + <Unit filename="src/core/host.cc" />
  54 + <Unit filename="src/core/session.cc" />
  55 + <Unit filename="src/os/linux/request.cc" />
  56 + <Unit filename="src/os/linux/session.cc" />
  57 + <Unit filename="src/os/windows/request.cc" />
  58 + <Unit filename="src/os/windows/session.cc" />
  59 + <Unit filename="src/session/local/events.cc" />
  60 + <Unit filename="src/session/local/session.cc" />
  61 + <Unit filename="src/session/remote/session.cc" />
  62 + <Unit filename="src/testprogram/testprogram.cc" />
63 <Extensions> 63 <Extensions>
64 <code_completion /> 64 <code_completion />
65 <envvars /> 65 <envvars />
src/client/private.h
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin 18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19 * St, Fifth Floor, Boston, MA 02110-1301 USA 19 * St, Fifth Floor, Boston, MA 02110-1301 USA
20 * 20 *
21 - * Este programa está nomeado como lib3270++.h e possui - linhas de código. 21 + * Este programa está nomeado como - e possui - linhas de código.
22 * 22 *
23 * Contatos: 23 * Contatos:
24 * 24 *
src/client/src/abstract.cc
@@ -1,153 +0,0 @@ @@ -1,153 +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 lib3270++.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 - */  
29 -  
30 -/**  
31 - * @file src/lib3270++/abstract.cc  
32 - *  
33 - * @brief  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "private.h"  
40 - #include <cstring>  
41 -  
42 -  
43 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
44 -  
45 - namespace TN3270 {  
46 -  
47 - Abstract::Session::Session() {  
48 -  
49 -#ifdef HAVE_ICONV  
50 - this->converter.local = (iconv_t) (-1);  
51 - this->converter.host = (iconv_t) (-1);  
52 -#endif  
53 -  
54 - this->baddr = 0;  
55 -  
56 - }  
57 -  
58 - Abstract::Session::~Session() {  
59 -  
60 -#ifdef HAVE_ICONV  
61 -  
62 - if(this->converter.local != (iconv_t) (-1))  
63 - iconv_close(this->converter.local);  
64 -  
65 - if(this->converter.host != (iconv_t) (-1))  
66 - iconv_close(this->converter.host);  
67 -  
68 -#endif  
69 -  
70 - }  
71 -  
72 - /// @brief Setup charsets  
73 - void Abstract::Session::setCharSet(const char *remote, const char *local) {  
74 -  
75 -#ifdef HAVE_ICONV  
76 -  
77 - if(this->converter.local != (iconv_t) (-1))  
78 - iconv_close(converter.local);  
79 -  
80 - if(this->converter.host != (iconv_t) (-1))  
81 - iconv_close(converter.host);  
82 -  
83 - if(strcmp(local,remote)) {  
84 -  
85 - // Local and remote charsets aren't the same, setup conversion  
86 - converter.local = iconv_open(local, remote);  
87 - converter.host = iconv_open(remote,local);  
88 -  
89 - } else {  
90 - // Same charset, doesn't convert  
91 - converter.local = converter.host = (iconv_t)(-1);  
92 - }  
93 -  
94 -#else  
95 -  
96 - #error No ICONV Support  
97 -  
98 -#endif  
99 -  
100 -  
101 - }  
102 -  
103 - /// @brief Converte charset.  
104 - std::string Abstract::Session::convertCharset(iconv_t &converter, const char *str) {  
105 -  
106 - std::string rc;  
107 -  
108 -#ifdef HAVE_ICONV  
109 - size_t in = strlen(str);  
110 -  
111 - if(in && converter != (iconv_t)(-1)) {  
112 -  
113 - size_t out = (in << 1);  
114 - char * ptr;  
115 - char * outBuffer = (char *) malloc(out);  
116 - ICONV_CONST char * inBuffer = (ICONV_CONST char *) str;  
117 -  
118 - memset(ptr=outBuffer,0,out);  
119 -  
120 - iconv(converter,NULL,NULL,NULL,NULL); // Reset state  
121 -  
122 - if(iconv(converter,&inBuffer,&in,&ptr,&out) != ((size_t) -1))  
123 - rc.assign(outBuffer);  
124 -  
125 - free(outBuffer);  
126 -  
127 - }  
128 -  
129 -#else  
130 -  
131 - rc = str;  
132 -  
133 -#endif // HAVE_ICONV  
134 -  
135 - return rc;  
136 - }  
137 -  
138 - /// @brief Converte string recebida do host para o charset atual.  
139 - std::string Abstract::Session::convertFromHost(const char *str) const {  
140 - return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str);  
141 - }  
142 -  
143 - /// @brief Converte string do charset atual para o charset do host.  
144 - std::string Abstract::Session::convertToHost(const char *str) const {  
145 - return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,str);  
146 - }  
147 -  
148 -  
149 - }  
150 -  
151 -  
152 -  
153 -  
src/client/src/core/abstract.cc 0 → 100644
@@ -0,0 +1,153 @@ @@ -0,0 +1,153 @@
  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/core/abstract.cc
  32 + *
  33 + * @brief Implements abstract session object.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 + #include <cstring>
  41 +
  42 +
  43 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  44 +
  45 + namespace TN3270 {
  46 +
  47 + Abstract::Session::Session() {
  48 +
  49 +#ifdef HAVE_ICONV
  50 + this->converter.local = (iconv_t) (-1);
  51 + this->converter.host = (iconv_t) (-1);
  52 +#endif
  53 +
  54 + this->baddr = 0;
  55 +
  56 + }
  57 +
  58 + Abstract::Session::~Session() {
  59 +
  60 +#ifdef HAVE_ICONV
  61 +
  62 + if(this->converter.local != (iconv_t) (-1))
  63 + iconv_close(this->converter.local);
  64 +
  65 + if(this->converter.host != (iconv_t) (-1))
  66 + iconv_close(this->converter.host);
  67 +
  68 +#endif
  69 +
  70 + }
  71 +
  72 + /// @brief Setup charsets
  73 + void Abstract::Session::setCharSet(const char *remote, const char *local) {
  74 +
  75 +#ifdef HAVE_ICONV
  76 +
  77 + if(this->converter.local != (iconv_t) (-1))
  78 + iconv_close(converter.local);
  79 +
  80 + if(this->converter.host != (iconv_t) (-1))
  81 + iconv_close(converter.host);
  82 +
  83 + if(strcmp(local,remote)) {
  84 +
  85 + // Local and remote charsets aren't the same, setup conversion
  86 + converter.local = iconv_open(local, remote);
  87 + converter.host = iconv_open(remote,local);
  88 +
  89 + } else {
  90 + // Same charset, doesn't convert
  91 + converter.local = converter.host = (iconv_t)(-1);
  92 + }
  93 +
  94 +#else
  95 +
  96 + throw std::runtime_error("No ICONV Support");
  97 +
  98 +#endif
  99 +
  100 +
  101 + }
  102 +
  103 + /// @brief Converte charset.
  104 + std::string Abstract::Session::convertCharset(iconv_t &converter, const char *str) {
  105 +
  106 + std::string rc;
  107 +
  108 +#ifdef HAVE_ICONV
  109 + size_t in = strlen(str);
  110 +
  111 + if(in && converter != (iconv_t)(-1)) {
  112 +
  113 + size_t out = (in << 1);
  114 + char * ptr;
  115 + char * outBuffer = (char *) malloc(out);
  116 + ICONV_CONST char * inBuffer = (ICONV_CONST char *) str;
  117 +
  118 + memset(ptr=outBuffer,0,out);
  119 +
  120 + iconv(converter,NULL,NULL,NULL,NULL); // Reset state
  121 +
  122 + if(iconv(converter,&inBuffer,&in,&ptr,&out) != ((size_t) -1))
  123 + rc.assign(outBuffer);
  124 +
  125 + free(outBuffer);
  126 +
  127 + }
  128 +
  129 +#else
  130 +
  131 + rc = str;
  132 +
  133 +#endif // HAVE_ICONV
  134 +
  135 + return rc;
  136 + }
  137 +
  138 + /// @brief Converte string recebida do host para o charset atual.
  139 + std::string Abstract::Session::convertFromHost(const char *str) const {
  140 + return convertCharset(const_cast<Abstract::Session *>(this)->converter.local,str);
  141 + }
  142 +
  143 + /// @brief Converte string do charset atual para o charset do host.
  144 + std::string Abstract::Session::convertToHost(const char *str) const {
  145 + return convertCharset(const_cast<Abstract::Session *>(this)->converter.host,str);
  146 + }
  147 +
  148 +
  149 + }
  150 +
  151 +
  152 +
  153 +
src/client/src/core/events.cc 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  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/core/events.cc
  32 + *
  33 + * @brief Implements event object.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + Event::Event(enum Event::Type type) {
  47 + this->type = type;
  48 + }
  49 +
  50 + Event::~Event() {
  51 + }
  52 +
  53 + }
  54 +
  55 +
  56 +
src/client/src/core/host.cc 0 → 100644
@@ -0,0 +1,180 @@ @@ -0,0 +1,180 @@
  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/core/host.cc
  32 + *
  33 + * @brief Implements host object.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + Host::Host(const char *id, const char *url, time_t timeout) {
  47 + this->timeout = timeout;
  48 + this->session = Session::create(id);
  49 + if(url) {
  50 + this->connect(url);
  51 + }
  52 + }
  53 +
  54 + Host::~Host() {
  55 + delete this->session;
  56 + this->session = nullptr;
  57 + }
  58 +
  59 + void Host::connect(const char *url, bool sync) {
  60 + this->session->connect(url);
  61 + if(sync) {
  62 + this->sync();
  63 + }
  64 + }
  65 +
  66 +
  67 + /// @brief Writes characters to the associated file from the put area
  68 + int Host::sync() {
  69 + this->session->waitForReady(this->timeout);
  70 + return 0;
  71 + }
  72 +
  73 + /// @brief Writes characters to the associated output sequence from the put area.
  74 + int Host::overflow(int c) {
  75 +
  76 + if (c != EOF) {
  77 + char str[] = { static_cast<char>(c), 0 };
  78 + this->session->push((const char *) str);
  79 + } else {
  80 + sync();
  81 + }
  82 +
  83 + return c;
  84 +
  85 + }
  86 +
  87 + Host & Host::push(const Action action) {
  88 + session->push(action);
  89 + sync();
  90 + return *this;
  91 + }
  92 +
  93 + bool Host::isReady() const {
  94 + this->session->waitForReady(this->timeout);
  95 + return getProgramMessage() == MESSAGE_NONE;
  96 + }
  97 +
  98 + bool Host::isConnected() const {
  99 + this->session->waitForReady(this->timeout);
  100 + return getConnectionState() == CONNECTED_TN3270E;
  101 + }
  102 +
  103 + std::string Host::toString() const {
  104 +
  105 + this->session->waitForReady(this->timeout);
  106 +
  107 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  108 + throw std::system_error(ENOTCONN, std::system_category());
  109 + }
  110 +
  111 + return this->session->toString();
  112 + }
  113 +
  114 + std::string Host::toString(int baddr, size_t len, char lf) const {
  115 +
  116 + this->session->waitForReady(this->timeout);
  117 +
  118 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  119 + throw std::system_error(ENOTCONN, std::system_category());
  120 + }
  121 +
  122 + return this->session->toString(baddr,len,lf);
  123 +
  124 + }
  125 +
  126 + std::string Host::toString(int row, int col, size_t sz, char lf) const {
  127 +
  128 + this->session->waitForReady(this->timeout);
  129 +
  130 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  131 + throw std::system_error(ENOTCONN, std::system_category());
  132 + }
  133 +
  134 + return this->session->toString(row,col,sz,lf);
  135 +
  136 +
  137 + }
  138 +
  139 + Host & Host::pop(int baddr, std::string &text) {
  140 +
  141 + this->session->waitForReady(this->timeout);
  142 +
  143 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  144 + throw std::system_error(ENOTCONN, std::system_category());
  145 + }
  146 +
  147 + session->pop(baddr, text);
  148 +
  149 + return *this;
  150 + }
  151 +
  152 + Host & Host::pop(int row, int col, std::string &text) {
  153 +
  154 + this->session->waitForReady(this->timeout);
  155 +
  156 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  157 + throw std::system_error(ENOTCONN, std::system_category());
  158 + }
  159 +
  160 + session->pop(row,col,text);
  161 +
  162 + return *this;
  163 + }
  164 +
  165 + Host & Host::pop(std::string &text) {
  166 +
  167 + this->session->waitForReady(this->timeout);
  168 +
  169 + if(this->session->getConnectionState() == TN3270::DISCONNECTED) {
  170 + throw std::system_error(ENOTCONN, std::system_category());
  171 + }
  172 +
  173 + session->pop(text);
  174 +
  175 + return *this;
  176 + }
  177 +
  178 +
  179 + }
  180 +
src/client/src/core/session.cc 0 → 100644
@@ -0,0 +1,78 @@ @@ -0,0 +1,78 @@
  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/core/session.cc
  32 + *
  33 + * @brief Implements common session object.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "private.h"
  40 +
  41 +
  42 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  43 +
  44 + namespace TN3270 {
  45 +
  46 + /// @brief Create a tn3270 session.
  47 + Session * Session::create(const char *id) {
  48 +
  49 + if(!id) {
  50 + return new Local::Session();
  51 + }
  52 +
  53 + return new IPC::Session(id);
  54 +
  55 + }
  56 +
  57 +
  58 + Session::Session() {
  59 +
  60 + }
  61 +
  62 + Session::~Session() {
  63 +
  64 + }
  65 +
  66 + void Session::insert(Event::Type type, std::function <void(const Event &event)> listener) {
  67 + }
  68 +
  69 + /// @brief Fire event.
  70 + void Session::fire(const Event &event) {
  71 +
  72 +
  73 + }
  74 +
  75 + }
  76 +
  77 +
  78 +
src/client/src/events.cc
@@ -1,56 +0,0 @@ @@ -1,56 +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 lib3270++.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 - */  
29 -  
30 -/**  
31 - * @file src/lib3270++/events.cc  
32 - *  
33 - * @brief  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "private.h"  
40 -  
41 -  
42 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
43 -  
44 - namespace TN3270 {  
45 -  
46 - Event::Event(enum Event::Type type) {  
47 - this->type = type;  
48 - }  
49 -  
50 - Event::~Event() {  
51 - }  
52 -  
53 - }  
54 -  
55 -  
56 -  
src/client/src/host.cc
@@ -1,180 +0,0 @@ @@ -1,180 +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 lib3270++.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 - */  
29 -  
30 -/**  
31 - * @file src/lib3270++/host.cc  
32 - *  
33 - * @brief  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "private.h"  
40 -  
41 -  
42 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
43 -  
44 - namespace TN3270 {  
45 -  
46 - Host::Host(const char *id, const char *url, time_t timeout) {  
47 - this->timeout = timeout;  
48 - this->session = Session::create(id);  
49 - if(url) {  
50 - this->connect(url);  
51 - }  
52 - }  
53 -  
54 - Host::~Host() {  
55 - delete this->session;  
56 - this->session = nullptr;  
57 - }  
58 -  
59 - void Host::connect(const char *url, bool sync) {  
60 - this->session->connect(url);  
61 - if(sync) {  
62 - this->sync();  
63 - }  
64 - }  
65 -  
66 -  
67 - /// @brief Writes characters to the associated file from the put area  
68 - int Host::sync() {  
69 - this->session->waitForReady(this->timeout);  
70 - return 0;  
71 - }  
72 -  
73 - /// @brief Writes characters to the associated output sequence from the put area.  
74 - int Host::overflow(int c) {  
75 -  
76 - if (c != EOF) {  
77 - char str[] = { static_cast<char>(c), 0 };  
78 - this->session->push((const char *) str);  
79 - } else {  
80 - sync();  
81 - }  
82 -  
83 - return c;  
84 -  
85 - }  
86 -  
87 - Host & Host::push(const Action action) {  
88 - session->push(action);  
89 - sync();  
90 - return *this;  
91 - }  
92 -  
93 - bool Host::isReady() const {  
94 - this->session->waitForReady(this->timeout);  
95 - return getProgramMessage() == MESSAGE_NONE;  
96 - }  
97 -  
98 - bool Host::isConnected() const {  
99 - this->session->waitForReady(this->timeout);  
100 - return getConnectionState() == CONNECTED_TN3270E;  
101 - }  
102 -  
103 - std::string Host::toString() const {  
104 -  
105 - this->session->waitForReady(this->timeout);  
106 -  
107 - if(this->session->getConnectionState() == TN3270::DISCONNECTED) {  
108 - throw std::system_error(ENOTCONN, std::system_category());  
109 - }  
110 -  
111 - return this->session->toString();  
112 - }  
113 -  
114 - std::string Host::toString(int baddr, size_t len, char lf) const {  
115 -  
116 - this->session->waitForReady(this->timeout);  
117 -  
118 - if(this->session->getConnectionState() == TN3270::DISCONNECTED) {  
119 - throw std::system_error(ENOTCONN, std::system_category());  
120 - }  
121 -  
122 - return this->session->toString(baddr,len,lf);  
123 -  
124 - }  
125 -  
126 - std::string Host::toString(int row, int col, size_t sz, char lf) const {  
127 -  
128 - this->session->waitForReady(this->timeout);  
129 -  
130 - if(this->session->getConnectionState() == TN3270::DISCONNECTED) {  
131 - throw std::system_error(ENOTCONN, std::system_category());  
132 - }  
133 -  
134 - return this->session->toString(row,col,sz,lf);  
135 -  
136 -  
137 - }  
138 -  
139 - Host & Host::pop(int baddr, std::string &text) {  
140 -  
141 - this->session->waitForReady(this->timeout);  
142 -  
143 - if(this->session->getConnectionState() == TN3270::DISCONNECTED) {  
144 - throw std::system_error(ENOTCONN, std::system_category());  
145 - }  
146 -  
147 - session->pop(baddr, text);  
148 -  
149 - return *this;  
150 - }  
151 -  
152 - Host & Host::pop(int row, int col, std::string &text) {  
153 -  
154 - this->session->waitForReady(this->timeout);  
155 -  
156 - if(this->session->getConnectionState() == TN3270::DISCONNECTED) {  
157 - throw std::system_error(ENOTCONN, std::system_category());  
158 - }  
159 -  
160 - session->pop(row,col,text);  
161 -  
162 - return *this;  
163 - }  
164 -  
165 - Host & Host::pop(std::string &text) {  
166 -  
167 - this->session->waitForReady(this->timeout);  
168 -  
169 - if(this->session->getConnectionState() == TN3270::DISCONNECTED) {  
170 - throw std::system_error(ENOTCONN, std::system_category());  
171 - }  
172 -  
173 - session->pop(text);  
174 -  
175 - return *this;  
176 - }  
177 -  
178 -  
179 - }  
180 -  
src/client/src/ipc/session.cc
@@ -1,365 +0,0 @@ @@ -1,365 +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/lib3270++/ipc/session.cc  
32 - *  
33 - * @brief Implements lib3270 access using IPC calls.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "../private.h"  
40 - #include <cstring>  
41 -  
42 - using std::string;  
43 -  
44 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
45 -  
46 - namespace TN3270 {  
47 -  
48 - void IPC::Session::connect(const char *url) {  
49 - Request request(*this,"connect");  
50 - request.push(url).call();  
51 - }  
52 -  
53 - void IPC::Session::disconnect() {  
54 - Request(*this,"disconnect").call();  
55 - }  
56 -  
57 - // Wait for session state.  
58 - void IPC::Session::waitForReady(time_t timeout) {  
59 -  
60 - int rc;  
61 -  
62 - time_t end = time(nullptr) + timeout;  
63 -  
64 - while(time(nullptr) < end) {  
65 -  
66 - debug("Running waitForReady request...");  
67 -  
68 - Request(*this,"waitForReady")  
69 - .push((uint32_t) 1)  
70 - .call()  
71 - .pop(rc);  
72 -  
73 - debug("Wait for ready returned ",rc);  
74 -  
75 - if(rc == 0)  
76 - return;  
77 -  
78 - }  
79 -  
80 - throw std::system_error(ETIMEDOUT, std::system_category());  
81 - }  
82 -  
83 - std::string IPC::Session::toString(int baddr, size_t len, char lf) const {  
84 -  
85 - std::string rc;  
86 -  
87 - Request(*this,"getStringAtAddress")  
88 - .push((uint32_t) baddr)  
89 - .push((uint32_t) len)  
90 - .push((uint8_t) lf)  
91 - .call()  
92 - .pop(rc);  
93 -  
94 - return rc;  
95 - }  
96 -  
97 - std::string IPC::Session::toString(int row, int col, size_t sz, char lf) const {  
98 -  
99 - std::string rc;  
100 -  
101 - Request(*this,"getStringAt")  
102 - .push((uint32_t) row)  
103 - .push((uint32_t) col)  
104 - .push((uint32_t) sz)  
105 - .push((uint8_t) lf)  
106 - .call()  
107 - .pop(rc);  
108 -  
109 - return rc;  
110 - }  
111 -  
112 - ProgramMessage IPC::Session::getProgramMessage() const {  
113 -  
114 - int program_message;  
115 - getProperty("program_message",program_message);  
116 - return (ProgramMessage) program_message;  
117 -  
118 - }  
119 -  
120 - ConnectionState IPC::Session::getConnectionState() const {  
121 -  
122 - int cstate;  
123 - getProperty("cstate",cstate);  
124 - return (ConnectionState) cstate;  
125 -  
126 - }  
127 -  
128 - /// @brief Set field at current position, jumps to next writable field.  
129 - TN3270::Session & IPC::Session::push(const char *text) {  
130 -  
131 - int rc;  
132 -  
133 - Request(*this,"setString")  
134 - .push(text)  
135 - .call()  
136 - .pop(rc);  
137 -  
138 - if(rc) {  
139 - throw std::system_error((int) rc, std::system_category());  
140 - }  
141 -  
142 - return *this;  
143 -  
144 - }  
145 -  
146 - TN3270::Session & IPC::Session::push(int baddr, const std::string &text) {  
147 -  
148 - int rc;  
149 -  
150 - Request(*this,"setStringAtAddress")  
151 - .push((uint32_t) baddr)  
152 - .push(text.c_str())  
153 - .call()  
154 - .pop(rc);  
155 -  
156 - if(rc) {  
157 - throw std::system_error((int) rc, std::system_category());  
158 - }  
159 -  
160 - return *this;  
161 -  
162 - }  
163 -  
164 - TN3270::Session & IPC::Session::push(int row, int col, const std::string &text) {  
165 -  
166 - int32_t rc;  
167 -  
168 - Request(*this,"setStringAt")  
169 - .push((uint32_t) row)  
170 - .push((uint32_t) col)  
171 - .push(text.c_str())  
172 - .call()  
173 - .pop(rc);  
174 -  
175 - if(rc) {  
176 - throw std::system_error((int) rc, std::system_category());  
177 - }  
178 -  
179 - return *this;  
180 -  
181 - }  
182 -  
183 - TN3270::Session & IPC::Session::push(const PFKey key) {  
184 -  
185 - int32_t rc;  
186 -  
187 - Request(*this,"pfkey")  
188 - .push((uint32_t) key)  
189 - .call()  
190 - .pop(rc);  
191 -  
192 - if(rc) {  
193 - throw std::system_error((int) rc, std::system_category());  
194 - }  
195 -  
196 - return *this;  
197 -  
198 - }  
199 -  
200 - TN3270::Session & IPC::Session::push(const PAKey key) {  
201 -  
202 - int32_t rc;  
203 -  
204 - Request(*this,"pakey")  
205 - .push((uint32_t) key)  
206 - .call()  
207 - .pop(rc);  
208 -  
209 - if(rc) {  
210 - throw std::system_error((int) rc, std::system_category());  
211 - }  
212 -  
213 - return *this;  
214 -  
215 - }  
216 -  
217 - TN3270::Session & IPC::Session::push(const Action action) {  
218 -  
219 - const char * actions[] = {  
220 - "enter",  
221 - "erase",  
222 - "eraseeof",  
223 - "eraseeol",  
224 - "eraseinput"  
225 - };  
226 -  
227 - if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) {  
228 - throw std::system_error(EINVAL, std::system_category());  
229 - }  
230 -  
231 - return this->action(actions[action]);  
232 -  
233 - }  
234 -  
235 - TN3270::Session & IPC::Session::pop(int baddr, std::string &text) {  
236 -  
237 - Request(*this,"getFieldAtAddress")  
238 - .push((uint32_t) baddr)  
239 - .call()  
240 - .pop(text);  
241 -  
242 - return *this;  
243 - }  
244 -  
245 - TN3270::Session & IPC::Session::pop(int row, int col, std::string &text) {  
246 -  
247 - Request(*this,"getFieldAt")  
248 - .push((uint32_t) row)  
249 - .push((uint32_t) col)  
250 - .call()  
251 - .pop(text);  
252 -  
253 - return *this;  
254 - }  
255 -  
256 - TN3270::Session & IPC::Session::pop(std::string &text) {  
257 -  
258 - Request(*this,"getFieldAtCursor")  
259 - .call()  
260 - .pop(text);  
261 -  
262 - return *this;  
263 -  
264 - }  
265 -  
266 - /// @brief Set cursor address.  
267 - ///  
268 - /// @param addr Cursor address.  
269 - TN3270::Session & IPC::Session::setCursorPosition(unsigned short addr) {  
270 -  
271 - int32_t rc;  
272 -  
273 - Request(*this,"setCursorAddress")  
274 - .push((uint32_t) addr)  
275 - .call()  
276 - .pop(rc);  
277 -  
278 - if(rc) {  
279 - throw std::system_error((int) rc, std::system_category());  
280 - }  
281 -  
282 - return *this;  
283 -  
284 - }  
285 -  
286 - /// @brief Set cursor position.  
287 - ///  
288 - /// @param row New cursor row.  
289 - /// @param col New cursor column.  
290 - TN3270::Session & IPC::Session::setCursorPosition(unsigned short row, unsigned short col) {  
291 -  
292 - int32_t rc;  
293 -  
294 - Request(*this,"setCursorPosition")  
295 - .push((uint32_t) row)  
296 - .push((uint32_t) col)  
297 - .call()  
298 - .pop(rc);  
299 -  
300 - if(rc) {  
301 - throw std::system_error((int) rc, std::system_category());  
302 - }  
303 -  
304 - return *this;  
305 -  
306 - }  
307 -  
308 - void IPC::Session::getProperty(const char *name, int &value) const {  
309 -  
310 - Request(*this,false,name)  
311 - .call()  
312 - .pop(value);  
313 -  
314 - }  
315 -  
316 - void IPC::Session::getProperty(const char *name, std::string &value) const {  
317 -  
318 - Request(*this,false,name)  
319 - .call()  
320 - .pop(value);  
321 -  
322 - }  
323 -  
324 - void IPC::Session::getProperty(const char *name, bool &value) const {  
325 - throw std::system_error(ENOENT, std::system_category());  
326 - }  
327 -  
328 - /// @brief Get lib3270 version.  
329 - std::string IPC::Session::getVersion() const {  
330 -  
331 - string rc;  
332 - getProperty("version",rc);  
333 - return rc;  
334 -  
335 - }  
336 -  
337 - /// @brief Get lib3270 revision.  
338 - std::string IPC::Session::getRevision() const {  
339 -  
340 - string rc;  
341 - getProperty("revision",rc);  
342 - return rc;  
343 -  
344 - }  
345 -  
346 - /// @brief Execute action by name.  
347 - TN3270::Session & IPC::Session::action(const char *action_name) {  
348 -  
349 - int32_t rc;  
350 -  
351 - Request(*this,"action")  
352 - .push(action_name)  
353 - .call()  
354 - .pop(rc);  
355 -  
356 - if(rc) {  
357 - throw std::system_error((int) rc, std::system_category());  
358 - }  
359 -  
360 - return *this;  
361 - }  
362 -  
363 - }  
364 -  
365 -  
src/client/src/linux/request.cc
@@ -1,267 +0,0 @@ @@ -1,267 +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/lib3270++/linux/request.cc  
32 - *  
33 - * @brief Implements D-Bus message.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "../private.h"  
40 -  
41 - using std::string;  
42 -  
43 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
44 -  
45 - namespace TN3270 {  
46 -  
47 - IPC::Request::Request(const Session &session) {  
48 - this->conn = session.conn;  
49 - this->msg.in = nullptr;  
50 - this->msg.out = nullptr;  
51 - }  
52 -  
53 - IPC::Request::Request(const Session &session, const char *method) : Request(session) {  
54 -  
55 - this->msg.out = dbus_message_new_method_call(  
56 - session.name.c_str(), // Destination  
57 - session.path.c_str(), // Path  
58 - session.interface.c_str(), // Interface  
59 - method // Method  
60 - );  
61 -  
62 - if(!msg.out) {  
63 - throw std::runtime_error("Can't create D-Bus Method Call");  
64 - }  
65 -  
66 - }  
67 -  
68 - IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) {  
69 -  
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(  
81 - session.name.c_str(), // Destination  
82 - session.path.c_str(), // Path  
83 - "org.freedesktop.DBus.Properties", // Interface  
84 - (isSet ? "Set" : "Get")  
85 - );  
86 -  
87 - if(!msg.out) {  
88 - throw std::runtime_error("Can't create D-Bus Property Call");  
89 - }  
90 -  
91 - //  
92 - // https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties  
93 - // org.freedesktop.DBus.Properties.Get (in STRING interface_name,  
94 - // in STRING property_name,  
95 - // out VARIANT value);  
96 - // org.freedesktop.DBus.Properties.Set (in STRING interface_name,  
97 - // in STRING property_name,  
98 - //  
99 - const char *interface_name = session.interface.c_str();  
100 -  
101 - dbus_message_append_args(  
102 - this->msg.out,  
103 - DBUS_TYPE_STRING,&interface_name,  
104 - DBUS_TYPE_STRING,&property,  
105 - DBUS_TYPE_INVALID  
106 - );  
107 -  
108 - }  
109 -  
110 - IPC::Request::~Request() {  
111 - if(msg.out) {  
112 - dbus_message_unref(msg.out);  
113 - }  
114 - if(msg.in) {  
115 - dbus_message_unref(msg.in);  
116 - }  
117 - }  
118 -  
119 - IPC::Request & IPC::Request::call() {  
120 -  
121 - if(msg.in) {  
122 - dbus_message_unref(msg.in);  
123 - msg.in = nullptr;  
124 - }  
125 -  
126 - DBusError error;  
127 - dbus_error_init(&error);  
128 - this->msg.in = dbus_connection_send_with_reply_and_block(this->conn,this->msg.out,10000,&error);  
129 -  
130 - if(!this->msg.in) {  
131 - string message = error.message;  
132 - dbus_error_free(&error);  
133 - throw std::runtime_error(message.c_str());  
134 - }  
135 -  
136 - dbus_message_iter_init(msg.in, &msg.iter);  
137 -  
138 - debug(__FUNCTION__," got a valid response");  
139 -  
140 - return *this;  
141 -  
142 - }  
143 -  
144 - IPC::Request & IPC::Request::push(const char *arg) {  
145 - dbus_message_append_args(this->msg.out,DBUS_TYPE_STRING,&arg,DBUS_TYPE_INVALID);  
146 - return *this;  
147 - }  
148 -  
149 - IPC::Request & IPC::Request::push(const bool arg) {  
150 - dbus_message_append_args(this->msg.out,DBUS_TYPE_BOOLEAN,&arg,DBUS_TYPE_INVALID);  
151 - return *this;  
152 - }  
153 -  
154 - IPC::Request & IPC::Request::push(const uint8_t arg) {  
155 - dbus_message_append_args(this->msg.out,DBUS_TYPE_BYTE,&arg,DBUS_TYPE_INVALID);  
156 - return *this;  
157 - }  
158 -  
159 - IPC::Request & IPC::Request::push(const int32_t arg) {  
160 - dbus_message_append_args(this->msg.out,DBUS_TYPE_INT32,&arg,DBUS_TYPE_INVALID);  
161 - return *this;  
162 - }  
163 -  
164 - IPC::Request & IPC::Request::push(const uint32_t arg) {  
165 - dbus_message_append_args(this->msg.out,DBUS_TYPE_UINT32,&arg,DBUS_TYPE_INVALID);  
166 - return *this;  
167 - }  
168 -  
169 -  
170 - IPC::Request & IPC::Request::pop(std::string &value) {  
171 -  
172 - const char * str = "";  
173 -  
174 - if(dbus_message_iter_get_arg_type(&msg.iter) == DBUS_TYPE_STRING) {  
175 -  
176 - dbus_message_iter_get_basic(&msg.iter, &str);  
177 -  
178 - } else if(dbus_message_iter_get_arg_type(&msg.iter) == DBUS_TYPE_VARIANT) {  
179 -  
180 - DBusMessageIter sub;  
181 - int current_type;  
182 -  
183 - dbus_message_iter_recurse(&msg.iter, &sub);  
184 -  
185 - while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) {  
186 -  
187 - if (current_type == DBUS_TYPE_STRING) {  
188 - dbus_message_iter_get_basic(&sub, &str);  
189 - break;  
190 - }  
191 - dbus_message_iter_next(&sub);  
192 - }  
193 -  
194 - } else {  
195 -  
196 - debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&msg.iter)) );  
197 - throw std::runtime_error("Expected an string data type");  
198 -  
199 - }  
200 -  
201 - dbus_message_iter_next(&msg.iter);  
202 -  
203 - value.assign(str);  
204 -  
205 - debug(__FUNCTION__,"= \"",str,"\"");  
206 -  
207 - return *this;  
208 - }  
209 -  
210 - static int getIntValue(DBusMessageIter &iter) {  
211 -  
212 - if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) {  
213 -  
214 - dbus_int32_t rc = 0;  
215 - dbus_message_iter_get_basic(&iter, &rc);  
216 - return (int) rc;  
217 -  
218 - } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT16) {  
219 -  
220 - dbus_int16_t rc = 0;  
221 - dbus_message_iter_get_basic(&iter, &rc);  
222 - return (int) rc;  
223 -  
224 - } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) {  
225 -  
226 - DBusMessageIter sub;  
227 - int current_type;  
228 -  
229 - dbus_message_iter_recurse(&iter, &sub);  
230 -  
231 - while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) {  
232 -  
233 - if (current_type == DBUS_TYPE_INT32) {  
234 -  
235 - dbus_int32_t rc = 0;  
236 - dbus_message_iter_get_basic(&sub, &rc);  
237 - return (int) rc;  
238 -  
239 - } else if (current_type == DBUS_TYPE_INT16) {  
240 - dbus_int16_t rc = 0;  
241 - dbus_message_iter_get_basic(&sub, &rc);  
242 - return (int) rc;  
243 -  
244 - }  
245 - dbus_message_iter_next(&sub);  
246 - }  
247 -  
248 - }  
249 -  
250 - debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) );  
251 - throw std::runtime_error("Expected an integer data type");  
252 -  
253 - }  
254 -  
255 - IPC::Request & IPC::Request::Request::pop(int &value) {  
256 -  
257 - value = getIntValue(msg.iter);  
258 - dbus_message_iter_next(&msg.iter);  
259 - debug(__FUNCTION__,"= \"",value,"\"");  
260 -  
261 - return *this;  
262 -  
263 - }  
264 -  
265 - }  
266 -  
267 -  
src/client/src/linux/session.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 - 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/lib3270++/ipc/linux/session.cc  
32 - *  
33 - * @brief Implements Linux session create/destroy session.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "../private.h"  
40 - #include <cstring>  
41 - #include <lib3270/trace.h>  
42 -  
43 - using std::string;  
44 -  
45 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
46 -  
47 - static void throws_if_error(DBusError &err) {  
48 -  
49 - if(dbus_error_is_set(&err)) {  
50 - string message = err.message;  
51 - dbus_error_free(&err);  
52 - throw std::runtime_error(message.c_str());  
53 - }  
54 -  
55 - return;  
56 -  
57 - }  
58 -  
59 - namespace TN3270 {  
60 -  
61 - IPC::Session::Session(const char *id) : Abstract::Session() {  
62 -  
63 - // Create D-Bus session.  
64 - DBusError err;  
65 -  
66 - dbus_error_init(&err);  
67 - this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err);  
68 -  
69 - debug("dbus_bus_get conn=",conn);  
70 -  
71 - throws_if_error(err);  
72 -  
73 - if(!conn)  
74 - throw std::runtime_error("DBUS Connection failed");  
75 -  
76 - auto sep = strchr(id,':');  
77 - if(!sep) {  
78 - throw std::system_error(EINVAL, std::system_category());  
79 - }  
80 -  
81 - this->name = "br.com.bb.";  
82 - this->name += string(id,(sep - id));  
83 - this->name += ".";  
84 - this->name += (sep+1);  
85 - this->path = "/br/com/bb/tn3270/session";  
86 - this->interface = "br.com.bb.tn3270.session";  
87 -  
88 - debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\"");  
89 -  
90 - }  
91 -  
92 - IPC::Session::~Session() {  
93 -  
94 - }  
95 -  
96 - }  
97 -  
98 -  
src/client/src/local/events.cc
@@ -1,175 +0,0 @@ @@ -1,175 +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 lib3270++.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 - */  
29 -  
30 -/**  
31 - * @file src/lib3270++/local/events.cc  
32 - *  
33 - * @brief Implement lib3270 direct access events.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "../private.h"  
40 - #include <stdio.h>  
41 -  
42 - extern "C" {  
43 - #include <lib3270/actions.h>  
44 - #include <lib3270/session.h>  
45 - }  
46 -  
47 - using std::string;  
48 -  
49 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
50 -  
51 -#ifndef HAVE_VASPRINTF  
52 - int vasprintf(char **strp, const char *fmt, va_list ap) {  
53 - char buf[1024];  
54 -  
55 - int nc = vsnprintf(buf, sizeof(buf), fmt, args);  
56 -  
57 - if(nc < 0) {  
58 -  
59 - *strp = strdup(_("Error in vasprintf"));  
60 -  
61 - } else if (nc < sizeof(buf)) {  
62 -  
63 - *strp = malloc(nc+1);  
64 - strcpy(*strp, buf);  
65 -  
66 - } else {  
67 -  
68 - *strp = malloc(nc + 1);  
69 - if(vsnprintf(*strp, nc, fmt, args) < 0) {  
70 - free(*strp);  
71 - *strp = strdup(NULL,_( "Out of memory in vasprintf" ) );  
72 - }  
73 -  
74 - }  
75 -  
76 - return nc;  
77 - }  
78 -#endif // !HAVE_VASPRINTF  
79 -  
80 - namespace TN3270 {  
81 -  
82 - /// @brief Popup Handler.  
83 - void Local::Session::popupHandler(H3270 *h3270, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) {  
84 -  
85 - Local::Session * session = (Local::Session *) lib3270_get_user_data(h3270);  
86 -  
87 - if(!session) {  
88 - throw std::runtime_error(_( "Invalid session handler" ));  
89 - }  
90 -  
91 - class PopupEvent : public TN3270::Event {  
92 - private:  
93 - LIB3270_NOTIFY type;  
94 - string title;  
95 - string msg;  
96 - string description;  
97 -  
98 - public:  
99 - PopupEvent(LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) : Event(Event::Popup) {  
100 -  
101 - this->type = type;  
102 - this->title = title;  
103 - this->msg = msg;  
104 -  
105 - char * buffer = NULL;  
106 - if(vasprintf(&buffer,fmt,arg) != -1) {  
107 - this->description = buffer;  
108 - free(buffer);  
109 - }  
110 -  
111 -#ifdef DEBUG  
112 - std::cerr << "Popup:" << std::endl  
113 - << "\t" << title << std::endl  
114 - << "\t" << msg << std::endl  
115 - << "\t" << description << std::endl;  
116 -#endif // DEBUG  
117 -  
118 - }  
119 -  
120 - virtual ~PopupEvent() {  
121 - }  
122 -  
123 - /// @brief Get event description.  
124 - std::string toString() const override {  
125 - return msg;  
126 - }  
127 -  
128 -  
129 - };  
130 -  
131 - session->fire(PopupEvent(type,title,msg,fmt,arg));  
132 -  
133 - }  
134 -  
135 - /// @brief Connect Handler.  
136 - void Local::Session::connectHandler(H3270 *h3270, unsigned char connected) {  
137 -  
138 - Local::Session * session = (Local::Session *) lib3270_get_user_data(h3270);  
139 -  
140 - if(!session) {  
141 - throw std::runtime_error(_("Invalid session handler"));  
142 - }  
143 -  
144 - class ConnectionEvent : public TN3270::Event {  
145 - private:  
146 - bool connected;  
147 -  
148 - public:  
149 - ConnectionEvent(unsigned char connected) : Event(Event::Connection) {  
150 - this->connected = (connected != 0);  
151 -  
152 -#ifdef DEBUG  
153 - std::cerr << "Session is " << this->toString().c_str() << std::endl;  
154 -#endif // DEBUG  
155 -  
156 - }  
157 -  
158 - virtual ~ConnectionEvent() {  
159 - }  
160 -  
161 - /// @brief Get event description.  
162 - std::string toString() const override {  
163 - return this->connected ? _("connected") : _("disconnected");  
164 - }  
165 -  
166 - };  
167 -  
168 - session->fire(ConnectionEvent(connected));  
169 -  
170 - }  
171 -  
172 -  
173 - }  
174 -  
175 -  
src/client/src/local/session.cc
@@ -1,389 +0,0 @@ @@ -1,389 +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 lib3270++.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 - */  
29 -  
30 -/**  
31 - * @file src/lib3270++/local/session.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 - #include <lib3270/actions.h>  
41 - #include <lib3270/properties.h>  
42 - #include <cstring>  
43 -  
44 - extern "C" {  
45 - #include <lib3270/session.h>  
46 - }  
47 -  
48 - using std::string;  
49 -  
50 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
51 -  
52 - namespace TN3270 {  
53 -  
54 - Local::Session::Session() : Abstract::Session() {  
55 -  
56 - std::lock_guard<std::mutex> lock(sync);  
57 -  
58 - this->hSession = lib3270_session_new("");  
59 - lib3270_set_user_data(this->hSession,(void *) this);  
60 - setCharSet(lib3270_get_display_charset(this->hSession));  
61 -  
62 - lib3270_set_popup_handler(this->hSession, popupHandler);  
63 -  
64 - // Setup callbacks  
65 - struct lib3270_session_callbacks *cbk;  
66 -  
67 - cbk = lib3270_get_session_callbacks(this->hSession,sizeof(struct lib3270_session_callbacks));  
68 - if(!cbk) {  
69 - throw std::runtime_error( _("Invalid callback table, possible version mismatch in lib3270") );  
70 - }  
71 -  
72 - cbk->update_connect = connectHandler;  
73 -  
74 -  
75 - }  
76 -  
77 - Local::Session::~Session() {  
78 -  
79 - std::lock_guard<std::mutex> lock(sync);  
80 -  
81 - lib3270_session_free(this->hSession);  
82 - this->hSession = nullptr;  
83 - }  
84 -  
85 - void Local::Session::wait(time_t timeout) {  
86 -  
87 - std::lock_guard<std::mutex> lock(sync);  
88 -  
89 - int rc = lib3270_wait_for_ready(this->hSession, timeout);  
90 -  
91 - if(rc) {  
92 - throw std::system_error(rc, std::system_category());  
93 - }  
94 -  
95 - }  
96 -  
97 - void Local::Session::connect(const char *url) {  
98 - std::lock_guard<std::mutex> lock(sync);  
99 - int rc = lib3270_connect_url(hSession,url,0);  
100 -  
101 - if(rc) {  
102 - throw std::system_error(rc, std::system_category());  
103 - }  
104 -  
105 - }  
106 -  
107 - void Local::Session::disconnect() {  
108 - std::lock_guard<std::mutex> lock(sync);  
109 - lib3270_disconnect(hSession);  
110 - }  
111 -  
112 - // Wait for session state.  
113 - void Local::Session::waitForReady(time_t timeout) throw() {  
114 - this->wait(timeout);  
115 - }  
116 -  
117 - std::string Local::Session::toString(int baddr, size_t len, char lf) const {  
118 -  
119 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
120 -  
121 - char * text = lib3270_get_string_at_address(hSession, baddr, len, lf);  
122 -  
123 - if(!text) {  
124 - throw std::runtime_error( _("Can't get screen contents") );  
125 - }  
126 -  
127 - string rc = convertFromHost(text);  
128 -  
129 - lib3270_free(text);  
130 -  
131 - return rc;  
132 -  
133 - }  
134 -  
135 - std::string Local::Session::toString(int row, int col, size_t sz, char lf) const {  
136 -  
137 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
138 -  
139 - char * text = lib3270_get_string_at(hSession, row, col, sz, lf);  
140 -  
141 - if(!text) {  
142 - throw std::runtime_error( _("Can't get screen contents") );  
143 - }  
144 -  
145 - string rc = convertFromHost(text);  
146 -  
147 - lib3270_free(text);  
148 -  
149 - return rc;  
150 - }  
151 -  
152 - void Local::Session::getProperty(const char *name, int &value) const {  
153 -  
154 - const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list();  
155 - for(size_t ix = 0; intprop[ix].name; ix++) {  
156 -  
157 - if(!strcasecmp(name,intprop[ix].name)) {  
158 -  
159 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
160 -  
161 - value = intprop[ix].get(hSession);  
162 -  
163 - if(value < 0 && errno != 0) {  
164 - throw std::system_error(errno, std::system_category());  
165 - }  
166 -  
167 -  
168 - }  
169 -  
170 - }  
171 -  
172 - throw std::system_error(ENOENT, std::system_category());  
173 -  
174 - }  
175 -  
176 - void Local::Session::getProperty(const char *name, std::string &value) const {  
177 -  
178 - const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list();  
179 -  
180 - for(size_t ix = 0; strprop[ix].name; ix++) {  
181 -  
182 - if(!strcasecmp(name,strprop[ix].name)) {  
183 -  
184 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
185 -  
186 - // Found it!  
187 - const char * str = strprop[ix].get(hSession);  
188 -  
189 - if(str) {  
190 - value.assign(str);  
191 - return;  
192 - }  
193 -  
194 - throw std::system_error(errno, std::system_category());  
195 -  
196 - }  
197 -  
198 - }  
199 -  
200 - throw std::system_error(ENOENT, std::system_category());  
201 - }  
202 -  
203 - void Local::Session::getProperty(const char *name, bool &value) const {  
204 -  
205 - LIB3270_TOGGLE toggle = lib3270_get_toggle_id(name);  
206 - if(toggle != (LIB3270_TOGGLE) -1) {  
207 -  
208 - // Is a Tn3270 toggle, get it!  
209 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
210 - value = lib3270_get_toggle(hSession,toggle);  
211 -  
212 - }  
213 -  
214 - throw std::system_error(ENOENT, std::system_category());  
215 - }  
216 -  
217 - ProgramMessage Local::Session::getProgramMessage() const {  
218 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
219 - return (ProgramMessage) lib3270_get_program_message(this->hSession);  
220 - }  
221 -  
222 - ConnectionState Local::Session::getConnectionState() const {  
223 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
224 - return (ConnectionState) lib3270_get_connection_state(this->hSession);  
225 - }  
226 -  
227 - /// @brief Set field at current position, jumps to next writable field.  
228 - TN3270::Session & Local::Session::push(const char *text) {  
229 - std::lock_guard<std::mutex> lock(sync);  
230 - return *this;  
231 - }  
232 -  
233 - TN3270::Session & Local::Session::push(int baddr, const std::string &text) {  
234 - std::lock_guard<std::mutex> lock(sync);  
235 - return *this;  
236 - }  
237 -  
238 - TN3270::Session & Local::Session::push(int row, int col, const std::string &text) {  
239 - std::lock_guard<std::mutex> lock(sync);  
240 - return *this;  
241 - }  
242 -  
243 - TN3270::Session & Local::Session::push(const PFKey key) {  
244 - std::lock_guard<std::mutex> lock(sync);  
245 - lib3270_pfkey(hSession,(int) key);  
246 - return *this;  
247 - }  
248 -  
249 - TN3270::Session & Local::Session::push(const PAKey key) {  
250 - std::lock_guard<std::mutex> lock(sync);  
251 - lib3270_pakey(hSession,(int) key);  
252 - return *this;  
253 - }  
254 -  
255 - TN3270::Session & Local::Session::push(const Action action) {  
256 -  
257 - typedef int (*ActionCallback)(H3270 *);  
258 -  
259 - static const ActionCallback actions[] = {  
260 - lib3270_enter,  
261 - lib3270_erase,  
262 - lib3270_eraseeof,  
263 - lib3270_eraseeol,  
264 - lib3270_eraseinput  
265 - };  
266 -  
267 - if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) {  
268 - throw std::system_error(EINVAL, std::system_category());  
269 - }  
270 -  
271 - std::lock_guard<std::mutex> lock(sync);  
272 -  
273 - int rc = actions[(size_t) action](hSession);  
274 -  
275 - if(rc) {  
276 - throw std::system_error(errno, std::system_category());  
277 - }  
278 -  
279 - return *this;  
280 - }  
281 -  
282 - TN3270::Session & Local::Session::pop(int baddr, std::string &text) {  
283 -  
284 - std::lock_guard<std::mutex> lock(sync);  
285 -  
286 - if(!lib3270_is_connected(hSession)) {  
287 - throw std::system_error(ENOTCONN, std::system_category());  
288 - }  
289 -  
290 - char *contents = lib3270_get_field_text_at(hSession, baddr);  
291 -  
292 - if(!contents) {  
293 - throw std::system_error(errno, std::system_category());  
294 - }  
295 -  
296 - text.assign(convertFromHost(contents).c_str());  
297 -  
298 - lib3270_free(contents);  
299 -  
300 - return *this;  
301 - }  
302 -  
303 - TN3270::Session & Local::Session::pop(int row, int col, std::string &text) {  
304 - return this->pop(lib3270_translate_to_address(hSession,row,col),text);  
305 - }  
306 -  
307 - TN3270::Session & Local::Session::pop(std::string &text) {  
308 -  
309 - std::lock_guard<std::mutex> lock(sync);  
310 -  
311 - if(!lib3270_is_connected(hSession)) {  
312 - throw std::system_error(ENOTCONN, std::system_category());  
313 - }  
314 -  
315 - int baddr = lib3270_get_cursor_address(hSession);  
316 - if(baddr < 0) {  
317 - throw std::system_error(errno, std::system_category());  
318 - }  
319 -  
320 - char *contents = lib3270_get_field_text_at(hSession, baddr);  
321 -  
322 - if(!contents) {  
323 - throw std::system_error(errno, std::system_category());  
324 - }  
325 -  
326 - text.assign(convertFromHost(contents).c_str());  
327 -  
328 - lib3270_free(contents);  
329 -  
330 - baddr = lib3270_get_next_unprotected(hSession,baddr);  
331 - if(!baddr) {  
332 - baddr = lib3270_get_next_unprotected(hSession,0);  
333 - }  
334 -  
335 - if(lib3270_set_cursor_address(hSession,baddr)) {  
336 - throw std::system_error(errno, std::system_category());  
337 - }  
338 -  
339 - return *this;  
340 - }  
341 -  
342 - /// @brief Set cursor address.  
343 - ///  
344 - /// @param addr Cursor address.  
345 - TN3270::Session & Local::Session::setCursorPosition(unsigned short addr) {  
346 -  
347 - if(lib3270_set_cursor_address(hSession,addr) < 0) {  
348 - throw std::system_error(errno, std::system_category());  
349 - }  
350 -  
351 - return *this;  
352 - }  
353 -  
354 - /// @brief Set cursor position.  
355 - ///  
356 - /// @param row New cursor row.  
357 - /// @param col New cursor column.  
358 - TN3270::Session & Local::Session::setCursorPosition(unsigned short row, unsigned short col) {  
359 -  
360 - if(lib3270_set_cursor_position(hSession,row,col)) {  
361 - throw std::system_error(errno, std::system_category());  
362 - }  
363 -  
364 - return *this;  
365 -  
366 - }  
367 -  
368 - // Get properties.  
369 - std::string Local::Session::getVersion() const {  
370 - return lib3270_get_version();  
371 - }  
372 -  
373 - std::string Local::Session::getRevision() const {  
374 - return lib3270_get_revision();  
375 - }  
376 -  
377 - /// @brief Execute action by name.  
378 - TN3270::Session & Local::Session::action(const char *action_name) {  
379 -  
380 - if(lib3270_action(hSession,action_name)) {  
381 - throw std::system_error(errno, std::system_category());  
382 - }  
383 -  
384 - return *this;  
385 - }  
386 -  
387 - }  
388 -  
389 -  
src/client/src/os/linux/request.cc 0 → 100644
@@ -0,0 +1,267 @@ @@ -0,0 +1,267 @@
  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/os/linux/request.cc
  32 + *
  33 + * @brief Implements linux request methods for remote session.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 +
  41 + using std::string;
  42 +
  43 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  44 +
  45 + namespace TN3270 {
  46 +
  47 + IPC::Request::Request(const Session &session) {
  48 + this->conn = session.conn;
  49 + this->msg.in = nullptr;
  50 + this->msg.out = nullptr;
  51 + }
  52 +
  53 + IPC::Request::Request(const Session &session, const char *method) : Request(session) {
  54 +
  55 + this->msg.out = dbus_message_new_method_call(
  56 + session.name.c_str(), // Destination
  57 + session.path.c_str(), // Path
  58 + session.interface.c_str(), // Interface
  59 + method // Method
  60 + );
  61 +
  62 + if(!msg.out) {
  63 + throw std::runtime_error("Can't create D-Bus Method Call");
  64 + }
  65 +
  66 + }
  67 +
  68 + IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) {
  69 +
  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(
  81 + session.name.c_str(), // Destination
  82 + session.path.c_str(), // Path
  83 + "org.freedesktop.DBus.Properties", // Interface
  84 + (isSet ? "Set" : "Get")
  85 + );
  86 +
  87 + if(!msg.out) {
  88 + throw std::runtime_error("Can't create D-Bus Property Call");
  89 + }
  90 +
  91 + //
  92 + // https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
  93 + // org.freedesktop.DBus.Properties.Get (in STRING interface_name,
  94 + // in STRING property_name,
  95 + // out VARIANT value);
  96 + // org.freedesktop.DBus.Properties.Set (in STRING interface_name,
  97 + // in STRING property_name,
  98 + //
  99 + const char *interface_name = session.interface.c_str();
  100 +
  101 + dbus_message_append_args(
  102 + this->msg.out,
  103 + DBUS_TYPE_STRING,&interface_name,
  104 + DBUS_TYPE_STRING,&property,
  105 + DBUS_TYPE_INVALID
  106 + );
  107 +
  108 + }
  109 +
  110 + IPC::Request::~Request() {
  111 + if(msg.out) {
  112 + dbus_message_unref(msg.out);
  113 + }
  114 + if(msg.in) {
  115 + dbus_message_unref(msg.in);
  116 + }
  117 + }
  118 +
  119 + IPC::Request & IPC::Request::call() {
  120 +
  121 + if(msg.in) {
  122 + dbus_message_unref(msg.in);
  123 + msg.in = nullptr;
  124 + }
  125 +
  126 + DBusError error;
  127 + dbus_error_init(&error);
  128 + this->msg.in = dbus_connection_send_with_reply_and_block(this->conn,this->msg.out,10000,&error);
  129 +
  130 + if(!this->msg.in) {
  131 + string message = error.message;
  132 + dbus_error_free(&error);
  133 + throw std::runtime_error(message.c_str());
  134 + }
  135 +
  136 + dbus_message_iter_init(msg.in, &msg.iter);
  137 +
  138 + debug(__FUNCTION__," got a valid response");
  139 +
  140 + return *this;
  141 +
  142 + }
  143 +
  144 + IPC::Request & IPC::Request::push(const char *arg) {
  145 + dbus_message_append_args(this->msg.out,DBUS_TYPE_STRING,&arg,DBUS_TYPE_INVALID);
  146 + return *this;
  147 + }
  148 +
  149 + IPC::Request & IPC::Request::push(const bool arg) {
  150 + dbus_message_append_args(this->msg.out,DBUS_TYPE_BOOLEAN,&arg,DBUS_TYPE_INVALID);
  151 + return *this;
  152 + }
  153 +
  154 + IPC::Request & IPC::Request::push(const uint8_t arg) {
  155 + dbus_message_append_args(this->msg.out,DBUS_TYPE_BYTE,&arg,DBUS_TYPE_INVALID);
  156 + return *this;
  157 + }
  158 +
  159 + IPC::Request & IPC::Request::push(const int32_t arg) {
  160 + dbus_message_append_args(this->msg.out,DBUS_TYPE_INT32,&arg,DBUS_TYPE_INVALID);
  161 + return *this;
  162 + }
  163 +
  164 + IPC::Request & IPC::Request::push(const uint32_t arg) {
  165 + dbus_message_append_args(this->msg.out,DBUS_TYPE_UINT32,&arg,DBUS_TYPE_INVALID);
  166 + return *this;
  167 + }
  168 +
  169 +
  170 + IPC::Request & IPC::Request::pop(std::string &value) {
  171 +
  172 + const char * str = "";
  173 +
  174 + if(dbus_message_iter_get_arg_type(&msg.iter) == DBUS_TYPE_STRING) {
  175 +
  176 + dbus_message_iter_get_basic(&msg.iter, &str);
  177 +
  178 + } else if(dbus_message_iter_get_arg_type(&msg.iter) == DBUS_TYPE_VARIANT) {
  179 +
  180 + DBusMessageIter sub;
  181 + int current_type;
  182 +
  183 + dbus_message_iter_recurse(&msg.iter, &sub);
  184 +
  185 + while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) {
  186 +
  187 + if (current_type == DBUS_TYPE_STRING) {
  188 + dbus_message_iter_get_basic(&sub, &str);
  189 + break;
  190 + }
  191 + dbus_message_iter_next(&sub);
  192 + }
  193 +
  194 + } else {
  195 +
  196 + debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&msg.iter)) );
  197 + throw std::runtime_error("Expected an string data type");
  198 +
  199 + }
  200 +
  201 + dbus_message_iter_next(&msg.iter);
  202 +
  203 + value.assign(str);
  204 +
  205 + debug(__FUNCTION__,"= \"",str,"\"");
  206 +
  207 + return *this;
  208 + }
  209 +
  210 + static int getIntValue(DBusMessageIter &iter) {
  211 +
  212 + if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT32) {
  213 +
  214 + dbus_int32_t rc = 0;
  215 + dbus_message_iter_get_basic(&iter, &rc);
  216 + return (int) rc;
  217 +
  218 + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_INT16) {
  219 +
  220 + dbus_int16_t rc = 0;
  221 + dbus_message_iter_get_basic(&iter, &rc);
  222 + return (int) rc;
  223 +
  224 + } else if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) {
  225 +
  226 + DBusMessageIter sub;
  227 + int current_type;
  228 +
  229 + dbus_message_iter_recurse(&iter, &sub);
  230 +
  231 + while ((current_type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) {
  232 +
  233 + if (current_type == DBUS_TYPE_INT32) {
  234 +
  235 + dbus_int32_t rc = 0;
  236 + dbus_message_iter_get_basic(&sub, &rc);
  237 + return (int) rc;
  238 +
  239 + } else if (current_type == DBUS_TYPE_INT16) {
  240 + dbus_int16_t rc = 0;
  241 + dbus_message_iter_get_basic(&sub, &rc);
  242 + return (int) rc;
  243 +
  244 + }
  245 + dbus_message_iter_next(&sub);
  246 + }
  247 +
  248 + }
  249 +
  250 + debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) );
  251 + throw std::runtime_error("Expected an integer data type");
  252 +
  253 + }
  254 +
  255 + IPC::Request & IPC::Request::Request::pop(int &value) {
  256 +
  257 + value = getIntValue(msg.iter);
  258 + dbus_message_iter_next(&msg.iter);
  259 + debug(__FUNCTION__,"= \"",value,"\"");
  260 +
  261 + return *this;
  262 +
  263 + }
  264 +
  265 + }
  266 +
  267 +
src/client/src/os/linux/session.cc 0 → 100644
@@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
  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/os/linux/linux/session.cc
  32 + *
  33 + * @brief Implements Linux session methods.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 + #include <cstring>
  41 + #include <lib3270/trace.h>
  42 +
  43 + using std::string;
  44 +
  45 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  46 +
  47 + static void throws_if_error(DBusError &err) {
  48 +
  49 + if(dbus_error_is_set(&err)) {
  50 + string message = err.message;
  51 + dbus_error_free(&err);
  52 + throw std::runtime_error(message.c_str());
  53 + }
  54 +
  55 + return;
  56 +
  57 + }
  58 +
  59 + namespace TN3270 {
  60 +
  61 + IPC::Session::Session(const char *id) : Abstract::Session() {
  62 +
  63 + // Create D-Bus session.
  64 + DBusError err;
  65 +
  66 + dbus_error_init(&err);
  67 + this->conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
  68 +
  69 + debug("dbus_bus_get conn=",conn);
  70 +
  71 + throws_if_error(err);
  72 +
  73 + if(!conn)
  74 + throw std::runtime_error("DBUS Connection failed");
  75 +
  76 + auto sep = strchr(id,':');
  77 + if(!sep) {
  78 + throw std::system_error(EINVAL, std::system_category());
  79 + }
  80 +
  81 + this->name = "br.com.bb.";
  82 + this->name += string(id,(sep - id));
  83 + this->name += ".";
  84 + this->name += (sep+1);
  85 + this->path = "/br/com/bb/tn3270/session";
  86 + this->interface = "br.com.bb.tn3270.session";
  87 +
  88 + debug("D-Bus Object name=\"",this->name,"\" D-Bus Object path=\"",this->path,"\"");
  89 +
  90 + }
  91 +
  92 + IPC::Session::~Session() {
  93 +
  94 + }
  95 +
  96 + }
  97 +
  98 +
src/client/src/os/windows/request.cc 0 → 100644
@@ -0,0 +1,191 @@ @@ -0,0 +1,191 @@
  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/os/windows/request.cc
  32 + *
  33 + * @brief Implements WIN32 request methods.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 +
  41 + using std::string;
  42 +
  43 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  44 +
  45 + namespace TN3270 {
  46 +
  47 + #define PIPE_BUFFER_LENGTH 8192
  48 +
  49 + IPC::Request::Request(const Session &session) {
  50 +
  51 + this->hPipe = session.hPipe;
  52 +
  53 + in.length = PIPE_BUFFER_LENGTH;
  54 + in.used = 0;
  55 + in.block = new uint8_t[in.length];
  56 +
  57 + out.length = PIPE_BUFFER_LENGTH;
  58 + out.used = 0;
  59 + out.block = new uint8_t[out.length];
  60 +
  61 + }
  62 +
  63 + IPC::Request::Request(const Session &session, const char *method) : Request(session) {
  64 +
  65 + // Add name
  66 + strcpy((char *) out.block, method);
  67 + out.used += strlen((char *) method) + 1;
  68 +
  69 + // Add ID
  70 + *((uint16_t *) (out.block + out.used)) = (uint16_t) 3;
  71 + out.used += sizeof(uint16_t);
  72 +
  73 + }
  74 +
  75 + IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) {
  76 +
  77 + // Add name
  78 + strcpy((char *) out.block, property);
  79 + out.used += strlen((char *) property) + 1;
  80 +
  81 + // Add ID (SetProperty = 2, getProperty = 1)
  82 + *((uint16_t *) (out.block + out.used)) = (uint16_t) (isSet ? 2 : 1);
  83 + out.used += sizeof(uint16_t);
  84 +
  85 + }
  86 +
  87 + IPC::Request::~Request() {
  88 +
  89 + delete[] ((uint8_t *) in.block);
  90 + delete[] ((uint8_t *) out.block);
  91 +
  92 + }
  93 +
  94 + /// @brief Store value on data block.
  95 + IPC::Request::DataBlock * IPC::Request::pushBlock(const void *ptr, size_t length) {
  96 +
  97 + if((out.used + length + sizeof(IPC::Request::DataBlock)) >= out.length) {
  98 + throw std::runtime_error("Too big");
  99 + }
  100 +
  101 + IPC::Request::DataBlock * rc = (IPC::Request::DataBlock *) (out.block + out.used);
  102 + memcpy(((uint8_t *) (rc+1)), ((uint8_t *) ptr), length);
  103 +
  104 + out.used += (sizeof(IPC::Request::DataBlock) + length);
  105 +
  106 + return rc;
  107 +
  108 + }
  109 +
  110 + /// @brief Get next argument.
  111 + IPC::Request::DataBlock * IPC::Request::getNextBlock() const {
  112 +
  113 + if((in.current + sizeof(IPC::Request::DataBlock)) >= in.used) {
  114 + throw std::runtime_error("Out of range");
  115 + }
  116 +
  117 + return (IPC::Request::DataBlock *) (in.block + in.current);
  118 +
  119 + }
  120 +
  121 + IPC::Request & IPC::Request::push(const char *arg) {
  122 + pushBlock(arg, strlen(arg)+1)->type = IPC::Request::String;
  123 + return *this;
  124 + }
  125 +
  126 + IPC::Request & IPC::Request::push(const bool arg) {
  127 + uint8_t value = (uint8_t) (arg ? 0xff : 0);
  128 + pushBlock(&value, sizeof(value))->type = IPC::Request::Boolean;
  129 + return *this;
  130 + }
  131 +
  132 + IPC::Request & IPC::Request::push(const uint8_t arg) {
  133 + pushBlock(&arg, sizeof(arg))->type = IPC::Request::Uchar;
  134 + return *this;
  135 + }
  136 +
  137 + IPC::Request & IPC::Request::push(const int32_t arg) {
  138 + pushBlock(&arg, sizeof(arg))->type = IPC::Request::Int32;
  139 + return *this;
  140 + }
  141 +
  142 + IPC::Request & IPC::Request::push(const uint32_t arg) {
  143 + pushBlock(&arg, sizeof(arg))->type = IPC::Request::Uint32;
  144 + return *this;
  145 + }
  146 +
  147 + IPC::Request & IPC::Request::pop(std::string &value) {
  148 + DataBlock * block = getNextBlock();
  149 +
  150 + if(block->type != IPC::Request::String)
  151 + throw std::runtime_error("Invalid format");
  152 +
  153 + const char *ptr = (const char *) (block+1);
  154 +
  155 + in.current += (strlen(ptr)+1+sizeof(DataBlock));
  156 +
  157 + value.assign(ptr);
  158 +
  159 + return *this;
  160 + }
  161 +
  162 + IPC::Request & IPC::Request::Request::pop(int &value) {
  163 +
  164 + DataBlock * block = getNextBlock();
  165 +
  166 + switch(block->type) {
  167 + case IPC::Request::Int16:
  168 + value = * ((int16_t *) (block+1));
  169 + in.current += sizeof(int16_t) + sizeof(DataBlock);
  170 + break;
  171 +
  172 + case IPC::Request::Int32:
  173 + value = * ((int32_t *) (block+1));
  174 + in.current += sizeof(int32_t) + sizeof(DataBlock);
  175 + break;
  176 +
  177 + case IPC::Request::Int64:
  178 + value = * ((int64_t *) (block+1));
  179 + in.current += sizeof(int64_t) + sizeof(DataBlock);
  180 + break;
  181 +
  182 + default:
  183 + throw std::runtime_error("Invalid format");
  184 + }
  185 +
  186 + return *this;
  187 + }
  188 +
  189 + }
  190 +
  191 +
src/client/src/os/windows/resources.rc.in 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +#include <windows.h>
  2 +
  3 +VS_VERSION_INFO VERSIONINFO
  4 +FILEVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0
  5 +PRODUCTVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0
  6 +
  7 +BEGIN
  8 +
  9 + BLOCK "StringFileInfo"
  10 + BEGIN
  11 + BLOCK "080904E4"
  12 + BEGIN
  13 + VALUE "FileDescription", "3270 C++ Access Library\0"
  14 + VALUE "CompanyName", "Banco do Brasil S/A.\0"
  15 + VALUE "FileVersion", "@WIN32_VERSION@\0"
  16 + VALUE "LegalCopyright", "(C) 2017 Banco do Brasil S/A. All Rights Reserved\0"
  17 + VALUE "OriginalFilename", "@PACKAGE_TARNAME@@DLLEXT@\0"
  18 + VALUE "ProductName", "@PACKAGE_NAME@\0"
  19 + VALUE "ProductVersion", "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.0\0"
  20 + END
  21 + END
  22 +
  23 + BLOCK "VarFileInfo"
  24 + BEGIN
  25 + VALUE "Translation", 0x809, 0x04E4
  26 + END
  27 +
  28 +END
  29 +
src/client/src/os/windows/session.cc 0 → 100644
@@ -0,0 +1,142 @@ @@ -0,0 +1,142 @@
  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/os/windows/session.cc
  32 + *
  33 + * @brief Implements WIN32 remote session methods.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 + #include <cstring>
  41 + #include <lib3270/trace.h>
  42 + #include <algorithm>
  43 +
  44 + using std::string;
  45 +
  46 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  47 +
  48 + namespace TN3270 {
  49 +
  50 + IPC::Session::Session(const char *id) : Abstract::Session() {
  51 +
  52 + char *ptr = strchr(id,':');
  53 +
  54 + if(!ptr)
  55 + throw std::system_error(EINVAL, std::system_category());
  56 +
  57 + string pipename{"\\\\.\\pipe\\"};
  58 +
  59 + pipename += string(id,ptr - id);
  60 + pipename += "\\";
  61 + pipename += (ptr+1);
  62 +
  63 + std::transform(pipename.begin(), pipename.end(), pipename.begin(), ::tolower);
  64 +
  65 + debug("pipename: \"%s\"",pipename.c_str());
  66 +
  67 + this->hPipe = CreateFile(
  68 + TEXT(pipename.c_str()), // pipe name
  69 + GENERIC_READ | // read and write access
  70 + GENERIC_WRITE,
  71 + 0, // no sharing
  72 + NULL, // default security attributes
  73 + OPEN_EXISTING, // opens existing pipe
  74 + 0, // default attributes
  75 + NULL // no template file
  76 + );
  77 +
  78 + if (hPipe == INVALID_HANDLE_VALUE) {
  79 + throw std::runtime_error("Can't open IPC Channel");
  80 + }
  81 +
  82 + // The pipe connected; change to message-read mode.
  83 + DWORD dwMode = PIPE_READMODE_MESSAGE;
  84 + if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) {
  85 + throw std::runtime_error("Can't set IPC Channel mode");
  86 + }
  87 +
  88 + }
  89 +
  90 + IPC::Session::~Session() {
  91 + CloseHandle(this->hPipe);
  92 + }
  93 +
  94 +
  95 + IPC::Request & IPC::Request::call() {
  96 +
  97 +#ifdef DEBUG
  98 + // lib3270_trace_data(NULL,"Request block",(const char *) this->out.block, this->out.used);
  99 +#endif // DEBUG
  100 +
  101 + in.current = 0;
  102 +
  103 + if(!TransactNamedPipe(
  104 + this->hPipe,
  105 + this->out.block,
  106 + this->out.used,
  107 + this->in.block,
  108 + this->in.length,
  109 + &this->in.used,
  110 + NULL)
  111 + ) {
  112 +
  113 + throw std::runtime_error("Can't transact on IPC Channel");
  114 +
  115 + }
  116 +
  117 + debug("Received response \"", in.block, "\" with ", in.used, " bytes");
  118 +#ifdef DEBUG
  119 + // lib3270_trace_data(NULL,"Response block",(const char *) this->in.block, this->in.used);
  120 +#endif // DEBUG
  121 +
  122 + // Extract response name
  123 + in.current = strlen((const char *) in.block)+1;
  124 +
  125 + // Extract return code
  126 + uint16_t rc = *((uint16_t *) (in.block + in.current));
  127 + in.current += sizeof(uint16_t);
  128 +
  129 + // Extract argc
  130 + uint16_t argc = *((uint16_t *) (in.block + in.current));
  131 + in.current += sizeof(uint16_t);
  132 +
  133 + debug("Received response \"", ((const char *) in.block), "\" with rc=", rc, " and ", argc, " arguments");
  134 +
  135 + return *this;
  136 + }
  137 +
  138 +
  139 +
  140 + }
  141 +
  142 +
src/client/src/session.cc
@@ -1,78 +0,0 @@ @@ -1,78 +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 lib3270++.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 - */  
29 -  
30 -/**  
31 - * @file src/lib3270++/session.cc  
32 - *  
33 - * @brief  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "private.h"  
40 -  
41 -  
42 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
43 -  
44 - namespace TN3270 {  
45 -  
46 - /// @brief Create a tn3270 session.  
47 - Session * Session::create(const char *id) {  
48 -  
49 - if(!id) {  
50 - return new Local::Session();  
51 - }  
52 -  
53 - return new IPC::Session(id);  
54 -  
55 - }  
56 -  
57 -  
58 - Session::Session() {  
59 -  
60 - }  
61 -  
62 - Session::~Session() {  
63 -  
64 - }  
65 -  
66 - void Session::insert(Event::Type type, std::function <void(const Event &event)> listener) {  
67 - }  
68 -  
69 - /// @brief Fire event.  
70 - void Session::fire(const Event &event) {  
71 -  
72 -  
73 - }  
74 -  
75 - }  
76 -  
77 -  
78 -  
src/client/src/session/local/events.cc 0 → 100644
@@ -0,0 +1,175 @@ @@ -0,0 +1,175 @@
  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/events.cc
  32 + *
  33 + * @brief Implement lib3270 direct access events.
  34 + *
  35 + * @author perry.werneck@gmail.com
  36 + *
  37 + */
  38 +
  39 + #include "../private.h"
  40 + #include <stdio.h>
  41 +
  42 + extern "C" {
  43 + #include <lib3270/actions.h>
  44 + #include <lib3270/session.h>
  45 + }
  46 +
  47 + using std::string;
  48 +
  49 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  50 +
  51 +#ifndef HAVE_VASPRINTF
  52 + int vasprintf(char **strp, const char *fmt, va_list ap) {
  53 + char buf[1024];
  54 +
  55 + int nc = vsnprintf(buf, sizeof(buf), fmt, args);
  56 +
  57 + if(nc < 0) {
  58 +
  59 + *strp = strdup(_("Error in vasprintf"));
  60 +
  61 + } else if (nc < sizeof(buf)) {
  62 +
  63 + *strp = malloc(nc+1);
  64 + strcpy(*strp, buf);
  65 +
  66 + } else {
  67 +
  68 + *strp = malloc(nc + 1);
  69 + if(vsnprintf(*strp, nc, fmt, args) < 0) {
  70 + free(*strp);
  71 + *strp = strdup(NULL,_( "Out of memory in vasprintf" ) );
  72 + }
  73 +
  74 + }
  75 +
  76 + return nc;
  77 + }
  78 +#endif // !HAVE_VASPRINTF
  79 +
  80 + namespace TN3270 {
  81 +
  82 + /// @brief Popup Handler.
  83 + void Local::Session::popupHandler(H3270 *h3270, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) {
  84 +
  85 + Local::Session * session = (Local::Session *) lib3270_get_user_data(h3270);
  86 +
  87 + if(!session) {
  88 + throw std::runtime_error(_( "Invalid session handler" ));
  89 + }
  90 +
  91 + class PopupEvent : public TN3270::Event {
  92 + private:
  93 + LIB3270_NOTIFY type;
  94 + string title;
  95 + string msg;
  96 + string description;
  97 +
  98 + public:
  99 + PopupEvent(LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) : Event(Event::Popup) {
  100 +
  101 + this->type = type;
  102 + this->title = title;
  103 + this->msg = msg;
  104 +
  105 + char * buffer = NULL;
  106 + if(vasprintf(&buffer,fmt,arg) != -1) {
  107 + this->description = buffer;
  108 + free(buffer);
  109 + }
  110 +
  111 +#ifdef DEBUG
  112 + std::cerr << "Popup:" << std::endl
  113 + << "\t" << title << std::endl
  114 + << "\t" << msg << std::endl
  115 + << "\t" << description << std::endl;
  116 +#endif // DEBUG
  117 +
  118 + }
  119 +
  120 + virtual ~PopupEvent() {
  121 + }
  122 +
  123 + /// @brief Get event description.
  124 + std::string toString() const override {
  125 + return msg;
  126 + }
  127 +
  128 +
  129 + };
  130 +
  131 + session->fire(PopupEvent(type,title,msg,fmt,arg));
  132 +
  133 + }
  134 +
  135 + /// @brief Connect Handler.
  136 + void Local::Session::connectHandler(H3270 *h3270, unsigned char connected) {
  137 +
  138 + Local::Session * session = (Local::Session *) lib3270_get_user_data(h3270);
  139 +
  140 + if(!session) {
  141 + throw std::runtime_error(_("Invalid session handler"));
  142 + }
  143 +
  144 + class ConnectionEvent : public TN3270::Event {
  145 + private:
  146 + bool connected;
  147 +
  148 + public:
  149 + ConnectionEvent(unsigned char connected) : Event(Event::Connection) {
  150 + this->connected = (connected != 0);
  151 +
  152 +#ifdef DEBUG
  153 + std::cerr << "Session is " << this->toString().c_str() << std::endl;
  154 +#endif // DEBUG
  155 +
  156 + }
  157 +
  158 + virtual ~ConnectionEvent() {
  159 + }
  160 +
  161 + /// @brief Get event description.
  162 + std::string toString() const override {
  163 + return this->connected ? _("connected") : _("disconnected");
  164 + }
  165 +
  166 + };
  167 +
  168 + session->fire(ConnectionEvent(connected));
  169 +
  170 + }
  171 +
  172 +
  173 + }
  174 +
  175 +
src/client/src/session/local/session.cc 0 → 100644
@@ -0,0 +1,389 @@ @@ -0,0 +1,389 @@
  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 + #include "../private.h"
  40 + #include <lib3270/actions.h>
  41 + #include <lib3270/properties.h>
  42 + #include <cstring>
  43 +
  44 + extern "C" {
  45 + #include <lib3270/session.h>
  46 + }
  47 +
  48 + using std::string;
  49 +
  50 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  51 +
  52 + namespace TN3270 {
  53 +
  54 + Local::Session::Session() : Abstract::Session() {
  55 +
  56 + std::lock_guard<std::mutex> lock(sync);
  57 +
  58 + this->hSession = lib3270_session_new("");
  59 + lib3270_set_user_data(this->hSession,(void *) this);
  60 + setCharSet(lib3270_get_display_charset(this->hSession));
  61 +
  62 + lib3270_set_popup_handler(this->hSession, popupHandler);
  63 +
  64 + // Setup callbacks
  65 + struct lib3270_session_callbacks *cbk;
  66 +
  67 + cbk = lib3270_get_session_callbacks(this->hSession,sizeof(struct lib3270_session_callbacks));
  68 + if(!cbk) {
  69 + throw std::runtime_error( _("Invalid callback table, possible version mismatch in lib3270") );
  70 + }
  71 +
  72 + cbk->update_connect = connectHandler;
  73 +
  74 +
  75 + }
  76 +
  77 + Local::Session::~Session() {
  78 +
  79 + std::lock_guard<std::mutex> lock(sync);
  80 +
  81 + lib3270_session_free(this->hSession);
  82 + this->hSession = nullptr;
  83 + }
  84 +
  85 + void Local::Session::wait(time_t timeout) {
  86 +
  87 + std::lock_guard<std::mutex> lock(sync);
  88 +
  89 + int rc = lib3270_wait_for_ready(this->hSession, timeout);
  90 +
  91 + if(rc) {
  92 + throw std::system_error(rc, std::system_category());
  93 + }
  94 +
  95 + }
  96 +
  97 + void Local::Session::connect(const char *url) {
  98 + std::lock_guard<std::mutex> lock(sync);
  99 + int rc = lib3270_connect_url(hSession,url,0);
  100 +
  101 + if(rc) {
  102 + throw std::system_error(rc, std::system_category());
  103 + }
  104 +
  105 + }
  106 +
  107 + void Local::Session::disconnect() {
  108 + std::lock_guard<std::mutex> lock(sync);
  109 + lib3270_disconnect(hSession);
  110 + }
  111 +
  112 + // Wait for session state.
  113 + void Local::Session::waitForReady(time_t timeout) throw() {
  114 + this->wait(timeout);
  115 + }
  116 +
  117 + std::string Local::Session::toString(int baddr, size_t len, char lf) const {
  118 +
  119 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  120 +
  121 + char * text = lib3270_get_string_at_address(hSession, baddr, len, lf);
  122 +
  123 + if(!text) {
  124 + throw std::runtime_error( _("Can't get screen contents") );
  125 + }
  126 +
  127 + string rc = convertFromHost(text);
  128 +
  129 + lib3270_free(text);
  130 +
  131 + return rc;
  132 +
  133 + }
  134 +
  135 + std::string Local::Session::toString(int row, int col, size_t sz, char lf) const {
  136 +
  137 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  138 +
  139 + char * text = lib3270_get_string_at(hSession, row, col, sz, lf);
  140 +
  141 + if(!text) {
  142 + throw std::runtime_error( _("Can't get screen contents") );
  143 + }
  144 +
  145 + string rc = convertFromHost(text);
  146 +
  147 + lib3270_free(text);
  148 +
  149 + return rc;
  150 + }
  151 +
  152 + void Local::Session::getProperty(const char *name, int &value) const {
  153 +
  154 + const LIB3270_INT_PROPERTY * intprop = lib3270_get_int_properties_list();
  155 + for(size_t ix = 0; intprop[ix].name; ix++) {
  156 +
  157 + if(!strcasecmp(name,intprop[ix].name)) {
  158 +
  159 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  160 +
  161 + value = intprop[ix].get(hSession);
  162 +
  163 + if(value < 0 && errno != 0) {
  164 + throw std::system_error(errno, std::system_category());
  165 + }
  166 +
  167 +
  168 + }
  169 +
  170 + }
  171 +
  172 + throw std::system_error(ENOENT, std::system_category());
  173 +
  174 + }
  175 +
  176 + void Local::Session::getProperty(const char *name, std::string &value) const {
  177 +
  178 + const LIB3270_STRING_PROPERTY * strprop = lib3270_get_string_properties_list();
  179 +
  180 + for(size_t ix = 0; strprop[ix].name; ix++) {
  181 +
  182 + if(!strcasecmp(name,strprop[ix].name)) {
  183 +
  184 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  185 +
  186 + // Found it!
  187 + const char * str = strprop[ix].get(hSession);
  188 +
  189 + if(str) {
  190 + value.assign(str);
  191 + return;
  192 + }
  193 +
  194 + throw std::system_error(errno, std::system_category());
  195 +
  196 + }
  197 +
  198 + }
  199 +
  200 + throw std::system_error(ENOENT, std::system_category());
  201 + }
  202 +
  203 + void Local::Session::getProperty(const char *name, bool &value) const {
  204 +
  205 + LIB3270_TOGGLE toggle = lib3270_get_toggle_id(name);
  206 + if(toggle != (LIB3270_TOGGLE) -1) {
  207 +
  208 + // Is a Tn3270 toggle, get it!
  209 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  210 + value = lib3270_get_toggle(hSession,toggle);
  211 +
  212 + }
  213 +
  214 + throw std::system_error(ENOENT, std::system_category());
  215 + }
  216 +
  217 + ProgramMessage Local::Session::getProgramMessage() const {
  218 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  219 + return (ProgramMessage) lib3270_get_program_message(this->hSession);
  220 + }
  221 +
  222 + ConnectionState Local::Session::getConnectionState() const {
  223 + std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);
  224 + return (ConnectionState) lib3270_get_connection_state(this->hSession);
  225 + }
  226 +
  227 + /// @brief Set field at current position, jumps to next writable field.
  228 + TN3270::Session & Local::Session::push(const char *text) {
  229 + std::lock_guard<std::mutex> lock(sync);
  230 + return *this;
  231 + }
  232 +
  233 + TN3270::Session & Local::Session::push(int baddr, const std::string &text) {
  234 + std::lock_guard<std::mutex> lock(sync);
  235 + return *this;
  236 + }
  237 +
  238 + TN3270::Session & Local::Session::push(int row, int col, const std::string &text) {
  239 + std::lock_guard<std::mutex> lock(sync);
  240 + return *this;
  241 + }
  242 +
  243 + TN3270::Session & Local::Session::push(const PFKey key) {
  244 + std::lock_guard<std::mutex> lock(sync);
  245 + lib3270_pfkey(hSession,(int) key);
  246 + return *this;
  247 + }
  248 +
  249 + TN3270::Session & Local::Session::push(const PAKey key) {
  250 + std::lock_guard<std::mutex> lock(sync);
  251 + lib3270_pakey(hSession,(int) key);
  252 + return *this;
  253 + }
  254 +
  255 + TN3270::Session & Local::Session::push(const Action action) {
  256 +
  257 + typedef int (*ActionCallback)(H3270 *);
  258 +
  259 + static const ActionCallback actions[] = {
  260 + lib3270_enter,
  261 + lib3270_erase,
  262 + lib3270_eraseeof,
  263 + lib3270_eraseeol,
  264 + lib3270_eraseinput
  265 + };
  266 +
  267 + if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) {
  268 + throw std::system_error(EINVAL, std::system_category());
  269 + }
  270 +
  271 + std::lock_guard<std::mutex> lock(sync);
  272 +
  273 + int rc = actions[(size_t) action](hSession);
  274 +
  275 + if(rc) {
  276 + throw std::system_error(errno, std::system_category());
  277 + }
  278 +
  279 + return *this;
  280 + }
  281 +
  282 + TN3270::Session & Local::Session::pop(int baddr, std::string &text) {
  283 +
  284 + std::lock_guard<std::mutex> lock(sync);
  285 +
  286 + if(!lib3270_is_connected(hSession)) {
  287 + throw std::system_error(ENOTCONN, std::system_category());
  288 + }
  289 +
  290 + char *contents = lib3270_get_field_text_at(hSession, baddr);
  291 +
  292 + if(!contents) {
  293 + throw std::system_error(errno, std::system_category());
  294 + }
  295 +
  296 + text.assign(convertFromHost(contents).c_str());
  297 +
  298 + lib3270_free(contents);
  299 +
  300 + return *this;
  301 + }
  302 +
  303 + TN3270::Session & Local::Session::pop(int row, int col, std::string &text) {
  304 + return this->pop(lib3270_translate_to_address(hSession,row,col),text);
  305 + }
  306 +
  307 + TN3270::Session & Local::Session::pop(std::string &text) {
  308 +
  309 + std::lock_guard<std::mutex> lock(sync);
  310 +
  311 + if(!lib3270_is_connected(hSession)) {
  312 + throw std::system_error(ENOTCONN, std::system_category());
  313 + }
  314 +
  315 + int baddr = lib3270_get_cursor_address(hSession);
  316 + if(baddr < 0) {
  317 + throw std::system_error(errno, std::system_category());
  318 + }
  319 +
  320 + char *contents = lib3270_get_field_text_at(hSession, baddr);
  321 +
  322 + if(!contents) {
  323 + throw std::system_error(errno, std::system_category());
  324 + }
  325 +
  326 + text.assign(convertFromHost(contents).c_str());
  327 +
  328 + lib3270_free(contents);
  329 +
  330 + baddr = lib3270_get_next_unprotected(hSession,baddr);
  331 + if(!baddr) {
  332 + baddr = lib3270_get_next_unprotected(hSession,0);
  333 + }
  334 +
  335 + if(lib3270_set_cursor_address(hSession,baddr)) {
  336 + throw std::system_error(errno, std::system_category());
  337 + }
  338 +
  339 + return *this;
  340 + }
  341 +
  342 + /// @brief Set cursor address.
  343 + ///
  344 + /// @param addr Cursor address.
  345 + TN3270::Session & Local::Session::setCursorPosition(unsigned short addr) {
  346 +
  347 + if(lib3270_set_cursor_address(hSession,addr) < 0) {
  348 + throw std::system_error(errno, std::system_category());
  349 + }
  350 +
  351 + return *this;
  352 + }
  353 +
  354 + /// @brief Set cursor position.
  355 + ///
  356 + /// @param row New cursor row.
  357 + /// @param col New cursor column.
  358 + TN3270::Session & Local::Session::setCursorPosition(unsigned short row, unsigned short col) {
  359 +
  360 + if(lib3270_set_cursor_position(hSession,row,col)) {
  361 + throw std::system_error(errno, std::system_category());
  362 + }
  363 +
  364 + return *this;
  365 +
  366 + }
  367 +
  368 + // Get properties.
  369 + std::string Local::Session::getVersion() const {
  370 + return lib3270_get_version();
  371 + }
  372 +
  373 + std::string Local::Session::getRevision() const {
  374 + return lib3270_get_revision();
  375 + }
  376 +
  377 + /// @brief Execute action by name.
  378 + TN3270::Session & Local::Session::action(const char *action_name) {
  379 +
  380 + if(lib3270_action(hSession,action_name)) {
  381 + throw std::system_error(errno, std::system_category());
  382 + }
  383 +
  384 + return *this;
  385 + }
  386 +
  387 + }
  388 +
  389 +
src/client/src/session/remote/session.cc 0 → 100644
@@ -0,0 +1,365 @@ @@ -0,0 +1,365 @@
  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 "../private.h"
  40 + #include <cstring>
  41 +
  42 + using std::string;
  43 +
  44 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  45 +
  46 + namespace TN3270 {
  47 +
  48 + void IPC::Session::connect(const char *url) {
  49 + Request request(*this,"connect");
  50 + request.push(url).call();
  51 + }
  52 +
  53 + void IPC::Session::disconnect() {
  54 + Request(*this,"disconnect").call();
  55 + }
  56 +
  57 + // Wait for session state.
  58 + void IPC::Session::waitForReady(time_t timeout) {
  59 +
  60 + int rc;
  61 +
  62 + time_t end = time(nullptr) + timeout;
  63 +
  64 + while(time(nullptr) < end) {
  65 +
  66 + debug("Running waitForReady request...");
  67 +
  68 + Request(*this,"waitForReady")
  69 + .push((uint32_t) 1)
  70 + .call()
  71 + .pop(rc);
  72 +
  73 + debug("Wait for ready returned ",rc);
  74 +
  75 + if(rc == 0)
  76 + return;
  77 +
  78 + }
  79 +
  80 + throw std::system_error(ETIMEDOUT, std::system_category());
  81 + }
  82 +
  83 + std::string IPC::Session::toString(int baddr, size_t len, char lf) const {
  84 +
  85 + std::string rc;
  86 +
  87 + Request(*this,"getStringAtAddress")
  88 + .push((uint32_t) baddr)
  89 + .push((uint32_t) len)
  90 + .push((uint8_t) lf)
  91 + .call()
  92 + .pop(rc);
  93 +
  94 + return rc;
  95 + }
  96 +
  97 + std::string IPC::Session::toString(int row, int col, size_t sz, char lf) const {
  98 +
  99 + std::string rc;
  100 +
  101 + Request(*this,"getStringAt")
  102 + .push((uint32_t) row)
  103 + .push((uint32_t) col)
  104 + .push((uint32_t) sz)
  105 + .push((uint8_t) lf)
  106 + .call()
  107 + .pop(rc);
  108 +
  109 + return rc;
  110 + }
  111 +
  112 + ProgramMessage IPC::Session::getProgramMessage() const {
  113 +
  114 + int program_message;
  115 + getProperty("program_message",program_message);
  116 + return (ProgramMessage) program_message;
  117 +
  118 + }
  119 +
  120 + ConnectionState IPC::Session::getConnectionState() const {
  121 +
  122 + int cstate;
  123 + getProperty("cstate",cstate);
  124 + return (ConnectionState) cstate;
  125 +
  126 + }
  127 +
  128 + /// @brief Set field at current position, jumps to next writable field.
  129 + TN3270::Session & IPC::Session::push(const char *text) {
  130 +
  131 + int rc;
  132 +
  133 + Request(*this,"setString")
  134 + .push(text)
  135 + .call()
  136 + .pop(rc);
  137 +
  138 + if(rc) {
  139 + throw std::system_error((int) rc, std::system_category());
  140 + }
  141 +
  142 + return *this;
  143 +
  144 + }
  145 +
  146 + TN3270::Session & IPC::Session::push(int baddr, const std::string &text) {
  147 +
  148 + int rc;
  149 +
  150 + Request(*this,"setStringAtAddress")
  151 + .push((uint32_t) baddr)
  152 + .push(text.c_str())
  153 + .call()
  154 + .pop(rc);
  155 +
  156 + if(rc) {
  157 + throw std::system_error((int) rc, std::system_category());
  158 + }
  159 +
  160 + return *this;
  161 +
  162 + }
  163 +
  164 + TN3270::Session & IPC::Session::push(int row, int col, const std::string &text) {
  165 +
  166 + int32_t rc;
  167 +
  168 + Request(*this,"setStringAt")
  169 + .push((uint32_t) row)
  170 + .push((uint32_t) col)
  171 + .push(text.c_str())
  172 + .call()
  173 + .pop(rc);
  174 +
  175 + if(rc) {
  176 + throw std::system_error((int) rc, std::system_category());
  177 + }
  178 +
  179 + return *this;
  180 +
  181 + }
  182 +
  183 + TN3270::Session & IPC::Session::push(const PFKey key) {
  184 +
  185 + int32_t rc;
  186 +
  187 + Request(*this,"pfkey")
  188 + .push((uint32_t) key)
  189 + .call()
  190 + .pop(rc);
  191 +
  192 + if(rc) {
  193 + throw std::system_error((int) rc, std::system_category());
  194 + }
  195 +
  196 + return *this;
  197 +
  198 + }
  199 +
  200 + TN3270::Session & IPC::Session::push(const PAKey key) {
  201 +
  202 + int32_t rc;
  203 +
  204 + Request(*this,"pakey")
  205 + .push((uint32_t) key)
  206 + .call()
  207 + .pop(rc);
  208 +
  209 + if(rc) {
  210 + throw std::system_error((int) rc, std::system_category());
  211 + }
  212 +
  213 + return *this;
  214 +
  215 + }
  216 +
  217 + TN3270::Session & IPC::Session::push(const Action action) {
  218 +
  219 + const char * actions[] = {
  220 + "enter",
  221 + "erase",
  222 + "eraseeof",
  223 + "eraseeol",
  224 + "eraseinput"
  225 + };
  226 +
  227 + if( ((size_t) action) > (sizeof(actions)/sizeof(actions[0]))) {
  228 + throw std::system_error(EINVAL, std::system_category());
  229 + }
  230 +
  231 + return this->action(actions[action]);
  232 +
  233 + }
  234 +
  235 + TN3270::Session & IPC::Session::pop(int baddr, std::string &text) {
  236 +
  237 + Request(*this,"getFieldAtAddress")
  238 + .push((uint32_t) baddr)
  239 + .call()
  240 + .pop(text);
  241 +
  242 + return *this;
  243 + }
  244 +
  245 + TN3270::Session & IPC::Session::pop(int row, int col, std::string &text) {
  246 +
  247 + Request(*this,"getFieldAt")
  248 + .push((uint32_t) row)
  249 + .push((uint32_t) col)
  250 + .call()
  251 + .pop(text);
  252 +
  253 + return *this;
  254 + }
  255 +
  256 + TN3270::Session & IPC::Session::pop(std::string &text) {
  257 +
  258 + Request(*this,"getFieldAtCursor")
  259 + .call()
  260 + .pop(text);
  261 +
  262 + return *this;
  263 +
  264 + }
  265 +
  266 + /// @brief Set cursor address.
  267 + ///
  268 + /// @param addr Cursor address.
  269 + TN3270::Session & IPC::Session::setCursorPosition(unsigned short addr) {
  270 +
  271 + int32_t rc;
  272 +
  273 + Request(*this,"setCursorAddress")
  274 + .push((uint32_t) addr)
  275 + .call()
  276 + .pop(rc);
  277 +
  278 + if(rc) {
  279 + throw std::system_error((int) rc, std::system_category());
  280 + }
  281 +
  282 + return *this;
  283 +
  284 + }
  285 +
  286 + /// @brief Set cursor position.
  287 + ///
  288 + /// @param row New cursor row.
  289 + /// @param col New cursor column.
  290 + TN3270::Session & IPC::Session::setCursorPosition(unsigned short row, unsigned short col) {
  291 +
  292 + int32_t rc;
  293 +
  294 + Request(*this,"setCursorPosition")
  295 + .push((uint32_t) row)
  296 + .push((uint32_t) col)
  297 + .call()
  298 + .pop(rc);
  299 +
  300 + if(rc) {
  301 + throw std::system_error((int) rc, std::system_category());
  302 + }
  303 +
  304 + return *this;
  305 +
  306 + }
  307 +
  308 + void IPC::Session::getProperty(const char *name, int &value) const {
  309 +
  310 + Request(*this,false,name)
  311 + .call()
  312 + .pop(value);
  313 +
  314 + }
  315 +
  316 + void IPC::Session::getProperty(const char *name, std::string &value) const {
  317 +
  318 + Request(*this,false,name)
  319 + .call()
  320 + .pop(value);
  321 +
  322 + }
  323 +
  324 + void IPC::Session::getProperty(const char *name, bool &value) const {
  325 + throw std::system_error(ENOENT, std::system_category());
  326 + }
  327 +
  328 + /// @brief Get lib3270 version.
  329 + std::string IPC::Session::getVersion() const {
  330 +
  331 + string rc;
  332 + getProperty("version",rc);
  333 + return rc;
  334 +
  335 + }
  336 +
  337 + /// @brief Get lib3270 revision.
  338 + std::string IPC::Session::getRevision() const {
  339 +
  340 + string rc;
  341 + getProperty("revision",rc);
  342 + return rc;
  343 +
  344 + }
  345 +
  346 + /// @brief Execute action by name.
  347 + TN3270::Session & IPC::Session::action(const char *action_name) {
  348 +
  349 + int32_t rc;
  350 +
  351 + Request(*this,"action")
  352 + .push(action_name)
  353 + .call()
  354 + .pop(rc);
  355 +
  356 + if(rc) {
  357 + throw std::system_error((int) rc, std::system_category());
  358 + }
  359 +
  360 + return *this;
  361 + }
  362 +
  363 + }
  364 +
  365 +
src/client/src/testprogram/testprogram.cc
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin 18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19 * St, Fifth Floor, Boston, MA 02110-1301 USA 19 * St, Fifth Floor, Boston, MA 02110-1301 USA
20 * 20 *
21 - * Este programa está nomeado como lib3270++.h e possui - linhas de código. 21 + * Este programa está nomeado como - e possui - linhas de código.
22 * 22 *
23 * Contatos: 23 * Contatos:
24 * 24 *
src/client/src/windows/request.cc
@@ -1,191 +0,0 @@ @@ -1,191 +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/lib3270++/windows/request.cc  
32 - *  
33 - * @brief Implements WIN32 Pipe Based IPC.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "../private.h"  
40 -  
41 - using std::string;  
42 -  
43 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
44 -  
45 - namespace TN3270 {  
46 -  
47 - #define PIPE_BUFFER_LENGTH 8192  
48 -  
49 - IPC::Request::Request(const Session &session) {  
50 -  
51 - this->hPipe = session.hPipe;  
52 -  
53 - in.length = PIPE_BUFFER_LENGTH;  
54 - in.used = 0;  
55 - in.block = new uint8_t[in.length];  
56 -  
57 - out.length = PIPE_BUFFER_LENGTH;  
58 - out.used = 0;  
59 - out.block = new uint8_t[out.length];  
60 -  
61 - }  
62 -  
63 - IPC::Request::Request(const Session &session, const char *method) : Request(session) {  
64 -  
65 - // Add name  
66 - strcpy((char *) out.block, method);  
67 - out.used += strlen((char *) method) + 1;  
68 -  
69 - // Add ID  
70 - *((uint16_t *) (out.block + out.used)) = (uint16_t) 3;  
71 - out.used += sizeof(uint16_t);  
72 -  
73 - }  
74 -  
75 - IPC::Request::Request(const Session &session, bool isSet, const char *property) : Request(session) {  
76 -  
77 - // Add name  
78 - strcpy((char *) out.block, property);  
79 - out.used += strlen((char *) property) + 1;  
80 -  
81 - // Add ID (SetProperty = 2, getProperty = 1)  
82 - *((uint16_t *) (out.block + out.used)) = (uint16_t) (isSet ? 2 : 1);  
83 - out.used += sizeof(uint16_t);  
84 -  
85 - }  
86 -  
87 - IPC::Request::~Request() {  
88 -  
89 - delete[] ((uint8_t *) in.block);  
90 - delete[] ((uint8_t *) out.block);  
91 -  
92 - }  
93 -  
94 - /// @brief Store value on data block.  
95 - IPC::Request::DataBlock * IPC::Request::pushBlock(const void *ptr, size_t length) {  
96 -  
97 - if((out.used + length + sizeof(IPC::Request::DataBlock)) >= out.length) {  
98 - throw std::runtime_error("Too big");  
99 - }  
100 -  
101 - IPC::Request::DataBlock * rc = (IPC::Request::DataBlock *) (out.block + out.used);  
102 - memcpy(((uint8_t *) (rc+1)), ((uint8_t *) ptr), length);  
103 -  
104 - out.used += (sizeof(IPC::Request::DataBlock) + length);  
105 -  
106 - return rc;  
107 -  
108 - }  
109 -  
110 - /// @brief Get next argument.  
111 - IPC::Request::DataBlock * IPC::Request::getNextBlock() const {  
112 -  
113 - if((in.current + sizeof(IPC::Request::DataBlock)) >= in.used) {  
114 - throw std::runtime_error("Out of range");  
115 - }  
116 -  
117 - return (IPC::Request::DataBlock *) (in.block + in.current);  
118 -  
119 - }  
120 -  
121 - IPC::Request & IPC::Request::push(const char *arg) {  
122 - pushBlock(arg, strlen(arg)+1)->type = IPC::Request::String;  
123 - return *this;  
124 - }  
125 -  
126 - IPC::Request & IPC::Request::push(const bool arg) {  
127 - uint8_t value = (uint8_t) (arg ? 0xff : 0);  
128 - pushBlock(&value, sizeof(value))->type = IPC::Request::Boolean;  
129 - return *this;  
130 - }  
131 -  
132 - IPC::Request & IPC::Request::push(const uint8_t arg) {  
133 - pushBlock(&arg, sizeof(arg))->type = IPC::Request::Uchar;  
134 - return *this;  
135 - }  
136 -  
137 - IPC::Request & IPC::Request::push(const int32_t arg) {  
138 - pushBlock(&arg, sizeof(arg))->type = IPC::Request::Int32;  
139 - return *this;  
140 - }  
141 -  
142 - IPC::Request & IPC::Request::push(const uint32_t arg) {  
143 - pushBlock(&arg, sizeof(arg))->type = IPC::Request::Uint32;  
144 - return *this;  
145 - }  
146 -  
147 - IPC::Request & IPC::Request::pop(std::string &value) {  
148 - DataBlock * block = getNextBlock();  
149 -  
150 - if(block->type != IPC::Request::String)  
151 - throw std::runtime_error("Invalid format");  
152 -  
153 - const char *ptr = (const char *) (block+1);  
154 -  
155 - in.current += (strlen(ptr)+1+sizeof(DataBlock));  
156 -  
157 - value.assign(ptr);  
158 -  
159 - return *this;  
160 - }  
161 -  
162 - IPC::Request & IPC::Request::Request::pop(int &value) {  
163 -  
164 - DataBlock * block = getNextBlock();  
165 -  
166 - switch(block->type) {  
167 - case IPC::Request::Int16:  
168 - value = * ((int16_t *) (block+1));  
169 - in.current += sizeof(int16_t) + sizeof(DataBlock);  
170 - break;  
171 -  
172 - case IPC::Request::Int32:  
173 - value = * ((int32_t *) (block+1));  
174 - in.current += sizeof(int32_t) + sizeof(DataBlock);  
175 - break;  
176 -  
177 - case IPC::Request::Int64:  
178 - value = * ((int64_t *) (block+1));  
179 - in.current += sizeof(int64_t) + sizeof(DataBlock);  
180 - break;  
181 -  
182 - default:  
183 - throw std::runtime_error("Invalid format");  
184 - }  
185 -  
186 - return *this;  
187 - }  
188 -  
189 - }  
190 -  
191 -  
src/client/src/windows/resources.rc.in
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -#include <windows.h>  
2 -  
3 -VS_VERSION_INFO VERSIONINFO  
4 -FILEVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0  
5 -PRODUCTVERSION @PACKAGE_MAJOR_VERSION@,@PACKAGE_MINOR_VERSION@,@PACKAGE_MAJOR_RELEASE@,0  
6 -  
7 -BEGIN  
8 -  
9 - BLOCK "StringFileInfo"  
10 - BEGIN  
11 - BLOCK "080904E4"  
12 - BEGIN  
13 - VALUE "FileDescription", "3270 C++ Access Library\0"  
14 - VALUE "CompanyName", "Banco do Brasil S/A.\0"  
15 - VALUE "FileVersion", "@WIN32_VERSION@\0"  
16 - VALUE "LegalCopyright", "(C) 2017 Banco do Brasil S/A. All Rights Reserved\0"  
17 - VALUE "OriginalFilename", "@PACKAGE_TARNAME@@DLLEXT@\0"  
18 - VALUE "ProductName", "@PACKAGE_NAME@\0"  
19 - VALUE "ProductVersion", "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.0\0"  
20 - END  
21 - END  
22 -  
23 - BLOCK "VarFileInfo"  
24 - BEGIN  
25 - VALUE "Translation", 0x809, 0x04E4  
26 - END  
27 -  
28 -END  
29 -  
src/client/src/windows/session.cc
@@ -1,142 +0,0 @@ @@ -1,142 +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/lib3270++/ipc/windows/session.cc  
32 - *  
33 - * @brief Implements Windows session create/destroy session.  
34 - *  
35 - * @author perry.werneck@gmail.com  
36 - *  
37 - */  
38 -  
39 - #include "../private.h"  
40 - #include <cstring>  
41 - #include <lib3270/trace.h>  
42 - #include <algorithm>  
43 -  
44 - using std::string;  
45 -  
46 -/*---[ Implement ]----------------------------------------------------------------------------------*/  
47 -  
48 - namespace TN3270 {  
49 -  
50 - IPC::Session::Session(const char *id) : Abstract::Session() {  
51 -  
52 - char *ptr = strchr(id,':');  
53 -  
54 - if(!ptr)  
55 - throw std::system_error(EINVAL, std::system_category());  
56 -  
57 - string pipename{"\\\\.\\pipe\\"};  
58 -  
59 - pipename += string(id,ptr - id);  
60 - pipename += "\\";  
61 - pipename += (ptr+1);  
62 -  
63 - std::transform(pipename.begin(), pipename.end(), pipename.begin(), ::tolower);  
64 -  
65 - debug("pipename: \"%s\"",pipename.c_str());  
66 -  
67 - this->hPipe = CreateFile(  
68 - TEXT(pipename.c_str()), // pipe name  
69 - GENERIC_READ | // read and write access  
70 - GENERIC_WRITE,  
71 - 0, // no sharing  
72 - NULL, // default security attributes  
73 - OPEN_EXISTING, // opens existing pipe  
74 - 0, // default attributes  
75 - NULL // no template file  
76 - );  
77 -  
78 - if (hPipe == INVALID_HANDLE_VALUE) {  
79 - throw std::runtime_error("Can't open IPC Channel");  
80 - }  
81 -  
82 - // The pipe connected; change to message-read mode.  
83 - DWORD dwMode = PIPE_READMODE_MESSAGE;  
84 - if(!SetNamedPipeHandleState(hPipe,&dwMode,NULL,NULL)) {  
85 - throw std::runtime_error("Can't set IPC Channel mode");  
86 - }  
87 -  
88 - }  
89 -  
90 - IPC::Session::~Session() {  
91 - CloseHandle(this->hPipe);  
92 - }  
93 -  
94 -  
95 - IPC::Request & IPC::Request::call() {  
96 -  
97 -#ifdef DEBUG  
98 - // lib3270_trace_data(NULL,"Request block",(const char *) this->out.block, this->out.used);  
99 -#endif // DEBUG  
100 -  
101 - in.current = 0;  
102 -  
103 - if(!TransactNamedPipe(  
104 - this->hPipe,  
105 - this->out.block,  
106 - this->out.used,  
107 - this->in.block,  
108 - this->in.length,  
109 - &this->in.used,  
110 - NULL)  
111 - ) {  
112 -  
113 - throw std::runtime_error("Can't transact on IPC Channel");  
114 -  
115 - }  
116 -  
117 - debug("Received response \"", in.block, "\" with ", in.used, " bytes");  
118 -#ifdef DEBUG  
119 - // lib3270_trace_data(NULL,"Response block",(const char *) this->in.block, this->in.used);  
120 -#endif // DEBUG  
121 -  
122 - // Extract response name  
123 - in.current = strlen((const char *) in.block)+1;  
124 -  
125 - // Extract return code  
126 - uint16_t rc = *((uint16_t *) (in.block + in.current));  
127 - in.current += sizeof(uint16_t);  
128 -  
129 - // Extract argc  
130 - uint16_t argc = *((uint16_t *) (in.block + in.current));  
131 - in.current += sizeof(uint16_t);  
132 -  
133 - debug("Received response \"", ((const char *) in.block), "\" with rc=", rc, " and ", argc, " arguments");  
134 -  
135 - return *this;  
136 - }  
137 -  
138 -  
139 -  
140 - }  
141 -  
142 -