diff --git a/hllapi.cbp b/hllapi.cbp index 723fd82..b0cc389 100644 --- a/hllapi.cbp +++ b/hllapi.cbp @@ -38,6 +38,7 @@ + diff --git a/src/core/actions.cc b/src/core/actions.cc index b356e3f..fcb6628 100644 --- a/src/core/actions.cc +++ b/src/core/actions.cc @@ -28,10 +28,11 @@ */ #include "private.h" + #include /*--[ Implement ]------------------------------------------------------------------------------------*/ - static DWORD action(const TN3270::Action id) { + static DWORD action(std::function worker) noexcept { try { @@ -40,20 +41,32 @@ if(!host.isConnected()) return HLLAPI_STATUS_DISCONNECTED; - host.push(id); + worker(host); - return 0; + return HLLAPI_STATUS_SUCCESS; - } catch(std::exception &e) { + } catch(const std::exception &e) { hllapi_lasterror = e.what(); + } catch(...) { + + hllapi_lasterror = "Unexpected error"; + } return HLLAPI_STATUS_SYSTEM_ERROR; } + static DWORD action(const TN3270::Action id) noexcept { + + return action([id](TN3270::Host &host) { + host.push(id); + }); + + } + HLLAPI_API_CALL hllapi_enter(void) { return action(TN3270::ENTER); } @@ -80,28 +93,16 @@ HLLAPI_API_CALL hllapi_action(LPSTR action_name) { - try { - - getSession().action((const char *) action_name); - - return HLLAPI_STATUS_SUCCESS; - - } catch(std::exception &e) { - - hllapi_lasterror = e.what(); - - } - - return HLLAPI_STATUS_SYSTEM_ERROR; + return action([action_name](TN3270::Host &host) { + host.action(action_name); + }); } -/* - - HLLAPI_API_CALL hllapi_print(void) - { - return session::get_default()->print(); - } + HLLAPI_API_CALL hllapi_print(void) { - */ + return action([](TN3270::Host &host) { + host.print(); + }); + } diff --git a/src/core/calls.cc b/src/core/calls.cc index 84562cc..0498975 100644 --- a/src/core/calls.cc +++ b/src/core/calls.cc @@ -207,68 +207,6 @@ } - 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 HLLAPI_STATUS_SUCCESS; - - } catch(std::exception &e) { - - hllapi_lasterror = e.what(); - - } - - return HLLAPI_STATUS_SYSTEM_ERROR; - - } - - 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 HLLAPI_STATUS_SUCCESS; - - } catch(std::exception &e) { - - hllapi_lasterror = e.what(); - - } - - return HLLAPI_STATUS_SYSTEM_ERROR; - - } - - HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms) { - - try { - - getSession().setUnlockDelay((unsigned short) ms); - return HLLAPI_STATUS_SUCCESS; - - } catch(std::exception &e) { - - hllapi_lasterror = e.what(); - - } - - return HLLAPI_STATUS_SYSTEM_ERROR; - } - HLLAPI_API_CALL hllapi_set_charset(LPSTR text) { try { @@ -383,3 +321,20 @@ } + DWORD hllapi_translate_keyboard_state(LIB3270_KEYBOARD_LOCK_STATE state, HLLAPI_STATUS def) { + + // Is unlocked. + if(state == LIB3270_KL_UNLOCKED) + return def; + + // Is connected? + if((state & LIB3270_KL_NOT_CONNECTED) != 0) + return HLLAPI_STATUS_DISCONNECTED; + + if( (state & (LIB3270_KL_AWAITING_FIRST|LIB3270_KL_OIA_TWAIT)) != 0) + return HLLAPI_STATUS_WAITING; + + return HLLAPI_STATUS_KEYBOARD_LOCKED; + + } + diff --git a/src/core/cursor.cc b/src/core/cursor.cc index 8c85cd6..c9f3d72 100644 --- a/src/core/cursor.cc +++ b/src/core/cursor.cc @@ -31,7 +31,7 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ - HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) { + static DWORD set(std::function worker) noexcept { try { @@ -40,22 +40,47 @@ if(!host.isConnected()) return HLLAPI_STATUS_DISCONNECTED; - host.setCursor((unsigned short) pos -1); + worker(host); - return 0; + return HLLAPI_STATUS_SUCCESS; - } catch(std::exception &e) { + } catch(const std::exception &e) { hllapi_lasterror = e.what(); + } catch(...) { + + hllapi_lasterror = "Unexpected error"; + } return HLLAPI_STATUS_SYSTEM_ERROR; } + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) { + + return set([pos](TN3270::Host &host) { + host.setCursor((unsigned short) pos -1); + }); + + + } + HLLAPI_API_CALL hllapi_setcursor(WORD pos) { - return hllapi_set_cursor_address(pos); + + return set([pos](TN3270::Host &host) { + host.setCursor((unsigned short) pos -1); + }); + + } + + HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col) { + + return set([row,col](TN3270::Host &host) { + host.setCursor((unsigned short) row, (unsigned short) col); + }); + } HLLAPI_API_CALL hllapi_get_cursor_address() { diff --git a/src/core/keyboard.cc b/src/core/keyboard.cc new file mode 100644 index 0000000..f852b9b --- /dev/null +++ b/src/core/keyboard.cc @@ -0,0 +1,101 @@ +/* + * "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 set(std::function worker) noexcept { + + try { + + TN3270::Host &host = getSession(); + + if(!host.isConnected()) + return HLLAPI_STATUS_DISCONNECTED; + + host.waitForReady(); + + worker(host); + + } catch(const std::exception &e) { + + // Worker has failed! + hllapi_lasterror = e.what(); + return HLLAPI_STATUS_SYSTEM_ERROR; + + } catch(...) { + + // Unexpected error getting session or lock state + hllapi_lasterror = "Unexpected error"; + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + + } + + + HLLAPI_API_CALL hllapi_pfkey(WORD key) { + + return set([key](TN3270::Host &host) { + + host.pfkey((unsigned short) key); + + }); + + + } + + HLLAPI_API_CALL hllapi_pakey(WORD key) { + + return set([key](TN3270::Host &host) { + + host.pakey((unsigned short) key); + + }); + + } + + HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms) { + + try { + + getSession().setUnlockDelay((unsigned short) ms); + return HLLAPI_STATUS_SUCCESS; + + } catch(std::exception &e) { + + hllapi_lasterror = e.what(); + + } + + return HLLAPI_STATUS_SYSTEM_ERROR; + } + diff --git a/src/core/private.h b/src/core/private.h index 49d0956..279be8c 100644 --- a/src/core/private.h +++ b/src/core/private.h @@ -45,8 +45,9 @@ using TN3270::Host; using std::exception; - extern string hllapi_lasterror; + extern TN3270_PRIVATE std::string hllapi_lasterror; - TN3270::Host & getSession(); + TN3270_PRIVATE TN3270::Host & getSession(); + TN3270_PRIVATE DWORD hllapi_translate_keyboard_state(LIB3270_KEYBOARD_LOCK_STATE state, HLLAPI_STATUS def = HLLAPI_STATUS_SYSTEM_ERROR); #endif // PRIVATE_H_INCLUDED diff --git a/src/core/set.cc b/src/core/set.cc index 357fc77..81e95b3 100644 --- a/src/core/set.cc +++ b/src/core/set.cc @@ -36,23 +36,6 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ - DWORD hllapi_translate_keyboard_state(LIB3270_KEYBOARD_LOCK_STATE state, HLLAPI_STATUS def = HLLAPI_STATUS_SYSTEM_ERROR) { - - // Is unlocked. - if(state == LIB3270_KL_UNLOCKED) - return def; - - // Is connected? - if((state & LIB3270_KL_NOT_CONNECTED) != 0) - return HLLAPI_STATUS_DISCONNECTED; - - if( (state & (LIB3270_KL_AWAITING_FIRST|LIB3270_KL_OIA_TWAIT)) != 0) - return HLLAPI_STATUS_WAITING; - - return HLLAPI_STATUS_KEYBOARD_LOCKED; - - } - static DWORD set(std::function worker) noexcept { LIB3270_KEYBOARD_LOCK_STATE kLock = LIB3270_KL_UNLOCKED; diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index 9c350cc..38bd618 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -229,6 +229,9 @@ HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms); + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos); + HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); + /** * @brief Get cursor address. * -- libgit2 0.21.2