From 09f7edb3def3e459c58886c5962acd5e9d2614d6 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 21 Nov 2018 15:50:55 -0200 Subject: [PATCH] Working on new C++ API. --- src/include/lib3270++.h | 29 +++++++++++++++++++++++++---- src/lib3270++/events.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib3270++/lib3270++.cbp | 1 + src/lib3270++/local.cc | 28 +++++++++++++++++++++------- src/lib3270++/private.h | 3 +++ src/lib3270++/session.cc | 9 +++++++++ src/lib3270++/testprogram/testprogram.cc | 3 ++- 7 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 src/lib3270++/events.cc diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 438e296..68f8480 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -33,6 +33,8 @@ #include #include + #include + #include #include #if defined(_WIN32) @@ -63,8 +65,9 @@ namespace TN3270 { class Host; + class Controller; - class Event { + class TN3270_PUBLIC Event { public: enum Type : uint8_t { All, ///< @brief All events (undefined). @@ -77,9 +80,7 @@ Type type; protected: - Event(enum Type type) { - this->type = type; - } + Event(enum Type type); public: virtual ~Event(); @@ -89,6 +90,15 @@ return this->type == type; } + /// @brief Check event type + inline bool operator==(Event::Type type) const noexcept { + return this->type == type; + } + + inline operator Event::Type() const noexcept { + return this->type; + } + /// @brief Get event description. virtual std::string toString() const = 0; @@ -174,6 +184,7 @@ /// @brief Write error to log file. void error(const char *fmt, ...) const; + /// @brief Fire event. void fire(const Event &event); public: @@ -228,6 +239,9 @@ virtual Session & pop(int row, int col, std::string &text) = 0; virtual Session & pop(std::string &text) = 0; + /// @brief Insert event listener. + void insert(Event::Type type, std::function listener); + }; /// @brief TN3270 Host @@ -334,6 +348,13 @@ return *this; } + // Event listeners + inline Host & insert(Event::Type type, std::function listener) noexcept { + session->insert(type, listener); + return *this; + } + + }; } diff --git a/src/lib3270++/events.cc b/src/lib3270++/events.cc new file mode 100644 index 0000000..c29f39f --- /dev/null +++ b/src/lib3270++/events.cc @@ -0,0 +1,56 @@ +/* + * "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++/events.cc + * + * @brief + * + * @author perry.werneck@gmail.com + * + */ + + #include "private.h" + + +/*---[ Implement ]----------------------------------------------------------------------------------*/ + + namespace TN3270 { + + Event::Event(enum Event::Type type) { + this->type = type; + } + + Event::~Event() { + } + + } + + + diff --git a/src/lib3270++/lib3270++.cbp b/src/lib3270++/lib3270++.cbp index 49535d3..20c1d7f 100644 --- a/src/lib3270++/lib3270++.cbp +++ b/src/lib3270++/lib3270++.cbp @@ -44,6 +44,7 @@ + diff --git a/src/lib3270++/local.cc b/src/lib3270++/local.cc index 11cbd59..3dc4534 100644 --- a/src/lib3270++/local.cc +++ b/src/lib3270++/local.cc @@ -86,6 +86,13 @@ free(buffer); } +#ifdef DEBUG + std::cerr << "Popup:" << std::endl + << "\t" << title << std::endl + << "\t" << msg << std::endl + << "\t" << description << std::endl; +#endif // DEBUG + } virtual ~PopupEvent() { @@ -113,14 +120,26 @@ this->hSession = nullptr; } + void LocalSession::wait(time_t timeout) { + + int rc = lib3270_wait_for_ready(this->hSession, timeout); + + if(rc) { + throw std::system_error(rc, std::system_category()); + } + + } + void LocalSession::connect(const char *url) { std::lock_guard lock(sync); int rc = lib3270_connect_url(hSession,url,0); - if(!rc) { + if(rc) { throw std::system_error(rc, std::system_category()); } + wait(); + } void LocalSession::disconnect() { @@ -132,12 +151,7 @@ void LocalSession::waitForReady(time_t timeout) throw() { std::lock_guard lock(sync); - - int rc = lib3270_wait_for_ready(this->hSession, timeout); - - if(rc) { - throw std::system_error(rc, std::system_category()); - } + wait(timeout); } diff --git a/src/lib3270++/private.h b/src/lib3270++/private.h index 71955c8..2ad33d8 100644 --- a/src/lib3270++/private.h +++ b/src/lib3270++/private.h @@ -112,6 +112,9 @@ /// @brief Popup Handler. static int popupHandler(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg); + /// @brief Wait for network events + void wait(time_t timeout = 5); + public: LocalSession(); virtual ~LocalSession(); diff --git a/src/lib3270++/session.cc b/src/lib3270++/session.cc index 61f84b5..60651c9 100644 --- a/src/lib3270++/session.cc +++ b/src/lib3270++/session.cc @@ -63,6 +63,15 @@ } + void Session::insert(Event::Type type, std::function listener) { + } + + /// @brief Fire event. + void Session::fire(const Event &event) { + + + } + } diff --git a/src/lib3270++/testprogram/testprogram.cc b/src/lib3270++/testprogram/testprogram.cc index cf2e559..75fe18b 100644 --- a/src/lib3270++/testprogram/testprogram.cc +++ b/src/lib3270++/testprogram/testprogram.cc @@ -36,6 +36,7 @@ * */ + #include #include /*---[ Implement ]----------------------------------------------------------------------------------*/ @@ -44,7 +45,7 @@ TN3270::Host host; - host.connect(nullptr); + host.connect(getenv("TN3270URL")); return 0; } -- libgit2 0.21.2