Commit 4e94d4aa5d745476423aa1ed0ee4026c44100d0c
1 parent
e828a3d8
Exists in
master
and in
1 other branch
Refactoring HLLAPI module.
Showing
8 changed files
with
180 additions
and
110 deletions
Show diff stats
hllapi.cbp
| ... | ... | @@ -38,6 +38,7 @@ |
| 38 | 38 | <Unit filename="src/core/cursor.cc" /> |
| 39 | 39 | <Unit filename="src/core/get.cc" /> |
| 40 | 40 | <Unit filename="src/core/hllapi.cc" /> |
| 41 | + <Unit filename="src/core/keyboard.cc" /> | |
| 41 | 42 | <Unit filename="src/core/private.h" /> |
| 42 | 43 | <Unit filename="src/core/set.cc" /> |
| 43 | 44 | <Unit filename="src/core/windows/resources.rc" /> | ... | ... |
src/core/actions.cc
| ... | ... | @@ -28,10 +28,11 @@ |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | #include "private.h" |
| 31 | + #include <functional> | |
| 31 | 32 | |
| 32 | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 33 | 34 | |
| 34 | - static DWORD action(const TN3270::Action id) { | |
| 35 | + static DWORD action(std::function<void(TN3270::Host &)> worker) noexcept { | |
| 35 | 36 | |
| 36 | 37 | try { |
| 37 | 38 | |
| ... | ... | @@ -40,20 +41,32 @@ |
| 40 | 41 | if(!host.isConnected()) |
| 41 | 42 | return HLLAPI_STATUS_DISCONNECTED; |
| 42 | 43 | |
| 43 | - host.push(id); | |
| 44 | + worker(host); | |
| 44 | 45 | |
| 45 | - return 0; | |
| 46 | + return HLLAPI_STATUS_SUCCESS; | |
| 46 | 47 | |
| 47 | - } catch(std::exception &e) { | |
| 48 | + } catch(const std::exception &e) { | |
| 48 | 49 | |
| 49 | 50 | hllapi_lasterror = e.what(); |
| 50 | 51 | |
| 52 | + } catch(...) { | |
| 53 | + | |
| 54 | + hllapi_lasterror = "Unexpected error"; | |
| 55 | + | |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | 58 | return HLLAPI_STATUS_SYSTEM_ERROR; |
| 54 | 59 | |
| 55 | 60 | } |
| 56 | 61 | |
| 62 | + static DWORD action(const TN3270::Action id) noexcept { | |
| 63 | + | |
| 64 | + return action([id](TN3270::Host &host) { | |
| 65 | + host.push(id); | |
| 66 | + }); | |
| 67 | + | |
| 68 | + } | |
| 69 | + | |
| 57 | 70 | HLLAPI_API_CALL hllapi_enter(void) { |
| 58 | 71 | return action(TN3270::ENTER); |
| 59 | 72 | } |
| ... | ... | @@ -80,28 +93,16 @@ |
| 80 | 93 | |
| 81 | 94 | HLLAPI_API_CALL hllapi_action(LPSTR action_name) { |
| 82 | 95 | |
| 83 | - try { | |
| 84 | - | |
| 85 | - getSession().action((const char *) action_name); | |
| 86 | - | |
| 87 | - return HLLAPI_STATUS_SUCCESS; | |
| 88 | - | |
| 89 | - } catch(std::exception &e) { | |
| 90 | - | |
| 91 | - hllapi_lasterror = e.what(); | |
| 92 | - | |
| 93 | - } | |
| 94 | - | |
| 95 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 96 | + return action([action_name](TN3270::Host &host) { | |
| 97 | + host.action(action_name); | |
| 98 | + }); | |
| 96 | 99 | |
| 97 | 100 | } |
| 98 | 101 | |
| 99 | -/* | |
| 100 | - | |
| 101 | - HLLAPI_API_CALL hllapi_print(void) | |
| 102 | - { | |
| 103 | - return session::get_default()->print(); | |
| 104 | - } | |
| 102 | + HLLAPI_API_CALL hllapi_print(void) { | |
| 105 | 103 | |
| 106 | - */ | |
| 104 | + return action([](TN3270::Host &host) { | |
| 105 | + host.print(); | |
| 106 | + }); | |
| 107 | 107 | |
| 108 | + } | ... | ... |
src/core/calls.cc
| ... | ... | @@ -207,68 +207,6 @@ |
| 207 | 207 | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - HLLAPI_API_CALL hllapi_pfkey(WORD key) { | |
| 211 | - | |
| 212 | - try { | |
| 213 | - | |
| 214 | - TN3270::Host &host = getSession(); | |
| 215 | - | |
| 216 | - if(!host.isConnected()) | |
| 217 | - return HLLAPI_STATUS_DISCONNECTED; | |
| 218 | - | |
| 219 | - host.pfkey((unsigned short) key); | |
| 220 | - | |
| 221 | - return HLLAPI_STATUS_SUCCESS; | |
| 222 | - | |
| 223 | - } catch(std::exception &e) { | |
| 224 | - | |
| 225 | - hllapi_lasterror = e.what(); | |
| 226 | - | |
| 227 | - } | |
| 228 | - | |
| 229 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 230 | - | |
| 231 | - } | |
| 232 | - | |
| 233 | - HLLAPI_API_CALL hllapi_pakey(WORD key) { | |
| 234 | - | |
| 235 | - try { | |
| 236 | - | |
| 237 | - TN3270::Host &host = getSession(); | |
| 238 | - | |
| 239 | - if(!host.isConnected()) | |
| 240 | - return HLLAPI_STATUS_DISCONNECTED; | |
| 241 | - | |
| 242 | - host.pakey((unsigned short) key); | |
| 243 | - | |
| 244 | - return HLLAPI_STATUS_SUCCESS; | |
| 245 | - | |
| 246 | - } catch(std::exception &e) { | |
| 247 | - | |
| 248 | - hllapi_lasterror = e.what(); | |
| 249 | - | |
| 250 | - } | |
| 251 | - | |
| 252 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 253 | - | |
| 254 | - } | |
| 255 | - | |
| 256 | - HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms) { | |
| 257 | - | |
| 258 | - try { | |
| 259 | - | |
| 260 | - getSession().setUnlockDelay((unsigned short) ms); | |
| 261 | - return HLLAPI_STATUS_SUCCESS; | |
| 262 | - | |
| 263 | - } catch(std::exception &e) { | |
| 264 | - | |
| 265 | - hllapi_lasterror = e.what(); | |
| 266 | - | |
| 267 | - } | |
| 268 | - | |
| 269 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 270 | - } | |
| 271 | - | |
| 272 | 210 | HLLAPI_API_CALL hllapi_set_charset(LPSTR text) { |
| 273 | 211 | |
| 274 | 212 | try { |
| ... | ... | @@ -383,3 +321,20 @@ |
| 383 | 321 | |
| 384 | 322 | } |
| 385 | 323 | |
| 324 | + DWORD hllapi_translate_keyboard_state(LIB3270_KEYBOARD_LOCK_STATE state, HLLAPI_STATUS def) { | |
| 325 | + | |
| 326 | + // Is unlocked. | |
| 327 | + if(state == LIB3270_KL_UNLOCKED) | |
| 328 | + return def; | |
| 329 | + | |
| 330 | + // Is connected? | |
| 331 | + if((state & LIB3270_KL_NOT_CONNECTED) != 0) | |
| 332 | + return HLLAPI_STATUS_DISCONNECTED; | |
| 333 | + | |
| 334 | + if( (state & (LIB3270_KL_AWAITING_FIRST|LIB3270_KL_OIA_TWAIT)) != 0) | |
| 335 | + return HLLAPI_STATUS_WAITING; | |
| 336 | + | |
| 337 | + return HLLAPI_STATUS_KEYBOARD_LOCKED; | |
| 338 | + | |
| 339 | + } | |
| 340 | + | ... | ... |
src/core/cursor.cc
| ... | ... | @@ -31,7 +31,7 @@ |
| 31 | 31 | |
| 32 | 32 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 33 | 33 | |
| 34 | - HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) { | |
| 34 | + static DWORD set(std::function<void(TN3270::Host &)> worker) noexcept { | |
| 35 | 35 | |
| 36 | 36 | try { |
| 37 | 37 | |
| ... | ... | @@ -40,22 +40,47 @@ |
| 40 | 40 | if(!host.isConnected()) |
| 41 | 41 | return HLLAPI_STATUS_DISCONNECTED; |
| 42 | 42 | |
| 43 | - host.setCursor((unsigned short) pos -1); | |
| 43 | + worker(host); | |
| 44 | 44 | |
| 45 | - return 0; | |
| 45 | + return HLLAPI_STATUS_SUCCESS; | |
| 46 | 46 | |
| 47 | - } catch(std::exception &e) { | |
| 47 | + } catch(const std::exception &e) { | |
| 48 | 48 | |
| 49 | 49 | hllapi_lasterror = e.what(); |
| 50 | 50 | |
| 51 | + } catch(...) { | |
| 52 | + | |
| 53 | + hllapi_lasterror = "Unexpected error"; | |
| 54 | + | |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | 57 | return HLLAPI_STATUS_SYSTEM_ERROR; |
| 54 | 58 | |
| 55 | 59 | } |
| 56 | 60 | |
| 61 | + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) { | |
| 62 | + | |
| 63 | + return set([pos](TN3270::Host &host) { | |
| 64 | + host.setCursor((unsigned short) pos -1); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + | |
| 68 | + } | |
| 69 | + | |
| 57 | 70 | HLLAPI_API_CALL hllapi_setcursor(WORD pos) { |
| 58 | - return hllapi_set_cursor_address(pos); | |
| 71 | + | |
| 72 | + return set([pos](TN3270::Host &host) { | |
| 73 | + host.setCursor((unsigned short) pos -1); | |
| 74 | + }); | |
| 75 | + | |
| 76 | + } | |
| 77 | + | |
| 78 | + HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col) { | |
| 79 | + | |
| 80 | + return set([row,col](TN3270::Host &host) { | |
| 81 | + host.setCursor((unsigned short) row, (unsigned short) col); | |
| 82 | + }); | |
| 83 | + | |
| 59 | 84 | } |
| 60 | 85 | |
| 61 | 86 | HLLAPI_API_CALL hllapi_get_cursor_address() { | ... | ... |
| ... | ... | @@ -0,0 +1,101 @@ |
| 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., 59 Temple | |
| 19 | + * Place, Suite 330, Boston, MA, 02111-1307, 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 | + #include "private.h" | |
| 31 | + | |
| 32 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 33 | + | |
| 34 | +static DWORD set(std::function<void(TN3270::Host &)> worker) noexcept { | |
| 35 | + | |
| 36 | + try { | |
| 37 | + | |
| 38 | + TN3270::Host &host = getSession(); | |
| 39 | + | |
| 40 | + if(!host.isConnected()) | |
| 41 | + return HLLAPI_STATUS_DISCONNECTED; | |
| 42 | + | |
| 43 | + host.waitForReady(); | |
| 44 | + | |
| 45 | + worker(host); | |
| 46 | + | |
| 47 | + } catch(const std::exception &e) { | |
| 48 | + | |
| 49 | + // Worker has failed! | |
| 50 | + hllapi_lasterror = e.what(); | |
| 51 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 52 | + | |
| 53 | + } catch(...) { | |
| 54 | + | |
| 55 | + // Unexpected error getting session or lock state | |
| 56 | + hllapi_lasterror = "Unexpected error"; | |
| 57 | + | |
| 58 | + } | |
| 59 | + | |
| 60 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | + | |
| 65 | + HLLAPI_API_CALL hllapi_pfkey(WORD key) { | |
| 66 | + | |
| 67 | + return set([key](TN3270::Host &host) { | |
| 68 | + | |
| 69 | + host.pfkey((unsigned short) key); | |
| 70 | + | |
| 71 | + }); | |
| 72 | + | |
| 73 | + | |
| 74 | + } | |
| 75 | + | |
| 76 | + HLLAPI_API_CALL hllapi_pakey(WORD key) { | |
| 77 | + | |
| 78 | + return set([key](TN3270::Host &host) { | |
| 79 | + | |
| 80 | + host.pakey((unsigned short) key); | |
| 81 | + | |
| 82 | + }); | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms) { | |
| 87 | + | |
| 88 | + try { | |
| 89 | + | |
| 90 | + getSession().setUnlockDelay((unsigned short) ms); | |
| 91 | + return HLLAPI_STATUS_SUCCESS; | |
| 92 | + | |
| 93 | + } catch(std::exception &e) { | |
| 94 | + | |
| 95 | + hllapi_lasterror = e.what(); | |
| 96 | + | |
| 97 | + } | |
| 98 | + | |
| 99 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
| 100 | + } | |
| 101 | + | ... | ... |
src/core/private.h
| ... | ... | @@ -45,8 +45,9 @@ |
| 45 | 45 | using TN3270::Host; |
| 46 | 46 | using std::exception; |
| 47 | 47 | |
| 48 | - extern string hllapi_lasterror; | |
| 48 | + extern TN3270_PRIVATE std::string hllapi_lasterror; | |
| 49 | 49 | |
| 50 | - TN3270::Host & getSession(); | |
| 50 | + TN3270_PRIVATE TN3270::Host & getSession(); | |
| 51 | + TN3270_PRIVATE DWORD hllapi_translate_keyboard_state(LIB3270_KEYBOARD_LOCK_STATE state, HLLAPI_STATUS def = HLLAPI_STATUS_SYSTEM_ERROR); | |
| 51 | 52 | |
| 52 | 53 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/core/set.cc
| ... | ... | @@ -36,23 +36,6 @@ |
| 36 | 36 | |
| 37 | 37 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 38 | 38 | |
| 39 | - DWORD hllapi_translate_keyboard_state(LIB3270_KEYBOARD_LOCK_STATE state, HLLAPI_STATUS def = HLLAPI_STATUS_SYSTEM_ERROR) { | |
| 40 | - | |
| 41 | - // Is unlocked. | |
| 42 | - if(state == LIB3270_KL_UNLOCKED) | |
| 43 | - return def; | |
| 44 | - | |
| 45 | - // Is connected? | |
| 46 | - if((state & LIB3270_KL_NOT_CONNECTED) != 0) | |
| 47 | - return HLLAPI_STATUS_DISCONNECTED; | |
| 48 | - | |
| 49 | - if( (state & (LIB3270_KL_AWAITING_FIRST|LIB3270_KL_OIA_TWAIT)) != 0) | |
| 50 | - return HLLAPI_STATUS_WAITING; | |
| 51 | - | |
| 52 | - return HLLAPI_STATUS_KEYBOARD_LOCKED; | |
| 53 | - | |
| 54 | - } | |
| 55 | - | |
| 56 | 39 | static DWORD set(std::function<void(TN3270::Host &)> worker) noexcept { |
| 57 | 40 | |
| 58 | 41 | LIB3270_KEYBOARD_LOCK_STATE kLock = LIB3270_KL_UNLOCKED; | ... | ... |
src/include/lib3270/hllapi.h
| ... | ... | @@ -229,6 +229,9 @@ |
| 229 | 229 | |
| 230 | 230 | HLLAPI_API_CALL hllapi_set_unlock_delay(WORD ms); |
| 231 | 231 | |
| 232 | + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos); | |
| 233 | + HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); | |
| 234 | + | |
| 232 | 235 | /** |
| 233 | 236 | * @brief Get cursor address. |
| 234 | 237 | * | ... | ... |