From dddb96d184291324ca8076e3c9f5f1ed308bd24a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 16 Nov 2018 17:38:36 -0200 Subject: [PATCH] Planejando novo componente C++. --- src/include/lib3270++.h | 50 ++++++++++++++++++++++++++++++++++++++++---------- src/lib3270++/abstract.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270++/host.cc | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270++/lib3270++.cbp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270++/local.cc | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270++/private.h | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270++/session.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 565 insertions(+), 10 deletions(-) create mode 100644 src/lib3270++/abstract.cc create mode 100644 src/lib3270++/host.cc create mode 100644 src/lib3270++/lib3270++.cbp create mode 100644 src/lib3270++/local.cc create mode 100644 src/lib3270++/private.h create mode 100644 src/lib3270++/session.cc diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 3030491..4abe974 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -81,7 +81,7 @@ MESSAGE_X = LIB3270_MESSAGE_X, ///< @brief -- MESSAGE_RESOLVING = LIB3270_MESSAGE_RESOLVING, ///< @brief Resolving hostname (running DNS query) - MESSAGE_CONNECTING, = LIB3270_MESSAGE_CONNECTING ///< @brief Connecting to host +// MESSAGE_CONNECTING, = LIB3270_MESSAGE_CONNECTING ///< @brief Connecting to host }; @@ -124,7 +124,11 @@ /// @brief Actions keys enum Action : uint8_t { - ENTER ///< Enter key + ENTER, ///< Enter key + ERASE, + ERASE_EOF, + ERASE_EOL, + ERASE_INPUT }; /// @brief TN3270 Session. @@ -143,13 +147,14 @@ virtual void connect(const char *url) = 0; virtual void disconnect(); + // Wait for session state. + virtual void waitForReady(time_t timeout = 5) throw() = 0; + // Gets + virtual std::string toString() const = 0; virtual std::string toString(int baddr = 0, size_t len = -1, bool lf = false) = 0; virtual std::string toString(int row, int col, size_t sz, bool lf = false) = 0; - /// @brief Get field at current position, update to next one. - virtual Session & pop(std::string &value) = 0; - inline operator std::string() const { return toString(); } @@ -164,7 +169,7 @@ return getConnectionState(); } - // Sets + // Set contents. /// @brief Set field at current posicion, jumps to next writable field. virtual Session & push(const char *text) = 0; @@ -178,6 +183,11 @@ virtual Session & push(const PAKey key) = 0; virtual Session & push(const Action action) = 0; + // Get contents. + virtual Session & pop(int baddr, std::string &text) = 0; + virtual Session & pop(int row, int col, std::string &text) = 0; + virtual Session & pop(std::string &text) = 0; + }; /// @brief TN3270 Host @@ -199,6 +209,10 @@ Host(const char *id = nullptr, const char *url = nullptr); ~Host(); + inline void connect(const char *url) { + this->session->connect(url); + } + inline ProgramMessage getProgramMessage() const { return session->getProgramMessage(); } @@ -215,8 +229,7 @@ return getConnectionState(); } - - // Sets + // Set contents. /// @brief Set field at current posicion, jumps to next writable field. inline Host & push(const char *text) { @@ -225,7 +238,7 @@ }; inline Host & push(const std::string &text) { - session->push(text)); + session->push(text); return *this; } @@ -255,6 +268,23 @@ return *this; } + // Get contents. + + inline Host & pop(int baddr, std::string &text) { + session->pop(baddr, text); + return *this; + } + + inline Host & pop(int row, int col, std::string &text) { + session->pop(row,col,text); + return *this; + } + + inline Host & pop(std::string &text) { + session->pop(text); + return *this; + } + }; } @@ -279,7 +309,7 @@ template inline TN3270_PUBLIC TN3270::Host & operator>>(TN3270::Host& host, const T value) { - return Host.pop(value); + return host.pop(value); } #endif diff --git a/src/lib3270++/abstract.cc b/src/lib3270++/abstract.cc new file mode 100644 index 0000000..34018f0 --- /dev/null +++ b/src/lib3270++/abstract.cc @@ -0,0 +1,75 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como lib3270++.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/abstract.cc + * + * @brief + * + * @author perry.werneck@gmail.com + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + namespace TN3270 { + + Abstract::Session::Session() { + +#ifdef HAVE_ICONV + this->iconv.local = (iconv_t) (-1); + this->iconv.host = (iconv_t) (-1); +#endif + + this->baddr = 0; + + } + + Abstract::Session::~Session() { + +#ifdef HAVE_ICONV + + if(this->iconv.local != (iconv_t) (-1)) + iconv_close(this->iconv.local); + + if(this->iconv.host != (iconv_t) (-1)) + iconv_close(this->iconv.host); + +#endif + + } + + } + + + + diff --git a/src/lib3270++/host.cc b/src/lib3270++/host.cc new file mode 100644 index 0000000..82a05b5 --- /dev/null +++ b/src/lib3270++/host.cc @@ -0,0 +1,78 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como lib3270++.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/host.cc + * + * @brief + * + * @author perry.werneck@gmail.com + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + namespace TN3270 { + + Host::Host(const char *id, const char *url) { + this->session = Session::create(id); + if(url) { + this->connect(url); + } + } + + Host::~Host() { + delete this->session; + this->session = nullptr; + } + + /// @brief Writes characters to the associated file from the put area + int Host::sync() { + return 0; + } + + /// @brief Writes characters to the associated output sequence from the put area. + int Host::overflow(int c) { + + if (c != EOF) { + char str[] = { static_cast(c), 0 }; + this->session->push((const char *) str); + } else { + sync(); + } + + return c; + + } + + } + diff --git a/src/lib3270++/lib3270++.cbp b/src/lib3270++/lib3270++.cbp new file mode 100644 index 0000000..5cde9f1 --- /dev/null +++ b/src/lib3270++/lib3270++.cbp @@ -0,0 +1,56 @@ + + + + + + diff --git a/src/lib3270++/local.cc b/src/lib3270++/local.cc new file mode 100644 index 0000000..8112143 --- /dev/null +++ b/src/lib3270++/local.cc @@ -0,0 +1,132 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como lib3270++.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/local.cc + * + * @brief + * + * @author perry.werneck@gmail.com + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + namespace TN3270 { + + LocalSession::LocalSession() : Abstract::Session() { + this->hSession = lib3270_session_new(""); + lib3270_set_user_data(this->hSession,(void *) this); + } + + LocalSession::~LocalSession() { + lib3270_session_free(this->hSession); + this->hSession = nullptr; + } + + void LocalSession::connect(const char *url) { + lib3270_connect_url(hSession,url,0); + } + + void LocalSession::disconnect() { + lib3270_disconnect(hSession); + } + + // Wait for session state. + void LocalSession::waitForReady(time_t timeout) throw() { + + int rc = lib3270_wait_for_ready(this->hSession, timeout); + + if(rc) { + throw std::system_error(rc, std::system_category()); + } + + } + + // Gets + std::string LocalSession::toString() const { + } + + std::string LocalSession::toString(int baddr, size_t len, bool lf) { + } + + std::string LocalSession::toString(int row, int col, size_t sz, bool lf) { + } + + ProgramMessage LocalSession::getProgramMessage() const { + return (ProgramMessage) lib3270_get_program_message(this->hSession); + } + + ConnectionState LocalSession::getConnectionState() const { + return (ConnectionState) lib3270_get_connection_state(this->hSession); + } + + /// @brief Set field at current posicion, jumps to next writable field. + TN3270::Session & LocalSession::push(const char *text) { + return *this; + } + + TN3270::Session & LocalSession::push(int baddr, const std::string &text) { + return *this; + } + + TN3270::Session & LocalSession::push(int row, int col, const std::string &text) { + return *this; + } + + TN3270::Session & LocalSession::push(const PFKey key) { + return *this; + } + + TN3270::Session & LocalSession::push(const PAKey key) { + return *this; + } + + TN3270::Session & LocalSession::push(const Action action) { + return *this; + } + + TN3270::Session & LocalSession::pop(int baddr, std::string &text) { + return *this; + } + + TN3270::Session & LocalSession::pop(int row, int col, std::string &text) { + return *this; + } + + TN3270::Session & LocalSession::pop(std::string &text) { + return *this; + } + + } + + diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h new file mode 100644 index 0000000..c66b587 --- /dev/null +++ b/src/lib3270++/private.h @@ -0,0 +1,127 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como lib3270++.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/private.h + * + * @brief + * + * @author perry.werneck@gmail.com + * + */ + +#ifndef PRIVATE_H_INCLUDED + + #define PRIVATE_H_INCLUDED + + #include + #include + #include + + +#ifdef HAVE_ICONV + #include +#endif // HAVE_ICONV + + namespace TN3270 { + + namespace Abstract { + + class TN3270_PRIVATE Session : public TN3270::Session { + private: + +#ifdef HAVE_ICONV + struct { + + /// @brief Convert strings from host codepage to local codepage. + iconv_t local; + + /// @brief Convert string from local codepage to host codepage. + iconv_t host; + + } iconv; +#endif + + protected: + + /// @brief Current in/out position. + int baddr; + + Session(); + virtual ~Session(); + + }; + + } + + class TN3270_PRIVATE LocalSession : public Abstract::Session { + private: + + /// @brief Handle of the related instance of lib3270 + H3270 * hSession; + + public: + LocalSession(); + virtual ~LocalSession(); + + // Connect/disconnect + void connect(const char *url) override; + void disconnect() override; + + // Wait for session state. + void waitForReady(time_t timeout = 5) throw() override; + + // Gets + std::string toString() const override; + std::string toString(int baddr = 0, size_t len = -1, bool lf = false) override; + std::string toString(int row, int col, size_t sz, bool lf = false) override; + + ProgramMessage getProgramMessage() const override; + + ConnectionState getConnectionState() const override; + + /// @brief Set field at current posicion, jumps to next writable field. + TN3270::Session & push(const char *text) override; + + TN3270::Session & push(int baddr, const std::string &text) override; + TN3270::Session & push(int row, int col, const std::string &text) override; + TN3270::Session & push(const PFKey key) override; + TN3270::Session & push(const PAKey key) override; + TN3270::Session & push(const Action action) override; + + // Get contents. + TN3270::Session & pop(int baddr, std::string &text) override; + TN3270::Session & pop(int row, int col, std::string &text) override; + TN3270::Session & pop(std::string &text) override; + + }; + + } + +#endif // PRIVATE_H_INCLUDED diff --git a/src/lib3270++/session.cc b/src/lib3270++/session.cc new file mode 100644 index 0000000..2ed957c --- /dev/null +++ b/src/lib3270++/session.cc @@ -0,0 +1,57 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como lib3270++.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +/** + * @file src/lib3270++/session.cc + * + * @brief + * + * @author perry.werneck@gmail.com + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + namespace TN3270 { + + Session::Session() { + + } + + Session::~Session() { + + } + + } + + + -- libgit2 0.21.2