Commit 52be7bafa1b8bb6726ef9215a5980248d1effac8

Authored by Perry Werneck
1 parent 1870de30
Exists in master and in 1 other branch develop

Refactoring hllapi calls.

@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 <Compiler> 32 <Compiler>
33 <Add option="-Wall" /> 33 <Add option="-Wall" />
34 </Compiler> 34 </Compiler>
  35 + <Unit filename="src/core/actions.cc" />
35 <Unit filename="src/core/calls.cc" /> 36 <Unit filename="src/core/calls.cc" />
36 <Unit filename="src/core/controller.cc" /> 37 <Unit filename="src/core/controller.cc" />
37 <Unit filename="src/core/hllapi.cc" /> 38 <Unit filename="src/core/hllapi.cc" />
src/core/actions.cc 0 → 100644
@@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
  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 action(const TN3270::Action id) {
  35 +
  36 + try {
  37 +
  38 + TN3270::Host &host = getSession();
  39 +
  40 + if(!host.isConnected())
  41 + return HLLAPI_STATUS_DISCONNECTED;
  42 +
  43 + host.push(id);
  44 +
  45 + return 0;
  46 +
  47 + } catch(std::exception &e) {
  48 +
  49 + hllapi_lasterror = e.what();
  50 +
  51 + }
  52 +
  53 + return HLLAPI_STATUS_SYSTEM_ERROR;
  54 +
  55 + }
  56 +
  57 + HLLAPI_API_CALL hllapi_enter(void) {
  58 + return action(TN3270::ENTER);
  59 + }
  60 +
  61 + HLLAPI_API_CALL hllapi_erase(void) {
  62 + return action(TN3270::ERASE);
  63 + }
  64 +
  65 + HLLAPI_API_CALL hllapi_erase_eof(void) {
  66 + return action(TN3270::ERASE_EOF);
  67 + }
  68 +
  69 + HLLAPI_API_CALL hllapi_erase_eol(void) {
  70 + return action(TN3270::ERASE_EOL);
  71 + }
  72 +
  73 + HLLAPI_API_CALL hllapi_erase_input(void) {
  74 + return action(TN3270::ERASE_INPUT);
  75 + }
  76 +
  77 +/*
  78 +
  79 + HLLAPI_API_CALL hllapi_reset(void)
  80 + {
  81 + return HLLAPI_STATUS_SUCCESS;
  82 + }
  83 +
  84 + HLLAPI_API_CALL hllapi_action(LPSTR buffer) {
  85 + try
  86 + {
  87 + session::get_default()->action((const char *) buffer);
  88 + }
  89 + catch(std::exception &e)
  90 + {
  91 + return HLLAPI_STATUS_SYSTEM_ERROR;
  92 + }
  93 + return HLLAPI_STATUS_SUCCESS;
  94 + }
  95 +
  96 + HLLAPI_API_CALL hllapi_print(void)
  97 + {
  98 + return session::get_default()->print();
  99 + }
  100 +
  101 + */
  102 +
