From 52be7bafa1b8bb6726ef9215a5980248d1effac8 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 8 Aug 2019 15:51:03 -0300 Subject: [PATCH] Refactoring hllapi calls. --- hllapi.cbp | 1 + src/core/actions.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/calls.cc | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------ src/core/private.h | 1 + src/include/lib3270/hllapi.h | 12 ++++++++++++ 5 files changed, 184 insertions(+), 114 deletions(-) create mode 100644 src/core/actions.cc diff --git a/hllapi.cbp b/hllapi.cbp index f624bcd..cd113a5 100644 --- a/hllapi.cbp +++ b/hllapi.cbp @@ -32,6 +32,7 @@ + diff --git a/src/core/actions.cc b/src/core/actions.cc new file mode 100644 index 0000000..c6ad06d --- /dev/null +++ b/src/core/actions.cc @@ -0,0 +1,102 @@ +/* + * "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., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + static DWORD action(const TN3270::Action id) { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + host.push(id); + + return 0; + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + HLLAPI_API_CALL hllapi_enter(void) { + return action(TN3270::ENTER); + } + + HLLAPI_API_CALL hllapi_erase(void) { + return action(TN3270::ERASE); + } + + HLLAPI_API_CALL hllapi_erase_eof(void) { + return action(TN3270::ERASE_EOF); + } + + HLLAPI_API_CALL hllapi_erase_eol(void) { + return action(TN3270::ERASE_EOL); + } + + HLLAPI_API_CALL hllapi_erase_input(void) { + return action(TN3270::ERASE_INPUT); + } + +/* + + HLLAPI_API_CALL hllapi_reset(void) + { + return HLLAPI_STATUS_SUCCESS; + } + + HLLAPI_API_CALL hllapi_action(LPSTR buffer) { + try + { + session::get_default()->action((const char *) buffer); + } + catch(std::exception &e) + { + return HLLAPI_STATUS_SYSTEM_ERROR; + } + return HLLAPI_STATUS_SUCCESS; + } + + HLLAPI_API_CALL hllapi_print(void) + { + return session::get_default()->print(); + } + + */ + diff --git a/src/core/calls.cc b/src/core/calls.cc index d8222c4..c6264c2 100644 --- a/src/core/calls.cc +++ b/src/core/calls.cc @@ -50,7 +50,10 @@ { try { - getSession().connect((const char *) uri, wait); + getSession().connect((const char *) uri, false); + + if(wait) + return hllapi_wait_for_ready(wait); } catch(std::exception &e) { @@ -152,21 +155,78 @@ } return HLLAPI_STATUS_SUCCESS; + } + HLLAPI_API_CALL hllapi_wait_for_ready(WORD seconds) { - /* + try { - HLLAPI_API_CALL hllapi_wait_for_ready(WORD seconds) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; + TN3270::Host &host = getSession(); - session::get_default()->wait_for_ready(seconds); + if(host.isConnected()) + host.waitForReady((unsigned int) seconds); + + return hllapi_get_state(); + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + HLLAPI_API_CALL hllapi_pfkey(WORD key) { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + host.pfkey((unsigned short) key); + + return 0; + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; - return hllapi_get_state(); } + HLLAPI_API_CALL hllapi_pakey(WORD key) { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + host.pakey((unsigned short) key); + + return 0; + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + /* + HLLAPI_API_CALL hllapi_wait(WORD seconds) { if(!hllapi_is_connected()) @@ -199,13 +259,6 @@ return HLLAPI_STATUS_SUCCESS; } - HLLAPI_API_CALL hllapi_enter(void) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - return session::get_default()->enter(); - } HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text) { @@ -274,22 +327,6 @@ return 0; } - HLLAPI_API_CALL hllapi_pfkey(WORD key) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - return session::get_default()->pfkey(key); - } - - HLLAPI_API_CALL hllapi_pakey(WORD key) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - return session::get_default()->pakey(key); - } - HLLAPI_API_CALL hllapi_get_datadir(LPSTR datadir) { #ifdef _WIN32 @@ -409,84 +446,6 @@ return HLLAPI_STATUS_SUCCESS; } - HLLAPI_API_CALL hllapi_erase(void) - { - try - { - session::get_default()->erase(); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; - } - return HLLAPI_STATUS_SUCCESS; - } - - HLLAPI_API_CALL hllapi_erase_eof(void) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - try - { - session::get_default()->erase_eof(); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; - } - return HLLAPI_STATUS_SUCCESS; - } - - HLLAPI_API_CALL hllapi_erase_eol(void) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - try - { - session::get_default()->erase_eol(); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; - } - return HLLAPI_STATUS_SUCCESS; - } - - HLLAPI_API_CALL hllapi_erase_input(void) - { - if(!hllapi_is_connected()) - return HLLAPI_STATUS_DISCONNECTED; - - try - { - session::get_default()->erase_input(); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; - } - return HLLAPI_STATUS_SUCCESS; - } - - HLLAPI_API_CALL hllapi_action(LPSTR buffer) { - try - { - session::get_default()->action((const char *) buffer); - } - catch(std::exception &e) - { - return HLLAPI_STATUS_SYSTEM_ERROR; - } - return HLLAPI_STATUS_SUCCESS; - } - - HLLAPI_API_CALL hllapi_print(void) - { - return session::get_default()->print(); - } - char * hllapi_get_string(int offset, size_t len) { try @@ -507,11 +466,6 @@ free(p); } - HLLAPI_API_CALL hllapi_reset(void) - { - return HLLAPI_STATUS_SUCCESS; - } - HLLAPI_API_CALL hllapi_input_string(LPSTR input, WORD length) { static const char control_char = '@'; diff --git a/src/core/private.h b/src/core/private.h index 7dfedc6..d34be79 100644 --- a/src/core/private.h +++ b/src/core/private.h @@ -42,6 +42,7 @@ using std::runtime_error; using std::string; + using TN3270::Host; extern string hllapi_lasterror; diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index f637e12..3db9c7c 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -172,7 +172,19 @@ HLLAPI_API_CALL hllapi_reset(void); + /** + * @brief Connect to host. + * + * @param uri Host URI (tn3270://hostname:port). + * @param wait How many seconds to wait for the connection. + * + */ HLLAPI_API_CALL hllapi_connect(const LPSTR uri, WORD wait); + + /** + * @brief Disconnect from host. + * + */ HLLAPI_API_CALL hllapi_disconnect(void); HLLAPI_API_CALL hllapi_get_message_id(void); -- libgit2 0.21.2