src/core/calls.cc
@@ -50,7 +50,10 @@ @@ -50,7 +50,10 @@
50 { 50 {
51 try { 51 try {
52 52
53 - getSession().connect((const char *) uri, wait); 53 + getSession().connect((const char *) uri, false);
  54 +
  55 + if(wait)
  56 + return hllapi_wait_for_ready(wait);
54 57
55 } catch(std::exception &e) { 58 } catch(std::exception &e) {
56 59
@@ -152,21 +155,78 @@ @@ -152,21 +155,78 @@
152 } 155 }
153 156
154 return HLLAPI_STATUS_SUCCESS; 157 return HLLAPI_STATUS_SUCCESS;
  158 +
155 } 159 }
156 160
  161 + HLLAPI_API_CALL hllapi_wait_for_ready(WORD seconds) {
157 162
158 - /* 163 + try {
159 164
160 - HLLAPI_API_CALL hllapi_wait_for_ready(WORD seconds)  
161 - {  
162 - if(!hllapi_is_connected())  
163 - return HLLAPI_STATUS_DISCONNECTED; 165 + TN3270::Host &host = getSession();
164 166
165 - session::get_default()->wait_for_ready(seconds); 167 + if(host.isConnected())
  168 + host.waitForReady((unsigned int) seconds);
  169 +
  170 + return hllapi_get_state();
  171 +
  172 + } catch(std::exception &e) {
  173 +
  174 + hllapi_lasterror = e.what();
  175 +
  176 + }
  177 +
  178 + return HLLAPI_STATUS_SYSTEM_ERROR;
  179 +
  180 + }
  181 +
  182 + HLLAPI_API_CALL hllapi_pfkey(WORD key) {
  183 +
  184 + try {
  185 +
  186 + TN3270::Host &host = getSession();
  187 +
  188 + if(!host.isConnected())
  189 + return HLLAPI_STATUS_DISCONNECTED;
  190 +
  191 + host.pfkey((unsigned short) key);
  192 +
  193 + return 0;
  194 +
  195 + } catch(std::exception &e) {
  196 +
  197 + hllapi_lasterror = e.what();
  198 +
  199 + }
  200 +
  201 + return HLLAPI_STATUS_SYSTEM_ERROR;
166 202
167 - return hllapi_get_state();  
168 } 203 }
169 204
  205 + HLLAPI_API_CALL hllapi_pakey(WORD key) {
  206 +
  207 + try {
  208 +
  209 + TN3270::Host &host = getSession();
  210 +
  211 + if(!host.isConnected())
  212 + return HLLAPI_STATUS_DISCONNECTED;
  213 +
  214 + host.pakey((unsigned short) key);
  215 +
  216 + return 0;
  217 +
  218 + } catch(std::exception &e) {
  219 +
  220 + hllapi_lasterror = e.what();
  221 +
  222 + }
  223 +
  224 + return HLLAPI_STATUS_SYSTEM_ERROR;
  225 +
  226 + }
  227 +
  228 + /*
  229 +
170 HLLAPI_API_CALL hllapi_wait(WORD seconds) 230 HLLAPI_API_CALL hllapi_wait(WORD seconds)
171 { 231 {
172 if(!hllapi_is_connected()) 232 if(!hllapi_is_connected())
@@ -199,13 +259,6 @@ @@ -199,13 +259,6 @@
199 return HLLAPI_STATUS_SUCCESS; 259 return HLLAPI_STATUS_SUCCESS;
200 } 260 }
201 261
202 - HLLAPI_API_CALL hllapi_enter(void)  
203 - {  
204 - if(!hllapi_is_connected())  
205 - return HLLAPI_STATUS_DISCONNECTED;  
206 -  
207 - return session::get_default()->enter();  
208 - }  
209 262
210 HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text) 263 HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text)
211 { 264 {
@@ -274,22 +327,6 @@ @@ -274,22 +327,6 @@
274 return 0; 327 return 0;
275 } 328 }
276 329
277 - HLLAPI_API_CALL hllapi_pfkey(WORD key)  
278 - {  
279 - if(!hllapi_is_connected())  
280 - return HLLAPI_STATUS_DISCONNECTED;  
281 -  
282 - return session::get_default()->pfkey(key);  
283 - }  
284 -  
285 - HLLAPI_API_CALL hllapi_pakey(WORD key)  
286 - {  
287 - if(!hllapi_is_connected())  
288 - return HLLAPI_STATUS_DISCONNECTED;  
289 -  
290 - return session::get_default()->pakey(key);  
291 - }  
292 -  
293 HLLAPI_API_CALL hllapi_get_datadir(LPSTR datadir) 330 HLLAPI_API_CALL hllapi_get_datadir(LPSTR datadir)
294 { 331 {
295 #ifdef _WIN32 332 #ifdef _WIN32
@@ -409,84 +446,6 @@ @@ -409,84 +446,6 @@
409 return HLLAPI_STATUS_SUCCESS; 446 return HLLAPI_STATUS_SUCCESS;
410 } 447 }
411 448
412 - HLLAPI_API_CALL hllapi_erase(void)  
413 - {  
414 - try  
415 - {  
416 - session::get_default()->erase();  
417 - }  
418 - catch(std::exception &e)  
419 - {  
420 - return HLLAPI_STATUS_SYSTEM_ERROR;  
421 - }  
422 - return HLLAPI_STATUS_SUCCESS;  
423 - }  
424 -  
425 - HLLAPI_API_CALL hllapi_erase_eof(void)  
426 - {  
427 - if(!hllapi_is_connected())  
428 - return HLLAPI_STATUS_DISCONNECTED;  
429 -  
430 - try  
431 - {  
432 - session::get_default()->erase_eof();  
433 - }  
434 - catch(std::exception &e)  
435 - {  
436 - return HLLAPI_STATUS_SYSTEM_ERROR;  
437 - }  
438 - return HLLAPI_STATUS_SUCCESS;  
439 - }  
440 -  
441 - HLLAPI_API_CALL hllapi_erase_eol(void)  
442 - {  
443 - if(!hllapi_is_connected())  
444 - return HLLAPI_STATUS_DISCONNECTED;  
445 -  
446 - try  
447 - {  
448 - session::get_default()->erase_eol();  
449 - }  
450 - catch(std::exception &e)  
451 - {  
452 - return HLLAPI_STATUS_SYSTEM_ERROR;  
453 - }  
454 - return HLLAPI_STATUS_SUCCESS;  
455 - }  
456 -  
457 - HLLAPI_API_CALL hllapi_erase_input(void)  
458 - {  
459 - if(!hllapi_is_connected())  
460 - return HLLAPI_STATUS_DISCONNECTED;  
461 -  
462 - try  
463 - {  
464 - session::get_default()->erase_input();  
465 - }  
466 - catch(std::exception &e)  
467 - {  
468 - return HLLAPI_STATUS_SYSTEM_ERROR;  
469 - }  
470 - return HLLAPI_STATUS_SUCCESS;  
471 - }  
472 -  
473 - HLLAPI_API_CALL hllapi_action(LPSTR buffer) {  
474 - try  
475 - {  
476 - session::get_default()->action((const char *) buffer);  
477 - }  
478 - catch(std::exception &e)  
479 - {  
480 - return HLLAPI_STATUS_SYSTEM_ERROR;  
481 - }  
482 - return HLLAPI_STATUS_SUCCESS;  
483 - }  
484 -  
485 - HLLAPI_API_CALL hllapi_print(void)  
486 - {  
487 - return session::get_default()->print();  
488 - }  
489 -  
490 char * hllapi_get_string(int offset, size_t len) 449 char * hllapi_get_string(int offset, size_t len)
491 { 450 {
492 try 451 try
@@ -507,11 +466,6 @@ @@ -507,11 +466,6 @@
507 free(p); 466 free(p);
508 } 467 }
509 468
510 - HLLAPI_API_CALL hllapi_reset(void)  
511 - {  
512 - return HLLAPI_STATUS_SUCCESS;  
513 - }  
514 -  
515 HLLAPI_API_CALL hllapi_input_string(LPSTR input, WORD length) 469 HLLAPI_API_CALL hllapi_input_string(LPSTR input, WORD length)
516 { 470 {
517 static const char control_char = '@'; 471 static const char control_char = '@';
src/core/private.h
@@ -42,6 +42,7 @@ @@ -42,6 +42,7 @@
42 42
43 using std::runtime_error; 43 using std::runtime_error;
44 using std::string; 44 using std::string;
  45 + using TN3270::Host;
45 46
46 extern string hllapi_lasterror; 47 extern string hllapi_lasterror;
47 48
src/include/lib3270/hllapi.h
@@ -172,7 +172,19 @@ @@ -172,7 +172,19 @@
172 172
173 HLLAPI_API_CALL hllapi_reset(void); 173 HLLAPI_API_CALL hllapi_reset(void);
174 174
  175 + /**
  176 + * @brief Connect to host.
  177 + *
  178 + * @param uri Host URI (tn3270://hostname:port).
  179 + * @param wait How many seconds to wait for the connection.
  180 + *
  181 + */
175 HLLAPI_API_CALL hllapi_connect(const LPSTR uri, WORD wait); 182 HLLAPI_API_CALL hllapi_connect(const LPSTR uri, WORD wait);
  183 +
  184 + /**
  185 + * @brief Disconnect from host.
  186 + *
  187 + */
176 HLLAPI_API_CALL hllapi_disconnect(void); 188 HLLAPI_API_CALL hllapi_disconnect(void);
177 189
178 HLLAPI_API_CALL hllapi_get_message_id(void); 190 HLLAPI_API_CALL hllapi_get_message_id(void);